From d4f7bf1e0a5b015913b03803e7843e10cdeddda8 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 13 May 2011 14:55:04 +0200 Subject: [PATCH] --- openlp/core/lib/mediamanageritem.py | 34 ++++++++++++++++++++--------- openlp/core/lib/ui.py | 2 ++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index e5e8ed3b1..225d4023e 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -238,13 +238,21 @@ class MediaManagerItem(QtGui.QWidget): self.plugin.getString(action[0])[u'tooltip'], action[1], action[2]) + def contextMenu(self, point): + item = self.listView.itemAt(point) + if item is None: + return + if not item.flags() & QtCore.Qt.ItemIsSelectable: + return + self.menu.exec_(self.listView.mapToGlobal(point)) + def addListViewToToolBar(self): """ Creates the main widget for listing items the media item is tracking """ # Add the List widget self.listView = ListWidgetWithDnD(self, self.plugin.name) - self.listView.uniformItemSizes = True + self.listView.setUniformItemSizes(True) self.listView.setSpacing(1) self.listView.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) @@ -254,43 +262,46 @@ class MediaManagerItem(QtGui.QWidget): # Add to pageLayout self.pageLayout.addWidget(self.listView) # define and add the context menu - self.listView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) + self.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.menu = QtGui.QMenu() + # Create the actions. All actions are automatically added to the + # listView. if self.hasEditIcon: - self.listView.addAction( + self.menu.addAction( context_menu_action( self.listView, u':/general/general_edit.png', self.plugin.getString(StringContent.Edit)[u'title'], self.onEditClick, context=QtCore.Qt.WidgetShortcut)) - self.listView.addAction(context_menu_separator(self.listView)) + self.menu.addAction(context_menu_separator(self.listView)) if self.hasDeleteIcon: - self.listView.addAction( + self.menu.addAction( context_menu_action( self.listView, u':/general/general_delete.png', self.plugin.getString(StringContent.Delete)[u'title'], self.onDeleteClick, [QtCore.Qt.Key_Delete], context=QtCore.Qt.WidgetShortcut)) - self.listView.addAction(context_menu_separator(self.listView)) - self.listView.addAction( + self.menu.addAction(context_menu_separator(self.listView)) + self.menu.addAction( context_menu_action( self.listView, u':/general/general_preview.png', self.plugin.getString(StringContent.Preview)[u'title'], self.onPreviewClick, [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], context=QtCore.Qt.WidgetShortcut)) - self.listView.addAction( + self.menu.addAction( context_menu_action( self.listView, u':/general/general_live.png', self.plugin.getString(StringContent.Live)[u'title'], self.onLiveClick, [QtCore.Qt.ShiftModifier + \ QtCore.Qt.Key_Enter, QtCore.Qt.ShiftModifier + \ QtCore.Qt.Key_Return], context=QtCore.Qt.WidgetShortcut)) - self.listView.addAction( + self.menu.addAction( context_menu_action( self.listView, u':/general/general_add.png', self.plugin.getString(StringContent.Service)[u'title'], self.onAddClick, [QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal], context=QtCore.Qt.WidgetShortcut)) if self.addToServiceItem: - self.listView.addAction( + self.menu.addAction( context_menu_action( self.listView, u':/general/general_add.png', translate('OpenLP.MediaManagerItem', @@ -302,6 +313,9 @@ class MediaManagerItem(QtGui.QWidget): QtCore.QObject.connect(self.listView, QtCore.SIGNAL(u'itemSelectionChanged()'), self.onSelectionChange) + QtCore.QObject.connect(self.listView, + QtCore.SIGNAL('customContextMenuRequested(QPoint)'), + self.contextMenu) def initialise(self): """ diff --git a/openlp/core/lib/ui.py b/openlp/core/lib/ui.py index e8be32a92..3fdf9642d 100644 --- a/openlp/core/lib/ui.py +++ b/openlp/core/lib/ui.py @@ -364,6 +364,7 @@ def context_menu_action(base, icon, text, slot, shortcuts=None, category=None, action.setShortcutContext(context) action_list = ActionList.get_instance() action_list.add_action(action) + base.addAction(action) return action def context_menu(base, icon, text): @@ -392,6 +393,7 @@ def context_menu_separator(base): """ action = QtGui.QAction(u'', base) action.setSeparator(True) + base.addAction(action) return action def add_widget_completer(cache, widget):