From 9b84319c249cf09b66e90d7f28c7eb38c5afe134 Mon Sep 17 00:00:00 2001
From: Andreas Preikschat <googol@lavabit.com>
Date: Thu, 7 Apr 2011 16:26:29 +0200
Subject: [PATCH] added new dialog from superfly + few own changes

---
 openlp/core/ui/shortcutlistdialog.py  | 109 ++++++++++++++++----------
 openlp/core/ui/shortcutlistform.py    |  62 ++++++++-------
 resources/forms/shortcutlistdialog.ui |  80 +++++++++++++------
 3 files changed, 158 insertions(+), 93 deletions(-)

diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py
index 83f897bd8..6531a1a19 100644
--- a/openlp/core/ui/shortcutlistdialog.py
+++ b/openlp/core/ui/shortcutlistdialog.py
@@ -30,44 +30,71 @@ from openlp.core.lib import translate, build_icon
 
 class Ui_ShortcutListDialog(object):
     def setupUi(self, shortcutListDialog):
-        shortcutListDialog.resize(440, 450)
-        shortcutListDialog.setObjectName(u'shortcutListDialog')
-        self.dialogLayout = QtGui.QVBoxLayout(shortcutListDialog)
-        self.dialogLayout.setObjectName(u'dialogLayout')
-        self.descriptionLabel = QtGui.QLabel(shortcutListDialog)
-        self.descriptionLabel.setObjectName(u'descriptionLabel')
-        self.descriptionLabel.setWordWrap(True)
-        self.dialogLayout.addWidget(self.descriptionLabel)
+        shortcutListDialog.setObjectName("shortcutListDialog")
+        shortcutListDialog.resize(500, 438)
+        self.shortcutListLayout = QtGui.QVBoxLayout(shortcutListDialog)
+        self.shortcutListLayout.setSpacing(8)
+        self.shortcutListLayout.setMargin(8)
+        self.shortcutListLayout.setObjectName("shortcutListLayout")
         self.treeWidget = QtGui.QTreeWidget(shortcutListDialog)
         self.treeWidget.setAlternatingRowColors(True)
-        self.treeWidget.setObjectName(u'treeWidget')
+        self.treeWidget.setObjectName("treeWidget")
         self.treeWidget.setColumnCount(3)
-        self.dialogLayout.addWidget(self.treeWidget)
-        self.customLayout = QtGui.QHBoxLayout()
-        self.customLayout.setObjectName(u'customLayout')
-        self.shortcutButtonLabel = QtGui.QLabel(shortcutListDialog)
-        self.shortcutButtonLabel.setObjectName(u'descriptionLabel')
-        self.customLayout.addWidget(self.shortcutButtonLabel)
-        self.shortcutButton = QtGui.QPushButton(shortcutListDialog)
-        self.shortcutButton.setIcon(
-            build_icon(u':/system/system_configure_shortcuts.png'))
-        self.shortcutButton.setCheckable(True)
-        self.shortcutButton.setObjectName(u'shortcutButton')
-        self.shortcutButton.setFixedSize(150, 30)
-        self.customLayout.addWidget(self.shortcutButton)
-        self.clearShortcutButton = QtGui.QToolButton(shortcutListDialog)
-        self.clearShortcutButton.setIcon(
-            build_icon(u':/system/clear_shortcut.png'))
-        self.clearShortcutButton.setAutoRaise(True)
-        self.clearShortcutButton.setObjectName(u'clearShortcutButton')
-        self.customLayout.addWidget(self.clearShortcutButton)
-        self.customLayout.addStretch()
-        self.dialogLayout.addLayout(self.customLayout)
+        self.shortcutListLayout.addWidget(self.treeWidget)
+        self.detailsLayout = QtGui.QGridLayout()
+        self.detailsLayout.setSpacing(8)
+        self.detailsLayout.setContentsMargins(-1, 0, -1, -1)
+        self.detailsLayout.setObjectName("detailsLayout")
+        self.defaultRadioButton = QtGui.QRadioButton(shortcutListDialog)
+        self.defaultRadioButton.setChecked(True)
+        self.defaultRadioButton.setObjectName("defaultRadioButton")
+        self.detailsLayout.addWidget(self.defaultRadioButton, 0, 0, 1, 1)
+        self.customRadioButton = QtGui.QRadioButton(shortcutListDialog)
+        self.customRadioButton.setObjectName("customRadioButton")
+        self.detailsLayout.addWidget(self.customRadioButton, 1, 0, 1, 1)
+        self.primaryLayout = QtGui.QHBoxLayout()
+        self.primaryLayout.setSpacing(8)
+        self.primaryLayout.setObjectName("primaryLayout")
+        self.primaryPushButton = QtGui.QPushButton(shortcutListDialog)
+        self.primaryPushButton.setMinimumSize(QtCore.QSize(84, 0))
+        self.primaryPushButton.setIcon(build_icon(u':/system/system_configure_shortcuts.png'))
+        self.primaryPushButton.setCheckable(True)
+        self.primaryPushButton.setChecked(False)
+        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.setOrientation(QtCore.Qt.Horizontal)
         self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
-            QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.RestoreDefaults)
-        self.buttonBox.setObjectName(u'buttonBox')
-        self.dialogLayout.addWidget(self.buttonBox)
+            QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Reset)
+        self.buttonBox.setObjectName("buttonBox")
+        self.shortcutListLayout.addWidget(self.buttonBox)
         self.retranslateUi(shortcutListDialog)
         QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'),
             shortcutListDialog.accept)
@@ -78,15 +105,17 @@ class Ui_ShortcutListDialog(object):
     def retranslateUi(self, shortcutListDialog):
         shortcutListDialog.setWindowTitle(
             translate('OpenLP.ShortcutListDialog', 'Customize Shortcuts'))
-        self.descriptionLabel.setText(translate('OpenLP.ShortcutListDialog',
-            'Select an action and click the button below to start capturing '
-            'a new shortcut.'))
+        #self.descriptionLabel.setText(translate('OpenLP.ShortcutListDialog',
+            #'Select an action and click the button below to start capturing '
+            #'a new shortcut.'))
         self.treeWidget.setHeaderLabels([
             translate('OpenLP.ShortcutListDialog', 'Action'),
             translate('OpenLP.ShortcutListDialog', 'Shortcut'),
             translate('OpenLP.ShortcutListDialog', 'Alternate')])
-        self.shortcutButtonLabel.setText(
+        self.primaryPushButton.setText(
             translate('OpenLP.ShortcutListDialog', 'Capture shortcut:'))
-        self.clearShortcutButton.setToolTip(
-            translate('OpenLP.ShortcutListDialog',
-            'Restore the default shortcut(s) of this action.'))
+        self.alternatePushButton.setText(
+            translate('OpenLP.ShortcutListDialog', 'Capture shortcut:'))
+        #self.clearShortcutButton.setToolTip(
+            #translate('OpenLP.ShortcutListDialog',
+            #'Restore the default shortcut(s) of this action.'))
diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py
index a99b7c3bb..00e216c2a 100644
--- a/openlp/core/ui/shortcutlistform.py
+++ b/openlp/core/ui/shortcutlistform.py
@@ -47,24 +47,28 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
         self.setupUi(self)
         self.column = -1
         self.changedActions = {}
-        self.shortcutButton.setText(u'')
-        self.shortcutButton.setEnabled(False)
-        QtCore.QObject.connect(self.shortcutButton,
-            QtCore.SIGNAL(u'toggled(bool)'), self.onShortcutButtonClicked)
+        self.primaryPushButton.setText(u'')
+        self.alternatePushButton.setText(u'')
+        self.primaryPushButton.setEnabled(False)
+        self.alternatePushButton.setEnabled(False)
+        QtCore.QObject.connect(self.primaryPushButton,
+            QtCore.SIGNAL(u'toggled(bool)'), self.onPrimaryPushButtonClicked)
         QtCore.QObject.connect(self.treeWidget,
             QtCore.SIGNAL(u'itemPressed(QTreeWidgetItem*, int)'),
             self.onItemPressed)
         QtCore.QObject.connect(self.treeWidget,
             QtCore.SIGNAL(u'itemDoubleClicked(QTreeWidgetItem*, int)'),
             self.onItemDoubleClicked)
-        QtCore.QObject.connect(self.clearShortcutButton,
-            QtCore.SIGNAL(u'clicked(bool)'), self.onClearShortcutButtonClicked)
+        QtCore.QObject.connect(self.clearPrimaryButton,
+            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.SIGNAL(u'clicked(QAbstractButton*)'),
             self.onRestoreDefaultsClicked)
 
     def keyPressEvent(self, event):
-        if self.shortcutButton.isChecked():
+        if self.primaryPushButton.isChecked():
             event.ignore()
         elif event.key() == QtCore.Qt.Key_Escape:
             event.accept()
@@ -72,7 +76,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
 
     def keyReleaseEvent(self, event):
         Qt = QtCore.Qt
-        if not self.shortcutButton.isChecked():
+        if not self.primaryPushButton.isChecked():
             return
         key = event.key()
         if key == Qt.Key_Shift or key == Qt.Key_Control or \
@@ -117,15 +121,15 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
                 QtGui.QMessageBox.Ok
             )
         else:
-            self.shortcutButton.setText(key_sequence.toString())
-            self.shortcutButton.setChecked(False)
+            self.primaryPushButton.setText(key_sequence.toString())
+            self.primaryPushButton.setChecked(False)
 
     def exec_(self):
         self.changedActions = {}
         self.reloadShortcutList()
-        self.shortcutButton.setChecked(False)
-        self.shortcutButton.setEnabled(False)
-        self.shortcutButton.setText(u'')
+        self.primaryPushButton.setChecked(False)
+        self.primaryPushButton.setEnabled(False)
+        self.primaryPushButton.setText(u'')
         return QtGui.QDialog.exec_(self)
 
     def reloadShortcutList(self):
@@ -172,7 +176,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
                 item.setText(1, shortcuts[0].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.
         """
@@ -188,14 +192,16 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
         new_shortcuts = []
         # We are changing the primary shortcut.
         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:
                 new_shortcuts.append(shortcuts[1])
         # We are changing the secondary shortcut.
         elif self.column == 2:
             if len(shortcuts) != 0:
                 new_shortcuts.append(shortcuts[0])
-            new_shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text()))
+            new_shortcuts.append(
+                QtGui.QKeySequence(self.primaryPushButton.text()))
         else:
             return
         self.changedActions[action] = new_shortcuts
@@ -203,14 +209,14 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
 
     def onItemDoubleClicked(self, item, column):
         """
-        A item has been double clicked. ``The shortcutButton`` will be checked
-        and the item's shortcut will be displayed.
+        A item has been double clicked. ``The primaryPushButton`` will be
+        checked and the item's shortcut will be displayed.
         """
         action = item.data(0, QtCore.Qt.UserRole).toPyObject()
         if action is None:
             return
-        self.shortcutButton.setChecked(True)
-        self.shortcutButton.setFocus(QtCore.Qt.OtherFocusReason)
+        self.primaryPushButton.setChecked(True)
+        self.primaryPushButton.setFocus(QtCore.Qt.OtherFocusReason)
         self.onItemPressed(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()
         text = u''
         if action is None:
-            self.shortcutButton.setChecked(False)
-            self.shortcutButton.setEnabled(False)
+            self.primaryPushButton.setChecked(False)
+            self.primaryPushButton.setEnabled(False)
         else:
-            self.shortcutButton.setEnabled(True)
+            self.primaryPushButton.setEnabled(True)
             shortcuts = self._actionShortcuts(action)
             if column != 2 and len(shortcuts) != 0:
                 text = shortcuts[0].toString()
             elif len(shortcuts) == 2:
                 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 
         """
         item = self.treeWidget.currentItem()
-        self.shortcutButton.setChecked(False)
+        self.primaryPushButton.setChecked(False)
         if item is None:
             return
         action = item.data(0, QtCore.Qt.UserRole).toPyObject()
@@ -261,8 +267,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog):
             QtGui.QMessageBox.Yes |
             QtGui.QMessageBox.No)) == QtGui.QMessageBox.No:
             return
-        self.shortcutButton.setChecked(False)
-        self.shortcutButton.setText(u'')
+        self.primaryPushButton.setChecked(False)
+        self.primaryPushButton.setText(u'')
         for category in ActionList.categories:
             for action in category.actions:
                 self.changedActions[action] = action.defaultShortcuts
diff --git a/resources/forms/shortcutlistdialog.ui b/resources/forms/shortcutlistdialog.ui
index 519925560..9a5c599d1 100644
--- a/resources/forms/shortcutlistdialog.ui
+++ b/resources/forms/shortcutlistdialog.ui
@@ -41,35 +41,35 @@
     </widget>
    </item>
    <item>
-    <layout class="QVBoxLayout" name="shortcutLayout">
+    <layout class="QGridLayout" name="detailsLayout">
+     <property name="topMargin">
+      <number>0</number>
+     </property>
      <property name="spacing">
       <number>8</number>
      </property>
-     <property name="leftMargin">
-      <number>0</number>
-     </property>
-     <item>
+     <item row="0" column="0">
       <widget class="QRadioButton" name="defaultRadioButton">
        <property name="text">
-        <string>Default: None</string>
+        <string>Default:</string>
        </property>
        <property name="checked">
         <bool>true</bool>
        </property>
       </widget>
      </item>
-     <item>
-      <layout class="QHBoxLayout" name="customShortcutLayout">
+     <item row="1" column="0">
+      <widget class="QRadioButton" name="customRadioButton">
+       <property name="text">
+        <string>Custom:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <layout class="QHBoxLayout" name="shortcutLayout">
        <property name="spacing">
         <number>8</number>
        </property>
-       <item>
-        <widget class="QRadioButton" name="customRadioButton">
-         <property name="text">
-          <string>Custom:</string>
-         </property>
-        </widget>
-       </item>
        <item>
         <widget class="QPushButton" name="shortcutPushButton">
          <property name="minimumSize">
@@ -83,7 +83,7 @@
          </property>
          <property name="icon">
           <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 name="checkable">
           <bool>true</bool>
@@ -110,21 +110,51 @@
          </property>
         </widget>
        </item>
+      </layout>
+     </item>
+     <item row="1" column="2">
+      <layout class="QHBoxLayout" name="alternateLayout">
+       <property name="spacing">
+        <number>8</number>
+       </property>
        <item>
-        <spacer name="customShortcutSpacer">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
+        <widget class="QPushButton" name="alternatePushButton">
+         <property name="text">
+          <string>None</string>
          </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>40</width>
-           <height>20</height>
-          </size>
+         <property name="icon">
+          <iconset resource="../images/openlp-2.qrc">
+           <normaloff>:/system/system_configure_shortcuts.png</normaloff>:/system/system_configure_shortcuts.png</iconset>
          </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>
       </layout>
      </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>
    </item>
    <item>