1 //=========================================================
2 // MusE
3 // Linux Music Editor
4 // $Id: pitchlabel.cpp,v 1.2 2004/05/16 16:55:01 wschweer Exp $
5 // (C) Copyright 2001 Werner Schweer (ws@seh.de)
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; version 2 of
10 // the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 //=========================================================
22
23 #include <QApplication>
24 #include <QStyle>
25
26 #include "pitchedit.h"
27 #include "pitchlabel.h"
28 #include "helper.h"
29
30 namespace MusEGui {
31
32 //---------------------------------------------------------
33 // PitchLabel
34 //---------------------------------------------------------
35
PitchLabel(QWidget * parent,const char * name)36 PitchLabel::PitchLabel(QWidget* parent, const char* name)
37 : QLabel(parent)
38 {
39 setObjectName(name);
40 _pitchMode = true;
41 _value = -1;
42 setFrameStyle(WinPanel | Sunken);
43 setLineWidth(2);
44 setMidLineWidth(3);
45 setValue(0);
46 //int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this); // ddskrjo 0
47 int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
48 setIndent(fw);
49 //setContentsMargins(0,0,0,0);
50 }
51
52 //---------------------------------------------------------
53 // setPitchMode
54 //---------------------------------------------------------
55
setPitchMode(bool val)56 void PitchLabel::setPitchMode(bool val)
57 {
58 _pitchMode = val;
59 }
60
61 //---------------------------------------------------------
62 // sizeHint
63 //---------------------------------------------------------
64
sizeHint() const65 QSize PitchLabel::sizeHint() const
66 {
67 QFontMetrics fm(font());
68 //int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this); // ddskrjo 0
69 int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
70 int h = fm.height() + fw * 2;
71 // Width() is obsolete. Qt >= 5.11 use horizontalAdvance().
72 #if QT_VERSION >= 0x050b00
73 // int w = 2 + fm.horizontalAdvance(QString("A#8")) + fw * 4;
74 int w = fm.horizontalAdvance(QString("-9999")) + fw * 2; // must display 14Bit controller values
75 #else
76 // int w = 2 + fm.width(QString("A#8")) + fw * 4;
77 int w = fm.width(QString("-9999")) + fw * 2; // must display 14Bit controller values
78 #endif
79 return QSize(w, h).expandedTo(QApplication::globalStrut());
80 }
81
82 //---------------------------------------------------------
83 // setValue
84 //---------------------------------------------------------
85
setValue(int val)86 void PitchLabel::setValue(int val)
87 {
88 if (val == _value)
89 return;
90 _value = val;
91 QString s;
92 if (_pitchMode)
93 s = MusECore::pitch2string(_value);
94 else
95 s = QString::number(_value);
96 setText(s);
97 }
98
99 //---------------------------------------------------------
100 // setInt
101 //---------------------------------------------------------
102
setInt(int val)103 void PitchLabel::setInt(int val)
104 {
105 if (_pitchMode)
106 setPitchMode(false);
107 setValue(val);
108 }
109
110 //---------------------------------------------------------
111 // setPitch
112 //---------------------------------------------------------
113
setPitch(int val)114 void PitchLabel::setPitch(int val)
115 {
116 if (!_pitchMode) {
117 setPitchMode(true);
118 }
119 setValue(val);
120 }
121
122 } // namespace MusEGui
123