Add support for titlebar buttons / search button

This commit is contained in:
Thomas Perl 2011-02-04 17:57:40 +01:00
parent a424097a74
commit 19fff36b14
4 changed files with 73 additions and 35 deletions

View file

@ -0,0 +1,40 @@
import Qt 4.7
import 'config.js' as Config
Item {
id: titlebarButton
signal clicked
property alias source: icon.source
property alias rotation: icon.rotation
anchors.top: parent.top
anchors.bottom: parent.bottom
width: taskSwitcher.width
Rectangle {
anchors.fill: parent
color: 'white'
opacity: mouseArea.pressed?.3:0
Behavior on opacity { NumberAnimation { duration: Config.slowTransition } }
}
ScaledIcon {
id: icon
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: (parent.width * .8 - width) / 2
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: titlebarButton.clicked()
}
}

View file

@ -260,7 +260,7 @@ Rectangle {
ShadowText {
anchors.verticalCenter: parent.verticalCenter
anchors.left: taskSwitcher.right
anchors.right: closeButton.left
anchors.right: searchButton.left
clip: true
text: (contextMenu.state == 'opened')?('Context menu'):(episodeDetails.state == 'visible'?"Now playing":(main.state == 'episodes'?uidata.episodeListTitle:"gPodder"))
color: Qt.lighter(main.color, 4)
@ -268,32 +268,24 @@ Rectangle {
font.bold: false
}
Item {
TitlebarButton {
id: searchButton
anchors.right: closeButton.left
source: 'icons/search.png'
onClicked: controller.searchButtonClicked()
visible: contextMenu.state == 'closed'
}
TitlebarButton {
id: closeButton
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
width: taskSwitcher.width
Rectangle {
anchors.fill: parent
color: 'white'
opacity: closeButtonMouseArea.pressed?.3:0
}
ScaledIcon {
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: (parent.width * .8 - width) / 2
}
source: (main.state == 'podcasts' && episodeDetails.state == 'hidden' && contextMenu.state == 'closed')?'icons/close.png':'icons/back.png'
rotation: (episodeDetails.state == 'visible')?-90:0
}
MouseArea {
id: closeButtonMouseArea
anchors.fill: parent
onClicked: {
if (contextMenu.state == 'opened') {
contextMenu.state = 'closed'
@ -308,7 +300,6 @@ Rectangle {
}
}
}
}
}

View file

@ -55,7 +55,7 @@ def AutoQObject(*class_def, **kwargs):
class Action(QtCore.QObject):
def __init__(self, caption, action, target):
def __init__(self, caption, action, target=None):
QtCore.QObject.__init__(self)
if isinstance(caption, str):
caption = caption.decode('utf-8')

View file

@ -87,6 +87,13 @@ class Controller(QObject):
helper.Action('Toggle new', 'episode-toggle-new', episode),
])
@Slot()
def searchButtonClicked(self):
self.show_context_menu([
helper.Action('Search podcasts', 'search-podcasts'),
helper.Action('Filter current list', 'filter-list'),
])
@Slot(str)
def action(self, action):
print 'action requested:', action