MuseScore/libmscore/box.h

165 lines
6.3 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
//=============================================================================
#ifndef __BOX_H__
#define __BOX_H__
/**
\file
Definition of HBox and VBox classes.
*/
#include "measurebase.h"
2013-05-13 18:49:17 +02:00
class QPainter;
namespace Ms {
2012-05-26 14:26:10 +02:00
class MuseScoreView;
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ Box
/// virtual base class for frames "boxes"
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class Box : public MeasureBase {
Q_OBJECT
Spatium _boxWidth { Spatium(0) }; // only valid for HBox
Spatium _boxHeight { Spatium(0) }; // only valid for VBox
qreal _topGap { 0.0 }; // distance from previous system (left border for hbox)
// initialized with StyleIdx::systemFrameDistance
qreal _bottomGap { 0.0 }; // distance to next system (right border for hbox)
// initialized with StyleIdx::frameSystemDistance
qreal _leftMargin { 0.0 };
qreal _rightMargin { 0.0 }; // inner margins in metric mm
qreal _topMargin { 0.0 };
qreal _bottomMargin { 0.0 };
bool editMode { false };
PropertyStyle topGapStyle { PropertyStyle::STYLED };
PropertyStyle bottomGapStyle { PropertyStyle::STYLED };
2016-01-04 14:48:58 +01:00
qreal dragX; // used during drag of hbox
2012-05-26 14:26:10 +02:00
public:
Box(Score*);
virtual void draw(QPainter*) const override;
virtual bool isEditable() const override { return true; }
virtual void startEdit(MuseScoreView*, const QPointF&) override;
virtual bool edit(MuseScoreView*, Grip grip, int key, Qt::KeyboardModifiers, const QString& s) override;
virtual void editDrag(const EditData&) override;
virtual void endEdit() override;
virtual void updateGrips(Grip*, QVector<QRectF>&) const override;
virtual int grips() const override { return 1; }
virtual void layout() override;
virtual void write(Xml&) const override;
virtual void write(Xml& xml, int, bool) const override { write(xml); }
2014-10-16 11:56:06 +02:00
virtual void writeProperties(Xml&) const override;
virtual bool readProperties(XmlReader&) override;
virtual void read(XmlReader&) override;
2014-08-13 21:01:21 +02:00
virtual bool acceptDrop(const DropData&) const override;
virtual Element* drop(const DropData&) override;
virtual void add(Element* e) override;
2012-05-26 14:26:10 +02:00
Spatium boxWidth() const { return _boxWidth; }
void setBoxWidth(Spatium val) { _boxWidth = val; }
Spatium boxHeight() const { return _boxHeight; }
void setBoxHeight(Spatium val) { _boxHeight = val; }
qreal leftMargin() const { return _leftMargin; }
qreal rightMargin() const { return _rightMargin; }
qreal topMargin() const { return _topMargin; }
qreal bottomMargin() const { return _bottomMargin; }
void setLeftMargin(qreal val) { _leftMargin = val; }
void setRightMargin(qreal val) { _rightMargin = val; }
void setTopMargin(qreal val) { _topMargin = val; }
void setBottomMargin(qreal val) { _bottomMargin = val; }
qreal topGap() const { return _topGap; }
void setTopGap(qreal val) { _topGap = val; }
qreal bottomGap() const { return _bottomGap; }
void setBottomGap(qreal val) { _bottomGap = val; }
void copyValues(Box* origin);
2012-05-26 14:26:10 +02:00
virtual QVariant getProperty(P_ID propertyId) const override;
virtual bool setProperty(P_ID propertyId, const QVariant&) override;
virtual QVariant propertyDefault(P_ID) const override;
virtual PropertyStyle propertyStyle(P_ID id) const override;
virtual void resetProperty(P_ID id) override;
virtual void styleChanged() override;
virtual StyleIdx getPropertyStyle(P_ID id) const override;
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ HBox
/// horizontal frame
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class HBox : public Box {
Q_OBJECT
2012-05-26 14:26:10 +02:00
public:
HBox(Score* score);
2016-03-30 22:33:04 +02:00
virtual ~HBox() {}
virtual HBox* clone() const override { return new HBox(*this); }
virtual Element::Type type() const override { return Element::Type::HBOX; }
2012-05-26 14:26:10 +02:00
virtual void layout() override;
2012-05-26 14:26:10 +02:00
2013-10-22 12:05:31 +02:00
virtual QRectF drag(EditData*) override;
virtual void endEditDrag() override;
2012-05-26 14:26:10 +02:00
void layout2();
virtual bool isMovable() const override;
2016-10-18 15:41:00 +02:00
virtual qreal computeMinWidth(bool /*isFirstMeasureInSystem*/) {
return point(boxWidth()) + topGap() + bottomGap(); // top/bottom is really left/right
}
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ VBox
/// vertical frame
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class VBox : public Box {
Q_OBJECT
2012-05-26 14:26:10 +02:00
public:
VBox(Score* score);
2016-03-30 22:33:04 +02:00
virtual ~VBox() {}
2016-05-18 15:43:47 +02:00
virtual VBox* clone() const override { return new VBox(*this); }
virtual Element::Type type() const override { return Element::Type::VBOX; }
2012-05-26 14:26:10 +02:00
virtual void layout() override;
2012-05-26 14:26:10 +02:00
virtual QPointF getGrip(Grip) const override;
virtual void setGrip(Grip, const QPointF&) override;
2012-05-26 14:26:10 +02:00
};
//---------------------------------------------------------
2012-07-25 11:49:34 +02:00
// @@ FBox
/// frame containing fret diagrams
2012-05-26 14:26:10 +02:00
//---------------------------------------------------------
class FBox : public VBox {
Q_OBJECT
2012-05-26 14:26:10 +02:00
public:
FBox(Score* score) : VBox(score) {}
2016-03-30 22:33:04 +02:00
virtual ~FBox() {}
virtual FBox* clone() const override { return new FBox(*this); }
virtual Element::Type type() const override { return Element::Type::FBOX; }
2012-05-26 14:26:10 +02:00
virtual void layout() override;
virtual void add(Element*) override;
2012-05-26 14:26:10 +02:00
};
2013-05-13 18:49:17 +02:00
} // namespace Ms
2012-05-26 14:26:10 +02:00
#endif