|
From: <cn...@us...> - 2020-10-24 21:10:40
|
Revision: 1058
http://sourceforge.net/p/seq/svn/1058
Author: cn187
Date: 2020-10-24 21:10:38 +0000 (Sat, 24 Oct 2020)
Log Message:
-----------
Work around map menu keyboard shortcut ambiguity issues
Since the map context menu is available in multiple places (right
clicking on the map, and also under the Windows menu), shortcuts weren't
working due to multiple menus wanting to handle them.
This works around the issue by turning off the menu shortcuts and
instead attaching them to the map instance itself.
This has a side effect of the shortcuts not working if more than one map
is visible, but it's a step forward and better than none working at all.
Modified Paths:
--------------
showeq/branches/pre_6_0_beta/src/map.cpp
Modified: showeq/branches/pre_6_0_beta/src/map.cpp
===================================================================
--- showeq/branches/pre_6_0_beta/src/map.cpp 2020-10-24 21:10:31 UTC (rev 1057)
+++ showeq/branches/pre_6_0_beta/src/map.cpp 2020-10-24 21:10:38 UTC (rev 1058)
@@ -762,23 +762,49 @@
addMenu(subMenu);
subMenu = new QMenu("Edit", m_map);
- int key;
+ QKeySequence key;
+ QShortcut *tmpShortcut = nullptr;
+ /* Since the map menus also get inserted into Window menu, simply adding
+ * a shortcut to the QAction gives "ambiguous shortcut" errors and causes
+ * the shortcuts not to work due to both menus trying to handle the shortcut.
+ *
+ * So as a hacky work-around, we don't define the shortcut on the QAction,
+ * but we do change the QAction's text to also show the shortcut, since
+ * otherwise it's not shown. Then we define the shortcut and attach it to
+ * the map itself.
+ *
+ * This allows the map menu keyboard shortcuts to work if there is only one
+ * map window open.
+ *
+ * If there are multiple maps open, then the menu entries will continue to
+ * work, but the keyboard shortcuts will not, since Qt doesn't know which
+ * window should handle the action. It's probably possible to deal with this
+ * by detecting which map has focus and giving it preference, but this
+ * behavior doesn't appear to be the default. FIXME
+ *
+ * - cn187
+ */
+
key = pSEQPrefs->getPrefKey("AddLocationKey", preferenceName, "Ctrl+O");
- m_action_addLocation = subMenu->addAction("Add Location...", m_map,
- SLOT(addLocation()), key);
+ m_action_addLocation = subMenu->addAction(
+ QString("Add Location...\t") + key.toString(), m_map, SLOT(addLocation()));
+ tmpShortcut = new QShortcut(key, m_map, SLOT(addLocation()));
key = pSEQPrefs->getPrefKey("StartLineKey", preferenceName, "Ctrl+L");
- m_action_startLine = subMenu->addAction("Start Line", m_map,
- SLOT(startLine()), key);
+ m_action_startLine = subMenu->addAction(
+ QString("Start Line\t") + key.toString(), m_map, SLOT(startLine()));
+ tmpShortcut = new QShortcut(key, m_map, SLOT(startLine()));
key = pSEQPrefs->getPrefKey("AddLinePointKey", preferenceName, "Ctrl+P");
- m_action_addLinePoint = subMenu->addAction("Add Line Point", m_map,
- SLOT(addLinePoint()), key);
+ m_action_addLinePoint = subMenu->addAction(
+ QString("Add Line Point\t") + key.toString(), m_map, SLOT(addLinePoint()));
+ tmpShortcut = new QShortcut(key, m_map, SLOT(addLinePoint()));
key = pSEQPrefs->getPrefKey("DelLinePointKey", preferenceName, "Ctrl+D");
- m_action_delLinePoint = subMenu->addAction("Delete Line Point", m_map,
- SLOT(delLinePoint()), key);
+ m_action_delLinePoint = subMenu->addAction(
+ QString("Delete Line Point\t") + key.toString(), m_map, SLOT(delLinePoint()));
+ tmpShortcut = new QShortcut(key, m_map, SLOT(delLinePoint()));
m_action_showLineDlg = subMenu->addAction("Show Line Dialog...", m_map,
SLOT(showLineDlg()));
@@ -815,33 +841,42 @@
subMenu = new QMenu("Map Line Display", m_map);
- m_action_mapLineStyle_Normal = subMenu->addAction("Normal");
+ /* NOTE: see the comments above for the Edit menu for an explanation of why
+ * the shortcuts are like this */
+
+ key = pSEQPrefs->getPrefKey("MapLineNormalKey", preferenceName, "Alt+1");
+ m_action_mapLineStyle_Normal = subMenu->addAction(QString("Normal\t") + key.toString());
m_action_mapLineStyle_Normal->setCheckable(true);
m_action_mapLineStyle_Normal->setData(tMap_Normal);
- key = pSEQPrefs->getPrefKey("MapLineNormalKey", preferenceName, "Alt+1");
- m_action_mapLineStyle_Normal->setShortcut(key);
+ tmpShortcut = new QShortcut(key, m_map);
+ connect(tmpShortcut, SIGNAL(activated()), m_action_mapLineStyle_Normal, SLOT(trigger()));
- m_action_mapLineStyle_DepthFiltered = subMenu->addAction("Depth Filtered");
+ key = pSEQPrefs->getPrefKey("MapLineDepthFilteredKey", preferenceName, "Alt+2");
+ m_action_mapLineStyle_DepthFiltered = subMenu->addAction(
+ QString("Depth Filtered\t") + key.toString());
m_action_mapLineStyle_DepthFiltered->setCheckable(true);
m_action_mapLineStyle_DepthFiltered->setData(tMap_DepthFiltered);
- key = pSEQPrefs->getPrefKey("MapLineDepthFilteredKey", preferenceName, "Alt+2");
- m_action_mapLineStyle_DepthFiltered->setShortcut(key);
+ tmpShortcut = new QShortcut(key, m_map);
+ connect(tmpShortcut, SIGNAL(activated()), m_action_mapLineStyle_DepthFiltered, SLOT(trigger()));
- m_action_mapLineStyle_FadedFloors = subMenu->addAction("Faded Floors");
+ key = pSEQPrefs->getPrefKey("MapLineFadedFloorsKey", preferenceName, "Alt+3");
+ m_action_mapLineStyle_FadedFloors = subMenu->addAction(
+ QString("Faded Floors\t") + key.toString());
m_action_mapLineStyle_FadedFloors->setCheckable(true);
m_action_mapLineStyle_FadedFloors->setData(tMap_FadedFloors);
- key = pSEQPrefs->getPrefKey("MapLineFadedFloorsKey", preferenceName, "Alt+3");
- m_action_mapLineStyle_FadedFloors->setShortcut(key);
+ tmpShortcut = new QShortcut(key, m_map);
+ connect(tmpShortcut, SIGNAL(activated()), m_action_mapLineStyle_FadedFloors, SLOT(trigger()));
connect(subMenu, SIGNAL(triggered(QAction*)), this,
SLOT(select_mapLine(QAction*)));
addMenu(subMenu);
- m_action_spawnDepthFilter = addAction("Spawn Depth Filter", this,
- SLOT(toggle_spawnDepthFilter()));
+ key = pSEQPrefs->getPrefKey("SpawnDepthFilteredKey", preferenceName, "Alt+5");
+ m_action_spawnDepthFilter = addAction(QString("Spawn Depth Filter\t") + key.toString(),
+ this, SLOT(toggle_spawnDepthFilter()));
m_action_spawnDepthFilter->setCheckable(true);
- key = pSEQPrefs->getPrefKey("SpawnDepthFilteredKey", preferenceName, "Alt+5");
- m_action_spawnDepthFilter->setShortcut(key);
+ tmpShortcut = new QShortcut(key, m_map);
+ connect(tmpShortcut, SIGNAL(activated()), m_action_spawnDepthFilter, SLOT(trigger()));
subMenu = new QMenu("Show", m_map);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|