changeset 18762:95249367d6fa gui-release

provide a second set of shortcuts * settings-dialog.cc (constructor): init new radio buttons from settings file; (write_changed_settings): save selected shortcut set into settings file * settings-dialog.ui: radio buttons for the shortcut sets, second set * shortcut-manager.cc (init): init also second shortcut set; (do_fill_treewidget): fill the tree view with both sets; (do_write_shortcuts): save the changed shortcuts to the settings file; (do_set_shortcut): consider the current set when assigning a shortcut; (handle_double_clicked): call dialog only when actual shortcuts are clicked; (shortcut_dialog): dialog for new shortcuts depending on clicked set; (shortcut_dialog_finished): action after dialog depends on the set; * shortcut-manager.h: shortcut structure with arrays for default and actual shortcuts, class variable for set selected by the double clicked
author Torsten <ttl@justmail.de>
date Mon, 05 May 2014 19:49:41 +0200
parents f017240310fb
children 0f9ed79fb206
files libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui libgui/src/shortcut-manager.cc libgui/src/shortcut-manager.h
diffstat 4 files changed, 141 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/settings-dialog.cc	Fri May 02 17:44:44 2014 +0200
+++ b/libgui/src/settings-dialog.cc	Mon May 05 19:49:41 2014 +0200
@@ -274,6 +274,9 @@
   // shortcuts
   ui->cb_prevent_readline_conflicts->setChecked (
     settings->value ("shortcuts/prevent_readline_conflicts", true).toBool ());
+  int set = settings->value ("shortcuts/set",0).toInt ();
+  ui->rb_sc_set1->setChecked (set == 0);
+  ui->rb_sc_set2->setChecked (set == 1);
 
 #ifdef HAVE_QSCINTILLA
   // editor styles: create lexer, read settings, and create dialog elements
@@ -691,6 +694,10 @@
   // shortcuts
   settings->setValue ("shortcuts/prevent_readline_conflicts",
                       ui->cb_prevent_readline_conflicts->isChecked ());
+  int set = 0;
+  if (ui->rb_sc_set2->isChecked ())
+    set = 1;
+  settings->setValue ("shortcuts/set",set);
   shortcut_manager::write_shortcuts ();
 
   // settings dialog's geometry
--- a/libgui/src/settings-dialog.ui	Fri May 02 17:44:44 2014 +0200
+++ b/libgui/src/settings-dialog.ui	Mon May 05 19:49:41 2014 +0200
@@ -1708,9 +1708,50 @@
               </widget>
              </item>
              <item>
+              <layout class="QHBoxLayout" name="horizontalLayout_14">
+               <item>
+                <widget class="QLabel" name="label_22">
+                 <property name="text">
+                  <string>Use Shortcut Set: </string>
+                 </property>
+                </widget>
+               </item>
+               <item>
+                <widget class="QRadioButton" name="rb_sc_set1">
+                 <property name="text">
+                  <string>Set 1</string>
+                 </property>
+                 <property name="checked">
+                  <bool>true</bool>
+                 </property>
+                </widget>
+               </item>
+               <item>
+                <widget class="QRadioButton" name="rb_sc_set2">
+                 <property name="text">
+                  <string>Set 2</string>
+                 </property>
+                </widget>
+               </item>
+               <item>
+                <spacer name="horizontalSpacer_17">
+                 <property name="orientation">
+                  <enum>Qt::Horizontal</enum>
+                 </property>
+                 <property name="sizeHint" stdset="0">
+                  <size>
+                   <width>40</width>
+                   <height>20</height>
+                  </size>
+                 </property>
+                </spacer>
+               </item>
+              </layout>
+             </item>
+             <item>
               <widget class="QLabel" name="label_21">
                <property name="text">
-                <string>Enter a new shortcut by double clicking on the related row.</string>
+                <string>Edit an actual shortcut by double clicking into the related cell</string>
                </property>
               </widget>
              </item>
@@ -1739,9 +1780,6 @@
                    <height>0</height>
                   </size>
                  </property>
-                 <property name="lineWidth">
-                  <number>0</number>
-                 </property>
                  <property name="alternatingRowColors">
                   <bool>true</bool>
                  </property>
@@ -1755,7 +1793,7 @@
                   <bool>false</bool>
                  </property>
                  <property name="columnCount">
-                  <number>3</number>
+                  <number>5</number>
                  </property>
                  <attribute name="headerCascadingSectionResizes">
                   <bool>false</bool>
@@ -1776,21 +1814,35 @@
                   <property name="text">
                    <string>Action</string>
                   </property>
+                  <property name="font">
+                   <font>
+                    <italic>false</italic>
+                   </font>
+                  </property>
                  </column>
                  <column>
                   <property name="text">
-                   <string>Default Shortcut</string>
-                  </property>
-                  <property name="textAlignment">
-                   <set>AlignLeft|AlignVCenter</set>
+                   <string>Set 1 Default</string>
                   </property>
                  </column>
                  <column>
                   <property name="text">
-                   <string>Actual Shortcut</string>
+                   <string>Set 1 Actual</string>
+                  </property>
+                 </column>
+                 <column>
+                  <property name="text">
+                   <string>Set 2 Default</string>
                   </property>
-                  <property name="textAlignment">
-                   <set>AlignLeft|AlignVCenter</set>
+                  <property name="font">
+                   <font>
+                    <italic>false</italic>
+                   </font>
+                  </property>
+                 </column>
+                 <column>
+                  <property name="text">
+                   <string>Set 2 Actual</string>
                   </property>
                  </column>
                 </widget>
--- a/libgui/src/shortcut-manager.cc	Fri May 02 17:44:44 2014 +0200
+++ b/libgui/src/shortcut-manager.cc	Mon May 05 19:49:41 2014 +0200
@@ -210,20 +210,25 @@
 void
 shortcut_manager::init (QString description, QString key, QKeySequence def_sc)
 {
-  QKeySequence actual = QKeySequence (_settings->value ("shortcuts/"+key, def_sc).toString ());
+  QKeySequence actual_0 = QKeySequence (_settings->value ("shortcuts/"+key, def_sc).toString ());
+  QKeySequence actual_1 = QKeySequence (_settings->value ("shortcuts/"+key+"_1", def_sc).toString ());
 
   // append the new shortcut to the list
   shortcut_t shortcut_info;
   shortcut_info.description = description;
   shortcut_info.settings_key = key;
-  shortcut_info.actual_sc = actual;
-  shortcut_info.default_sc = def_sc;
+  shortcut_info.actual_sc [0] = actual_0;
+  shortcut_info.actual_sc [1] = actual_1;
+  shortcut_info.default_sc [0] = def_sc;
+  shortcut_info.default_sc [1] = def_sc;  // TODO: Different defaults
   _sc << shortcut_info;
 
   // insert shortcut prepended by widget in order check for duplicates later
   QString widget = key.section ('_',0,0);  // get widget that uses the shortcut
-  if (! actual.isEmpty ())
-    _shortcut_hash[widget + ":" + actual.toString ()] = _sc.count ();  // offset of 1 to avoid 0
+  if (! actual_0.isEmpty ())
+    _shortcut_hash[widget + ":" + actual_0.toString ()] = _sc.count ();  // offset of 1 to avoid 0
+  if (! actual_1.isEmpty ())
+    _shortcut_hash[widget + "_1:" + actual_1.toString ()] = _sc.count ();  // offset of 1 to avoid 0
   _action_hash[key] = _sc.count ();  // offset of 1 to avoid 0
 }
 
@@ -291,9 +296,18 @@
       QTreeWidgetItem* section = _level_hash[sc.settings_key.section(':',0,0)];
       QTreeWidgetItem* tree_item = new QTreeWidgetItem (section);
 
+      // set a slightly transparent foreground for default columns
+      QColor fg = QColor (tree_item->foreground (1).color ());
+      fg.setAlpha (128);
+      tree_item->setForeground (1, QBrush (fg));
+      tree_item->setForeground (3,QBrush (fg));
+
+      // write the shortcuts
       tree_item->setText (0, sc.description);
-      tree_item->setText (1, sc.default_sc);
-      tree_item->setText (2, sc.actual_sc);
+      tree_item->setText (1, sc.default_sc [0]);
+      tree_item->setText (2, sc.actual_sc [0]);
+      tree_item->setText (3, sc.default_sc [1]);
+      tree_item->setText (4, sc.actual_sc [1]);
 
       _item_index_hash[tree_item] = i + 1; // index+1 to avoid 0
       _index_item_hash[i] = tree_item;
@@ -305,7 +319,10 @@
 shortcut_manager::do_write_shortcuts ()
 {
   for (int i = 0; i < _sc.count (); i++)
-    _settings->setValue("shortcuts/"+_sc.at (i).settings_key, _sc.at (i).actual_sc.toString ());
+    {
+      _settings->setValue("shortcuts/"+_sc.at (i).settings_key, _sc.at (i).actual_sc[0].toString ());
+      _settings->setValue("shortcuts/"+_sc.at (i).settings_key+"_1", _sc.at (i).actual_sc[1].toString ());
+    }
 
   _settings->sync ();
 
@@ -315,18 +332,36 @@
 void
 shortcut_manager::do_set_shortcut (QAction* action, const QString& key)
 {
-  int index = _action_hash[key] - 1;
+  int set = _settings->value ("shortcuts/set",0).toInt ();
+  int index;
+
+  index = _action_hash[key] - 1;
+
+  QString key_set = key;
+  if (set == 1)
+    key_set = key+"_1";
 
   if (index > -1 && index < _sc.count ())
     action->setShortcut ( QKeySequence (
-      _settings->value ("shortcuts/" + key, _sc.at (index).default_sc).toString ()));
+      _settings->value ("shortcuts/" + key_set, _sc.at (index).default_sc[set]).toString ()));
   else
-    qDebug () << "Key: " << key << " not found in _action_hash";
+    qDebug () << "Key: " << key_set << " not found in _action_hash";
 }
 
 void
-shortcut_manager::handle_double_clicked (QTreeWidgetItem* item, int)
+shortcut_manager::handle_double_clicked (QTreeWidgetItem* item, int col)
 {
+  switch (col)
+    {
+      case 2:
+      case 4:
+        _selected_set = col/2 - 1;
+        break;
+
+      default:
+        return;
+    }
+
   int i = _item_index_hash[item];
   if (i == 0)
     return;  // top-level-item clicked
@@ -341,7 +376,8 @@
     {
       _dialog = new QDialog (this);
 
-      _dialog->setWindowTitle (tr ("Enter new Shortcut"));
+      _dialog->setWindowTitle (tr ("Enter new Shortcut for Set %1")
+                               .arg (_selected_set + 1));
 
       QVBoxLayout *box = new QVBoxLayout(_dialog);
 
@@ -394,8 +430,8 @@
 
     }
 
-  _edit_actual->setText (_sc.at (index).actual_sc);
-  _label_default->setText (_sc.at (index).default_sc);
+  _edit_actual->setText (_sc.at (index).actual_sc[_selected_set]);
+  _label_default->setText (_sc.at (index).default_sc[_selected_set]);
   _handled_index = index;
 
   _edit_actual->setFocus ();
@@ -413,8 +449,12 @@
 
   // get the widget for which this shortcut is defined
   QString widget = _sc.at (_handled_index).settings_key.section ('_',0,0);
-  // and look
-  int double_index = _shortcut_hash[widget + ":" + _edit_actual->text()] - 1;
+  // and look for shortcut
+  QString sep = ":";
+  if (_selected_set)
+    sep = "_1:";
+
+  int double_index = _shortcut_hash[widget + sep + _edit_actual->text()] - 1;
 
   if (double_index >= 0 && double_index != _handled_index)
     {
@@ -430,24 +470,26 @@
       if (ret == QMessageBox::Yes)
         {
           shortcut_t double_shortcut = _sc.at (double_index);
-          double_shortcut.actual_sc = QKeySequence ();
+          double_shortcut.actual_sc[_selected_set] = QKeySequence ();
           _sc.replace (double_index, double_shortcut);
-          _index_item_hash[double_index]->setText (2, QKeySequence ());
+          _index_item_hash[double_index]->setText ((_selected_set + 1)*2, QKeySequence ());
         }
       else
         return;
     }
 
   shortcut_t shortcut = _sc.at (_handled_index);
-  if (! shortcut.actual_sc.isEmpty ())
-    _shortcut_hash.remove (widget + ":" + shortcut.actual_sc.toString ());
-  shortcut.actual_sc = _edit_actual->text();
+  if (! shortcut.actual_sc[_selected_set].isEmpty ())
+    _shortcut_hash.remove (widget + sep + shortcut.actual_sc[_selected_set].toString ());
+  shortcut.actual_sc[_selected_set] = _edit_actual->text();
   _sc.replace (_handled_index, shortcut);
 
-  _index_item_hash[_handled_index]->setText (2, shortcut.actual_sc);
+  _index_item_hash[_handled_index]->setText ((_selected_set + 1)*2,
+                                             shortcut.actual_sc[_selected_set]);
 
-  if (! shortcut.actual_sc.isEmpty ())
-    _shortcut_hash[widget + ":" + shortcut.actual_sc.toString ()] = _handled_index + 1;
+  if (! shortcut.actual_sc[_selected_set].isEmpty ())
+    _shortcut_hash[widget + sep + shortcut.actual_sc[_selected_set].toString ()] =
+        _handled_index + 1;
 }
 
 void
--- a/libgui/src/shortcut-manager.h	Fri May 02 17:44:44 2014 +0200
+++ b/libgui/src/shortcut-manager.h	Mon May 05 19:49:41 2014 +0200
@@ -116,8 +116,8 @@
   {
     QString description;
     QString settings_key;
-    QKeySequence actual_sc;
-    QKeySequence default_sc;
+    QKeySequence actual_sc[2];
+    QKeySequence default_sc[2];
     QTreeWidgetItem *tree_item;
   };
 
@@ -134,6 +134,7 @@
   int _handled_index;
 
   QSettings *_settings;
+  int _selected_set;
 
 };