- When you are capturing a shortcut, "space" won't uncheck the button (so you can use "space" as shortcut as well) (lines 8-26, 64-66)

- Now you can remove a shortcut (just abort the capturing)

bzr-revno: 1511
This commit is contained in:
Andreas Preikschat 2011-05-01 20:03:08 +02:00
commit a6790e60c1
2 changed files with 33 additions and 6 deletions

View File

@ -28,6 +28,24 @@ from PyQt4 import QtCore, QtGui
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():
# Ignore the event, so that the parent can take care of this.
event.ignore()
class Ui_ShortcutListDialog(object):
def setupUi(self, shortcutListDialog):
shortcutListDialog.setObjectName(u'shortcutListDialog')
@ -56,12 +74,11 @@ class Ui_ShortcutListDialog(object):
self.detailsLayout.addWidget(self.customRadioButton, 1, 0, 1, 1)
self.primaryLayout = QtGui.QHBoxLayout()
self.primaryLayout.setObjectName(u'primaryLayout')
self.primaryPushButton = QtGui.QPushButton(shortcutListDialog)
self.primaryPushButton = CaptureShortcutButton(shortcutListDialog)
self.primaryPushButton.setObjectName(u'primaryPushButton')
self.primaryPushButton.setMinimumSize(QtCore.QSize(84, 0))
self.primaryPushButton.setIcon(
build_icon(u':/system/system_configure_shortcuts.png'))
self.primaryPushButton.setCheckable(True)
self.primaryLayout.addWidget(self.primaryPushButton)
self.clearPrimaryButton = QtGui.QToolButton(shortcutListDialog)
self.clearPrimaryButton.setObjectName(u'clearPrimaryButton')
@ -72,9 +89,8 @@ class Ui_ShortcutListDialog(object):
self.detailsLayout.addLayout(self.primaryLayout, 1, 1, 1, 1)
self.alternateLayout = QtGui.QHBoxLayout()
self.alternateLayout.setObjectName(u'alternateLayout')
self.alternatePushButton = QtGui.QPushButton(shortcutListDialog)
self.alternatePushButton = CaptureShortcutButton(shortcutListDialog)
self.alternatePushButton.setObjectName(u'alternatePushButton')
self.alternatePushButton.setCheckable(True)
self.alternatePushButton.setIcon(
build_icon(u':/system/system_configure_shortcuts.png'))
self.alternateLayout.addWidget(self.alternatePushButton)

View File

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