Skip to content

Commit

Permalink
improved engraving accessible tree
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Sep 10, 2021
1 parent 492dce0 commit 6ff8dcf
Show file tree
Hide file tree
Showing 40 changed files with 267 additions and 82 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ option(ENGRAVING_COMPAT_WRITESTYLE_302 "Write style to score xml file" ON)
option(ENGRAVING_COMPAT_WRITEEXCERPTS_302 "Write excerpts to score xml file" ON)
# -----

option(ACCESSIBILITY_LOGGING_ENABLED "Enable accessibility logging" OFF)

option(SOUNDFONT3 "Ogg Vorbis compressed fonts" ON) # Enable Ogg Vorbis compressed fonts, requires Ogg & Vorbis
option(DOWNLOAD_SOUNDFONT "Download the latest soundfont version as part of the build process" ON)

Expand Down
2 changes: 2 additions & 0 deletions build/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
#cmakedefine ENGRAVING_COMPAT_WRITESTYLE_302
#cmakedefine ENGRAVING_COMPAT_WRITEEXCERPTS_302

#cmakedefine ACCESSIBILITY_LOGGING_ENABLED

#cmakedefine SPARKLE_ENABLED
#cmakedefine OPENGL
#cmakedefine SOUNDFONT3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ Rectangle {
itemDelegate: Item {
id: item

Rectangle {
anchors.fill: parent
visible: styleData.value.color ? true : false
color: styleData.value.color ? styleData.value.color : "#ffffff"
}

StyledTextLabel {
id: secLabel
anchors.fill: parent
Expand All @@ -189,6 +195,17 @@ Rectangle {
}
}

FlatButton {
id: btn1
anchors.right: selBtn.left
anchors.rightMargin: 8
height: 16
width: 32
anchors.verticalCenter: parent.verticalCenter
text: "Btn1"
onClicked: elementsModel.click1(styleData.index)
}

FlatButton {
id: selBtn
anchors.right: parent.right
Expand Down
63 changes: 52 additions & 11 deletions src/diagnostics/view/engraving/engravingelementsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,11 @@ QVariant EngravingElementsModel::data(const QModelIndex& index, int role) const
return QVariant();
}

if (item == m_lostItem) {
QVariantMap lostData;
lostData["info"] = "Lost items";
return lostData;
if (item->data().isEmpty()) {
item->setData(makeData(item->element()));
}
return makeData(item->element());

return item->data();
}

QHash<int, QByteArray> EngravingElementsModel::roleNames() const
Expand All @@ -152,11 +151,11 @@ EngravingElementsModel::Item* EngravingElementsModel::itemByModelIndex(const QMo
return m_allItems.value(index.internalId(), nullptr);
}

QVariant EngravingElementsModel::makeData(const Ms::EngravingObject* el) const
QVariantMap EngravingElementsModel::makeData(const Ms::EngravingObject* el) const
{
TRACEFUNC;
if (!el) {
return QVariant();
return QVariantMap();
}

auto formatRect = [](const mu::RectF& r) {
Expand Down Expand Up @@ -208,6 +207,10 @@ QVariant EngravingElementsModel::makeData(const Ms::EngravingObject* el) const
d["selected"] = elementsProvider()->isSelected(el);
d["info"] = info;

if (el->children().size() != size_t(el->treeChildCount())) {
d["color"] = "#ff0000";
}

return d;
}

Expand Down Expand Up @@ -238,8 +241,11 @@ void EngravingElementsModel::reload()
}
}

m_lostItem = createItem(m_rootItem);
findAndAddLost(elements, m_lostItem);
Item* lostItem = createItem(m_rootItem);
QVariantMap lostData;
lostData["info"] = "Lost items";
lostItem->setData(lostData);
findAndAddLost(elements, lostItem);

endResetModel();

Expand Down Expand Up @@ -290,8 +296,8 @@ void EngravingElementsModel::findAndAddLost(const std::list<const Ms::EngravingO

QSet<const Ms::EngravingObject*> used;
for (auto it = m_allItems.begin(); it != m_allItems.end(); ++it) {
const Item& item = it.value();
used.insert(item.element());
const Item* item = it.value();
used.insert(item->element());
}

for (const Ms::EngravingObject* el : elements) {
Expand All @@ -312,12 +318,47 @@ void EngravingElementsModel::select(QModelIndex index, bool arg)
}

elementsProvider()->select(item->element(), arg);
item->setData(QVariantMap());

emit dataChanged(index, index, { rItemData });

dispatcher()->dispatch("diagnostic-notationview-redraw");
}

void EngravingElementsModel::click1(QModelIndex index)
{
//! NOTE For debugging purposes
Item* item = itemByModelIndex(index);
if (!item) {
return;
}

const Ms::EngravingObject* el = item->element();
if (!el) {
return;
}

const Ms::EngravingObject* parent = el->parent();
UNUSED(parent);

const Ms::EngravingObject* parent2 = el->parent(true);
UNUSED(parent2);

const Ms::EngravingObject* treeParent = el->treeParent();
UNUSED(treeParent);

size_t children = el->children().size();
UNUSED(children);

int treeChildren = el->treeChildCount();
UNUSED(treeChildren);

if (parent2 != treeParent) {
int k = 1;
UNUSED(k);
}
}

void EngravingElementsModel::updateInfo()
{
std::list<const Ms::EngravingObject*> elements = elementsProvider()->elements();
Expand Down
9 changes: 6 additions & 3 deletions src/diagnostics/view/engraving/engravingelementsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <QAbstractItemModel>
#include <QHash>
#include <QSet>

#include "modularity/ioc.h"
#include "iengravingelementsprovider.h"
Expand Down Expand Up @@ -60,6 +59,7 @@ class EngravingElementsModel : public QAbstractItemModel
Q_INVOKABLE void reload();

Q_INVOKABLE void select(QModelIndex index, bool arg);
Q_INVOKABLE void click1(QModelIndex index);

signals:
void infoChanged();
Expand Down Expand Up @@ -91,15 +91,19 @@ public slots:
void setElement(const Ms::EngravingObject* el) { m_element = el; }
const Ms::EngravingObject* element() const { return m_element; }

void setData(const QVariantMap& data) { m_data = data; }
const QVariantMap& data() const { return m_data; }

private:
const Ms::EngravingObject* m_element = nullptr;
Item* m_parent = nullptr;
QList<Item*> m_children;
QVariantMap m_data;
};

Item* createItem(Item* parent);
Item* itemByModelIndex(const QModelIndex& index) const;
QVariant makeData(const Ms::EngravingObject* el) const;
QVariantMap makeData(const Ms::EngravingObject* el) const;

void load(const std::list<const Ms::EngravingObject*>& elements, Item* root);
void findAndAddLost(const std::list<const Ms::EngravingObject*>& elements, Item* lossRoot);
Expand All @@ -108,7 +112,6 @@ public slots:
void updateInfo();

Item* m_rootItem = nullptr;
Item* m_lostItem = nullptr;
QHash<quintptr, Item*> m_allItems;

QString m_info;
Expand Down
63 changes: 44 additions & 19 deletions src/engraving/accessibility/accessibleitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

using namespace mu::engraving;
using namespace mu::accessibility;
using namespace Ms;

bool AccessibleItem::enabled = true;

AccessibleItem::AccessibleItem(Ms::EngravingItem* e)
: m_element(e)
Expand Down Expand Up @@ -60,10 +63,20 @@ AccessibleItem* AccessibleItem::clone(Ms::EngravingItem* e) const

void AccessibleItem::setup()
{
if (accessibilityController()) {
accessibilityController()->reg(this);
m_registred = true;
if (!AccessibleItem::enabled) {
return;
}

if (!accessibilityController()) {
return;
}

if (m_element->score()->isPaletteScore()) {
return;
}

accessibilityController()->reg(this);
m_registred = true;
}

bool AccessibleItem::isAvalaible() const
Expand Down Expand Up @@ -143,23 +156,35 @@ const IAccessible* AccessibleItem::accessibleParent() const

size_t AccessibleItem::accessibleChildCount() const
{
return 0;
//! TODO Not completed, please don't remove (igor.korsukov@gmail.com)
// size_t count = static_cast<size_t>(m_element->treeChildCount());
// LOGI() << "count: " << count;
// return count;
}

const IAccessible* AccessibleItem::accessibleChild(size_t) const
{
TRACEFUNC;
size_t count = 0;
for (const EngravingObject* obj : m_element->children()) {
if (obj->isEngravingItem()) {
AccessibleItem* access = Ms::toEngravingItem(obj)->accessible();
if (access && access->isAvalaible()) {
++count;
}
}
}
return count;
}

const IAccessible* AccessibleItem::accessibleChild(size_t i) const
{
TRACEFUNC;
size_t count = 0;
for (const EngravingObject* obj : m_element->children()) {
if (obj->isEngravingItem()) {
AccessibleItem* access = Ms::toEngravingItem(obj)->accessible();
if (access && access->isAvalaible()) {
if (count == i) {
return access;
}
++count;
}
}
}
return nullptr;
//! TODO Not completed, please don't remove (igor.korsukov@gmail.com)
// Ms::ScoreElement* se = m_element->treeChild(static_cast<int>(i));
// if (!se || !se->isEngravingItem()) {
// return nullptr;
// }
// Ms::EngravingItem* p = static_cast<Ms::EngravingItem*>(se);
// return p->accessible();
}

IAccessible::Role AccessibleItem::accessibleRole() const
Expand Down
4 changes: 3 additions & 1 deletion src/engraving/accessibility/accessibleitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AccessibleItem : public accessibility::IAccessible
virtual AccessibleItem* clone(Ms::EngravingItem* e) const;

virtual void setup();
bool isAvalaible() const;

const Ms::EngravingItem* element() const;

Expand All @@ -66,9 +67,10 @@ class AccessibleItem : public accessibility::IAccessible
async::Channel<State, bool> accessibleStateChanged() const override;
// ---

static bool enabled;

private:

bool isAvalaible() const;
AccessibleScore* accessibleScore() const;

Ms::EngravingItem* m_element = nullptr;
Expand Down
49 changes: 47 additions & 2 deletions src/engraving/accessibility/accessiblescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

using namespace mu::engraving;
using namespace mu::accessibility;
using namespace Ms;

AccessibleScore::AccessibleScore(Ms::Score* score)
: m_score(score)
Expand All @@ -33,6 +34,27 @@ AccessibleScore::AccessibleScore(Ms::Score* score)

AccessibleScore::~AccessibleScore()
{
if (m_registred && accessibilityController()) {
accessibilityController()->unreg(this);
}
}

void AccessibleScore::setup()
{
if (!AccessibleItem::enabled) {
return;
}

if (!accessibilityController()) {
return;
}

if (m_score->isPaletteScore()) {
return;
}

accessibilityController()->reg(this);
m_registred = true;
}

void AccessibleScore::setActive(bool arg)
Expand Down Expand Up @@ -83,12 +105,35 @@ const IAccessible* AccessibleScore::accessibleParent() const

size_t AccessibleScore::accessibleChildCount() const
{
return m_children.size();
TRACEFUNC;
size_t count = 0;
for (const EngravingObject* obj : m_score->EngravingObject::children()) {
if (obj->isEngravingItem()) {
AccessibleItem* access = Ms::toEngravingItem(obj)->accessible();
if (access && access->isAvalaible()) {
++count;
}
}
}
return count;
}

const IAccessible* AccessibleScore::accessibleChild(size_t i) const
{
return m_children.at(int(i));
TRACEFUNC;
size_t count = 0;
for (const EngravingObject* obj : m_score->EngravingObject::children()) {
if (obj->isEngravingItem()) {
AccessibleItem* access = Ms::toEngravingItem(obj)->accessible();
if (access && access->isAvalaible()) {
if (count == i) {
return access;
}
++count;
}
}
}
return nullptr;
}

IAccessible::Role AccessibleScore::accessibleRole() const
Expand Down
2 changes: 2 additions & 0 deletions src/engraving/accessibility/accessiblescore.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class AccessibleScore : public accessibility::IAccessible
AccessibleScore(Ms::Score* score);
~AccessibleScore();

void setup();

void setActive(bool arg);

void setFocusedElement(AccessibleItem* e);
Expand Down
Loading

0 comments on commit 6ff8dcf

Please sign in to comment.