forked from Stellarium/stellarium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StelGuiItems.hpp
329 lines (289 loc) · 11.8 KB
/
StelGuiItems.hpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* Stellarium
* Copyright (C) 2008 Fabien Chereau
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#ifndef _STELGUIITEMS_HPP_
#define _STELGUIITEMS_HPP_
#include <QGraphicsPixmapItem>
#include <QGraphicsWidget>
#include <QDebug>
#include <QMap>
class QGraphicsSceneMouseEvent;
class QTimeLine;
class QGraphicsTextItem;
class QTimer;
class StelProgressController;
class QProgressBar;
// Progess bars in the lower right corner
class StelProgressBarMgr : public QGraphicsWidget
{
Q_OBJECT
public:
StelProgressBarMgr(QGraphicsItem* parent);
public slots:
void addProgressBar(const StelProgressController *p);
void removeProgressBar(const StelProgressController *p);
void oneBarChanged();
private:
QMap<const StelProgressController*, QProgressBar*> allBars;
};
// Buttons in the bottom left corner
class CornerButtons : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
CornerButtons(QGraphicsItem* parent=Q_NULLPTR);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
virtual QRectF boundingRect() const;
void setOpacity(double opacity);
private:
mutable double lastOpacity;
};
//! A Button Graphicsitem for use in Stellarium's graphic widgets
class StelButton : public QObject, public QGraphicsPixmapItem
{
friend class BottomStelBar;
friend class LeftStelBar;
Q_OBJECT
public:
//! Constructor
//! @param parent the parent item
//! @param pixOn the pixmap to display when the button is toggled
//! @param pixOff the pixmap to display when the button is not toggled
//! @param pixHover a pixmap slowly blended when mouse is over the button
//! @param action the associated action. Connections are automatically done with the signals if relevant.
//! @param noBackground define whether the button background image have to be used
StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
const QPixmap& pixHover=QPixmap(),
class StelAction* action=Q_NULLPTR, bool noBackground=false);
//! Constructor
//! @param parent the parent item
//! @param pixOn the pixmap to display when the button is toggled
//! @param pixOff the pixmap to display when the button is not toggled
//! @param pixHover a pixmap slowly blended when mouse is over the button
//! @param actionId the id of the associated action. Connections are automatically done with the signals if relevant.
//! @param noBackground define whether the button background image have to be used
StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
const QPixmap& pixHover,
const QString& actionId, bool noBackground=false);
//! Constructor
//! @param parent the parent item
//! @param pixOn the pixmap to display when the button is toggled
//! @param pixOff the pixmap to display when the button is not toggled
//! @param pixNoChange the pixmap to display when the button state of a tristate is not changed
//! @param pixHover a pixmap slowly blended when mouse is over the button
//! @param actionId the associated action. Connections are automatically done with the signals if relevant.
//! @param noBackground define whether the button background image have to be used
//! @param isTristate define whether the button is a tristate or an on/off button
StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff, const QPixmap& pixNoChange,
const QPixmap& pixHover,
const QString& actionId=QString(), bool noBackground=false, bool isTristate=true);
//! Button states
enum {ButtonStateOff = 0, ButtonStateOn = 1, ButtonStateNoChange = 2};
//! Get whether the button is checked
int isChecked() const {return checked;}
//! Get the width of the button image.
//! The width is based on pixOn.
int getButtonPixmapWidth() const {return pixOn.width();}
//! Set the button opacity
void setOpacity(double v) {opacity=v; updateIcon();}
//! Set the background pixmap of the button.
void setBackgroundPixmap(const QPixmap& newBackground);
//! While configuring buttons, call this with true when after key release
//! focus should go back to the sky (typical for bottom buttons;
//! left buttons call panels which receive focus after button press, so those should be configured with b=false)
void setFocusOnSky(bool b) { flagChangeFocus=b; }
//! Configure the button to trigger its action when the mouse click
//! is released (by default buttons trigger on press event).
void setTriggerOnRelease(bool b) { triggerOnRelease = b;}
signals:
//! Triggered when the button state changes
void toggled(bool);
//! Triggered when the button state changes
void triggered();
//! Emitted when the hover state change
//! @param b true if the mouse entered the button
void hoverChanged(bool b);
public slots:
//! set whether the button is checked
void setChecked(int b);
void setChecked(bool b) { setChecked((int)b); }
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private slots:
void animValueChanged(qreal value);
void updateIcon();
private:
void initCtor(const QPixmap& apixOn,
const QPixmap& apixOff,
const QPixmap& apixNoChange,
const QPixmap& apixHover,
StelAction* aaction,
bool noBackground,
bool isTristate);
int toggleChecked(int);
QPixmap pixOn;
QPixmap pixOff;
QPixmap pixNoChange;
QPixmap pixHover;
QPixmap pixBackground;
int checked;
bool flagChangeFocus;
QTimeLine* timeLine;
class StelAction* action;
bool noBckground;
bool isTristate_;
double opacity;
double hoverOpacity;
bool triggerOnRelease = false;
};
// The button bar on the left containing windows toggle buttons
class LeftStelBar : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
LeftStelBar(QGraphicsItem* parent);
~LeftStelBar();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
virtual QRectF boundingRect() const;
void addButton(StelButton* button);
QRectF boundingRectNoHelpLabel() const;
//! Set the color for all the sub elements
void setColor(const QColor& c);
private slots:
//! Update the help label when a button is hovered
void buttonHoverChanged(bool b);
private:
QTimeLine* hideTimeLine;
QGraphicsSimpleTextItem* helpLabel;
QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
};
// The button bar on the bottom containing actions toggle buttons
class BottomStelBar : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
virtual ~BottomStelBar();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
virtual QRectF boundingRect() const;
QRectF boundingRectNoHelpLabel() const;
//! Add a button in a group in the button bar. Group are displayed in alphabetic order.
//! @param button the button to add
//! @param groupName the name of the button group to which the button belongs to. If the group doesn't exist yet, a new one is created.
//! @param beforeActionName insert the button before the button associated to the given action. If the action doesn't exist, insert it at the end of the group.
void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
//! Hide the button associated with the action of the passed name
StelButton* hideButton(const QString& actionName);
//! Set the margin at the left and right of a button group in pixels
void setGroupMargin(const QString& groupName, int left, int right);
//! Set the background of a group
void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
const QPixmap& pixSingle=QPixmap());
//! Set the color for all the sub elements
void setColor(const QColor& c);
//! Set whether time must be displayed in the bottom bar
void setFlagShowTime(bool b) {flagShowTime=b;}
bool getFlagShowTime() { return flagShowTime; }
//! Set whether location info must be displayed in the bottom bar
void setFlagShowLocation(bool b) {flagShowLocation=b;}
bool getFlagShowLocation() { return flagShowLocation; }
//! Set whether FPS info must be displayed in the bottom bar
void setFlagShowFps(bool b) {flagShowFps=b;}
bool getFlagShowFps() { return flagShowFps; }
//! Set whether FOV info must be displayed in the bottom bar
void setFlagShowFov(bool b) {flagShowFov=b;}
bool getFlagShowFov() { return flagShowFov; }
//! Set whether DMS format for FOV info must be displayed in the bottom bar
void setFlagFovDms(bool b) {flagFovDms=b;}
bool getFlagFovDms() { return flagFovDms; }
//! Set whether JD for time info must be displayed in the bottom bar
void setFlagTimeJd(bool b) {flagTimeJd=b;}
bool getFlagTimeJd() { return flagTimeJd; }
void setFlagShowTz(bool b) { flagShowTZ=b; }
bool getFlagShowTz() { return flagShowTZ; }
signals:
void sizeChanged();
private slots:
//! Update the help label when a button is hovered
void buttonHoverChanged(bool b);
private:
void updateText(bool forceUpdatePos=false);
void updateButtonsGroups();
QRectF getButtonsBoundingRect() const;
// Elements which get displayed above the buttons:
QGraphicsSimpleTextItem* location;
QGraphicsSimpleTextItem* datetime;
QGraphicsSimpleTextItem* fov;
QGraphicsSimpleTextItem* fps;
// For bad graphics, show these instead. We can use location etc for font info.
// We use ad-hoc pixmaps instead if command-line arg. -t (--text-fix) is given.
QGraphicsPixmapItem* locationPixmap;
QGraphicsPixmapItem* datetimePixmap;
QGraphicsPixmapItem* fovPixmap;
QGraphicsPixmapItem* fpsPixmap;
struct ButtonGroup
{
ButtonGroup() : leftMargin(0), rightMargin(0),
pixBackgroundLeft(Q_NULLPTR), pixBackgroundRight(Q_NULLPTR),
pixBackgroundMiddle(Q_NULLPTR), pixBackgroundSingle(Q_NULLPTR) {;}
//! Elements of the group
QList<StelButton*> elems;
//! Left margin size in pixel
int leftMargin;
//! Right margin size in pixel
int rightMargin;
//! Background Images;
QPixmap* pixBackgroundLeft;
QPixmap* pixBackgroundRight;
QPixmap* pixBackgroundMiddle;
QPixmap* pixBackgroundSingle;
};
QMap<QString, ButtonGroup> buttonGroups;
QPixmap pixBackgroundLeft;
QPixmap pixBackgroundRight;
QPixmap pixBackgroundMiddle;
QPixmap pixBackgroundSingle;
bool flagShowTime;
bool flagShowLocation;
bool flagShowFps;
bool flagShowFov;
bool flagFovDms;
bool flagTimeJd;
bool flagShowTZ;
QGraphicsSimpleTextItem* helpLabel;
QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
};
// The path around the bottom left button bars
class StelBarsPath : public QGraphicsPathItem
{
public:
StelBarsPath(QGraphicsItem* parent);
void updatePath(BottomStelBar* bot, LeftStelBar* lef);
double getRoundSize() const {return roundSize;}
void setBackgroundOpacity(double opacity);
private:
double roundSize;
};
#endif // _STELGUIITEMS_HPP_