File: textframe.cpp

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 214,188 kB
  • sloc: cpp: 291,198; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 244; perl: 82; pascal: 79
file content (182 lines) | stat: -rw-r--r-- 4,997 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2010-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 "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 "textframe.h"
#include "xml.h"

namespace Ms {

//---------------------------------------------------------
//   TBox
//---------------------------------------------------------

TBox::TBox(Score* score)
   : VBox(score)
      {
      setBoxHeight(Spatium(1));
      _text  = new Text(score, Tid::FRAME);
      _text->setLayoutToParentWidth(true);
      _text->setParent(this);
      }

TBox::TBox(const TBox& tbox)
   : VBox(tbox)
      {
      _text = new Text(*(tbox._text));
      }

TBox::~TBox()
      {
      delete _text;
      }

//---------------------------------------------------------
//   layout
///   The text box layout() adjusts the frame height to text
///   height.
//---------------------------------------------------------

void TBox::layout()
      {
      setPos(QPointF());      // !?
      bbox().setRect(0.0, 0.0, system()->width(), 0);
      _text->layout();

      qreal h = _text->height();
      if (_text->empty()) {
            QFontMetricsF fm = QFontMetricsF(_text->font(), MScore::paintDevice());
            h = fm.ascent();
            }
      else
            h = _text->height();
      qreal y = topMargin() * DPMM;
#if 0
      if (_text->align() & Align::BOTTOM)
            y += h;
      else if (_text->align() & Align::VCENTER)
            y +=  h * .5;
      else
            ; // y = 0;
#endif
      _text->setPos(leftMargin() * DPMM, y);
      h += topMargin() * DPMM + bottomMargin() * DPMM;
      bbox().setRect(0.0, 0.0, system()->width(), h);

      MeasureBase::layout();  // layout LayoutBreak's
      }

//---------------------------------------------------------
//   write
//---------------------------------------------------------

void TBox::write(XmlWriter& xml) const
      {
      xml.stag(this);
      Box::writeProperties(xml);
      _text->write(xml);
      xml.etag();
      }

//---------------------------------------------------------
//   read
//---------------------------------------------------------

void TBox::read(XmlReader& e)
      {
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "Text")
                  _text->read(e);
            else if (Box::readProperties(e))
                  ;
            else
                  e.unknown();
            }
      }

//---------------------------------------------------------
//   scanElements
//---------------------------------------------------------

void TBox::scanElements(void* data, void (*func)(void*, Element*), bool all)
      {
      _text->scanElements(data, func, all);
      Box::scanElements(data, func, all);
      }

//---------------------------------------------------------
//   drop
//---------------------------------------------------------

Element* TBox::drop(EditData& data)
      {
      Element* e = data.dropElement;
      switch (e->type()) {
            case ElementType::TEXT:
                  _text->undoChangeProperty(Pid::TEXT, toText(e)->xmlText());
                  delete e;
                  return _text;
            default:
                  return VBox::drop(data);
            }
      }

//---------------------------------------------------------
//   add
///   Add new Element \a el to TBox
//---------------------------------------------------------

void TBox::add(Element* e)
      {
      if (e->isText()) {
            // does not normally happen, since drop() handles this directly
            _text->undoChangeProperty(Pid::TEXT, toText(e)->xmlText());
            }
      else {
            VBox::add(e);
            }
      }

//---------------------------------------------------------
//   remove
//---------------------------------------------------------

void TBox::remove(Element* el)
      {
      if (el == _text) {
            // does not normally happen, since Score::deleteItem() handles this directly
            // but if it does:
            // replace with new empty text element
            // this keeps undo/redo happier than just clearing the text
            qDebug("TBox::remove() - replacing _text");
            _text = new Text(score(), Tid::FRAME);
            _text->setLayoutToParentWidth(true);
            _text->setParent(this);
           }
      else {
            VBox::remove(el);
           }
      }

}