Stellarium 0.15.0
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=NULL);
57  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
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=NULL, 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 
121  void setFocusOnSky(bool b) { flagChangeFocus=b; }
122 
123 signals:
125  void toggled(bool);
127  void triggered();
130  void hoverChanged(bool b);
131 
132 public slots:
134  void setChecked(int b);
135  void setChecked(bool b) { setChecked((int)b); }
136 
137 protected:
138  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
139  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
140  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
141  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
142 private slots:
143  void animValueChanged(qreal value);
144 private:
145  void initCtor(const QPixmap& apixOn,
146  const QPixmap& apixOff,
147  const QPixmap& apixNoChange,
148  const QPixmap& apixHover,
149  StelAction* aaction,
150  bool noBackground,
151  bool isTristate);
152  void updateIcon();
153  int toggleChecked(int);
154 
155  QPixmap pixOn;
156  QPixmap pixOff;
157  QPixmap pixNoChange;
158  QPixmap pixHover;
159  QPixmap pixBackground;
160 
161  int checked;
162  bool flagChangeFocus;
163 
164  QTimeLine* timeLine;
165  class StelAction* action;
166  bool noBckground;
167  bool isTristate_;
168  double opacity;
169  double hoverOpacity;
170 };
171 
172 // The button bar on the left containing windows toggle buttons
173 class LeftStelBar : public QObject, public QGraphicsItem
174 {
175  Q_OBJECT
176  Q_INTERFACES(QGraphicsItem)
177 public:
178  LeftStelBar(QGraphicsItem* parent);
179  ~LeftStelBar();
180  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
181  virtual QRectF boundingRect() const;
182  void addButton(StelButton* button);
183  QRectF boundingRectNoHelpLabel() const;
185  void setColor(const QColor& c);
186 private slots:
188  void buttonHoverChanged(bool b);
189 private:
190  QTimeLine* hideTimeLine;
191  QGraphicsSimpleTextItem* helpLabel;
192  QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
193 };
194 
195 // The button bar on the bottom containing actions toggle buttons
196 class BottomStelBar : public QObject, public QGraphicsItem
197 {
198  Q_OBJECT
199  Q_INTERFACES(QGraphicsItem)
200 public:
201  BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
202  virtual ~BottomStelBar();
203  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
204  virtual QRectF boundingRect() const;
205  QRectF boundingRectNoHelpLabel() const;
206 
211  void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
213  StelButton* hideButton(const QString& actionName);
214 
216  void setGroupMargin(const QString& groupName, int left, int right);
217 
219  void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
220  const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
221  const QPixmap& pixSingle=QPixmap());
222 
224  void setColor(const QColor& c);
225 
227  void setFlagShowTime(bool b) {flagShowTime=b;}
228  bool getFlagShowTime() { return flagShowTime; }
230  void setFlagShowLocation(bool b) {flagShowLocation=b;}
231  bool getFlagShowLocation() { return flagShowLocation; }
233  void setFlagShowFps(bool b) {flagShowFps=b;}
234  bool getFlagShowFps() { return flagShowFps; }
236  void setFlagShowFov(bool b) {flagShowFov=b;}
237  bool getFlagShowFov() { return flagShowFov; }
239  void setFlagFovDms(bool b) {flagFovDms=b;}
240  bool getFlagFovDms() { return flagFovDms; }
242  void setFlagTimeJd(bool b) {flagTimeJd=b;}
243  bool getFlagTimeJd() { return flagTimeJd; }
244 
245  void setFlagShowTz(bool b) { flagShowTZ=b; }
246  bool getFlagShowTz() { return flagShowTZ; }
247 
248 signals:
249  void sizeChanged();
250 
251 private slots:
253  void buttonHoverChanged(bool b);
254 
255 private:
256  void updateText(bool forceUpdatePos=false);
257  void updateButtonsGroups();
258  QRectF getButtonsBoundingRect() const;
259  // Elements which get displayed above the buttons:
260  QGraphicsSimpleTextItem* location;
261  QGraphicsSimpleTextItem* datetime;
262  QGraphicsSimpleTextItem* fov;
263  QGraphicsSimpleTextItem* fps;
264  // For bad graphics, show these instead. We can use location etc for font info.
265  // We use ad-hoc pixmaps instead if command-line arg. -t (--text-fix) is given.
266  QGraphicsPixmapItem* locationPixmap;
267  QGraphicsPixmapItem* datetimePixmap;
268  QGraphicsPixmapItem* fovPixmap;
269  QGraphicsPixmapItem* fpsPixmap;
270 
271 
272 
273  struct ButtonGroup
274  {
275  ButtonGroup() : leftMargin(0), rightMargin(0),
276  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
277  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
279  QList<StelButton*> elems;
281  int leftMargin;
283  int rightMargin;
285  QPixmap* pixBackgroundLeft;
286  QPixmap* pixBackgroundRight;
287  QPixmap* pixBackgroundMiddle;
288  QPixmap* pixBackgroundSingle;
289  };
290 
291  QMap<QString, ButtonGroup> buttonGroups;
292  QPixmap pixBackgroundLeft;
293  QPixmap pixBackgroundRight;
294  QPixmap pixBackgroundMiddle;
295  QPixmap pixBackgroundSingle;
296 
297  bool flagShowTime;
298  bool flagShowLocation;
299  bool flagShowFps;
300  bool flagShowFov;
301  bool flagFovDms;
302  bool flagTimeJd;
303  bool flagShowTZ;
304 
305  QGraphicsSimpleTextItem* helpLabel;
306  QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
307 };
308 
309 // The path around the bottom left button bars
310 class StelBarsPath : public QGraphicsPathItem
311 {
312  public:
313  StelBarsPath(QGraphicsItem* parent);
314  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
315  double getRoundSize() const {return roundSize;}
316  void setBackgroundOpacity(double opacity);
317  private:
318  double roundSize;
319 };
320 
321 #endif // _STELGUIITEMS_HPP_
void toggled(bool)
Triggered when the button state changes.
void setColor(const QColor &c)
Set the color for all the sub elements.
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 triggered()
Triggered when the button state changes.
void setFlagFovDms(bool b)
Set whether DMS format for FOV info must be displayed in the bottom bar.
void hoverChanged(bool b)
Emitted when the hover state change.
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 setGroupMargin(const QString &groupName, int left, int right)
Set the margin at the left and right of a button group in pixels.
void setFlagShowFov(bool b)
Set whether FOV info must be displayed in the bottom bar.
void setChecked(int b)
set whether the button is checked
void setFlagShowFps(bool b)
Set whether FPS info must be displayed in the bottom bar.
void setBackgroundPixmap(const QPixmap &newBackground)
Set the background pixmap of the button.
A Button Graphicsitem for use in Stellarium's graphic widgets.
void setFlagTimeJd(bool b)
Set whether JD for time info must be displayed in the bottom bar.
void setColor(const QColor &c)
Set the color for all the sub elements.
StelButton * hideButton(const QString &actionName)
Hide the button associated with the action of the passed name.
Maintain the state of a progress bar.
void addButton(StelButton *button, const QString &groupName="defaultGroup", const QString &beforeActionName="")
Add a button in a group in the button bar.
StelButton(QGraphicsItem *parent, const QPixmap &pixOn, const QPixmap &pixOff, const QPixmap &pixHover=QPixmap(), class StelAction *action=NULL, bool noBackground=false)
Constructor.
void setGroupBackground(const QString &groupName, const QPixmap &pixLeft=QPixmap(), const QPixmap &pixRight=QPixmap(), const QPixmap &pixMiddle=QPixmap(), const QPixmap &pixSingle=QPixmap())
Set the background of a group.
void setOpacity(double v)
Set the button opacity.