Fixed navigation for table widget

This commit is contained in:
Eism 2021-11-15 10:00:20 +02:00
parent 1aa603cd9d
commit 56bd962114
5 changed files with 135 additions and 0 deletions

View file

@ -122,6 +122,8 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/view/mainwindowprovider.h
${CMAKE_CURRENT_LIST_DIR}/view/focuslistener.cpp
${CMAKE_CURRENT_LIST_DIR}/view/focuslistener.h
${CMAKE_CURRENT_LIST_DIR}/view/widgetnavigationfix.cpp
${CMAKE_CURRENT_LIST_DIR}/view/widgetnavigationfix.h
${CMAKE_CURRENT_LIST_DIR}/dev/interactivetestsmodel.cpp
${CMAKE_CURRENT_LIST_DIR}/dev/interactivetestsmodel.h

View file

@ -0,0 +1,68 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "widgetnavigationfix.h"
#include <QWidget>
#include <QTableWidget>
using namespace mu::ui;
bool WidgetNavigationFix::fixNavigationForTableWidget(const WidgetNavigationFix::NavigationChain* chain, int key)
{
QTableWidget* tableWidget = qobject_cast<QTableWidget*>(chain->widget);
if (!tableWidget || !tableWidget->hasFocus()) {
return false;
}
switch (key) {
case Qt::Key_Tab: {
if (!chain->nextWidget) {
return false;
}
auto lastItem = tableWidget->item(tableWidget->rowCount() - 1, tableWidget->columnCount() - 1);
if (lastItem == tableWidget->currentItem()) {
chain->nextWidget->setFocus();
return true;
}
break;
}
case Qt::Key_Backtab: {
if (!chain->prevWidget) {
return false;
}
auto firstItem = tableWidget->item(0, 0);
if (firstItem == tableWidget->currentItem()) {
chain->prevWidget->setFocus();
return true;
}
break;
}
default:
break;
}
return false;
}

View file

@ -0,0 +1,42 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MU_UI_WIDGETNAVIGATIONFIX_H
#define MU_UI_WIDGETNAVIGATIONFIX_H
class QWidget;
namespace mu::ui {
class WidgetNavigationFix
{
public:
struct NavigationChain {
QWidget* widget = nullptr;
QWidget* nextWidget = nullptr;
QWidget* prevWidget = nullptr;
};
static bool fixNavigationForTableWidget(const NavigationChain* chain, int key);
};
}
#endif // MU_UI_WIDGETNAVIGATIONFIX_H

View file

@ -31,6 +31,7 @@
#include "notation/inotationelements.h"
#include "global/widgetstatestore.h"
#include "ui/view/iconcodes.h"
#include "ui/view/widgetnavigationfix.h"
static const int ITEM_ACCESSIBLE_TITLE_ROLE = Qt::UserRole + 1;
@ -62,6 +63,11 @@ MeasurePropertiesDialog::MeasurePropertiesDialog(QWidget* parent)
}
WidgetStateStore::restoreGeometry(this);
//! NOTE: It is necessary for the correct start of navigation in the dialog
setFocus();
qApp->installEventFilter(this);
}
MeasurePropertiesDialog::MeasurePropertiesDialog(const MeasurePropertiesDialog& dialog)
@ -141,6 +147,21 @@ void MeasurePropertiesDialog::gotoPreviousMeasure()
m_notation->notationChanged().notify();
}
bool MeasurePropertiesDialog::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
if (keyEvent
&& WidgetNavigationFix::fixNavigationForTableWidget(
new WidgetNavigationFix::NavigationChain { staves, actualZ, buttonBox },
keyEvent->key())) {
return true;
}
}
return QDialog::eventFilter(obj, event);
}
//---------------------------------------------------------
// setMeasure
//---------------------------------------------------------

View file

@ -53,6 +53,8 @@ private slots:
void gotoPreviousMeasure();
private:
bool eventFilter(QObject* obj, QEvent* event) override;
void initMeasure();
void apply();