Implemented the general component for inspector's properties

This commit is contained in:
pereverzev_v 2020-06-17 20:33:13 +02:00 committed by pereverzev+v
parent bb98d81b40
commit 397ce12f94
5 changed files with 131 additions and 7 deletions

View file

@ -152,5 +152,6 @@
<file>view/qml/notation/bends/BendPopup.qml</file>
<file>view/qml/notation/tremolobars/TremoloBarSettings.qml</file>
<file>view/qml/notation/tremolobars/TremoloBarPopup.qml</file>
<file>view/qml/common/InspectorPropertyView.qml</file>
</qresource>
</RCC>

View file

@ -370,10 +370,7 @@ QVariant AbstractInspectorModel::valueFromElementUnits(const Ms::Pid& pid, const
PropertyItem* AbstractInspectorModel::buildPropertyItem(const Ms::Pid& propertyId, std::function<void(const int propertyId,
const QVariant& newValue)> onPropertyChangedCallBack)
{
Ms::Sid styleId = styleIdByPropertyId(propertyId);
PropertyItem* newPropertyItem = new PropertyItem(static_cast<int>(propertyId), static_cast<int>(styleId), this);
newPropertyItem->setIsStyled(styleId != Ms::Sid::NOSTYLE);
PropertyItem* newPropertyItem = new PropertyItem(static_cast<int>(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<Ms::Sid>(sid), newStyleValue);
emit requestReloadPropertyItems();
});
return newPropertyItem;
@ -400,6 +399,10 @@ void AbstractInspectorModel::loadPropertyItem(PropertyItem* propertyItem, std::f
Ms::Pid pid = static_cast<Ms::Pid>(propertyItem->propertyId());
Ms::Sid styleId = styleIdByPropertyId(pid);
propertyItem->setStyleId(static_cast<int>(styleId));
propertyItem->setIsStyled(styleId != Ms::Sid::NOSTYLE);
QVariant propertyValue;
QVariant defaultPropertyValue;

View file

@ -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)

View file

@ -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);

View file

@ -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()
}
}
}