diff --git a/inspectors/inspectors_resources.qrc b/inspectors/inspectors_resources.qrc index 2c554b8f38..b23986a5c1 100644 --- a/inspectors/inspectors_resources.qrc +++ b/inspectors/inspectors_resources.qrc @@ -152,5 +152,6 @@ view/qml/notation/bends/BendPopup.qml view/qml/notation/tremolobars/TremoloBarSettings.qml view/qml/notation/tremolobars/TremoloBarPopup.qml + view/qml/common/InspectorPropertyView.qml diff --git a/inspectors/models/abstractinspectormodel.cpp b/inspectors/models/abstractinspectormodel.cpp index c9914df08a..931c4e91e4 100644 --- a/inspectors/models/abstractinspectormodel.cpp +++ b/inspectors/models/abstractinspectormodel.cpp @@ -370,10 +370,7 @@ QVariant AbstractInspectorModel::valueFromElementUnits(const Ms::Pid& pid, const PropertyItem* AbstractInspectorModel::buildPropertyItem(const Ms::Pid& propertyId, std::function onPropertyChangedCallBack) { - Ms::Sid styleId = styleIdByPropertyId(propertyId); - - PropertyItem* newPropertyItem = new PropertyItem(static_cast(propertyId), static_cast(styleId), this); - newPropertyItem->setIsStyled(styleId != Ms::Sid::NOSTYLE); + PropertyItem* newPropertyItem = new PropertyItem(static_cast(propertyId), this); auto callback = onPropertyChangedCallBack; @@ -386,6 +383,8 @@ PropertyItem* AbstractInspectorModel::buildPropertyItem(const Ms::Pid& propertyI connect(newPropertyItem, &PropertyItem::propertyModified, this, callback); connect(newPropertyItem, &PropertyItem::applyToStyleRequested, this, [this] (const int sid, const QVariant& newStyleValue) { updateStyleValue(static_cast(sid), newStyleValue); + + emit requestReloadPropertyItems(); }); return newPropertyItem; @@ -400,6 +399,10 @@ void AbstractInspectorModel::loadPropertyItem(PropertyItem* propertyItem, std::f Ms::Pid pid = static_cast(propertyItem->propertyId()); + Ms::Sid styleId = styleIdByPropertyId(pid); + propertyItem->setStyleId(static_cast(styleId)); + propertyItem->setIsStyled(styleId != Ms::Sid::NOSTYLE); + QVariant propertyValue; QVariant defaultPropertyValue; diff --git a/inspectors/models/propertyitem.cpp b/inspectors/models/propertyitem.cpp index ad7ecfdf77..79a669b79c 100644 --- a/inspectors/models/propertyitem.cpp +++ b/inspectors/models/propertyitem.cpp @@ -1,6 +1,6 @@ #include "propertyitem.h" -PropertyItem::PropertyItem(const int propertyId, const int styleId, QObject* parent) : QObject(parent) +PropertyItem::PropertyItem(const int propertyId, QObject* parent) : QObject(parent) { m_propertyId = propertyId; } @@ -10,6 +10,8 @@ void PropertyItem::fillValues(const QVariant& currentValue, const QVariant& defa updateCurrentValue(currentValue); setDefaultValue(defaultValue); + + emit isModifiedChanged(isModified()); } void PropertyItem::updateCurrentValue(const QVariant& currentValue) @@ -17,7 +19,6 @@ void PropertyItem::updateCurrentValue(const QVariant& currentValue) m_currentValue = currentValue; emit isUndefinedChanged(isUndefined()); - emit isModifiedChanged(isModified()); emit valueChanged(m_currentValue); } @@ -66,6 +67,11 @@ bool PropertyItem::isModified() const return m_currentValue != m_defaultValue; } +void PropertyItem::setStyleId(const int styleId) +{ + m_styleId = styleId; +} + void PropertyItem::setValue(const QVariant& value) { if (m_currentValue == value) @@ -74,6 +80,7 @@ void PropertyItem::setValue(const QVariant& value) updateCurrentValue(value); emit propertyModified(m_propertyId, m_currentValue); + emit isModifiedChanged(isModified()); } void PropertyItem::setDefaultValue(const QVariant& defaultValue) diff --git a/inspectors/models/propertyitem.h b/inspectors/models/propertyitem.h index a8471dfe00..73bb8fb8af 100644 --- a/inspectors/models/propertyitem.h +++ b/inspectors/models/propertyitem.h @@ -16,7 +16,7 @@ class PropertyItem : public QObject Q_PROPERTY(bool isModified READ isModified NOTIFY isModifiedChanged) public: - explicit PropertyItem(const int propertyId, const int styleId, QObject* parent = nullptr); + explicit PropertyItem(const int propertyId, QObject* parent = nullptr); void fillValues(const QVariant& currentValue, const QVariant& defaultValue); void updateCurrentValue(const QVariant& currentValue); @@ -32,6 +32,8 @@ public: bool isStyled() const; bool isModified() const; + void setStyleId(const int styleId); + public slots: void setValue(const QVariant& value); void setDefaultValue(const QVariant& defaultValue); diff --git a/inspectors/view/qml/common/InspectorPropertyView.qml b/inspectors/view/qml/common/InspectorPropertyView.qml new file mode 100644 index 0000000000..9e889ba72f --- /dev/null +++ b/inspectors/view/qml/common/InspectorPropertyView.qml @@ -0,0 +1,111 @@ +import QtQuick 2.0 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 1.4 +import QtQuick.Controls 2.2 +import MuseScore.UiComponents 1.0 +import MuseScore.Ui 1.0 + +Column { + id: root + + property QtObject propertyItem: null + + property alias titleText: titleLabel.text + property bool isStyled: propertyItem ? propertyItem.isStyled : false + property bool isModified: propertyItem ? propertyItem.isModified : false + + width: parent.width + + spacing: 8 + + Item { + height: contentRow.implicitHeight + width: parent.width + + RowLayout { + id: contentRow + + width: parent.width + + spacing: 4 + + StyledTextLabel { + id: titleLabel + + Layout.alignment: Qt.AlignLeft + Layout.fillWidth: true + Layout.maximumWidth: parent.width/2 + + horizontalAlignment: Text.AlignLeft + } + + ContextMenu { + id: menu + + Layout.alignment: Qt.AlignRight + Layout.fillWidth: true + Layout.maximumWidth: 24 + Layout.preferredHeight: 24 + Layout.preferredWidth: 24 + + Action { + id: resetToDefaultAction + + checkable: false + enabled: root.isModified + + onTriggered: { + menu.forceClose() + + if (propertyItem) { + propertyItem.resetToDefault() + } + } + } + + Action { + id: applyToStyleAction + + checkable: true + checked: !root.isModified + enabled: root.isModified + + onTriggered: { + menu.forceClose() + + if (propertyItem) { + propertyItem.applyToStyle() + } + } + } + + function updateMenuModel() { + menu.clearMenuItems() + + if (root.isStyled) { + menu.addMenuItem(qsTr("Reset to style default"), resetToDefaultAction) + menu.addMenuItem(qsTr("Set as style"), applyToStyleAction) + } else { + menu.addMenuItem( qsTr("Reset to default"), resetToDefaultAction) + } + } + } + } + + MouseArea { + anchors.fill: contentRow + hoverEnabled: true + propagateComposedEvents: true + + onContainsMouseChanged: { + menu.hovered = containsMouse + } + } + } + + onPropertyItemChanged: { + if (propertyItem) { + menu.updateMenuModel() + } + } +}