src/configDialog.cc

changeset 806
4240f47aa2d4
parent 795
195fa1fff9c3
child 814
c8ef30fd0e54
--- a/src/configDialog.cc	Mon Jun 16 18:31:13 2014 +0300
+++ b/src/configDialog.cc	Sun Jun 22 03:55:56 2014 +0300
@@ -122,15 +122,10 @@
 	ui->roundPosition->setValue (cfg::roundPosition);
 	ui->roundMatrix->setValue (cfg::roundMatrix);
 
-	int i = 0;
-
-	for (QAction* act : g_win->findChildren<QAction*>())
+	g_win->applyToActions ([&](QAction* act)
 	{
-		KeySequenceConfigEntry* cfg = g_win->shortcutForAction (act);
-
-		if (cfg)
-			addShortcut (*cfg, act, i);
-	}
+		addShortcut (act);
+	});
 
 	ui->shortcutsList->setSortingEnabled (true);
 	ui->shortcutsList->sortItems();
@@ -197,12 +192,12 @@
 // =============================================================================
 // Adds a shortcut entry to the list of shortcuts.
 // =============================================================================
-void ConfigDialog::addShortcut (KeySequenceConfigEntry& cfg, QAction* act, int& i)
+void ConfigDialog::addShortcut (QAction* act)
 {
 	ShortcutListItem* item = new ShortcutListItem;
 	item->setIcon (act->icon());
-	item->setKeyConfig (&cfg);
 	item->setAction (act);
+	item->setSequence (act->shortcut());
 	setShortcutText (item);
 
 	// If the action doesn't have a valid icon, use an empty one
@@ -210,7 +205,7 @@
 	if (act->icon().isNull())
 		item->setIcon (getIcon ("empty"));
 
-	ui->shortcutsList->insertItem (i++, item);
+	ui->shortcutsList->insertItem (ui->shortcutsList->count(), item);
 }
 
 // =============================================================================
@@ -320,9 +315,6 @@
 	cfg::gridFineCoordinateSnap = ui->gridFineCoordinateSnap->value();
 	cfg::gridFineAngleSnap = ui->gridFineAngleSnap->value();
 
-	// Apply key shortcuts
-	g_win->updateActionShortcuts();
-
 	// Ext program settings
 	for (const LDExtProgInfo& info : g_LDExtProgInfo)
 	{
@@ -333,6 +325,13 @@
 #endif // _WIN32
 	}
 
+	// Apply shortcuts
+	for (int i = 0; i < ui->shortcutsList->count(); ++i)
+	{
+		auto item = static_cast<ShortcutListItem*> (ui->shortcutsList->item (i));
+		item->action()->setShortcut (item->sequence());
+	}
+
 	Config::save();
 	reloadAllSubfiles();
 	loadLogoedStuds();
@@ -393,7 +392,7 @@
 			}
 			else
 			{
-				item->setText (col->name());
+				item->setText (col.name());
 				item->setIcon (makeColorIcon (col, 16));
 			}
 		}
@@ -617,7 +616,7 @@
 
 	ShortcutListItem* item = sel[0];
 
-	if (KeySequenceDialog::staticDialog (item->keyConfig(), this))
+	if (KeySequenceDialog::staticDialog (item, this))
 		setShortcutText (item);
 }
 
@@ -630,7 +629,7 @@
 
 	for (ShortcutListItem* item : sel)
 	{
-		item->keyConfig()->resetValue();
+		item->setSequence (MainWindow::defaultShortcut (item->action()));
 		setShortcutText (item);
 	}
 }
@@ -644,7 +643,7 @@
 
 	for (ShortcutListItem* item : sel)
 	{
-		item->keyConfig()->setValue (QKeySequence());
+		item->setSequence (QKeySequence());
 		setShortcutText (item);
 	}
 }
@@ -692,7 +691,7 @@
 {
 	QAction* act = item->action();
 	QString label = act->iconText();
-	QString keybind = item->keyConfig()->getValue().toString();
+	QString keybind = item->sequence().toString();
 	item->setText (format ("%1 (%2)", label, keybind));
 }
 
@@ -711,7 +710,7 @@
 		if (entry.isSeparator())
 			val += '|';
 		else
-			val += format ("%1", entry.color()->index());
+			val += format ("%1", entry.color().index());
 	}
 
 	return val;
@@ -744,14 +743,14 @@
 
 // =============================================================================
 // =============================================================================
-bool KeySequenceDialog::staticDialog (KeySequenceConfigEntry* cfg, QWidget* parent)
+bool KeySequenceDialog::staticDialog (ShortcutListItem* item, QWidget* parent)
 {
-	KeySequenceDialog dlg (cfg->getValue(), parent);
+	KeySequenceDialog dlg (item->sequence(), parent);
 
 	if (dlg.exec() == QDialog::Rejected)
 		return false;
 
-	cfg->setValue (dlg.seq);
+	item->setSequence (dlg.seq);
 	return true;
 }
 

mercurial