Stellarium  0.16.1
StelGuiItems.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELGUIITEMS_HPP_
21 #define _STELGUIITEMS_HPP_
22 
23 #include <QGraphicsPixmapItem>
24 #include <QGraphicsWidget>
25 #include <QDebug>
26 #include <QMap>
27 
28 class QGraphicsSceneMouseEvent;
29 class QTimeLine;
30 class QGraphicsTextItem;
31 class QTimer;
33 class QProgressBar;
34 
35 // Progess bars in the lower right corner
36 class StelProgressBarMgr : public QGraphicsWidget
37 {
38  Q_OBJECT
39 public:
40  StelProgressBarMgr(QGraphicsItem* parent);
41 
42 public slots:
43  void addProgressBar(const StelProgressController *p);
44  void removeProgressBar(const StelProgressController *p);
45  void oneBarChanged();
46 private:
47  QMap<const StelProgressController*, QProgressBar*> allBars;
48 };
49 
50 // Buttons in the bottom left corner
51 class CornerButtons : public QObject, public QGraphicsItem
52 {
53  Q_OBJECT
54  Q_INTERFACES(QGraphicsItem)
55 public:
56  CornerButtons(QGraphicsItem* parent=Q_NULLPTR);
57  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
58  virtual QRectF boundingRect() const;
59  void setOpacity(double opacity);
60 private:
61  mutable double lastOpacity;
62 };
63 
65 class StelButton : public QObject, public QGraphicsPixmapItem
66 {
67  friend class BottomStelBar;
68  friend class LeftStelBar;
69  Q_OBJECT
70 public:
78  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
79  const QPixmap& pixHover=QPixmap(),
80  class StelAction* action=Q_NULLPTR, bool noBackground=false);
81 
89  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
90  const QPixmap& pixHover,
91  const QString& actionId, bool noBackground=false);
101  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff, const QPixmap& pixNoChange,
102  const QPixmap& pixHover,
103  const QString& actionId=QString(), bool noBackground=false, bool isTristate=true);
104 
106  enum {ButtonStateOff = 0, ButtonStateOn = 1, ButtonStateNoChange = 2};
107 
109  int isChecked() const {return checked;}
110 
113  int getButtonPixmapWidth() const {return pixOn.width();}
114 
116  void setOpacity(double v) {opacity=v; updateIcon();}
117 
119  void setBackgroundPixmap(const QPixmap& newBackground);
120 
124  void setFocusOnSky(bool b) { flagChangeFocus=b; }
125 
126 signals:
128  void toggled(bool);
130  void triggered();
133  void hoverChanged(bool b);
134 
135 public slots:
137  void setChecked(int b);
138  void setChecked(bool b) { setChecked((int)b); }
139 
140 protected:
141  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
142  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
143  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
144  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
145 private slots:
146  void animValueChanged(qreal value);
147  void updateIcon();
148 private:
149  void initCtor(const QPixmap& apixOn,
150  const QPixmap& apixOff,
151  const QPixmap& apixNoChange,
152  const QPixmap& apixHover,
153  StelAction* aaction,
154  bool noBackground,
155  bool isTristate);
156  int toggleChecked(int);
157 
158  QPixmap pixOn;
159  QPixmap pixOff;
160  QPixmap pixNoChange;
161  QPixmap pixHover;
162  QPixmap pixBackground;
163 
164  int checked;
165  bool flagChangeFocus;
166 
167  QTimeLine* timeLine;
168  class StelAction* action;
169  bool noBckground;
170  bool isTristate_;
171  double opacity;
172  double hoverOpacity;
173 };
174 
175 // The button bar on the left containing windows toggle buttons
176 class LeftStelBar : public QObject, public QGraphicsItem
177 {
178  Q_OBJECT
179  Q_INTERFACES(QGraphicsItem)
180 public:
181  LeftStelBar(QGraphicsItem* parent);
182  ~LeftStelBar();
183  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
184  virtual QRectF boundingRect() const;
185  void addButton(StelButton* button);
186  QRectF boundingRectNoHelpLabel() const;
188  void setColor(const QColor& c);
189 private slots:
191  void buttonHoverChanged(bool b);
192 private:
193  QTimeLine* hideTimeLine;
194  QGraphicsSimpleTextItem* helpLabel;
195  QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
196 };
197 
198 // The button bar on the bottom containing actions toggle buttons
199 class BottomStelBar : public QObject, public QGraphicsItem
200 {
201  Q_OBJECT
202  Q_INTERFACES(QGraphicsItem)
203 public:
204  BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
205  virtual ~BottomStelBar();
206  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
207  virtual QRectF boundingRect() const;
208  QRectF boundingRectNoHelpLabel() const;
209 
214  void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
216  StelButton* hideButton(const QString& actionName);
217 
219  void setGroupMargin(const QString& groupName, int left, int right);
220 
222  void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
223  const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
224  const QPixmap& pixSingle=QPixmap());
225 
227  void setColor(const QColor& c);
228 
230  void setFlagShowTime(bool b) {flagShowTime=b;}
231  bool getFlagShowTime() { return flagShowTime; }
233  void setFlagShowLocation(bool b) {flagShowLocation=b;}
234  bool getFlagShowLocation() { return flagShowLocation; }
236  void setFlagShowFps(bool b) {flagShowFps=b;}
237  bool getFlagShowFps() { return flagShowFps; }
239  void setFlagShowFov(bool b) {flagShowFov=b;}
240  bool getFlagShowFov() { return flagShowFov; }
242  void setFlagFovDms(bool b) {flagFovDms=b;}
243  bool getFlagFovDms() { return flagFovDms; }
245  void setFlagTimeJd(bool b) {flagTimeJd=b;}
246  bool getFlagTimeJd() { return flagTimeJd; }
247 
248  void setFlagShowTz(bool b) { flagShowTZ=b; }
249  bool getFlagShowTz() { return flagShowTZ; }
250 
251 signals:
252  void sizeChanged();
253 
254 private slots:
256  void buttonHoverChanged(bool b);
257 
258 private:
259  void updateText(bool forceUpdatePos=false);
260  void updateButtonsGroups();
261  QRectF getButtonsBoundingRect() const;
262  // Elements which get displayed above the buttons:
263  QGraphicsSimpleTextItem* location;
264  QGraphicsSimpleTextItem* datetime;
265  QGraphicsSimpleTextItem* fov;
266  QGraphicsSimpleTextItem* fps;
267  // For bad graphics, show these instead. We can use location etc for font info.
268  // We use ad-hoc pixmaps instead if command-line arg. -t (--text-fix) is given.
269  QGraphicsPixmapItem* locationPixmap;
270  QGraphicsPixmapItem* datetimePixmap;
271  QGraphicsPixmapItem* fovPixmap;
272  QGraphicsPixmapItem* fpsPixmap;
273 
274 
275 
276  struct ButtonGroup
277  {
278  ButtonGroup() : leftMargin(0), rightMargin(0),
279  pixBackgroundLeft(Q_NULLPTR), pixBackgroundRight(Q_NULLPTR),
280  pixBackgroundMiddle(Q_NULLPTR), pixBackgroundSingle(Q_NULLPTR) {;}
282  QList<StelButton*> elems;
284  int leftMargin;
286  int rightMargin;
288  QPixmap* pixBackgroundLeft;
289  QPixmap* pixBackgroundRight;
290  QPixmap* pixBackgroundMiddle;
291  QPixmap* pixBackgroundSingle;
292  };
293 
294  QMap<QString, ButtonGroup> buttonGroups;
295  QPixmap pixBackgroundLeft;
296  QPixmap pixBackgroundRight;
297  QPixmap pixBackgroundMiddle;
298  QPixmap pixBackgroundSingle;
299 
300  bool flagShowTime;
301  bool flagShowLocation;
302  bool flagShowFps;
303  bool flagShowFov;
304  bool flagFovDms;
305  bool flagTimeJd;
306  bool flagShowTZ;
307 
308  QGraphicsSimpleTextItem* helpLabel;
309  QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
310 };
311 
312 // The path around the bottom left button bars
313 class StelBarsPath : public QGraphicsPathItem
314 {
315  public:
316  StelBarsPath(QGraphicsItem* parent);
317  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
318  double getRoundSize() const {return roundSize;}
319  void setBackgroundOpacity(double opacity);
320  private:
321  double roundSize;
322 };
323 
324 #endif // _STELGUIITEMS_HPP_
int getButtonPixmapWidth() const
Get the width of the button image.
void setFlagShowTime(bool b)
Set whether time must be displayed in the bottom bar.
void setFlagFovDms(bool b)
Set whether DMS format for FOV info must be displayed in the bottom bar.
Wrapper around an argumentless QObject slot or a bool Q_PROPERTY with WRITE method, allowing the slot to be called/property to be toggled using this action object.
int isChecked() const
Get whether the button is checked.
void setFlagShowLocation(bool b)
Set whether location info must be displayed in the bottom bar.
void setFlagShowFov(bool b)
Set whether FOV info must be displayed in the bottom bar.
void setFlagShowFps(bool b)
Set whether FPS info must be displayed in the bottom bar.
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
void setFlagTimeJd(bool b)
Set whether JD for time info must be displayed in the bottom bar.
void setFocusOnSky(bool b)
While configuring buttons, call this with true when after key release focus should go back to the sky...
Maintain the state of a progress bar.
void setOpacity(double v)
Set the button opacity.