|
3 | 3 | #include <QCheckBox> |
4 | 4 | #include <QDialogButtonBox> |
5 | 5 | #include <QInputDialog> |
| 6 | +#include <QKeyEvent> |
6 | 7 | #include <QList> |
7 | 8 | #include <QListWidget> |
8 | 9 | #include <QModelIndex> |
@@ -152,6 +153,29 @@ void WTrackMenu::closeEvent(QCloseEvent* event) { |
152 | 153 | emit trackMenuVisible(false); |
153 | 154 | } |
154 | 155 |
|
| 156 | +bool WTrackMenu::eventFilter(QObject* pObj, QEvent* e) { |
| 157 | + // If a checkbox in a QWidgetAction is focused, Left/Right keys are translated |
| 158 | + // to Up/Down which prevents closing the submenus with Left key like in other |
| 159 | + // submenus. |
| 160 | + // We simply call hide() of the submenu if Left is pressed. |
| 161 | + // We ignore Right. |
| 162 | + // Don't continue (close track menu) if the checkbox is at the top level. |
| 163 | + if (pObj->parent() != this && e->type() == QEvent::KeyPress) { |
| 164 | + QCheckBox* pCB = qobject_cast<QCheckBox*>(pObj); |
| 165 | + QKeyEvent* pKE = static_cast<QKeyEvent*>(e); |
| 166 | + if (!pCB || !pKE) { |
| 167 | + return QObject::eventFilter(pObj, e); |
| 168 | + } |
| 169 | + if (pKE->key() == Qt::Key_Left) { |
| 170 | + pCB->parentWidget()->hide(); |
| 171 | + return true; |
| 172 | + } else if (pKE->key() == Qt::Key_Right) { |
| 173 | + return true; |
| 174 | + } |
| 175 | + } |
| 176 | + return QObject::eventFilter(pObj, e); |
| 177 | +} |
| 178 | + |
155 | 179 | void WTrackMenu::popup(const QPoint& pos, QAction* at) { |
156 | 180 | if (isEmpty()) { |
157 | 181 | return; |
@@ -236,6 +260,16 @@ void WTrackMenu::createMenus() { |
236 | 260 | } |
237 | 261 | m_pSearchRelatedMenu->setEnabled( |
238 | 262 | !m_pSearchRelatedMenu->isEmpty()); |
| 263 | + if (!m_pSearchRelatedMenu->isEmpty()) { |
| 264 | + // We're interested in keypress Qt::Key_Left, so use our |
| 265 | + // event filter like we do for the crate checkboxes. |
| 266 | + for (const auto pObj : m_pSearchRelatedMenu->children()) { |
| 267 | + QCheckBox* pCB = qobject_cast<QCheckBox*>(pObj); |
| 268 | + if (pCB) { |
| 269 | + pCB->installEventFilter(this); |
| 270 | + } |
| 271 | + } |
| 272 | + } |
239 | 273 | }); |
240 | 274 | connect(m_pSearchRelatedMenu, |
241 | 275 | &WSearchRelatedTracksMenu::triggerSearch, |
@@ -1499,6 +1533,8 @@ void WTrackMenu::slotPopulateCrateMenu() { |
1499 | 1533 | m_pCrateMenu); |
1500 | 1534 | pCheckBox->setProperty("crateId", QVariant::fromValue(crate.getId())); |
1501 | 1535 | pCheckBox->setEnabled(!crate.isLocked()); |
| 1536 | + // We're interested in keypress Qt::Key_Left |
| 1537 | + pCheckBox->installEventFilter(this); |
1502 | 1538 | // Strangely, the normal styling of QActions does not automatically |
1503 | 1539 | // apply to QWidgetActions. The :selected pseudo-state unfortunately |
1504 | 1540 | // does not work with QWidgetAction. :hover works for selecting items |
|
0 commit comments