Mercurial > octave-libgccjit
diff libgui/src/shortcut-manager.cc @ 18728: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 | 9ef65c422f53 |
children | dff05c124017 3f6280d0a36b |
line wrap: on
line diff
--- 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