Stellarium 0.13.3
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 
82  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
83  const QPixmap& pixHover=QPixmap(),
84  const QString& actionId=QString(), bool noBackground=false);
94  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff, const QPixmap& pixNoChange,
95  const QPixmap& pixHover=QPixmap(),
96  const QString& actionId=QString(), bool noBackground=false, bool isTristate=true);
97 
99  enum {ButtonStateOff = 0, ButtonStateOn = 1, ButtonStateNoChange = 2};
100 
102  int isChecked() const {return checked;}
103 
106  int getButtonPixmapWidth() const {return pixOn.width();}
107 
109  void setOpacity(double v) {opacity=v; updateIcon();}
110 
112  void setBackgroundPixmap(const QPixmap& newBackground);
113 
114 signals:
116  void toggled(bool);
118  void triggered();
121  void hoverChanged(bool b);
122 
123 public slots:
125  void setChecked(int b);
126  void setChecked(bool b) { setChecked((int)b); }
127 
128 protected:
129  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
130  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
131  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
132  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
133 private slots:
134  void animValueChanged(qreal value);
135 private:
136  void initCtor(const QPixmap& apixOn,
137  const QPixmap& apixOff,
138  const QPixmap& apixNoChange,
139  const QPixmap& apixHover,
140  StelAction* aaction,
141  bool noBackground,
142  bool isTristate);
143  void updateIcon();
144  int toggleChecked(int);
145 
146  QPixmap pixOn;
147  QPixmap pixOff;
148  QPixmap pixNoChange;
149  QPixmap pixHover;
150  QPixmap pixBackground;
151 
152  int checked;
153 
154  QTimeLine* timeLine;
155  class StelAction* action;
156  bool noBckground;
157  bool isTristate_;
158  double opacity;
159  double hoverOpacity;
160 };
161 
162 // The button bar on the left containing windows toggle buttons
163 class LeftStelBar : public QObject, public QGraphicsItem
164 {
165  Q_OBJECT
166  Q_INTERFACES(QGraphicsItem);
167 public:
168  LeftStelBar(QGraphicsItem* parent);
169  ~LeftStelBar();
170  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
171  virtual QRectF boundingRect() const;
172  void addButton(StelButton* button);
173  QRectF boundingRectNoHelpLabel() const;
175  void setColor(const QColor& c);
176 private slots:
178  void buttonHoverChanged(bool b);
179 private:
180  QTimeLine* hideTimeLine;
181  QGraphicsSimpleTextItem* helpLabel;
182 };
183 
184 // The button bar on the bottom containing actions toggle buttons
185 class BottomStelBar : public QObject, public QGraphicsItem
186 {
187  Q_OBJECT
188  Q_INTERFACES(QGraphicsItem);
189 public:
190  BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
191  virtual ~BottomStelBar();
192  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
193  virtual QRectF boundingRect() const;
194  QRectF boundingRectNoHelpLabel() const;
195 
200  void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
202  StelButton* hideButton(const QString& actionName);
203 
205  void setGroupMargin(const QString& groupName, int left, int right);
206 
208  void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
209  const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
210  const QPixmap& pixSingle=QPixmap());
211 
213  void setColor(const QColor& c);
214 
216  void setFlagShowTime(bool b) {flagShowTime=b;}
217  bool getFlagShowTime() { return flagShowTime; }
219  void setFlagShowLocation(bool b) {flagShowLocation=b;}
220  bool getFlagShowLocation() { return flagShowLocation; }
222  void setFlagShowFps(bool b) {flagShowFps=b;}
223  bool getFlagShowFps() { return flagShowFps; }
225  void setFlagShowFov(bool b) {flagShowFov=b;}
226  bool getFlagShowFov() { return flagShowFov; }
228  void setFlagFovDms(bool b) {flagFovDms=b;}
229  bool getFlagFovDms() { return flagFovDms; }
231  void setFlagTimeJd(bool b) {flagTimeJd=b;}
232  bool getFlagTimeJd() { return flagTimeJd; }
233 
234  void setFlagShowTz(bool b) { flagShowTZ=b; }
235  bool getFlagShowTz() { return flagShowTZ; }
236 
237 signals:
238  void sizeChanged();
239 
240 private slots:
242  void buttonHoverChanged(bool b);
243 
244 private:
245  void updateText(bool forceUpdatePos=false);
246  void updateButtonsGroups();
247  QRectF getButtonsBoundingRect() const;
248  QGraphicsSimpleTextItem* location;
249  QGraphicsSimpleTextItem* datetime;
250  QGraphicsSimpleTextItem* fov;
251  QGraphicsSimpleTextItem* fps;
252 
253  struct ButtonGroup
254  {
255  ButtonGroup() : leftMargin(0), rightMargin(0),
256  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
257  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
259  QList<StelButton*> elems;
261  int leftMargin;
263  int rightMargin;
265  QPixmap* pixBackgroundLeft;
266  QPixmap* pixBackgroundRight;
267  QPixmap* pixBackgroundMiddle;
268  QPixmap* pixBackgroundSingle;
269  };
270 
271  QMap<QString, ButtonGroup> buttonGroups;
272  QPixmap pixBackgroundLeft;
273  QPixmap pixBackgroundRight;
274  QPixmap pixBackgroundMiddle;
275  QPixmap pixBackgroundSingle;
276 
277  bool flagShowTime;
278  bool flagShowLocation;
279  bool flagShowFps;
280  bool flagShowFov;
281  bool flagFovDms;
282  bool flagTimeJd;
283  bool flagShowTZ;
284 
285  QGraphicsSimpleTextItem* helpLabel;
286 };
287 
288 // The path around the bottom left button bars
289 class StelBarsPath : public QGraphicsPathItem
290 {
291  public:
292  StelBarsPath(QGraphicsItem* parent);
293  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
294  double getRoundSize() const {return roundSize;}
295  void setBackgroundOpacity(double opacity);
296  private:
297  double roundSize;
298 };
299 
300 #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.
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.