Stellarium 0.13.2
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 signals:
235  void sizeChanged();
236 
237 private slots:
239  void buttonHoverChanged(bool b);
240 
241 private:
242  void updateText(bool forceUpdatePos=false);
243  void updateButtonsGroups();
244  QRectF getButtonsBoundingRect() const;
245  QGraphicsSimpleTextItem* location;
246  QGraphicsSimpleTextItem* datetime;
247  QGraphicsSimpleTextItem* fov;
248  QGraphicsSimpleTextItem* fps;
249 
250  struct ButtonGroup
251  {
252  ButtonGroup() : leftMargin(0), rightMargin(0),
253  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
254  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
256  QList<StelButton*> elems;
258  int leftMargin;
260  int rightMargin;
262  QPixmap* pixBackgroundLeft;
263  QPixmap* pixBackgroundRight;
264  QPixmap* pixBackgroundMiddle;
265  QPixmap* pixBackgroundSingle;
266  };
267 
268  QMap<QString, ButtonGroup> buttonGroups;
269  QPixmap pixBackgroundLeft;
270  QPixmap pixBackgroundRight;
271  QPixmap pixBackgroundMiddle;
272  QPixmap pixBackgroundSingle;
273 
274  bool flagShowTime;
275  bool flagShowLocation;
276  bool flagShowFps;
277  bool flagShowFov;
278  bool flagFovDms;
279  bool flagTimeJd;
280 
281  QGraphicsSimpleTextItem* helpLabel;
282 };
283 
284 // The path around the bottom left button bars
285 class StelBarsPath : public QGraphicsPathItem
286 {
287  public:
288  StelBarsPath(QGraphicsItem* parent);
289  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
290  double getRoundSize() const {return roundSize;}
291  void setBackgroundOpacity(double opacity);
292  private:
293  double roundSize;
294 };
295 
296 #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.