1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef VIEWSETTINGS_H
18 #define VIEWSETTINGS_H
19 
20 #include "TimeDef.h"
21 #include <QWidget>
22 #include <QPushButton>
23 
24 class ViewSettings
25 {
26 public:
27     ViewSettings();
28     ~ViewSettings();
29 
30     // Display
31     double zoom() const;
32     void setZoom(double newValue);
33 
34     enum DisplayMode {
35         ILLUSTRATION,
36         OUTLINE,
37         ILLUSTRATION_OUTLINE
38     };
39     DisplayMode displayMode() const;
40     void setDisplayMode(DisplayMode mode);
41     void toggleOutline();
42     void toggleOutlineOnly();
43 
44     bool drawCursor() const;
45     void setDrawCursor(bool newValue);
46 
47     // XXX isMainDrawing is used to draw the rectangle of
48     // selection only once, only in 2D view, and never when
49     // exporting to an image. This is a hack. In the future, the
50     // rectangle of selection shouldn't be drawn by VAC::draw(),
51     // and this isMainDrawing() attribute should be removed.
52     bool isMainDrawing() const;
53     void setMainDrawing(bool newValue);
54 
55 
56     int vertexTopologySize() const;
57     void setVertexTopologySize(int newValue);
58 
59     int edgeTopologyWidth() const;
60     void setEdgeTopologyWidth(int newValue);
61 
62     bool drawTopologyFaces() const;
63     void setDrawTopologyFaces(bool newValue);
64 
65 
66     bool screenRelative() const;
67     void setScreenRelative(bool newValue);
68 
69     Time time() const;
70     void setTime(const Time & t);
71 
72     // Onion Skinning
73 
74     bool onionSkinningIsEnabled() const;
75     void setOnionSkinningIsEnabled(bool newValue);
76 
77     bool areOnionSkinsPickable() const;
78     void setAreOnionSkinsPickable(bool newValue);
79 
80     int numOnionSkinsBefore() const;
81     void setNumOnionSkinsBefore(int newValue);
82 
83     int numOnionSkinsAfter() const;
84     void setNumOnionSkinsAfter(int newValue);
85 
86     Time onionSkinsTimeOffset() const;
87     void setOnionSkinsTimeOffset(Time newValue);
88     void setOnionSkinsTimeOffset(double newValue);
89 
90     double onionSkinsXOffset() const;
91     void setOnionSkinsXOffset(double newValue);
92 
93     double onionSkinsYOffset() const;
94     void setOnionSkinsYOffset(double newValue);
95 
96     double onionSkinsTransparencyRatio() const;
97     void setOnionSkinsTransparencyRatio(double newValue);
98 
99 private:
100     // Display settings
101     double zoom_;
102     DisplayMode displayMode_;
103     bool outlineOnly_;
104     bool drawBackground_;
105     bool drawCursor_;
106     bool isMainDrawing_;
107     int vertexTopologySize_;
108     int edgeTopologyWidth_;
109     bool drawTopologyFaces_;
110     bool screenRelative_;
111     Time time_;
112 
113     // Onion skinning
114     bool onionSkinningIsEnabled_;
115     bool areOnionSkinsPickable_;
116     int numOnionSkinsBefore_;
117     int numOnionSkinsAfter_;
118     Time onionSkinsTimeOffset_;
119     double onionSkinsXOffset_;
120     double onionSkinsYOffset_;
121     double onionSkinsTransparencyRatio_;
122 };
123 
124 #include <QFormLayout>
125 #include <QCheckBox>
126 #include <QSpinBox>
127 #include <QDoubleSpinBox>
128 #include <QSlider>
129 
130 class ViewSettingsWidget: public QWidget
131 {
132     Q_OBJECT
133 
134 public:
135     ViewSettingsWidget(ViewSettings & viewSettings, QWidget * parent=0);
136     ~ViewSettingsWidget();
137 
138     void setActive(bool isActive);
139     void updateSettingsFromWidgetSilent();
140 
141 signals:
142     void changed();
143 
144 public slots:
145     void updateWidgetFromSettings();
146     void updateSettingsFromWidget();
147     void processZoomValueChangedSignal(int n);
148 
149 private slots:
150     void incrFrame();
151     void decrFrame();
152 
153 private:
154     int getFrame_();
155 
156     ViewSettings & viewSettings_;
157 
158     QSlider * vertexTopologySize_;
159     QSlider * edgeTopologyWidth_;
160     QCheckBox * drawTopologyFaces_;
161     QCheckBox * screenRelative_;
162 
163     QCheckBox * onionSkinIsEnabled_;
164     QCheckBox * areOnionSkinsPickable_;
165     QSpinBox * numOnionSkinsBefore_;
166     QSpinBox * numOnionSkinsAfter_;
167     QDoubleSpinBox * onionSkinsTimeOffset_;
168     QDoubleSpinBox * onionSkinsXOffset_;
169     QDoubleSpinBox * onionSkinsYOffset_;
170     QDoubleSpinBox * onionSkinsTransparencyRatio_;
171 
172     QPushButton * displayModeButton_;
173     QPushButton * displayModeButton_Normal_;
174     QPushButton * displayModeButton_NormalOutline_;
175     QPushButton * displayModeButton_Outline_;
176 
177     QPushButton * onionSkinningButton_;
178     QPushButton * onionSkinningButton_Off_;
179     QPushButton * onionSkinningButton_On_;
180 
181     bool ignoreZoomValueChangedSignal_;
182     double zoomValue_; // We need this to remember value before rounding by the spinbox
183     QSpinBox * zoomSpinBox_; // Note: using a QDOubleSpinBox doesn't solve the above issue,
184                              //       and just introduce more hassle
185     QLineEdit * frameLineEdit_;
186 };
187 
188 #endif // VIEWSETTINGS_H
189