Stellarium 0.12.4
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 
27 class QGraphicsSceneMouseEvent;
28 class QTimeLine;
29 class QAction;
30 class QGraphicsTextItem;
31 class QTimer;
32 
33 // Progess bars in the lower right corner
34 class StelProgressBarMgr : public QGraphicsWidget
35 {
36  Q_OBJECT
37 public:
38  StelProgressBarMgr(QGraphicsItem* parent);
39  class QProgressBar* addProgressBar();
40 };
41 
42 // Buttons in the bottom left corner
43 class CornerButtons : public QObject, public QGraphicsItem
44 {
45  Q_OBJECT
46  Q_INTERFACES(QGraphicsItem);
47 public:
48  CornerButtons(QGraphicsItem* parent=NULL);
49  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
50  virtual QRectF boundingRect() const;
51  void setOpacity(double opacity);
52 private:
53  mutable double lastOpacity;
54 };
55 
57 class StelButton : public QObject, public QGraphicsPixmapItem
58 {
59  friend class BottomStelBar;
60  friend class LeftStelBar;
61  Q_OBJECT
62 public:
70  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
71  const QPixmap& pixHover=QPixmap(),
72  QAction* action=NULL, bool noBackground=false);
82  StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff, const QPixmap& pixNoChange,
83  const QPixmap& pixHover=QPixmap(),
84  QAction* action=NULL, bool noBackground=false, bool isTristate=true);
86  enum {ButtonStateOff = 0, ButtonStateOn = 1, ButtonStateNoChange = 2};
87 
89  int isChecked() const {return checked;}
90 
93  int getButtonPixmapWidth() const {return pixOn.width();}
94 
96  void setOpacity(double v) {opacity=v; updateIcon();}
97 
99  void setRedMode(bool b) {redMode=b; updateIcon();}
100 
104  void setBackgroundPixmap(const QPixmap& newBackground);
105 
107  static QPixmap makeRed(const QPixmap& p);
108 
109 signals:
111  void toggled(bool);
113  void triggered();
116  void hoverChanged(bool b);
117 
118 public slots:
120  void setChecked(int b);
121  void setChecked(bool b) { setChecked((int)b); }
122 
123 protected:
124  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
125  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
126  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
127  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
128 private slots:
129  void animValueChanged(qreal value);
130 private:
131  void updateIcon();
132  int toggleChecked(int);
133 
134  QPixmap pixOn;
135  QPixmap pixOff;
136  QPixmap pixNoChange;
137  QPixmap pixHover;
138  QPixmap pixBackground;
139 
140  QPixmap pixOnRed;
141  QPixmap pixOffRed;
142  QPixmap pixNoChangeRed;
143  QPixmap pixHoverRed;
144  QPixmap pixBackgroundRed;
145 
146  int checked;
147 
148  QTimeLine* timeLine;
149  QAction* action;
150  bool noBckground;
151  bool isTristate_;
152  double opacity;
153  double hoverOpacity;
154 
155  bool redMode;
156 };
157 
158 // The button bar on the left containing windows toggle buttons
159 class LeftStelBar : public QObject, public QGraphicsItem
160 {
161  Q_OBJECT
162  Q_INTERFACES(QGraphicsItem);
163 public:
164  LeftStelBar(QGraphicsItem* parent);
165  ~LeftStelBar();
166  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
167  virtual QRectF boundingRect() const;
168  void addButton(StelButton* button);
169  QRectF boundingRectNoHelpLabel() const;
171  void setColor(const QColor& c);
173  void setRedMode(bool b);
174 private slots:
176  void buttonHoverChanged(bool b);
177 private:
178  QTimeLine* hideTimeLine;
179  QGraphicsSimpleTextItem* helpLabel;
180 };
181 
182 // The button bar on the bottom containing actions toggle buttons
183 class BottomStelBar : public QObject, public QGraphicsItem
184 {
185  Q_OBJECT
186  Q_INTERFACES(QGraphicsItem);
187 public:
188  BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
189  virtual ~BottomStelBar();
190  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
191  virtual QRectF boundingRect() const;
192  QRectF boundingRectNoHelpLabel() const;
193 
198  void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
200  StelButton* hideButton(const QString& actionName);
201 
203  void setGroupMargin(const QString& groupName, int left, int right);
204 
206  void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
207  const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
208  const QPixmap& pixSingle=QPixmap());
209 
211  void setColor(const QColor& c);
212 
214  void setRedMode(bool b);
215 
217  void setFlagShowTime(bool b) {flagShowTime=b;}
219  void setFlagShowLocation(bool b) {flagShowLocation=b;}
220 
221 
222 private slots:
224  void buttonHoverChanged(bool b);
225 
226 private:
227  void updateText(bool forceUpdatePos=false);
228  void updateButtonsGroups();
229  QRectF getButtonsBoundingRect() const;
230  QGraphicsSimpleTextItem* location;
231  QGraphicsSimpleTextItem* datetime;
232  QGraphicsSimpleTextItem* fov;
233  QGraphicsSimpleTextItem* fps;
234 
235  struct ButtonGroup
236  {
237  ButtonGroup() : leftMargin(0), rightMargin(0),
238  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
239  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
241  QList<StelButton*> elems;
243  int leftMargin;
245  int rightMargin;
247  QPixmap* pixBackgroundLeft;
248  QPixmap* pixBackgroundRight;
249  QPixmap* pixBackgroundMiddle;
250  QPixmap* pixBackgroundSingle;
251  };
252 
253  QMap<QString, ButtonGroup> buttonGroups;
254  QPixmap pixBackgroundLeft;
255  QPixmap pixBackgroundRight;
256  QPixmap pixBackgroundMiddle;
257  QPixmap pixBackgroundSingle;
258 
259  bool flagShowTime;
260  bool flagShowLocation;
261 
262  QGraphicsSimpleTextItem* helpLabel;
263 };
264 
265 // The path around the bottom left button bars
266 class StelBarsPath : public QGraphicsPathItem
267 {
268  public:
269  StelBarsPath(QGraphicsItem* parent);
270  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
271  double getRoundSize() const {return roundSize;}
272  void setBackgroundOpacity(double opacity);
273  private:
274  double roundSize;
275 };
276 
277 #endif // _STELGUIITEMS_HPP_