Skip to content

Commit daea458

Browse files
committed
Add frames to palette
1 parent 444125b commit daea458

File tree

8 files changed

+81
-5
lines changed

8 files changed

+81
-5
lines changed

src/engraving/dom/box.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ static const String FRET_BOX_DIAGRAMS_SEPARATOR = u",";
6262
Box::Box(const ElementType& type, System* parent)
6363
: MeasureBase(type, parent)
6464
{
65+
m_iconFont = Font(configuration()->iconsFontFamily(), Font::Type::Icon);
66+
m_iconFont.setPointSizeF(UI_ICONS_DEFAULT_FONT_SIZE);
67+
switch (type) {
68+
case ElementType::FBOX:
69+
m_iconCode = 0xF491;
70+
break;
71+
case ElementType::HBOX:
72+
m_iconCode = 0xEF6D;
73+
break;
74+
case ElementType::TBOX:
75+
m_iconCode = 0xEF6E;
76+
break;
77+
case ElementType::VBOX:
78+
m_iconCode = 0xEF6C;
79+
break;
80+
default:
81+
break;
82+
}
6583
}
6684

6785
//---------------------------------------------------------

src/engraving/dom/box.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "measurebase.h"
2626
#include "property.h"
2727

28+
#include "draw/types/font.h"
29+
2830
namespace mu::engraving {
2931
//---------------------------------------------------------
3032
// Box
@@ -88,6 +90,10 @@ class Box : public MeasureBase
8890
bool canBeExcludedFromOtherParts() const override { return true; }
8991
void manageExclusionFromParts(bool exclude) override;
9092

93+
// For use in palettes
94+
char16_t iconCode() const { return m_iconCode; }
95+
const muse::draw::Font& iconFont() const { return m_iconFont; }
96+
9197
private:
9298
Spatium m_boxWidth; // only valid for HBox
9399
Spatium m_boxHeight; // only valid for VBox
@@ -100,6 +106,9 @@ class Box : public MeasureBase
100106
double m_topMargin = 0.0;
101107
double m_bottomMargin = 0.0;
102108
bool m_isAutoSizeEnabled = true;
109+
110+
char16_t m_iconCode = 0;
111+
muse::draw::Font m_iconFont;
103112
};
104113

105114
//---------------------------------------------------------

src/engraving/rendering/single/singledraw.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "dom/barline.h"
3939
#include "dom/beam.h"
4040
#include "dom/bend.h"
41+
#include "dom/box.h"
4142
#include "dom/bracket.h"
4243
#include "dom/breath.h"
4344

@@ -191,6 +192,8 @@ void SingleDraw::drawItem(const EngravingItem* item, Painter* painter, const Pai
191192
case ElementType::EXPRESSION: draw(item_cast<const Expression*>(item), painter, opt);
192193
break;
193194

195+
case ElementType::FBOX: draw(item_cast<const Box*>(item), painter, opt);
196+
break;
194197
case ElementType::FERMATA: draw(item_cast<const Fermata*>(item), painter, opt);
195198
break;
196199
case ElementType::FIGURED_BASS: draw(item_cast<const FiguredBass*>(item), painter, opt);
@@ -223,6 +226,8 @@ void SingleDraw::drawItem(const EngravingItem* item, Painter* painter, const Pai
223226
break;
224227
case ElementType::HARMONY: draw(item_cast<const Harmony*>(item), painter, opt);
225228
break;
229+
case ElementType::HBOX: draw(item_cast<const Box*>(item), painter, opt);
230+
break;
226231
case ElementType::HOOK: draw(item_cast<const Hook*>(item), painter, opt);
227232
break;
228233

@@ -318,6 +323,8 @@ void SingleDraw::drawItem(const EngravingItem* item, Painter* painter, const Pai
318323

319324
case ElementType::TAPPING: draw(item_cast<const Tapping*>(item), painter, opt);
320325
break;
326+
case ElementType::TBOX: draw(item_cast<const Box*>(item), painter, opt);
327+
break;
321328
case ElementType::TEMPO_TEXT: draw(item_cast<const TempoText*>(item), painter, opt);
322329
break;
323330
case ElementType::TEXT: draw(item_cast<const Text*>(item), painter, opt);
@@ -341,6 +348,8 @@ void SingleDraw::drawItem(const EngravingItem* item, Painter* painter, const Pai
341348
case ElementType::TUPLET: draw(item_cast<const Tuplet*>(item), painter, opt);
342349
break;
343350

351+
case ElementType::VBOX: draw(item_cast<const Box*>(item), painter, opt);
352+
break;
344353
case ElementType::VIBRATO_SEGMENT: draw(item_cast<const VibratoSegment*>(item), painter, opt);
345354
break;
346355
case ElementType::VOLTA_SEGMENT: draw(item_cast<const VoltaSegment*>(item), painter, opt);
@@ -952,6 +961,14 @@ void SingleDraw::draw(const Bend* item, Painter* painter, const PaintOptions& op
952961
}
953962
}
954963

964+
void SingleDraw::draw(const Box* item, Painter* painter, const PaintOptions&)
965+
{
966+
TRACE_DRAW_ITEM;
967+
const Box::LayoutData* ldata = item->ldata();
968+
painter->setFont(item->iconFont());
969+
painter->drawText(ldata->bbox(), muse::draw::AlignCenter, Char(item->iconCode()));
970+
}
971+
955972
void SingleDraw::draw(const Bracket* item, Painter* painter, const PaintOptions& opt)
956973
{
957974
TRACE_DRAW_ITEM;

src/engraving/rendering/single/singledraw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class BagpipeEmbellishment;
4343
class BarLine;
4444
class Beam;
4545
class Bend;
46+
class Box;
4647
class Bracket;
4748
class Breath;
4849

@@ -183,6 +184,7 @@ class SingleDraw
183184
static void draw(const BarLine* item, muse::draw::Painter* painter, const PaintOptions& opt);
184185
static void draw(const Beam* item, muse::draw::Painter* painter, const PaintOptions& opt);
185186
static void draw(const Bend* item, muse::draw::Painter* painter, const PaintOptions& opt);
187+
static void draw(const Box* item, muse::draw::Painter* painter, const PaintOptions& opt);
186188
static void draw(const Bracket* item, muse::draw::Painter* painter, const PaintOptions& opt);
187189
static void draw(const Breath* item, muse::draw::Painter* painter, const PaintOptions& opt);
188190

src/engraving/rendering/single/singlelayout.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "dom/actionicon.h"
3939
#include "dom/ambitus.h"
4040
#include "dom/articulation.h"
41+
#include "dom/box.h"
4142
#include "dom/bagpembell.h"
4243
#include "dom/barline.h"
4344
#include "dom/bend.h"
@@ -148,6 +149,8 @@ void SingleLayout::layoutItem(EngravingItem* item)
148149
break;
149150
case ElementType::EXPRESSION: layout(toExpression(item), ctx);
150151
break;
152+
case ElementType::FBOX: layout(toBox(item), ctx);
153+
break;
151154
case ElementType::FERMATA: layout(toFermata(item), ctx);
152155
break;
153156
case ElementType::FINGERING: layout(toFingering(item), ctx);
@@ -168,6 +171,8 @@ void SingleLayout::layoutItem(EngravingItem* item)
168171
break;
169172
case ElementType::HARP_DIAGRAM: layout(toHarpPedalDiagram(item), ctx);
170173
break;
174+
case ElementType::HBOX: layout(toBox(item), ctx);
175+
break;
171176
case ElementType::IMAGE: layout(toImage(item), ctx);
172177
break;
173178
case ElementType::INSTRUMENT_CHANGE: layout(toInstrumentChange(item), ctx);
@@ -226,6 +231,8 @@ void SingleLayout::layoutItem(EngravingItem* item)
226231
break;
227232
case ElementType::TAPPING: layout(toTapping(item), ctx);
228233
break;
234+
case ElementType::TBOX: layout(toBox(item), ctx);
235+
break;
229236
case ElementType::TEMPO_TEXT: layout(toTempoText(item), ctx);
230237
break;
231238
case ElementType::TEXT: layout(toText(item), ctx);
@@ -242,6 +249,8 @@ void SingleLayout::layoutItem(EngravingItem* item)
242249
break;
243250
case ElementType::TRILL: layout(toTrill(item), ctx);
244251
break;
252+
case ElementType::VBOX: layout(toBox(item), ctx);
253+
break;
245254
case ElementType::VIBRATO: layout(toVibrato(item), ctx);
246255
break;
247256
case ElementType::VOLTA: layout(toVolta(item), ctx);
@@ -718,6 +727,12 @@ void SingleLayout::layout(Bend* item, const Context&)
718727
ldata->setPos(0.0, 0.0);
719728
}
720729

730+
void SingleLayout::layout(Box* item, const Context&)
731+
{
732+
FontMetrics fontMetrics(item->iconFont());
733+
item->setbbox(fontMetrics.boundingRect(Char(item->iconCode())));
734+
}
735+
721736
void SingleLayout::layout(Bracket* item, const Context& ctx)
722737
{
723738
Bracket::LayoutData* ldata = item->mutldata();

src/engraving/rendering/single/singlelayout.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Articulation;
4141
class BagpipeEmbellishment;
4242
class BarLine;
4343
class Bend;
44+
class Box;
4445
class Bracket;
4546
class Breath;
4647

@@ -165,6 +166,7 @@ class SingleLayout
165166
static void layout(BagpipeEmbellishment* item, const Context& ctx);
166167
static void layout(BarLine* item, const Context& ctx);
167168
static void layout(Bend* item, const Context& ctx);
169+
static void layout(Box* item, const Context& ctx); // Boxes share layout method
168170
static void layout(Bracket* item, const Context& ctx);
169171
static void layout(Breath* item, const Context&);
170172

src/notation/internal/notationinteraction.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,10 +1396,6 @@ bool NotationInteraction::isOutgoingDragElementAllowed(const EngravingItem* elem
13961396
switch (element->type()) {
13971397
case ElementType::MEASURE:
13981398
case ElementType::NOTE:
1399-
case ElementType::VBOX:
1400-
case ElementType::HBOX:
1401-
case ElementType::TBOX:
1402-
case ElementType::FBOX:
14031399
// TODO: Bends & NoteLines can't be copy-dragged until corresponding SingleLayout::layout and SingleDraw::draw methods have been implemented
14041400
case ElementType::GUITAR_BEND:
14051401
case ElementType::GUITAR_BEND_SEGMENT:

src/palette/internal/palettecell.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,24 @@ PaletteCellPtr PaletteCell::fromElementMimeData(const QByteArray& data)
341341
}
342342
}
343343

344-
const String name = (element->isFretDiagram()) ? toFretDiagram(element.get())->harmonyPlainText() : element->translatedTypeUserName();
344+
String name = (element->isFretDiagram()) ? toFretDiagram(element.get())->harmonyPlainText() : element->translatedTypeUserName();
345+
if (element->isBox()) {
346+
Text* t = nullptr;
347+
if (element->isTBox()) {
348+
t = toTBox(element.get())->text();
349+
} else {
350+
for (EngravingItem* e : toBox(element.get())->el()) {
351+
if (e->isText()) {
352+
t = toText(e);
353+
break;
354+
}
355+
}
356+
}
357+
String text = t ? t->plainText().simplified() : String();
358+
if (!text.empty()) {
359+
name = String("%1: %2").arg(name, text);
360+
}
361+
}
345362

346363
return std::make_shared<PaletteCell>(element, name);
347364
}

0 commit comments

Comments
 (0)