Stellarium 0.15.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  QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
183 };
184 
185 // The button bar on the bottom containing actions toggle buttons
186 class BottomStelBar : public QObject, public QGraphicsItem
187 {
188  Q_OBJECT
189  Q_INTERFACES(QGraphicsItem)
190 public:
191  BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
192  virtual ~BottomStelBar();
193  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
194  virtual QRectF boundingRect() const;
195  QRectF boundingRectNoHelpLabel() const;
196 
201  void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
203  StelButton* hideButton(const QString& actionName);
204 
206  void setGroupMargin(const QString& groupName, int left, int right);
207 
209  void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
210  const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
211  const QPixmap& pixSingle=QPixmap());
212 
214  void setColor(const QColor& c);
215 
217  void setFlagShowTime(bool b) {flagShowTime=b;}
218  bool getFlagShowTime() { return flagShowTime; }
220  void setFlagShowLocation(bool b) {flagShowLocation=b;}
221  bool getFlagShowLocation() { return flagShowLocation; }
223  void setFlagShowFps(bool b) {flagShowFps=b;}
224  bool getFlagShowFps() { return flagShowFps; }
226  void setFlagShowFov(bool b) {flagShowFov=b;}
227  bool getFlagShowFov() { return flagShowFov; }
229  void setFlagFovDms(bool b) {flagFovDms=b;}
230  bool getFlagFovDms() { return flagFovDms; }
232  void setFlagTimeJd(bool b) {flagTimeJd=b;}
233  bool getFlagTimeJd() { return flagTimeJd; }
234 
235  void setFlagShowTz(bool b) { flagShowTZ=b; }
236  bool getFlagShowTz() { return flagShowTZ; }
237 
238 signals:
239  void sizeChanged();
240 
241 private slots:
243  void buttonHoverChanged(bool b);
244 
245 private:
246  void updateText(bool forceUpdatePos=false);
247  void updateButtonsGroups();
248  QRectF getButtonsBoundingRect() const;
249  // Elements which get displayed above the buttons:
250  QGraphicsSimpleTextItem* location;
251  QGraphicsSimpleTextItem* datetime;
252  QGraphicsSimpleTextItem* fov;
253  QGraphicsSimpleTextItem* fps;
254  // For bad graphics, show these instead. We can use location etc for font info.
255  // We use ad-hoc pixmaps instead if command-line arg. -t (--text-fix) is given.
256  QGraphicsPixmapItem* locationPixmap;
257  QGraphicsPixmapItem* datetimePixmap;
258  QGraphicsPixmapItem* fovPixmap;
259  QGraphicsPixmapItem* fpsPixmap;
260 
261 
262 
263  struct ButtonGroup
264  {
265  ButtonGroup() : leftMargin(0), rightMargin(0),
266  pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
267  pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
269  QList<StelButton*> elems;
271  int leftMargin;
273  int rightMargin;
275  QPixmap* pixBackgroundLeft;
276  QPixmap* pixBackgroundRight;
277  QPixmap* pixBackgroundMiddle;
278  QPixmap* pixBackgroundSingle;
279  };
280 
281  QMap<QString, ButtonGroup> buttonGroups;
282  QPixmap pixBackgroundLeft;
283  QPixmap pixBackgroundRight;
284  QPixmap pixBackgroundMiddle;
285  QPixmap pixBackgroundSingle;
286 
287  bool flagShowTime;
288  bool flagShowLocation;
289  bool flagShowFps;
290  bool flagShowFov;
291  bool flagFovDms;
292  bool flagTimeJd;
293  bool flagShowTZ;
294 
295  QGraphicsSimpleTextItem* helpLabel;
296  QGraphicsPixmapItem* helpLabelPixmap; // bad-graphics replacement.
297 };
298 
299 // The path around the bottom left button bars
300 class StelBarsPath : public QGraphicsPathItem
301 {
302  public:
303  StelBarsPath(QGraphicsItem* parent);
304  void updatePath(BottomStelBar* bot, LeftStelBar* lef);
305  double getRoundSize() const {return roundSize;}
306  void setBackgroundOpacity(double opacity);
307  private:
308  double roundSize;
309 };
310 
311 #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.