Stellarium 0.13.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 
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;}
218  void setFlagShowLocation(bool b) {flagShowLocation=b;}
219 
220 
221 private slots:
223  void buttonHoverChanged(bool b);
224 
225 private:
226  void updateText(bool forceUpdatePos=false);
227  void updateButtonsGroups();
228  QRectF getButtonsBoundingRect() const;
229  QGraphicsSimpleTextItem* location;
230  QGraphicsSimpleTextItem* datetime;
231  QGraphicsSimpleTextItem* fov;
232  QGraphicsSimpleTextItem* fps;
233 
234  struct ButtonGroup
235  {
236  ButtonGroup() : leftMargin(0), rightMargin(0),
237  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
238  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
240  QList<StelButton*> elems;
242  int leftMargin;
244  int rightMargin;
246  QPixmap* pixBackgroundLeft;
247  QPixmap* pixBackgroundRight;
248  QPixmap* pixBackgroundMiddle;
249  QPixmap* pixBackgroundSingle;
250  };
251 
252  QMap<QString, ButtonGroup> buttonGroups;
253  QPixmap pixBackgroundLeft;
254  QPixmap pixBackgroundRight;
255  QPixmap pixBackgroundMiddle;
256  QPixmap pixBackgroundSingle;
257 
258  bool flagShowTime;
259  bool flagShowLocation;
260 
261  QGraphicsSimpleTextItem* helpLabel;
262 };
263 
264 // The path around the bottom left button bars
265 class StelBarsPath : public QGraphicsPathItem
266 {
267  public:
268  StelBarsPath(QGraphicsItem* parent);
269  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
270  double getRoundSize() const {return roundSize;}
271  void setBackgroundOpacity(double opacity);
272  private:
273  double roundSize;
274 };
275 
276 #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.
Definition: StelGuiItems.hpp:106
void setFlagShowTime(bool b)
Set whether time must be displayed in the bottom bar.
Definition: StelGuiItems.hpp:216
void triggered()
Triggered when the button state changes.
Definition: StelGuiItems.hpp:265
void hoverChanged(bool b)
Emitted when the hover state change.
Definition: StelGuiItems.hpp:185
Definition: StelActionMgr.hpp:29
int isChecked() const
Get whether the button is checked.
Definition: StelGuiItems.hpp:102
void setFlagShowLocation(bool b)
Set whether location info must be displayed in the bottom bar.
Definition: StelGuiItems.hpp:218
void setGroupMargin(const QString &groupName, int left, int right)
Set the margin at the left and right of a button group in pixels.
void setChecked(int b)
set whether the button is checked
void setBackgroundPixmap(const QPixmap &newBackground)
Set the background pixmap of the button.
A Button Graphicsitem for use in Stellarium's graphic widgets.
Definition: StelGuiItems.hpp:65
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.
Definition: StelProgressController.hpp:27
Definition: StelGuiItems.hpp:36
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.
Definition: StelGuiItems.hpp:51
Definition: StelGuiItems.hpp:163
void setOpacity(double v)
Set the button opacity.
Definition: StelGuiItems.hpp:109