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 signals:
221  void sizeChanged();
222 
223 private slots:
225  void buttonHoverChanged(bool b);
226 
227 private:
228  void updateText(bool forceUpdatePos=false);
229  void updateButtonsGroups();
230  QRectF getButtonsBoundingRect() const;
231  QGraphicsSimpleTextItem* location;
232  QGraphicsSimpleTextItem* datetime;
233  QGraphicsSimpleTextItem* fov;
234  QGraphicsSimpleTextItem* fps;
235 
236  struct ButtonGroup
237  {
238  ButtonGroup() : leftMargin(0), rightMargin(0),
239  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
240  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
242  QList<StelButton*> elems;
244  int leftMargin;
246  int rightMargin;
248  QPixmap* pixBackgroundLeft;
249  QPixmap* pixBackgroundRight;
250  QPixmap* pixBackgroundMiddle;
251  QPixmap* pixBackgroundSingle;
252  };
253 
254  QMap<QString, ButtonGroup> buttonGroups;
255  QPixmap pixBackgroundLeft;
256  QPixmap pixBackgroundRight;
257  QPixmap pixBackgroundMiddle;
258  QPixmap pixBackgroundSingle;
259 
260  bool flagShowTime;
261  bool flagShowLocation;
262 
263  QGraphicsSimpleTextItem* helpLabel;
264 };
265 
266 // The path around the bottom left button bars
267 class StelBarsPath : public QGraphicsPathItem
268 {
269  public:
270  StelBarsPath(QGraphicsItem* parent);
271  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
272  double getRoundSize() const {return roundSize;}
273  void setBackgroundOpacity(double opacity);
274  private:
275  double roundSize;
276 };
277 
278 #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 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 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.
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.