inspector fixes

This commit is contained in:
ws 2013-03-13 12:19:27 +01:00
parent 67cde95183
commit 46a4b3db2c
9 changed files with 85 additions and 64 deletions

View file

@ -23,6 +23,7 @@ struct PropertyData {
P_ID id;
bool link; // change for linked elements
const char* name; // xml name of property
bool spatium; // show real as spatium value
P_TYPE type;
};
@ -50,8 +51,8 @@ static const PropertyData propertyList[] = {
{ P_STEM_DIRECTION, true, "StemDirection", T_DIRECTION },
{ P_NO_STEM, false, "", T_INT },
{ P_SLUR_DIRECTION, false, "", T_INT },
{ P_LEADING_SPACE, false, "", T_INT },
{ P_TRAILING_SPACE, false, "", T_INT },
{ P_LEADING_SPACE, false, "", T_SPATIUM },
{ P_TRAILING_SPACE, false, "", T_SPATIUM },
{ P_DISTRIBUTE, false, "distribute", T_BOOL },
{ P_MIRROR_HEAD, false, "mirror", T_DIRECTION_H },
@ -79,8 +80,8 @@ static const PropertyData propertyList[] = {
{ P_GROW_RIGHT, false, "growRight", T_REAL },
{ P_BOX_HEIGHT, false, "height", T_REAL },
{ P_BOX_WIDTH, false, "width", T_REAL },
{ P_TOP_GAP, false, "topGap", T_SREAL },
{ P_BOTTOM_GAP, false, "bottomGap", T_SREAL },
{ P_TOP_GAP, false, "topGap", T_REAL },
{ P_BOTTOM_GAP, false, "bottomGap", T_REAL },
{ P_LEFT_MARGIN, false, "leftMargin", T_REAL },
{ P_RIGHT_MARGIN, false, "rightMargin", T_REAL },
{ P_TOP_MARGIN, false, "topMargin", T_REAL },
@ -192,7 +193,8 @@ QVariant getProperty(P_ID id, XmlReader& e)
case T_INT:
return QVariant(e.readInt());
case T_REAL:
case T_SREAL:
case T_SPATIUM:
case T_SP_REAL:
return QVariant(e.readDouble());
case T_FRACTION:
return QVariant::fromValue(e.readFraction());

View file

@ -147,7 +147,8 @@ enum P_TYPE {
T_BOOL,
T_INT,
T_REAL,
T_SREAL,
T_SPATIUM,
T_SP_REAL,
T_FRACTION,
T_POINT,
T_SIZE,

View file

@ -65,7 +65,7 @@ class SigEvent {
typedef std::map<const int, SigEvent>::iterator iSigEvent;
typedef std::map<const int, SigEvent>::const_iterator ciSigEvent;
class TimeSigMap : public std::map<const int, SigEvent > {
class TimeSigMap : public std::map<int, SigEvent > {
void normalize();
public:

View file

@ -462,7 +462,8 @@ void Xml::tag(P_ID id, QVariant data, QVariant defaultData)
case T_BOOL:
case T_SUBTYPE:
case T_INT:
case T_SREAL:
case T_SPATIUM:
case T_SP_REAL:
case T_REAL:
case T_SCALE:
case T_POINT:
@ -662,7 +663,7 @@ QString Xml::xmlString(const QString& s)
case 0x1C:
case 0x1D:
case 0x1E:
case 0x1F:
case 0x1F:
break;
default:
escaped += QChar(c);

View file

@ -122,11 +122,9 @@ void Inspector::setElement(Element* e)
void Inspector::setElements(const QList<Element*>& l)
{
if (_inspectorEdit) { // if within an inspector-originated edit
_inspectorEdit = false; // reset flag
if (_el == l) // if element is not changing...
return; // ...do nothing
}
if (_inspectorEdit) // if within an inspector-originated edit
return;
Element* e = l.isEmpty() ? 0 : l[0];
if (e == 0 || _element == 0 || (_el != l)) {
_el = l;

View file

@ -234,7 +234,6 @@ class Inspector : public QDockWidget {
void setElements(const QList<Element*>&);
Element* element() const { return _element; }
const QList<Element*>& el() const { return _el; }
bool inspectorEdit() const { return _inspectorEdit; }
void setInspectorEdit(bool val) { _inspectorEdit = val; }
};

View file

@ -45,26 +45,31 @@ QVariant InspectorBase::getValue(const InspectorItem& ii) const
{
QWidget* w = ii.w;
QVariant v;
if (qobject_cast<QDoubleSpinBox*>(w))
return w->property("value");
v = w->property("value");
else if (qobject_cast<QSpinBox*>(w))
return w->property("value");
v = w->property("value");
else if (qobject_cast<QComboBox*>(w)) {
QComboBox* cb = qobject_cast<QComboBox*>(w);
int val = cb->currentIndex();
if (cb->itemData(val).isValid())
val = cb->itemData(val).toInt();
return val;
v = val;
}
else if (qobject_cast<QCheckBox*>(w))
return w->property("checked");
v = w->property("checked");
else if (qobject_cast<QLineEdit*>(w))
return w->property("text");
v = w->property("text");
else if (qobject_cast<Awl::ColorLabel*>(w))
return static_cast<Awl::ColorLabel*>(w)->color();
v = static_cast<Awl::ColorLabel*>(w)->color();
else
qFatal("not supported widget %s", w->metaObject()->className());
return QVariant();
P_ID id = ii.t;
P_TYPE t = propertyType(id);
if (t == T_POINT)
v = v.toDouble() * inspector->element()->score()->spatium();
return v;
}
//---------------------------------------------------------
@ -72,10 +77,15 @@ QVariant InspectorBase::getValue(const InspectorItem& ii) const
// set gui element value
//---------------------------------------------------------
void InspectorBase::setValue(const InspectorItem& ii, const QVariant& val)
void InspectorBase::setValue(const InspectorItem& ii, QVariant val)
{
QWidget* w = ii.w;
P_ID id = ii.t;
P_TYPE t = propertyType(id);
if (t == T_POINT)
val = val.toDouble() / inspector->element()->score()->spatium();
if (qobject_cast<QDoubleSpinBox*>(w))
static_cast<QDoubleSpinBox*>(w)->setValue(val.toDouble());
else if (qobject_cast<QSpinBox*>(w))
@ -181,39 +191,50 @@ void InspectorBase::setElement()
w->blockSignals(true);
setValue(ii, val);
w->blockSignals(false);
bool valuesAreDifferent = false;
if (inspector->el().size() > 1) {
foreach(Element* e, inspector->el()) {
for (int k = 0; k < ii.parent; ++k)
e = e->parent();
if (pt == T_SIZE || pt == T_SCALE) {
QSizeF sz = e->getProperty(id).toSizeF();
if (ii.sv == 0)
valuesAreDifferent = sz.width() != val.toDouble();
else
valuesAreDifferent = sz.height() != val.toDouble();
}
else if (pt == T_POINT) {
QPointF sz = e->getProperty(id).toPointF();
if (ii.sv == 0)
valuesAreDifferent = sz.x() != val.toDouble();
else
valuesAreDifferent = sz.y() != val.toDouble();
}
else
valuesAreDifferent = e->getProperty(id) != val;
if (valuesAreDifferent)
break;
}
}
w->setEnabled(!valuesAreDifferent);
if (ii.r)
ii.r->setEnabled(!isDefault(ii) || valuesAreDifferent);
checkDifferentValues(ii);
}
}
//---------------------------------------------------------
// checkDifferentValues
//---------------------------------------------------------
void InspectorBase::checkDifferentValues(const InspectorItem& ii)
{
bool valuesAreDifferent = false;
if (inspector->el().size() > 1) {
P_ID id = ii.t;
P_TYPE pt = propertyType(id);
QVariant val = getValue(ii);
foreach(Element* e, inspector->el()) {
for (int k = 0; k < ii.parent; ++k)
e = e->parent();
if (pt == T_SIZE || pt == T_SCALE) {
QSizeF sz = e->getProperty(id).toSizeF();
if (ii.sv == 0)
valuesAreDifferent = sz.width() != val.toDouble();
else
valuesAreDifferent = sz.height() != val.toDouble();
}
else if (pt == T_POINT) {
QPointF sz = e->getProperty(id).toPointF();
if (ii.sv == 0)
valuesAreDifferent = sz.x() != val.toDouble();
else
valuesAreDifferent = sz.y() != val.toDouble();
}
else
valuesAreDifferent = e->getProperty(id) != val;
if (valuesAreDifferent)
break;
}
}
ii.w->setEnabled(!valuesAreDifferent);
if (ii.r)
ii.r->setEnabled(!isDefault(ii) || valuesAreDifferent);
}
//---------------------------------------------------------
// valueChanged
//---------------------------------------------------------
@ -221,9 +242,6 @@ void InspectorBase::setElement()
void InspectorBase::valueChanged(int idx)
{
const InspectorItem& ii = iList[idx];
if (ii.r)
ii.r->setEnabled(!isDefault(ii));
P_ID id = ii.t;
P_TYPE pt = propertyType(id);
QVariant val2 = getValue(ii);
@ -264,9 +282,11 @@ void InspectorBase::valueChanged(int idx)
score->undoChangeProperty(e, id, val2);
}
}
score->setLayoutAll(true); // ?
inspector->setInspectorEdit(true);
checkDifferentValues(ii);
score->endCmd();
mscore->endCmd();
inspector->setInspectorEdit(false);
}
//---------------------------------------------------------
@ -283,6 +303,7 @@ void InspectorBase::resetClicked(int i)
QVariant def = e->propertyDefault(id);
QWidget* w = ii.w;
w->blockSignals(true);
if (qobject_cast<QDoubleSpinBox*>(w))
static_cast<QDoubleSpinBox*>(w)->setValue(def.toDouble());
else if (qobject_cast<QSpinBox*>(w))
@ -293,12 +314,13 @@ void InspectorBase::resetClicked(int i)
static_cast<QCheckBox*>(w)->setChecked(def.toBool());
else if (qobject_cast<QLineEdit*>(w))
static_cast<QLineEdit*>(w)->setText(def.toString());
else if (qobject_cast<Awl::ColorLabel*>(w)) {
else if (qobject_cast<Awl::ColorLabel*>(w))
static_cast<Awl::ColorLabel*>(w)->setColor(def.value<QColor>());
valueChanged(i);
}
else
qFatal("not supported widget %s", w->metaObject()->className());
w->blockSignals(false);
valueChanged(i);
}
//---------------------------------------------------------

View file

@ -42,6 +42,7 @@ class InspectorBase : public QWidget {
QSignalMapper* valueMapper;
bool dirty() const;
void checkDifferentValues(const InspectorItem&);
protected slots:
virtual void valueChanged(int idx);
@ -52,7 +53,7 @@ class InspectorBase : public QWidget {
QVBoxLayout* _layout;
Inspector* inspector;
virtual void setValue(const InspectorItem&, const QVariant&);
virtual void setValue(const InspectorItem&, QVariant);
QVariant getValue(const InspectorItem&) const;
bool isDefault(const InspectorItem&);
void mapSignals();

View file

@ -279,12 +279,9 @@ void ScoreView::createElementPropertyMenu(Element* e, QMenu* popup)
popup->addAction(tr("Slur Properties..."))->setData("slur-props");
}
else if (e->type() == Element::REST) {
Rest* rest = static_cast<Rest*>(e);
genPropertyMenu1(e, popup);
}
else if (e->type() == Element::NOTE) {
Note* note = static_cast<Note*>(e);
QAction* b = popup->actions()[0];
QAction* a = popup->insertSeparator(b);
a->setText(tr("Staff"));