From 1949c008160f0f9c47a5d6f037bde2d74c67ceff Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 15 Jul 2011 11:45:13 +0200 Subject: [PATCH] QML UI: Add support for single-press context menu --- data/ui/qml/EpisodeItem.qml | 4 ++++ data/ui/qml/PodcastItem.qml | 3 +++ data/ui/qml/SelectableItem.qml | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/data/ui/qml/EpisodeItem.qml b/data/ui/qml/EpisodeItem.qml index 939f0241..c407e4cd 100644 --- a/data/ui/qml/EpisodeItem.qml +++ b/data/ui/qml/EpisodeItem.qml @@ -5,6 +5,9 @@ import 'config.js' as Config SelectableItem { id: episodeItem + // Show context menu when single-touching the icon + singlePressContextMenuLeftBorder: title.x + height: Config.listItemHeight Rectangle { @@ -44,6 +47,7 @@ SelectableItem { } Text { + id: title text: modelData.qtitle color: modelData.qdownloading?'#8ae234':(modelData.qplaying?'#729fcf':(modelData.qnew?"white":"#888")) font.pixelSize: episodeItem.height * .35 diff --git a/data/ui/qml/PodcastItem.qml b/data/ui/qml/PodcastItem.qml index 150cbea6..86503b5f 100644 --- a/data/ui/qml/PodcastItem.qml +++ b/data/ui/qml/PodcastItem.qml @@ -6,6 +6,9 @@ import 'config.js' as Config SelectableItem { id: podcastItem + // Show context menu when single-touching the count or cover art + singlePressContextMenuLeftBorder: titleBox.x + Text { id: counterText anchors.verticalCenter: parent.verticalCenter diff --git a/data/ui/qml/SelectableItem.qml b/data/ui/qml/SelectableItem.qml index 95c0995e..c8b15571 100644 --- a/data/ui/qml/SelectableItem.qml +++ b/data/ui/qml/SelectableItem.qml @@ -8,6 +8,11 @@ Item { signal selected(variant item) signal contextMenu(variant item) + /* The width of the area from the left edge that when + * pressed will signal contextMenu instead of selected. + */ + property int singlePressContextMenuLeftBorder: 0 + height: Config.listItemHeight width: parent.width @@ -32,7 +37,9 @@ Item { acceptedButtons: Qt.LeftButton | Qt.RightButton anchors.fill: parent onClicked: { - if (mouse.button == Qt.LeftButton) { + if (mouse.x <= selectableItem.singlePressContextMenuLeftBorder) { + selectableItem.contextMenu(modelData) + } else if (mouse.button == Qt.LeftButton) { selectableItem.selected(modelData) } else if (mouse.button == Qt.RightButton) { selectableItem.contextMenu(modelData)