MuseScore/libmscore/box.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

790 lines
21 KiB
C++
Raw Normal View History

2012-05-26 14:26:10 +02:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "box.h"
#include "textframe.h"
2012-05-26 14:26:10 +02:00
#include "text.h"
#include "score.h"
#include "barline.h"
#include "repeat.h"
#include "symbol.h"
#include "system.h"
#include "image.h"
#include "layoutbreak.h"
#include "fret.h"
#include "mscore.h"
#include "stafftext.h"
#include "icon.h"
2014-04-09 16:09:21 +02:00
#include "xml.h"
2016-10-18 15:41:00 +02:00
#include "measure.h"
#include "undo.h"
2012-05-26 14:26:10 +02:00
2013-05-13 18:49:17 +02:00
namespace Ms {
2018-08-01 11:46:07 +02:00
static const ElementStyle boxStyle {
{ Sid::systemFrameDistance, Pid::TOP_GAP },
{ Sid::frameSystemDistance, Pid::BOTTOM_GAP },
};
static const ElementStyle hBoxStyle {
};
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// Box
//---------------------------------------------------------
2020-05-29 18:47:27 +02:00
Box::Box(Score* score)
: MeasureBase(score)
2012-05-26 14:26:10 +02:00
{
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Box::layout()
{
MeasureBase::layout();
2016-01-04 14:48:58 +01:00
for (Element* e : el()) {
if (!e->isLayoutBreak()) {
2016-01-04 14:48:58 +01:00
e->layout();
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// computeMinWidth
//---------------------------------------------------------
void HBox::computeMinWidth()
{
setWidth(point(boxWidth()) + topGap() + bottomGap()); // top/bottom is really left/right
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Box::draw(QPainter* painter) const
{
if (score() && score()->printing()) {
return;
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
if (selected() || editMode || dropTarget() || score()->showFrames()) {
qreal w = spatium() * .15;
2013-07-04 21:07:53 +02:00
QPainterPathStroker stroker;
stroker.setWidth(w);
stroker.setJoinStyle(Qt::MiterJoin);
stroker.setCapStyle(Qt::SquareCap);
2020-05-26 15:54:26 +02:00
2013-07-04 21:07:53 +02:00
QVector<qreal> dashes;
dashes.append(1);
dashes.append(3);
stroker.setDashPattern(dashes);
QPainterPath path;
2012-05-26 14:26:10 +02:00
w *= .5;
2013-07-04 21:07:53 +02:00
path.addRect(bbox().adjusted(w, w, -w, -w));
QPainterPath stroke = stroker.createStroke(path);
painter->setBrush(Qt::NoBrush);
painter->fillPath(stroke,
(selected() || editMode || dropTarget()) ? MScore::selectColor[0] : MScore::frameMarginColor);
2012-05-26 14:26:10 +02:00
}
}
//---------------------------------------------------------
// startEdit
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
void Box::startEdit(EditData& ed)
2012-05-26 14:26:10 +02:00
{
2017-08-16 11:21:59 +02:00
Element::startEdit(ed);
2017-03-31 13:03:15 +02:00
editMode = true;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// edit
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
bool Box::edit(EditData&)
2012-05-26 14:26:10 +02:00
{
return false;
}
2017-08-16 11:21:59 +02:00
//---------------------------------------------------------
// startEditDrag
//---------------------------------------------------------
void Box::startEditDrag(EditData& ed)
{
ElementEditData* eed = ed.getData(this);
if (isHBox()) {
2018-03-27 15:36:00 +02:00
eed->pushProperty(Pid::BOX_WIDTH);
2017-08-16 11:21:59 +02:00
} else {
2018-03-27 15:36:00 +02:00
eed->pushProperty(Pid::BOX_HEIGHT);
2020-05-26 15:54:26 +02:00
}
2017-08-16 11:21:59 +02:00
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// editDrag
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
void Box::editDrag(EditData& ed)
2012-05-26 14:26:10 +02:00
{
if (isVBox()) {
2012-05-26 14:26:10 +02:00
_boxHeight = Spatium((ed.pos.y() - abbox().y()) / spatium());
if (ed.vRaster) {
qreal vRaster = 1.0 / MScore::vRaster();
int n = lrint(_boxHeight.val() / vRaster);
_boxHeight = Spatium(vRaster * n);
}
2013-01-02 09:29:17 +01:00
bbox().setRect(0.0, 0.0, system()->width(), point(boxHeight()));
2012-05-26 14:26:10 +02:00
system()->setHeight(height());
2019-10-24 15:49:23 +02:00
triggerLayout();
2012-05-26 14:26:10 +02:00
} else {
_boxWidth += Spatium(ed.delta.x() / spatium());
if (ed.hRaster) {
qreal hRaster = 1.0 / MScore::hRaster();
int n = lrint(_boxWidth.val() / hRaster);
_boxWidth = Spatium(hRaster * n);
}
2019-10-24 15:49:23 +02:00
triggerLayout();
2012-05-26 14:26:10 +02:00
}
layout();
}
//---------------------------------------------------------
// endEdit
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
void Box::endEdit(EditData&)
2012-05-26 14:26:10 +02:00
{
editMode = false;
layout();
}
//---------------------------------------------------------
// gripsPositions
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
std::vector<QPointF> HBox::gripsPositions(const EditData&) const
2012-05-26 14:26:10 +02:00
{
QRectF r(abbox());
return { QPointF(r.right(), r.top() + r.height() * .5) };
}
std::vector<QPointF> VBox::gripsPositions(const EditData&) const
{
QRectF r(abbox());
return { QPointF(r.x() + r.width() * .5, r.bottom()) };
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// write
//---------------------------------------------------------
2016-11-19 11:51:21 +01:00
void Box::write(XmlWriter& xml) const
2012-05-26 14:26:10 +02:00
{
xml.stag(this);
2014-10-16 11:56:06 +02:00
writeProperties(xml);
xml.etag();
}
//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
2016-11-19 11:51:21 +01:00
void Box::writeProperties(XmlWriter& xml) const
2014-10-16 11:56:06 +02:00
{
2018-03-27 15:36:00 +02:00
for (Pid id : {
Pid::BOX_HEIGHT, Pid::BOX_WIDTH, Pid::TOP_GAP, Pid::BOTTOM_GAP,
Pid::LEFT_MARGIN, Pid::RIGHT_MARGIN, Pid::TOP_MARGIN, Pid::BOTTOM_MARGIN }) {
2018-03-19 17:37:11 +01:00
writeProperty(xml, id);
}
2012-05-26 14:26:10 +02:00
Element::writeProperties(xml);
2016-01-04 14:48:58 +01:00
for (const Element* e : el()) {
e->write(xml);
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
2013-01-11 18:10:18 +01:00
void Box::read(XmlReader& e)
2012-05-26 14:26:10 +02:00
{
_leftMargin = 0.0;
_rightMargin = 0.0;
_topMargin = 0.0;
_bottomMargin = 0.0;
_boxHeight = Spatium(0); // override default set in constructor
_boxWidth = Spatium(0);
MeasureBase::read(e);
2012-05-26 14:26:10 +02:00
}
2014-10-16 11:56:06 +02:00
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool Box::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (tag == "height") {
_boxHeight = Spatium(e.readDouble());
} else if (tag == "width") {
_boxWidth = Spatium(e.readDouble());
} else if (tag == "topGap") {
2014-10-16 11:56:06 +02:00
_topGap = e.readDouble();
if (score()->mscVersion() >= 206) {
_topGap *= score()->spatium();
2020-05-26 15:54:26 +02:00
}
2018-03-27 15:36:00 +02:00
setPropertyFlags(Pid::TOP_GAP, PropertyFlags::UNSTYLED);
2014-10-16 11:56:06 +02:00
} else if (tag == "bottomGap") {
_bottomGap = e.readDouble();
if (score()->mscVersion() >= 206) {
2014-10-16 11:56:06 +02:00
_bottomGap *= score()->spatium();
2020-05-26 15:54:26 +02:00
}
2018-03-27 15:36:00 +02:00
setPropertyFlags(Pid::BOTTOM_GAP, PropertyFlags::UNSTYLED);
2014-10-16 11:56:06 +02:00
} else if (tag == "leftMargin") {
_leftMargin = e.readDouble();
} else if (tag == "rightMargin") {
_rightMargin = e.readDouble();
} else if (tag == "topMargin") {
_topMargin = e.readDouble();
} else if (tag == "bottomMargin") {
_bottomMargin = e.readDouble();
} else if (tag == "Text") {
Text* t;
if (isTBox()) {
t = toTBox(this)->text();
2014-10-16 11:56:06 +02:00
t->read(e);
2020-05-26 15:54:26 +02:00
} else {
2014-10-16 11:56:06 +02:00
t = new Text(score());
t->read(e);
if (t->empty()) {
qDebug("read empty text");
} else {
add(t);
}
2020-05-26 15:54:26 +02:00
}
2014-10-16 11:56:06 +02:00
} else if (tag == "Symbol") {
Symbol* s = new Symbol(score());
s->read(e);
2020-05-26 15:54:26 +02:00
add(s);
2014-10-16 11:56:06 +02:00
} else if (tag == "Image") {
if (MScore::noImages) {
e.skipCurrentElement();
2020-05-26 15:54:26 +02:00
} else {
2014-10-16 11:56:06 +02:00
Image* image = new Image(score());
image->setTrack(e.track());
image->read(e);
add(image);
2020-05-26 15:54:26 +02:00
}
2014-10-16 11:56:06 +02:00
} else if (tag == "FretDiagram") {
2017-12-20 16:49:30 +01:00
FretDiagram* f = new FretDiagram(score());
2014-10-16 11:56:06 +02:00
f->read(e);
2020-05-26 15:54:26 +02:00
add(f);
2014-10-16 11:56:06 +02:00
} else if (tag == "HBox") {
HBox* hb = new HBox(score());
hb->read(e);
2020-05-26 15:54:26 +02:00
add(hb);
2014-10-16 11:56:06 +02:00
} else if (tag == "VBox") {
VBox* vb = new VBox(score());
vb->read(e);
2020-05-26 15:54:26 +02:00
add(vb);
2016-01-04 14:48:58 +01:00
} else if (MeasureBase::readProperties(e)) {
2014-10-16 11:56:06 +02:00
} else {
return false;
2020-05-26 15:54:26 +02:00
}
2014-10-16 11:56:06 +02:00
return true;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// add
/// Add new Element \a el to Box
//---------------------------------------------------------
void Box::add(Element* e)
{
2017-12-20 16:49:30 +01:00
if (e->isText()) {
toText(e)->setLayoutToParentWidth(true);
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
MeasureBase::add(e);
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant Box::getProperty(Pid propertyId) const
2012-05-26 14:26:10 +02:00
{
2012-08-10 17:01:35 +02:00
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::BOX_HEIGHT:
2016-03-05 15:31:26 +01:00
return _boxHeight;
2018-03-27 15:36:00 +02:00
case Pid::BOX_WIDTH:
2016-03-05 15:31:26 +01:00
return _boxWidth;
2018-03-27 15:36:00 +02:00
case Pid::TOP_GAP:
2012-08-10 17:01:35 +02:00
return _topGap;
2018-03-27 15:36:00 +02:00
case Pid::BOTTOM_GAP:
2012-08-10 17:01:35 +02:00
return _bottomGap;
2018-03-27 15:36:00 +02:00
case Pid::LEFT_MARGIN:
2012-08-10 17:01:35 +02:00
return _leftMargin;
2018-03-27 15:36:00 +02:00
case Pid::RIGHT_MARGIN:
2012-08-10 17:01:35 +02:00
return _rightMargin;
2018-03-27 15:36:00 +02:00
case Pid::TOP_MARGIN:
2012-08-10 17:01:35 +02:00
return _topMargin;
2018-03-27 15:36:00 +02:00
case Pid::BOTTOM_MARGIN:
2012-08-10 17:01:35 +02:00
return _bottomMargin;
default:
return MeasureBase::getProperty(propertyId);
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
bool Box::setProperty(Pid propertyId, const QVariant& v)
2012-05-26 14:26:10 +02:00
{
score()->addRefresh(canvasBoundingRect());
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::BOX_HEIGHT:
2016-03-05 15:31:26 +01:00
_boxHeight = v.value<Spatium>();
2012-05-26 14:26:10 +02:00
break;
2018-03-27 15:36:00 +02:00
case Pid::BOX_WIDTH:
2016-03-05 15:31:26 +01:00
_boxWidth = v.value<Spatium>();
2012-08-10 17:01:35 +02:00
break;
2018-03-27 15:36:00 +02:00
case Pid::TOP_GAP:
2012-08-10 17:01:35 +02:00
_topGap = v.toDouble();
break;
2018-03-27 15:36:00 +02:00
case Pid::BOTTOM_GAP:
2012-08-10 17:01:35 +02:00
_bottomGap = v.toDouble();
break;
2018-03-27 15:36:00 +02:00
case Pid::LEFT_MARGIN:
2012-08-10 17:01:35 +02:00
_leftMargin = v.toDouble();
break;
2018-03-27 15:36:00 +02:00
case Pid::RIGHT_MARGIN:
2012-08-10 17:01:35 +02:00
_rightMargin = v.toDouble();
break;
2018-03-27 15:36:00 +02:00
case Pid::TOP_MARGIN:
2012-08-10 17:01:35 +02:00
_topMargin = v.toDouble();
break;
2018-03-27 15:36:00 +02:00
case Pid::BOTTOM_MARGIN:
2012-08-10 17:01:35 +02:00
_bottomMargin = v.toDouble();
break;
default:
return MeasureBase::setProperty(propertyId, v);
2012-05-26 14:26:10 +02:00
}
2019-10-24 15:49:23 +02:00
triggerLayout();
2012-08-10 17:01:35 +02:00
return true;
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant Box::propertyDefault(Pid id) const
2012-05-26 14:26:10 +02:00
{
2012-08-10 17:01:35 +02:00
switch (id) {
2018-03-27 15:36:00 +02:00
case Pid::BOX_HEIGHT:
case Pid::BOX_WIDTH:
2016-03-05 15:31:26 +01:00
return Spatium(0.0);
2020-05-26 15:54:26 +02:00
2018-03-27 15:36:00 +02:00
case Pid::TOP_GAP:
return isHBox() ? 0.0 : score()->styleP(Sid::systemFrameDistance);
case Pid::BOTTOM_GAP:
return isHBox() ? 0.0 : score()->styleP(Sid::frameSystemDistance);
2020-05-26 15:54:26 +02:00
2018-03-27 15:36:00 +02:00
case Pid::LEFT_MARGIN:
case Pid::RIGHT_MARGIN:
case Pid::TOP_MARGIN:
case Pid::BOTTOM_MARGIN:
return 0.0;
2012-08-10 17:01:35 +02:00
default:
return MeasureBase::propertyDefault(id);
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// copyValues
//---------------------------------------------------------
void Box::copyValues(Box* origin)
{
_boxHeight = origin->boxHeight();
_boxWidth = origin->boxWidth();
2020-05-26 15:54:26 +02:00
qreal factor = magS() / origin->magS();
_bottomGap = origin->bottomGap() * factor;
_topGap = origin->topGap() * factor;
_bottomMargin = origin->bottomMargin() * factor;
_topMargin = origin->topMargin() * factor;
_leftMargin = origin->leftMargin() * factor;
_rightMargin = origin->rightMargin() * factor;
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// HBox
//---------------------------------------------------------
2020-05-29 18:47:27 +02:00
HBox::HBox(Score* score)
: Box(score)
2012-05-26 14:26:10 +02:00
{
2018-08-01 11:46:07 +02:00
initElementStyle(&hBoxStyle);
2012-05-26 14:26:10 +02:00
setBoxWidth(Spatium(5.0));
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void HBox::layout()
{
2017-12-20 16:49:30 +01:00
if (parent() && parent()->isVBox()) {
VBox* vb = toVBox(parent());
2015-11-16 14:24:47 +01:00
qreal x = vb->leftMargin() * DPMM;
qreal y = vb->topMargin() * DPMM;
2012-05-26 14:26:10 +02:00
qreal w = point(boxWidth());
2015-11-16 14:24:47 +01:00
qreal h = vb->height() - (vb->topMargin() + vb->bottomMargin()) * DPMM;
2012-05-26 14:26:10 +02:00
setPos(x, y);
2013-01-02 09:29:17 +01:00
bbox().setRect(0.0, 0.0, w, h);
} else if (system()) {
2013-01-02 09:29:17 +01:00
bbox().setRect(0.0, 0.0, point(boxWidth()), system()->height());
} else {
bbox().setRect(0.0, 0.0, 50, 50);
}
2012-05-26 14:26:10 +02:00
Box::layout();
}
//---------------------------------------------------------
// layout2
// height (bbox) is defined now
//---------------------------------------------------------
void HBox::layout2()
{
Box::layout();
}
//---------------------------------------------------------
// acceptDrop
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
bool Box::acceptDrop(EditData& data) const
2012-05-26 14:26:10 +02:00
{
if (data.dropElement->flag(ElementFlag::ON_STAFF)) {
return false;
2020-05-26 15:54:26 +02:00
}
if (MScore::debugMode) {
qDebug("<%s>", data.dropElement->name());
2020-05-26 15:54:26 +02:00
}
ElementType t = data.dropElement->type();
2016-10-18 15:41:00 +02:00
switch (t) {
2017-01-18 14:16:33 +01:00
case ElementType::LAYOUT_BREAK:
case ElementType::TEXT:
case ElementType::STAFF_TEXT:
case ElementType::IMAGE:
case ElementType::SYMBOL:
2012-05-26 14:26:10 +02:00
return true;
2017-01-18 14:16:33 +01:00
case ElementType::ICON:
switch (toIcon(data.dropElement)->iconType()) {
case IconType::VFRAME:
case IconType::TFRAME:
case IconType::FFRAME:
case IconType::MEASURE:
2012-05-26 14:26:10 +02:00
return true;
default:
break;
2012-05-26 14:26:10 +02:00
}
break;
2017-01-18 14:16:33 +01:00
case ElementType::BAR_LINE:
return isHBox();
default:
break;
2012-05-26 14:26:10 +02:00
}
return false;
}
//---------------------------------------------------------
// drop
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
Element* Box::drop(EditData& data)
2012-05-26 14:26:10 +02:00
{
Element* e = data.dropElement;
if (e->flag(ElementFlag::ON_STAFF)) {
return 0;
2020-05-26 15:54:26 +02:00
}
if (MScore::debugMode) {
qDebug("<%s>", e->name());
2012-05-26 14:26:10 +02:00
}
2017-01-18 14:16:33 +01:00
switch (e->type()) {
case ElementType::LAYOUT_BREAK:
2020-05-26 15:54:26 +02:00
{
2018-08-01 11:46:07 +02:00
LayoutBreak* lb = toLayoutBreak(e);
if (pageBreak() || lineBreak()) {
2020-05-26 15:54:26 +02:00
if (
2012-05-26 14:26:10 +02:00
(lb->isPageBreak() && pageBreak())
2017-01-18 14:16:33 +01:00
|| (lb->isLineBreak() && lineBreak())
2012-05-26 14:26:10 +02:00
|| (lb->isSectionBreak() && sectionBreak())
2020-05-26 15:54:26 +02:00
) {
//
2017-01-18 14:16:33 +01:00
// if break already set
2020-05-26 15:54:26 +02:00
//
2017-01-18 14:16:33 +01:00
delete lb;
2012-05-26 14:26:10 +02:00
break;
2020-05-26 15:54:26 +02:00
}
2017-01-18 14:16:33 +01:00
for (Element* elem : el()) {
if (elem->type() == ElementType::LAYOUT_BREAK) {
2012-05-26 14:26:10 +02:00
score()->undoChangeElement(elem, e);
break;
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
}
2020-05-26 15:54:26 +02:00
break;
}
lb->setTrack(-1); // these are system elements
2012-05-26 14:26:10 +02:00
lb->setParent(this);
score()->undoAddElement(lb);
return lb;
2020-05-26 15:54:26 +02:00
}
2017-01-18 14:16:33 +01:00
case ElementType::STAFF_TEXT:
2020-05-26 15:54:26 +02:00
{
2018-08-01 11:46:07 +02:00
Text* text = new Text(score(), Tid::FRAME);
2012-05-26 14:26:10 +02:00
text->setParent(this);
2017-12-20 16:49:30 +01:00
text->setXmlText(toStaffText(e)->xmlText());
2012-05-26 14:26:10 +02:00
score()->undoAddElement(text);
delete e;
return text;
2020-05-26 15:54:26 +02:00
}
2017-01-18 14:16:33 +01:00
case ElementType::ICON:
2016-10-18 15:41:00 +02:00
switch (toIcon(e)->iconType()) {
case IconType::VFRAME:
2017-01-18 14:16:33 +01:00
score()->insertMeasure(ElementType::VBOX, this);
2020-05-26 15:54:26 +02:00
break;
case IconType::TFRAME:
2017-01-18 14:16:33 +01:00
score()->insertMeasure(ElementType::TBOX, this);
2020-05-26 15:54:26 +02:00
break;
case IconType::FFRAME:
2017-01-18 14:16:33 +01:00
score()->insertMeasure(ElementType::FBOX, this);
2020-05-26 15:54:26 +02:00
break;
case IconType::MEASURE:
2017-01-18 14:16:33 +01:00
score()->insertMeasure(ElementType::MEASURE, this);
2020-05-26 15:54:26 +02:00
break;
default:
break;
}
break;
2017-01-18 14:16:33 +01:00
case ElementType::TEXT:
case ElementType::IMAGE:
case ElementType::SYMBOL:
2012-05-26 14:26:10 +02:00
e->setParent(this);
score()->undoAddElement(e);
2020-05-26 15:54:26 +02:00
return e;
default:
2012-05-26 14:26:10 +02:00
return 0;
}
return 0;
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
// drag
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
QRectF HBox::drag(EditData& data)
2012-05-26 14:26:10 +02:00
{
QRectF r(canvasBoundingRect());
qreal diff = data.evtDelta.x();
qreal x1 = offset().x() + diff;
2017-01-18 14:16:33 +01:00
if (parent()->type() == ElementType::VBOX) {
2017-12-20 16:49:30 +01:00
VBox* vb = toVBox(parent());
2015-11-16 14:24:47 +01:00
qreal x2 = parent()->width() - width() - (vb->leftMargin() + vb->rightMargin()) * DPMM;
2012-05-26 14:26:10 +02:00
if (x1 < 0.0) {
x1 = 0.0;
} else if (x1 > x2) {
x1 = x2;
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
}
setOffset(QPointF(x1, 0.0));
2017-03-31 13:03:15 +02:00
// setStartDragPosition(data.delta);
2012-05-26 14:26:10 +02:00
return canvasBoundingRect() | r;
}
//---------------------------------------------------------
// endEditDrag
//---------------------------------------------------------
2017-03-31 13:03:15 +02:00
void HBox::endEditDrag(EditData&)
2012-05-26 14:26:10 +02:00
{
2019-10-24 15:49:23 +02:00
triggerLayout();
2013-06-05 15:47:34 +02:00
score()->update();
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// isMovable
//---------------------------------------------------------
bool HBox::isMovable() const
{
return parent() && (parent()->isHBox() || parent()->isVBox());
}
//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
void HBox::writeProperties(XmlWriter& xml) const
{
writeProperty(xml, Pid::CREATE_SYSTEM_HEADER);
Box::writeProperties(xml);
}
//---------------------------------------------------------
// readProperties
//---------------------------------------------------------
bool HBox::readProperties(XmlReader& e)
{
const QStringRef& tag(e.name());
if (readProperty(tag, e, Pid::CREATE_SYSTEM_HEADER)) {
} else if (Box::readProperties(e)) {
} else {
return false;
2020-05-26 15:54:26 +02:00
}
return true;
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant HBox::getProperty(Pid propertyId) const
{
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::CREATE_SYSTEM_HEADER:
return createSystemHeader();
default:
return Box::getProperty(propertyId);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
bool HBox::setProperty(Pid propertyId, const QVariant& v)
{
switch (propertyId) {
2018-03-27 15:36:00 +02:00
case Pid::CREATE_SYSTEM_HEADER:
setCreateSystemHeader(v.toBool());
2019-10-24 15:49:23 +02:00
triggerLayout();
break;
default:
return Box::setProperty(propertyId, v);
}
return true;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
2018-03-27 15:36:00 +02:00
QVariant HBox::propertyDefault(Pid id) const
{
switch (id) {
2018-03-27 15:36:00 +02:00
case Pid::CREATE_SYSTEM_HEADER:
return true;
default:
return Box::propertyDefault(id);
}
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// VBox
//---------------------------------------------------------
2020-05-29 18:47:27 +02:00
VBox::VBox(Score* score)
: Box(score)
2012-05-26 14:26:10 +02:00
{
2018-08-01 11:46:07 +02:00
initElementStyle(&boxStyle);
2012-05-26 14:26:10 +02:00
setBoxHeight(Spatium(10.0));
setLineBreak(true);
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void VBox::layout()
{
2018-10-26 10:41:07 +02:00
setPos(QPointF());
2012-05-26 14:26:10 +02:00
if (system()) {
2013-01-02 09:29:17 +01:00
bbox().setRect(0.0, 0.0, system()->width(), point(boxHeight()));
2012-05-26 14:26:10 +02:00
} else {
2013-01-02 09:29:17 +01:00
bbox().setRect(0.0, 0.0, 50, 50);
2020-05-26 15:54:26 +02:00
}
2012-05-26 14:26:10 +02:00
Box::layout();
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void FBox::layout()
{
2012-09-24 14:48:43 +02:00
// setPos(QPointF()); // !?
2013-01-02 09:29:17 +01:00
bbox().setRect(0.0, 0.0, system()->width(), point(boxHeight()));
2012-05-26 14:26:10 +02:00
Box::layout();
}
//---------------------------------------------------------
// add
/// Add new Element \a e to fret diagram box
//---------------------------------------------------------
void FBox::add(Element* e)
{
e->setParent(this);
2017-12-20 16:49:30 +01:00
if (e->isFretDiagram()) {
// FretDiagram* fd = toFretDiagram(e);
// fd->setFlag(ElementFlag::MOVABLE, false);
2012-05-26 14:26:10 +02:00
} else {
qDebug("FBox::add: element not allowed");
2012-05-26 14:26:10 +02:00
return;
}
2016-01-04 14:48:58 +01:00
el().push_back(e);
2012-05-26 14:26:10 +02:00
}
//---------------------------------------------------------
// accessibleExtraInfo
//---------------------------------------------------------
QString Box::accessibleExtraInfo() const
{
QString rez = "";
for (Element* e : el()) {
rez += " " + e->screenReaderInfo();
2020-05-26 15:54:26 +02:00
}
return rez;
}
//---------------------------------------------------------
// accessibleExtraInfo
//---------------------------------------------------------
QString TBox::accessibleExtraInfo() const
{
QString rez = _text->screenReaderInfo();
return rez;
}
2013-05-13 18:49:17 +02:00
}