allow to empty shortcuts; allow 'space' to be used as shortcut

This commit is contained in:
Andreas Preikschat 2011-05-01 09:17:30 +02:00
parent 03f10e72f2
commit f8fdcf8fba
2 changed files with 34 additions and 6 deletions

View File

@ -28,6 +28,25 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate, build_icon from openlp.core.lib import translate, build_icon
class CaptureShortcutButton(QtGui.QPushButton):
"""
A class to encapsulate a ``QPushButton``.
"""
def __init__(self, *args):
QtGui.QPushButton.__init__(self, *args)
self.setCheckable(True)
def keyPressEvent(self, event):
"""
Block the ``Key_Space`` key, so that the button will not change the
checked state.
"""
if event.key() == QtCore.Qt.Key_Space and self.isChecked():
event.ignore()
else:
self.setChecked(True)
class Ui_ShortcutListDialog(object): class Ui_ShortcutListDialog(object):
def setupUi(self, shortcutListDialog): def setupUi(self, shortcutListDialog):
shortcutListDialog.setObjectName(u'shortcutListDialog') shortcutListDialog.setObjectName(u'shortcutListDialog')
@ -56,12 +75,11 @@ class Ui_ShortcutListDialog(object):
self.detailsLayout.addWidget(self.customRadioButton, 1, 0, 1, 1) self.detailsLayout.addWidget(self.customRadioButton, 1, 0, 1, 1)
self.primaryLayout = QtGui.QHBoxLayout() self.primaryLayout = QtGui.QHBoxLayout()
self.primaryLayout.setObjectName(u'primaryLayout') self.primaryLayout.setObjectName(u'primaryLayout')
self.primaryPushButton = QtGui.QPushButton(shortcutListDialog) self.primaryPushButton = CaptureShortcutButton(shortcutListDialog)
self.primaryPushButton.setObjectName(u'primaryPushButton') self.primaryPushButton.setObjectName(u'primaryPushButton')
self.primaryPushButton.setMinimumSize(QtCore.QSize(84, 0)) self.primaryPushButton.setMinimumSize(QtCore.QSize(84, 0))
self.primaryPushButton.setIcon( self.primaryPushButton.setIcon(
build_icon(u':/system/system_configure_shortcuts.png')) build_icon(u':/system/system_configure_shortcuts.png'))
self.primaryPushButton.setCheckable(True)
self.primaryLayout.addWidget(self.primaryPushButton) self.primaryLayout.addWidget(self.primaryPushButton)
self.clearPrimaryButton = QtGui.QToolButton(shortcutListDialog) self.clearPrimaryButton = QtGui.QToolButton(shortcutListDialog)
self.clearPrimaryButton.setObjectName(u'clearPrimaryButton') self.clearPrimaryButton.setObjectName(u'clearPrimaryButton')
@ -72,9 +90,8 @@ class Ui_ShortcutListDialog(object):
self.detailsLayout.addLayout(self.primaryLayout, 1, 1, 1, 1) self.detailsLayout.addLayout(self.primaryLayout, 1, 1, 1, 1)
self.alternateLayout = QtGui.QHBoxLayout() self.alternateLayout = QtGui.QHBoxLayout()
self.alternateLayout.setObjectName(u'alternateLayout') self.alternateLayout.setObjectName(u'alternateLayout')
self.alternatePushButton = QtGui.QPushButton(shortcutListDialog) self.alternatePushButton = CaptureShortcutButton(shortcutListDialog)
self.alternatePushButton.setObjectName(u'alternatePushButton') self.alternatePushButton.setObjectName(u'alternatePushButton')
self.alternatePushButton.setCheckable(True)
self.alternatePushButton.setIcon( self.alternatePushButton.setIcon(
build_icon(u':/system/system_configure_shortcuts.png')) build_icon(u':/system/system_configure_shortcuts.png'))
self.alternateLayout.addWidget(self.alternatePushButton) self.alternateLayout.addWidget(self.alternatePushButton)

View File

@ -71,7 +71,9 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
QtCore.SIGNAL(u'clicked(bool)'), self.onCustomRadioButtonClicked) QtCore.SIGNAL(u'clicked(bool)'), self.onCustomRadioButtonClicked)
def keyPressEvent(self, event): def keyPressEvent(self, event):
if self.primaryPushButton.isChecked() or \ if event.key() == QtCore.Qt.Key_Space:
self.keyReleaseEvent(event)
elif self.primaryPushButton.isChecked() or \
self.alternatePushButton.isChecked(): self.alternatePushButton.isChecked():
event.ignore() event.ignore()
elif event.key() == QtCore.Qt.Key_Escape: elif event.key() == QtCore.Qt.Key_Escape:
@ -163,6 +165,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
self.customRadioButton.setChecked(True) self.customRadioButton.setChecked(True)
if toggled: if toggled:
self.alternatePushButton.setChecked(False) self.alternatePushButton.setChecked(False)
self.primaryPushButton.setText(u'')
return return
action = self._currentItemAction() action = self._currentItemAction()
if action is None: if action is None:
@ -181,6 +184,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
self.customRadioButton.setChecked(True) self.customRadioButton.setChecked(True)
if toggled: if toggled:
self.primaryPushButton.setChecked(False) self.primaryPushButton.setChecked(False)
self.alternatePushButton.setText(u'')
return return
action = self._currentItemAction() action = self._currentItemAction()
if action is None: if action is None:
@ -211,10 +215,11 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
self.primaryPushButton.setChecked(column in [0, 1]) self.primaryPushButton.setChecked(column in [0, 1])
self.alternatePushButton.setChecked(column not in [0, 1]) self.alternatePushButton.setChecked(column not in [0, 1])
if column in [0, 1]: if column in [0, 1]:
self.primaryPushButton.setText(u'')
self.primaryPushButton.setFocus(QtCore.Qt.OtherFocusReason) self.primaryPushButton.setFocus(QtCore.Qt.OtherFocusReason)
else: else:
self.alternatePushButton.setText(u'')
self.alternatePushButton.setFocus(QtCore.Qt.OtherFocusReason) self.alternatePushButton.setFocus(QtCore.Qt.OtherFocusReason)
self.onCurrentItemChanged(item)
def onCurrentItemChanged(self, item=None, previousItem=None): def onCurrentItemChanged(self, item=None, previousItem=None):
""" """
@ -247,6 +252,12 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
elif len(shortcuts) == 2: elif len(shortcuts) == 2:
primary_text = shortcuts[0].toString() primary_text = shortcuts[0].toString()
alternate_text = shortcuts[1].toString() alternate_text = shortcuts[1].toString()
# When we are capturing a new shortcut, we do not want, that the buttons
# display the current shortcut.
if self.primaryPushButton.isChecked():
primary_text = u''
if self.alternatePushButton.isChecked():
alternate_text = u''
self.primaryPushButton.setText(primary_text) self.primaryPushButton.setText(primary_text)
self.alternatePushButton.setText(alternate_text) self.alternatePushButton.setText(alternate_text)
self.primaryLabel.setText(primary_label_text) self.primaryLabel.setText(primary_label_text)