1 //=============================================================================
2 //  MusE Score
3 //  Linux Music Score Editor
4 //
5 //  Copyright (C) 2008-2009 Werner Schweer and others
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef ZOOMBOX_H
21 #define ZOOMBOX_H
22 
23 namespace Ms {
24 
25 class ScoreView;
26 
27 //---------------------------------------------------------
28 //   ZoomIndex
29 //    Indices of the items in the zoom box.
30 //---------------------------------------------------------
31 
32 enum class ZoomIndex : char {
33        ZOOM_25, ZOOM_50, ZOOM_75, ZOOM_100, ZOOM_150, ZOOM_200, ZOOM_400, ZOOM_800, ZOOM_1600,
34        ZOOM_PAGE_WIDTH, ZOOM_WHOLE_PAGE, ZOOM_TWO_PAGES,
35        ZOOM_FREE
36       };
37 
38 //---------------------------------------------------------
39 //   zoomEntry
40 //    The string, index, and zoom level for each item in the zoom box.
41 //---------------------------------------------------------
42 
43 struct ZoomEntry {
44       ZoomIndex index;
45       int level; // Must be set to 0 for all entries that aren't numeric presets (including ZOOM_FREE).
46       const char* txt;
47 
isNumericPresetZoomEntry48       bool isNumericPreset() const { return level != 0; }
49 
50       friend bool operator==(const ZoomEntry& e, const int l) { return e.level == l; }
51       friend bool operator==(const ZoomEntry& e, const ZoomIndex i) { return e.index == i; }
52       };
53 
54 //---------------------------------------------------------
55 //   ZoomState
56 //    The zoom index and level of a single zoom state.
57 //---------------------------------------------------------
58 
59 struct ZoomState {
60       ZoomIndex index;
61       qreal level;
62 
63       friend bool operator!=(const ZoomState& l, const ZoomState& r) { return (l.index != r.index) || (l.level != r.level); }
64       };
65 
66 //---------------------------------------------------------
67 //   zoomEntries
68 //    All of the entries in the zoom box.
69 //---------------------------------------------------------
70 
71 extern const std::array<ZoomEntry, 13> zoomEntries;
72 
73 //---------------------------------------------------------
74 //   ZoomValidator
75 //---------------------------------------------------------
76 
77 class ZoomValidator : public QValidator {
78       Q_OBJECT
79 
80       virtual State validate(QString&, int&) const;
81 
82    public:
83       ZoomValidator(QObject* parent = 0);
84 
85       static std::tuple<QValidator::State, ZoomIndex, int> validationHelper(const QString& input);
86       };
87 
88 //---------------------------------------------------------
89 //   ZoomBox
90 //---------------------------------------------------------
91 
92 class ZoomBox : public QComboBox {
93       Q_OBJECT
94 
95       qreal _previousLogicalLevel;
96       ScoreView* _previousScoreView;
97 
98    private slots:
99       void indexChanged(int);
100       void textChanged();
101 
102    signals:
103       void zoomChanged(const ZoomIndex zoomIndex, const qreal logicalFreeZoomLevel = 0.0);
104 
105    public:
106       ZoomBox(QWidget* parent = 0);
107 
108       static ZoomState getDefaultLogicalZoom();
109 
110       void setLogicalZoom(const ZoomIndex index, const qreal logicalLevel);
111       void resetToDefaultLogicalZoom();
setEnabled(bool val)112       void setEnabled(bool val) { QComboBox::setEnabled(val); }
currentText()113       QString currentText() const { return QComboBox::currentText(); }
count()114       int count() const { return QComboBox::count(); }
removeItem(int i)115       void removeItem(int i) { QComboBox::removeItem(i); }
116       };
117 
118 
119 } // namespace Ms
120 
121 Q_DECLARE_METATYPE(Ms::ZoomIndex);
122 
123 #endif
124