- only show the context menu if we are over an item

- ServiceManager clean ups

bzr-revno: 1539
This commit is contained in:
Andreas Preikschat 2011-05-13 18:42:48 +02:00
commit 998411ed9b
3 changed files with 80 additions and 86 deletions

View File

@ -244,7 +244,7 @@ class MediaManagerItem(QtGui.QWidget):
"""
# 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,54 +254,49 @@ 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)
if self.hasEditIcon:
self.listView.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))
context_menu_action(
self.listView, u':/general/general_edit.png',
self.plugin.getString(StringContent.Edit)[u'title'],
self.onEditClick)
context_menu_separator(self.listView)
if self.hasDeleteIcon:
self.listView.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(
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(
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.listView, u':/general/general_delete.png',
self.plugin.getString(StringContent.Delete)[u'title'],
self.onDeleteClick, [QtCore.Qt.Key_Delete])
context_menu_separator(self.listView)
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_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_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])
if self.addToServiceItem:
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(
context_menu_action(
self.listView, u':/general/general_add.png',
translate('OpenLP.MediaManagerItem',
'&Add to selected Service Item'),
self.onAddEditClick, context=QtCore.Qt.WidgetShortcut))
translate('OpenLP.MediaManagerItem',
'&Add to selected Service Item'), self.onAddEditClick)
# Create the context menu and add all actions from the listView.
self.menu = QtGui.QMenu()
self.menu.addActions(self.listView.actions())
QtCore.QObject.connect(self.listView,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onClickPressed)
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):
"""
@ -354,6 +349,15 @@ class MediaManagerItem(QtGui.QWidget):
self.settingsSection, self.getFileList())
Receiver.send_message(u'cursor_normal')
def contextMenu(self, point):
item = self.listView.itemAt(point)
# Decide if we have to show the context menu or not.
if item is None:
return
if not item.flags() & QtCore.Qt.ItemIsSelectable:
return
self.menu.exec_(self.listView.mapToGlobal(point))
def getFileList(self):
"""
Return the current list of files

View File

@ -329,9 +329,9 @@ def shortcut_action(parent, name, shortcuts, function, icon=None, checked=None,
return action
def context_menu_action(base, icon, text, slot, shortcuts=None, category=None,
context=QtCore.Qt.WindowShortcut):
context=QtCore.Qt.WidgetShortcut):
"""
Utility method to help build context menus for plugins
Utility method to help build context menus.
``base``
The parent menu to add this menu item to
@ -350,7 +350,7 @@ def context_menu_action(base, icon, text, slot, shortcuts=None, category=None,
``category``
The category the shortcut should be listed in the shortcut dialog. If
left to None, then the action will be hidden in the shortcut dialog.
left to ``None``, then the action will be hidden in the shortcut dialog.
``context``
The context the shortcut is valid.
@ -364,11 +364,12 @@ 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):
"""
Utility method to help build context menus for plugins
Utility method to help build context menus.
``base``
The parent object to add this menu to
@ -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):

View File

@ -36,7 +36,7 @@ from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, \
ItemCapabilities, SettingsManager, translate
from openlp.core.lib.theme import ThemeLevel
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
context_menu_action, find_and_set_in_combo_box
context_menu_action, context_menu_separator, find_and_set_in_combo_box
from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm
from openlp.core.ui.printserviceform import PrintServiceForm
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
@ -301,31 +301,34 @@ class ServiceManager(QtGui.QWidget):
self.addToAction.setIcon(build_icon(u':/general/general_edit.png'))
# build the context menu
self.menu = QtGui.QMenu()
self.editAction = self.menu.addAction(
translate('OpenLP.ServiceManager', '&Edit Item'))
self.editAction.setIcon(build_icon(u':/general/general_edit.png'))
self.maintainAction = self.menu.addAction(
translate('OpenLP.ServiceManager', '&Reorder Item'))
self.maintainAction.setIcon(build_icon(u':/general/general_edit.png'))
self.notesAction = self.menu.addAction(
translate('OpenLP.ServiceManager', '&Notes'))
self.notesAction.setIcon(build_icon(u':/services/service_notes.png'))
self.timeAction = self.menu.addAction(
translate('OpenLP.ServiceManager', '&Start Time'))
self.timeAction.setIcon(build_icon(u':/media/media_time.png'))
self.deleteAction = self.menu.addAction(
translate('OpenLP.ServiceManager', '&Delete From Service'))
self.deleteAction.setIcon(build_icon(u':/general/general_delete.png'))
self.sep1 = self.menu.addAction(u'')
self.sep1.setSeparator(True)
self.previewAction = self.menu.addAction(
translate('OpenLP.ServiceManager', 'Show &Preview'))
self.previewAction.setIcon(build_icon(u':/general/general_preview.png'))
self.liveAction = self.menu.addAction(
translate('OpenLP.ServiceManager', 'Show &Live'))
self.liveAction.setIcon(build_icon(u':/general/general_live.png'))
self.sep2 = self.menu.addAction(u'')
self.sep2.setSeparator(True)
self.editAction = context_menu_action(
self.menu, u':/general/general_edit.png',
translate('OpenLP.ServiceManager', '&Edit Item'), self.remoteEdit)
self.maintainAction = context_menu_action(
self.menu, u':/general/general_edit.png',
translate('OpenLP.ServiceManager', '&Reorder Item'),
self.onServiceItemEditForm)
self.notesAction = context_menu_action(
self.menu, u':/services/service_notes.png',
translate('OpenLP.ServiceManager', '&Notes'),
self.onServiceItemNoteForm)
self.timeAction = context_menu_action(
self.menu, u':/media/media_time.png',
translate('OpenLP.ServiceManager', '&Start Time'),
self.onStartTimeForm)
self.deleteAction = context_menu_action(
self.menu, u':/general/general_delete.png',
translate('OpenLP.ServiceManager', '&Delete From Service'),
self.onDeleteFromService)
context_menu_separator(self.menu)
self.previewAction = context_menu_action(
self.menu, u':/general/general_preview.png',
translate('OpenLP.ServiceManager', 'Show &Preview'),
self.makePreview)
self.liveAction = context_menu_action(
self.menu, u':/general/general_live.png',
translate('OpenLP.ServiceManager', 'Show &Live'), self.makeLive)
context_menu_separator(self.menu)
self.themeMenu = QtGui.QMenu(
translate('OpenLP.ServiceManager', '&Change Item Theme'))
self.menu.addMenu(self.themeMenu)
@ -675,20 +678,6 @@ class ServiceManager(QtGui.QWidget):
if serviceItem[u'service_item'].is_text():
self.themeMenu.menuAction().setVisible(True)
action = self.menu.exec_(self.serviceManagerList.mapToGlobal(point))
if action == self.editAction:
self.remoteEdit()
elif action == self.maintainAction:
self.onServiceItemEditForm()
elif action == self.deleteAction:
self.onDeleteFromService()
elif action == self.notesAction:
self.onServiceItemNoteForm()
elif action == self.timeAction:
self.onStartTimeForm()
elif action == self.previewAction:
self.makePreview()
elif action == self.liveAction:
self.makeLive()
def onServiceItemNoteForm(self):
item = self.findServiceItem()[0]
@ -840,7 +829,7 @@ class ServiceManager(QtGui.QWidget):
correct state.
"""
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
self.serviceItems[pos -1 ][u'expanded'] = False
self.serviceItems[pos - 1][u'expanded'] = False
def onExpandAll(self):
"""
@ -1288,9 +1277,8 @@ class ServiceManager(QtGui.QWidget):
self.themeComboBox.addItem(u'')
for theme in theme_list:
self.themeComboBox.addItem(theme)
action = context_menu_action(self.serviceManagerList, None, theme,
self.onThemeChangeAction, context=QtCore.Qt.WidgetShortcut)
self.themeMenu.addAction(action)
context_menu_action(self.themeMenu, None, theme,
self.onThemeChangeAction)
find_and_set_in_combo_box(self.themeComboBox, self.service_theme)
self.mainwindow.renderer.set_service_theme(self.service_theme)
self.regenerateServiceItems()