Highlight active beam properties cell

This commit is contained in:
Dmitri Ovodok 2019-09-14 15:28:50 +03:00
parent 97d85f2413
commit d1f1233aaf
11 changed files with 100 additions and 13 deletions

View file

@ -2491,5 +2491,29 @@ Fraction Beam::rtick() const
{
return _elements.empty() ? Fraction(0, 1) : _elements.front()->segment()->rtick();
}
}
//---------------------------------------------------------
// iconType
//---------------------------------------------------------
IconType Beam::iconType(Mode mode)
{
switch (mode) {
case Mode::BEGIN:
return IconType::SBEAM;
case Mode::MID:
return IconType::MBEAM;
case Mode::NONE:
return IconType::NBEAM;
case Mode::BEGIN32:
return IconType::BEAM32;
case Mode::BEGIN64:
return IconType::BEAM64;
case Mode::AUTO:
return IconType::AUTOBEAM;
default:
break;
}
return IconType::NONE;
}
}

View file

@ -25,6 +25,7 @@ class Chord;
class System;
class Skyline;
enum class IconType : signed char;
enum class SpannerSegmentType;
struct BeamFragment;
@ -155,6 +156,8 @@ class Beam final : public Element {
void addSkyline(Skyline&);
virtual void triggerLayout() const override;
static IconType iconType(Mode);
};

View file

@ -2294,6 +2294,9 @@ void MuseScore::selectionChanged(SelState selectionState)
void MuseScore::updatePaletteBeamMode(bool unselect)
{
if (paletteWorkspace)
paletteWorkspace->updateCellsState(cs->selection(), unselect);
#if 0 // old palettes code
for (Palette* p : paletteBox->palettes()) {
if (p->name() == "Beam Properties") {
if (unselect) {
@ -2344,6 +2347,7 @@ void MuseScore::updatePaletteBeamMode(bool unselect)
p->update();
}
}
#endif
}
//---------------------------------------------------------
@ -6000,7 +6004,7 @@ void MuseScore::endCmd()
selectionChanged(SelState::NONE);
}
updateInspector();
if (cv && paletteBox)
if (cv)
updatePaletteBeamMode(cv->clickOffElement);
}

View file

@ -19,6 +19,10 @@
#include "palettemodel.h"
#include "libmscore/beam.h"
#include "libmscore/chordrest.h"
#include "libmscore/icon.h"
#include "libmscore/select.h"
#include "palettetree.h"
#include "preferences.h"
@ -30,7 +34,7 @@ namespace Ms {
PaletteTreeModel::PaletteTreeModel(std::unique_ptr<PaletteTree> tree, QObject* parent)
: QAbstractItemModel(parent), _paletteTree(std::move(tree))
{
connect(this, &QAbstractItemModel::dataChanged, this, &PaletteTreeModel::setTreeChanged);
connect(this, &QAbstractItemModel::dataChanged, this, &PaletteTreeModel::onDataChanged);
connect(this, &QAbstractItemModel::layoutChanged, this, &PaletteTreeModel::setTreeChanged);
connect(this, &QAbstractItemModel::modelReset, this, &PaletteTreeModel::setTreeChanged);
connect(this, &QAbstractItemModel::rowsInserted, this, &PaletteTreeModel::setTreeChanged);
@ -272,6 +276,8 @@ QVariant PaletteTreeModel::data(const QModelIndex& index, int role) const
map[PaletteCell::mimeDataFormat] = cell->mimeData();
return map;
}
case CellActiveRole:
return cell->active;
default:
break;
}
@ -446,8 +452,9 @@ QHash<int, QByteArray> PaletteTreeModel::roleNames() const
roles[GridSizeRole] = "gridSize";
roles[DrawGridRole] = "drawGrid";
roles[CustomRole] = "custom";
roles[PaletteExpandedRole] = "expanded";
roles[EditableRole] = "editable";
roles[PaletteExpandedRole] = "expanded";
roles[CellActiveRole] = "cellActive";
return roles;
}
@ -730,6 +737,42 @@ bool PaletteTreeModel::insertRows(int row, int count, const QModelIndex& parent)
return false;
}
//---------------------------------------------------------
// PaletteTreeModel::updateCellsState
//---------------------------------------------------------
void PaletteTreeModel::updateCellsState(const Selection& sel, bool deactivateAll)
{
const ChordRest* cr = sel.cr();
const IconType beamIconType = cr ? Beam::iconType(cr->beamMode()) : IconType::NONE;
if (!sel.isSingle() || !cr)
deactivateAll = true;
const int npalettes = palettes().size();
for (int row = 0; row < npalettes; ++row) {
PalettePanel* palette = palettes()[row].get();
// TODO: should this be turned on for all palettes?
if (palette->type() != PalettePanel::Type::Beam)
continue;
for (int ci = 0; ci < palette->ncells(); ++ci) {
PaletteCellPtr cell = palette->cell(ci);
if (deactivateAll)
cell->active = false;
else if (cell->element && cell->element->isIcon()) {
const Icon* icon = toIcon(cell->element.get());
cell->active = (icon->iconType() == beamIconType);
}
}
const QModelIndex parent = index(row, 0, QModelIndex());
const QModelIndex first = index(0, 0, parent);
const QModelIndex last = index(palette->ncells() - 1, 0, parent);
emit dataChanged(first, last, { CellActiveRole });
}
}
//---------------------------------------------------------
// PaletteTreeModel::findPaletteCell
//---------------------------------------------------------

View file

@ -24,6 +24,8 @@
namespace Ms {
class Selection;
//---------------------------------------------------------
// PaletteCellFilter
/// Interface for filtering elements in a palette
@ -94,7 +96,8 @@ class PaletteTreeModel : public QAbstractItemModel {
GridSizeRole,
DrawGridRole,
PaletteExpandedRole,
PaletteTypeRole
PaletteTypeRole,
CellActiveRole
};
Q_ENUM(PaletteTreeModelRoles);
@ -109,6 +112,7 @@ class PaletteTreeModel : public QAbstractItemModel {
const PalettePanel* iptrToPalettePanel(void* iptr, int* idx = nullptr) const { return const_cast<PaletteTreeModel*>(this)->iptrToPalettePanel(iptr, idx); }
private slots:
void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
void setTreeChanged() { _treeChanged = true; }
public slots:
@ -156,6 +160,8 @@ class PaletteTreeModel : public QAbstractItemModel {
PalettePanel* findPalettePanel(const QModelIndex& index);
PaletteCellConstPtr findCell(const QModelIndex&) const;
PaletteCellPtr findCell(const QModelIndex& index);
void updateCellsState(const Selection&, bool deactivateAll);
};
//---------------------------------------------------------

View file

@ -717,13 +717,10 @@ void PaletteCellIconEngine::paint(QPainter* painter, const QRect& rect, QIcon::M
c.setAlpha(100);
p.fillRect(r, c);
}
// else if (idx == currentIdx) { // TODO: what is this?
// c.setAlpha(50);
// p.fillRect(r, c);
// }
// if (ccp()->at(idx) == 0)
// continue;
// PaletteCell* cc = ccp()->at(idx); // current cell
else if (state == QIcon::On) {
c.setAlpha(60);
p.fillRect(r, c);
}
PaletteCellConstPtr cc = cell();

View file

@ -48,6 +48,7 @@ struct PaletteCell {
bool visible { true };
bool custom { false };
bool active { false };
PaletteCell() = default;
PaletteCell(std::unique_ptr<Element> e, const QString& _name, QString _tag = QString(), qreal _mag = 1.0);

View file

@ -206,6 +206,8 @@ class PaletteWorkspace : public QObject {
void write(XmlWriter&) const;
bool read(XmlReader&);
void updateCellsState(const Selection& sel, bool deactivateAll) { userPalette->updateCellsState(sel, deactivateAll); }
};
} // namespace Ms

View file

@ -33,7 +33,8 @@ void QmlIconView::paint(QPainter* p)
}
const QIcon::Mode mode = _selected ? QIcon::Selected : QIcon::Active;
_icon.paint(p, QRect(0, 0, width(), height()), Qt::AlignCenter, mode);
const QIcon::State state = _active ? QIcon::On : QIcon::Off;
_icon.paint(p, QRect(0, 0, width(), height()), Qt::AlignCenter, mode, state);
}
//---------------------------------------------------------

View file

@ -32,9 +32,11 @@ class QmlIconView : public QQuickPaintedItem {
QColor _color;
QIcon _icon;
bool _selected;
bool _active = false;
Q_PROPERTY(QVariant icon READ icon WRITE setIcon)
Q_PROPERTY(bool selected READ selected WRITE setSelected)
Q_PROPERTY(bool active READ active WRITE setActive)
public:
QmlIconView(QQuickItem* parent = nullptr)
@ -46,6 +48,9 @@ class QmlIconView : public QQuickPaintedItem {
bool selected() const { return _selected; }
void setSelected(bool val) { _selected = val; update(); }
bool active() const { return _active; }
void setActive(bool val) { _active = val; update(); }
void paint(QPainter*) override;
};

View file

@ -344,6 +344,7 @@ GridView {
anchors.fill: parent
icon: model.decoration
selected: paletteCell.selected
active: model.cellActive
}
readonly property var toolTip: model.toolTip