forked from musescore/MuseScore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #301789: Accessibility: no speech for keysig chooser +collect_art…
…ifacts Re-implement the New Score Wizard's key signature chooser as a QListView using the same model as is used by the QML palettes. QListViews are accessible by default.
- Loading branch information
Showing
6 changed files
with
182 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
//============================================================================= | ||
// PaletteListView | ||
// | ||
// Copyright (C) 2020 Peter Jonas | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License version 2 | ||
// as published by the Free Software Foundation and appearing in | ||
// the file LICENCE.GPL | ||
//============================================================================= | ||
|
||
#include "palettelistview.h" | ||
|
||
#include "palettemodel.h" | ||
|
||
namespace Ms { | ||
|
||
//--------------------------------------------------------- | ||
// PaletteListView::PaletteListView | ||
//--------------------------------------------------------- | ||
|
||
PaletteListView::PaletteListView(PalettePanel* panel, QWidget* parent) | ||
: QListView(parent) | ||
{ | ||
setViewMode(QListView::IconMode); | ||
setMovement(QListView::Static); | ||
setResizeMode(QListView::Adjust); | ||
setIconSize(panel->gridSize()); | ||
setSpacing(-5); // zero spacing still has a large gap between icons | ||
|
||
PaletteTree* tree = new PaletteTree(); | ||
tree->append(panel); | ||
|
||
PaletteTreeModel* model = new PaletteTreeModel(tree); | ||
QModelIndex parentCategory = model->index(0, 0, QModelIndex()); | ||
|
||
setModel(model); | ||
setRootIndex(parentCategory); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// PaletteListView::currentCell | ||
//--------------------------------------------------------- | ||
|
||
const PaletteCell* PaletteListView::currentCell() const | ||
{ | ||
return model()->data(currentIndex(), PaletteTreeModel::PaletteCellRole).value<const PaletteCell*>(); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// PaletteListView::currentElement | ||
//--------------------------------------------------------- | ||
|
||
Element* PaletteListView::currentElement() const | ||
{ | ||
return currentCell()->element.get(); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// PaletteListView::focusNextMatchingCell | ||
//--------------------------------------------------------- | ||
|
||
void PaletteListView::focusNextMatchingCell(const QString& str) | ||
{ | ||
const int nextRow = (currentRow() == count() - 1) ? 0 : currentRow() + 1; | ||
const QModelIndex nextIndex = model()->index(nextRow, 0, rootIndex()); | ||
const auto matchedIndexList = model()->match(nextIndex, Qt::ToolTipRole, str); | ||
if (!matchedIndexList.isEmpty()) | ||
setCurrentIndex(matchedIndexList.first()); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// onlyContainsVisibleCharacters | ||
/// Return true if string is non-empty and contains no whitespace | ||
/// or control characters, otherwise false. | ||
//--------------------------------------------------------- | ||
|
||
static bool onlyContainsVisibleCharacters(const QString& str) | ||
{ | ||
constexpr auto options = QRegularExpression::UseUnicodePropertiesOption; | ||
const QRegularExpression pattern("^[[:graph:]]+$", options); | ||
return pattern.match(str).hasMatch(); | ||
} | ||
|
||
//--------------------------------------------------------- | ||
// PaletteListView::keyPressEvent | ||
//--------------------------------------------------------- | ||
|
||
void PaletteListView::keyPressEvent(QKeyEvent* event) | ||
{ | ||
const int key = event->key(); | ||
switch (key) { | ||
case Qt::Key_Down: | ||
case Qt::Key_Right: | ||
incrementCurrentRow(); | ||
break; | ||
case Qt::Key_Up: | ||
case Qt::Key_Left: | ||
decrementCurrentRow(); | ||
break; | ||
default: | ||
if (onlyContainsVisibleCharacters(event->text())) | ||
focusNextMatchingCell(event->text()); | ||
else | ||
QListView::keyPressEvent(event); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//============================================================================= | ||
// PaletteListView | ||
// | ||
// Copyright (C) 2020 Peter Jonas | ||
// | ||
// This program is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License version 2 | ||
// as published by the Free Software Foundation and appearing in | ||
// the file LICENCE.GPL | ||
//============================================================================= | ||
|
||
#ifndef __PALETTELISTVIEW_H__ | ||
#define __PALETTELISTVIEW_H__ | ||
|
||
namespace Ms { | ||
|
||
class Element; | ||
class PalettePanel; | ||
|
||
struct PaletteCell; | ||
|
||
//--------------------------------------------------------- | ||
// PaletteListView | ||
/// Display a simple icon list of elements from a single | ||
/// palette category (e.g. key signatures). | ||
//--------------------------------------------------------- | ||
|
||
class PaletteListView : public QListView // see also QListWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
PaletteListView(PalettePanel* panel, QWidget* parent = nullptr); | ||
const PaletteCell* currentCell() const; | ||
Element* currentElement() const; | ||
void focusNextMatchingCell(const QString& str); | ||
|
||
int count() { return model()->rowCount(rootIndex()); } | ||
int currentRow() { return currentIndex().row(); } | ||
void setCurrentRow(int row) { setCurrentIndex(model()->index(row, 0, rootIndex())); } | ||
|
||
void incrementCurrentRow() | ||
{ | ||
if (currentRow() < (count() - 1)) | ||
setCurrentRow(currentRow() + 1); | ||
} | ||
|
||
void decrementCurrentRow() | ||
{ | ||
if (currentRow() > 0) | ||
setCurrentRow(currentRow() - 1); | ||
} | ||
|
||
protected: | ||
virtual void keyPressEvent(QKeyEvent* event) override; | ||
|
||
}; | ||
} | ||
|
||
#endif // __PALETTELISTVIEW_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters