added new dialog from superfly + few own changes

This commit is contained in:
Andreas Preikschat 2011-04-07 16:26:29 +02:00
parent 38c9393624
commit 9b84319c24
3 changed files with 158 additions and 93 deletions

View File

@ -30,44 +30,71 @@ from openlp.core.lib import translate, build_icon
class Ui_ShortcutListDialog(object): class Ui_ShortcutListDialog(object):
def setupUi(self, shortcutListDialog): def setupUi(self, shortcutListDialog):
shortcutListDialog.resize(440, 450) shortcutListDialog.setObjectName("shortcutListDialog")
shortcutListDialog.setObjectName(u'shortcutListDialog') shortcutListDialog.resize(500, 438)
self.dialogLayout = QtGui.QVBoxLayout(shortcutListDialog) self.shortcutListLayout = QtGui.QVBoxLayout(shortcutListDialog)
self.dialogLayout.setObjectName(u'dialogLayout') self.shortcutListLayout.setSpacing(8)
self.descriptionLabel = QtGui.QLabel(shortcutListDialog) self.shortcutListLayout.setMargin(8)
self.descriptionLabel.setObjectName(u'descriptionLabel') self.shortcutListLayout.setObjectName("shortcutListLayout")
self.descriptionLabel.setWordWrap(True)
self.dialogLayout.addWidget(self.descriptionLabel)
self.treeWidget = QtGui.QTreeWidget(shortcutListDialog) self.treeWidget = QtGui.QTreeWidget(shortcutListDialog)
self.treeWidget.setAlternatingRowColors(True) self.treeWidget.setAlternatingRowColors(True)
self.treeWidget.setObjectName(u'treeWidget') self.treeWidget.setObjectName("treeWidget")
self.treeWidget.setColumnCount(3) self.treeWidget.setColumnCount(3)
self.dialogLayout.addWidget(self.treeWidget) self.shortcutListLayout.addWidget(self.treeWidget)
self.customLayout = QtGui.QHBoxLayout() self.detailsLayout = QtGui.QGridLayout()
self.customLayout.setObjectName(u'customLayout') self.detailsLayout.setSpacing(8)
self.shortcutButtonLabel = QtGui.QLabel(shortcutListDialog) self.detailsLayout.setContentsMargins(-1, 0, -1, -1)
self.shortcutButtonLabel.setObjectName(u'descriptionLabel') self.detailsLayout.setObjectName("detailsLayout")
self.customLayout.addWidget(self.shortcutButtonLabel) self.defaultRadioButton = QtGui.QRadioButton(shortcutListDialog)
self.shortcutButton = QtGui.QPushButton(shortcutListDialog) self.defaultRadioButton.setChecked(True)
self.shortcutButton.setIcon( self.defaultRadioButton.setObjectName("defaultRadioButton")
build_icon(u':/system/system_configure_shortcuts.png')) self.detailsLayout.addWidget(self.defaultRadioButton, 0, 0, 1, 1)
self.shortcutButton.setCheckable(True) self.customRadioButton = QtGui.QRadioButton(shortcutListDialog)
self.shortcutButton.setObjectName(u'shortcutButton') self.customRadioButton.setObjectName("customRadioButton")
self.shortcutButton.setFixedSize(150, 30) self.detailsLayout.addWidget(self.customRadioButton, 1, 0, 1, 1)
self.customLayout.addWidget(self.shortcutButton) self.primaryLayout = QtGui.QHBoxLayout()
self.clearShortcutButton = QtGui.QToolButton(shortcutListDialog) self.primaryLayout.setSpacing(8)
self.clearShortcutButton.setIcon( self.primaryLayout.setObjectName("primaryLayout")
build_icon(u':/system/clear_shortcut.png')) self.primaryPushButton = QtGui.QPushButton(shortcutListDialog)
self.clearShortcutButton.setAutoRaise(True) self.primaryPushButton.setMinimumSize(QtCore.QSize(84, 0))
self.clearShortcutButton.setObjectName(u'clearShortcutButton') self.primaryPushButton.setIcon(build_icon(u':/system/system_configure_shortcuts.png'))
self.customLayout.addWidget(self.clearShortcutButton) self.primaryPushButton.setCheckable(True)
self.customLayout.addStretch() self.primaryPushButton.setChecked(False)
self.dialogLayout.addLayout(self.customLayout) self.primaryPushButton.setObjectName("primaryPushButton")
self.primaryLayout.addWidget(self.primaryPushButton)
self.clearPrimaryButton = QtGui.QToolButton(shortcutListDialog)
self.clearPrimaryButton.setMinimumSize(QtCore.QSize(0, 16))
self.clearPrimaryButton.setText("")
self.clearPrimaryButton.setIcon(build_icon(u':/system/clear_shortcut.png'))
self.clearPrimaryButton.setObjectName("clearPrimaryButton")
self.primaryLayout.addWidget(self.clearPrimaryButton)
self.detailsLayout.addLayout(self.primaryLayout, 1, 1, 1, 1)
self.alternateLayout = QtGui.QHBoxLayout()
self.alternateLayout.setSpacing(8)
self.alternateLayout.setObjectName("alternateLayout")
self.alternatePushButton = QtGui.QPushButton(shortcutListDialog)
self.alternatePushButton.setIcon(build_icon(u':/system/system_configure_shortcuts.png'))
self.alternatePushButton.setObjectName("alternatePushButton")
self.alternateLayout.addWidget(self.alternatePushButton)
self.clearAlternateButton = QtGui.QToolButton(shortcutListDialog)
self.clearAlternateButton.setText("")
self.clearAlternateButton.setIcon(build_icon(u':/system/clear_shortcut.png'))
self.clearAlternateButton.setObjectName("clearAlternateButton")
self.alternateLayout.addWidget(self.clearAlternateButton)
self.detailsLayout.addLayout(self.alternateLayout, 1, 2, 1, 1)
self.primaryLabel = QtGui.QLabel(shortcutListDialog)
self.primaryLabel.setObjectName("primaryLabel")
self.detailsLayout.addWidget(self.primaryLabel, 0, 1, 1, 1)
self.alternateLabel = QtGui.QLabel(shortcutListDialog)
self.alternateLabel.setObjectName("alternateLabel")
self.detailsLayout.addWidget(self.alternateLabel, 0, 2, 1, 1)
self.shortcutListLayout.addLayout(self.detailsLayout)
self.buttonBox = QtGui.QDialogButtonBox(shortcutListDialog) self.buttonBox = QtGui.QDialogButtonBox(shortcutListDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.RestoreDefaults) QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Reset)
self.buttonBox.setObjectName(u'buttonBox') self.buttonBox.setObjectName("buttonBox")
self.dialogLayout.addWidget(self.buttonBox) self.shortcutListLayout.addWidget(self.buttonBox)
self.retranslateUi(shortcutListDialog) self.retranslateUi(shortcutListDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'), QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'),
shortcutListDialog.accept) shortcutListDialog.accept)
@ -78,15 +105,17 @@ class Ui_ShortcutListDialog(object):
def retranslateUi(self, shortcutListDialog): def retranslateUi(self, shortcutListDialog):
shortcutListDialog.setWindowTitle( shortcutListDialog.setWindowTitle(
translate('OpenLP.ShortcutListDialog', 'Customize Shortcuts')) translate('OpenLP.ShortcutListDialog', 'Customize Shortcuts'))
self.descriptionLabel.setText(translate('OpenLP.ShortcutListDialog', #self.descriptionLabel.setText(translate('OpenLP.ShortcutListDialog',
'Select an action and click the button below to start capturing ' #'Select an action and click the button below to start capturing '
'a new shortcut.')) #'a new shortcut.'))
self.treeWidget.setHeaderLabels([ self.treeWidget.setHeaderLabels([
translate('OpenLP.ShortcutListDialog', 'Action'), translate('OpenLP.ShortcutListDialog', 'Action'),
translate('OpenLP.ShortcutListDialog', 'Shortcut'), translate('OpenLP.ShortcutListDialog', 'Shortcut'),
translate('OpenLP.ShortcutListDialog', 'Alternate')]) translate('OpenLP.ShortcutListDialog', 'Alternate')])
self.shortcutButtonLabel.setText( self.primaryPushButton.setText(
translate('OpenLP.ShortcutListDialog', 'Capture shortcut:')) translate('OpenLP.ShortcutListDialog', 'Capture shortcut:'))
self.clearShortcutButton.setToolTip( self.alternatePushButton.setText(
translate('OpenLP.ShortcutListDialog', translate('OpenLP.ShortcutListDialog', 'Capture shortcut:'))
'Restore the default shortcut(s) of this action.')) #self.clearShortcutButton.setToolTip(
#translate('OpenLP.ShortcutListDialog',
#'Restore the default shortcut(s) of this action.'))

View File

@ -47,24 +47,28 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
self.setupUi(self) self.setupUi(self)
self.column = -1 self.column = -1
self.changedActions = {} self.changedActions = {}
self.shortcutButton.setText(u'') self.primaryPushButton.setText(u'')
self.shortcutButton.setEnabled(False) self.alternatePushButton.setText(u'')
QtCore.QObject.connect(self.shortcutButton, self.primaryPushButton.setEnabled(False)
QtCore.SIGNAL(u'toggled(bool)'), self.onShortcutButtonClicked) self.alternatePushButton.setEnabled(False)
QtCore.QObject.connect(self.primaryPushButton,
QtCore.SIGNAL(u'toggled(bool)'), self.onPrimaryPushButtonClicked)
QtCore.QObject.connect(self.treeWidget, QtCore.QObject.connect(self.treeWidget,
QtCore.SIGNAL(u'itemPressed(QTreeWidgetItem*, int)'), QtCore.SIGNAL(u'itemPressed(QTreeWidgetItem*, int)'),
self.onItemPressed) self.onItemPressed)
QtCore.QObject.connect(self.treeWidget, QtCore.QObject.connect(self.treeWidget,
QtCore.SIGNAL(u'itemDoubleClicked(QTreeWidgetItem*, int)'), QtCore.SIGNAL(u'itemDoubleClicked(QTreeWidgetItem*, int)'),
self.onItemDoubleClicked) self.onItemDoubleClicked)
QtCore.QObject.connect(self.clearShortcutButton, QtCore.QObject.connect(self.clearPrimaryButton,
QtCore.SIGNAL(u'clicked(bool)'), self.onClearShortcutButtonClicked) QtCore.SIGNAL(u'clicked(bool)'), self.onClearPrimaryButtonClicked)
# QtCore.QObject.connect(self.clearShortcutButton,
# QtCore.SIGNAL(u'clicked(bool)'), self.onClearPrimaryButtonClicked)
QtCore.QObject.connect(self.buttonBox, QtCore.QObject.connect(self.buttonBox,
QtCore.SIGNAL(u'clicked(QAbstractButton*)'), QtCore.SIGNAL(u'clicked(QAbstractButton*)'),
self.onRestoreDefaultsClicked) self.onRestoreDefaultsClicked)
def keyPressEvent(self, event): def keyPressEvent(self, event):
if self.shortcutButton.isChecked(): if self.primaryPushButton.isChecked():
event.ignore() event.ignore()
elif event.key() == QtCore.Qt.Key_Escape: elif event.key() == QtCore.Qt.Key_Escape:
event.accept() event.accept()
@ -72,7 +76,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
def keyReleaseEvent(self, event): def keyReleaseEvent(self, event):
Qt = QtCore.Qt Qt = QtCore.Qt
if not self.shortcutButton.isChecked(): if not self.primaryPushButton.isChecked():
return return
key = event.key() key = event.key()
if key == Qt.Key_Shift or key == Qt.Key_Control or \ if key == Qt.Key_Shift or key == Qt.Key_Control or \
@ -117,15 +121,15 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
QtGui.QMessageBox.Ok QtGui.QMessageBox.Ok
) )
else: else:
self.shortcutButton.setText(key_sequence.toString()) self.primaryPushButton.setText(key_sequence.toString())
self.shortcutButton.setChecked(False) self.primaryPushButton.setChecked(False)
def exec_(self): def exec_(self):
self.changedActions = {} self.changedActions = {}
self.reloadShortcutList() self.reloadShortcutList()
self.shortcutButton.setChecked(False) self.primaryPushButton.setChecked(False)
self.shortcutButton.setEnabled(False) self.primaryPushButton.setEnabled(False)
self.shortcutButton.setText(u'') self.primaryPushButton.setText(u'')
return QtGui.QDialog.exec_(self) return QtGui.QDialog.exec_(self)
def reloadShortcutList(self): def reloadShortcutList(self):
@ -172,7 +176,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
item.setText(1, shortcuts[0].toString()) item.setText(1, shortcuts[0].toString())
item.setText(2, shortcuts[1].toString()) item.setText(2, shortcuts[1].toString())
def onShortcutButtonClicked(self, toggled): def onPrimaryPushButtonClicked(self, toggled):
""" """
Save the new shortcut to the action if the button is unchanged. Save the new shortcut to the action if the button is unchanged.
""" """
@ -188,14 +192,16 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
new_shortcuts = [] new_shortcuts = []
# We are changing the primary shortcut. # We are changing the primary shortcut.
if self.column in [0, 1]: if self.column in [0, 1]:
new_shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text())) new_shortcuts.append(
QtGui.QKeySequence(self.primaryPushButton.text()))
if len(shortcuts) == 2: if len(shortcuts) == 2:
new_shortcuts.append(shortcuts[1]) new_shortcuts.append(shortcuts[1])
# We are changing the secondary shortcut. # We are changing the secondary shortcut.
elif self.column == 2: elif self.column == 2:
if len(shortcuts) != 0: if len(shortcuts) != 0:
new_shortcuts.append(shortcuts[0]) new_shortcuts.append(shortcuts[0])
new_shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text())) new_shortcuts.append(
QtGui.QKeySequence(self.primaryPushButton.text()))
else: else:
return return
self.changedActions[action] = new_shortcuts self.changedActions[action] = new_shortcuts
@ -203,14 +209,14 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
def onItemDoubleClicked(self, item, column): def onItemDoubleClicked(self, item, column):
""" """
A item has been double clicked. ``The shortcutButton`` will be checked A item has been double clicked. ``The primaryPushButton`` will be
and the item's shortcut will be displayed. checked and the item's shortcut will be displayed.
""" """
action = item.data(0, QtCore.Qt.UserRole).toPyObject() action = item.data(0, QtCore.Qt.UserRole).toPyObject()
if action is None: if action is None:
return return
self.shortcutButton.setChecked(True) self.primaryPushButton.setChecked(True)
self.shortcutButton.setFocus(QtCore.Qt.OtherFocusReason) self.primaryPushButton.setFocus(QtCore.Qt.OtherFocusReason)
self.onItemPressed(item, column) self.onItemPressed(item, column)
def onItemPressed(self, item, column): def onItemPressed(self, item, column):
@ -222,23 +228,23 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
action = item.data(0, QtCore.Qt.UserRole).toPyObject() action = item.data(0, QtCore.Qt.UserRole).toPyObject()
text = u'' text = u''
if action is None: if action is None:
self.shortcutButton.setChecked(False) self.primaryPushButton.setChecked(False)
self.shortcutButton.setEnabled(False) self.primaryPushButton.setEnabled(False)
else: else:
self.shortcutButton.setEnabled(True) self.primaryPushButton.setEnabled(True)
shortcuts = self._actionShortcuts(action) shortcuts = self._actionShortcuts(action)
if column != 2 and len(shortcuts) != 0: if column != 2 and len(shortcuts) != 0:
text = shortcuts[0].toString() text = shortcuts[0].toString()
elif len(shortcuts) == 2: elif len(shortcuts) == 2:
text = shortcuts[1].toString() text = shortcuts[1].toString()
self.shortcutButton.setText(text) self.primaryPushButton.setText(text)
def onClearShortcutButtonClicked(self, toggled): def onClearPrimaryButtonClicked(self, toggled):
""" """
Restore the defaults of this Restore the defaults of this
""" """
item = self.treeWidget.currentItem() item = self.treeWidget.currentItem()
self.shortcutButton.setChecked(False) self.primaryPushButton.setChecked(False)
if item is None: if item is None:
return return
action = item.data(0, QtCore.Qt.UserRole).toPyObject() action = item.data(0, QtCore.Qt.UserRole).toPyObject()
@ -261,8 +267,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
QtGui.QMessageBox.Yes | QtGui.QMessageBox.Yes |
QtGui.QMessageBox.No)) == QtGui.QMessageBox.No: QtGui.QMessageBox.No)) == QtGui.QMessageBox.No:
return return
self.shortcutButton.setChecked(False) self.primaryPushButton.setChecked(False)
self.shortcutButton.setText(u'') self.primaryPushButton.setText(u'')
for category in ActionList.categories: for category in ActionList.categories:
for action in category.actions: for action in category.actions:
self.changedActions[action] = action.defaultShortcuts self.changedActions[action] = action.defaultShortcuts

View File

@ -41,35 +41,35 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="shortcutLayout"> <layout class="QGridLayout" name="detailsLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="spacing"> <property name="spacing">
<number>8</number> <number>8</number>
</property> </property>
<property name="leftMargin"> <item row="0" column="0">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="defaultRadioButton"> <widget class="QRadioButton" name="defaultRadioButton">
<property name="text"> <property name="text">
<string>Default: None</string> <string>Default:</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<layout class="QHBoxLayout" name="customShortcutLayout">
<property name="spacing">
<number>8</number>
</property>
<item>
<widget class="QRadioButton" name="customRadioButton"> <widget class="QRadioButton" name="customRadioButton">
<property name="text"> <property name="text">
<string>Custom:</string> <string>Custom:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="shortcutLayout">
<property name="spacing">
<number>8</number>
</property>
<item> <item>
<widget class="QPushButton" name="shortcutPushButton"> <widget class="QPushButton" name="shortcutPushButton">
<property name="minimumSize"> <property name="minimumSize">
@ -83,7 +83,7 @@
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images/openlp-2.qrc"> <iconset resource="../images/openlp-2.qrc">
<normaloff>:/system/system_settings.png</normaloff>:/system/system_settings.png</iconset> <normaloff>:/system/system_configure_shortcuts.png</normaloff>:/system/system_configure_shortcuts.png</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
@ -110,21 +110,51 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item row="1" column="2">
<layout class="QHBoxLayout" name="alternateLayout">
<property name="spacing">
<number>8</number>
</property>
<item> <item>
<spacer name="customShortcutSpacer"> <widget class="QPushButton" name="alternatePushButton">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>None</string>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="icon">
<size> <iconset resource="../images/openlp-2.qrc">
<width>40</width> <normaloff>:/system/system_configure_shortcuts.png</normaloff>:/system/system_configure_shortcuts.png</iconset>
<height>20</height>
</size>
</property> </property>
</spacer> </widget>
</item>
<item>
<widget class="QToolButton" name="clearAlternateButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images/openlp-2.qrc">
<normaloff>:/system/clear_shortcut.png</normaloff>:/system/clear_shortcut.png</iconset>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="1">
<widget class="QLabel" name="shortcutLabel">
<property name="text">
<string>Ctrl+V</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="alternateLabel">
<property name="text">
<string>Shift+Ins</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>