Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

gui/StelGuiItems.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2008 Fabien Chereau
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #ifndef _STELGUIITEMS_HPP_
00021 #define _STELGUIITEMS_HPP_
00022 
00023 #include <QGraphicsPixmapItem>
00024 #include <QGraphicsWidget>
00025 #include <QDebug>
00026 
00027 class QGraphicsSceneMouseEvent;
00028 class QTimeLine;
00029 class QAction;
00030 class QGraphicsTextItem;
00031 class QTimer;
00032 
00033 // Progess bars in the lower right corner
00034 class StelProgressBarMgr : public QGraphicsWidget
00035 {
00036     Q_OBJECT
00037 public:
00038     StelProgressBarMgr(QGraphicsItem* parent);
00039     class QProgressBar* addProgressBar();
00040 };
00041 
00042 // Buttons in the bottom left corner
00043 class CornerButtons : public QObject, public QGraphicsItem
00044 {
00045     Q_OBJECT
00046     Q_INTERFACES(QGraphicsItem);
00047 public:
00048     CornerButtons(QGraphicsItem* parent=NULL);
00049     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00050     virtual QRectF boundingRect() const;
00051     void setOpacity(double opacity);
00052 private:
00053     mutable double lastOpacity;
00054 };
00055 
00057 class StelButton : public QObject, public QGraphicsPixmapItem
00058 {
00059     friend class BottomStelBar;
00060     friend class LeftStelBar;
00061     Q_OBJECT
00062 public:
00070     StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff,
00071                const QPixmap& pixHover=QPixmap(),
00072                QAction* action=NULL, bool noBackground=false);
00082     StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff, const QPixmap& pixNoChange,
00083                const QPixmap& pixHover=QPixmap(),
00084                QAction* action=NULL, bool noBackground=false, bool isTristate=true);
00086     enum {ButtonStateOff = 0, ButtonStateOn = 1, ButtonStateNoChange = 2};
00087 
00089     int isChecked() const {return checked;}
00090 
00092     void setOpacity(double v) {opacity=v; updateIcon();}
00093 
00095     void setRedMode(bool b) {redMode=b; updateIcon();}
00096 
00098     static QPixmap makeRed(const QPixmap& p);
00099 
00100 signals:
00102     void toggled(bool);
00104     void triggered();
00107     void hoverChanged(bool b);
00108 
00109 public slots:
00111     void setChecked(int b);
00112     void setChecked(bool b) { setChecked((int)b); }
00113 
00114 protected:
00115     virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
00116     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
00117     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
00118     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00119 private slots:
00120     void animValueChanged(qreal value);
00121 private:
00122     void updateIcon();
00123     int toggleChecked(int);
00124 
00125     QPixmap pixOn;
00126     QPixmap pixOff;
00127     QPixmap pixNoChange;
00128     QPixmap pixHover;
00129     QPixmap pixBackground;
00130 
00131     QPixmap pixOnRed;
00132     QPixmap pixOffRed;
00133     QPixmap pixNoChangeRed;
00134     QPixmap pixHoverRed;
00135     QPixmap pixBackgroundRed;
00136 
00137     int checked;
00138 
00139     QTimeLine* timeLine;
00140     QAction* action;
00141     bool noBckground;
00142     bool isTristate_;
00143     double opacity;
00144     double hoverOpacity;
00145 
00146     bool redMode;
00147 };
00148 
00149 // The button bar on the left containing windows toggle buttons
00150 class LeftStelBar : public QObject, public QGraphicsItem
00151 {
00152     Q_OBJECT
00153     Q_INTERFACES(QGraphicsItem);
00154 public:
00155     LeftStelBar(QGraphicsItem* parent);
00156     ~LeftStelBar();
00157     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00158     virtual QRectF boundingRect() const;
00159     void addButton(StelButton* button);
00160     QRectF boundingRectNoHelpLabel() const;
00162     void setColor(const QColor& c);
00164     void setRedMode(bool b);
00165 private slots:
00167     void buttonHoverChanged(bool b);
00168 private:
00169     QTimeLine* hideTimeLine;
00170     QGraphicsSimpleTextItem* helpLabel;
00171 };
00172 
00173 // The button bar on the bottom containing actions toggle buttons
00174 class BottomStelBar : public QObject, public QGraphicsItem
00175 {
00176     Q_OBJECT
00177     Q_INTERFACES(QGraphicsItem);
00178 public:
00179     BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
00180     virtual ~BottomStelBar();
00181     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00182     virtual QRectF boundingRect() const;
00183     QRectF boundingRectNoHelpLabel() const;
00184 
00189     void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
00191     StelButton* hideButton(const QString& actionName);
00192 
00194     void setGroupMargin(const QString& groupName, int left, int right);
00195 
00197     void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
00198                             const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
00199                             const QPixmap& pixSingle=QPixmap());
00200 
00202     void setColor(const QColor& c);
00203 
00205     void setRedMode(bool b);
00206 
00208     void setFlagShowTime(bool b) {flagShowTime=b;}
00210     void setFlagShowLocation(bool b) {flagShowLocation=b;}
00211 
00212 
00213 private slots:
00215     void buttonHoverChanged(bool b);
00216 
00217 private:
00218     void updateText(bool forceUpdatePos=false);
00219     void updateButtonsGroups();
00220     QRectF getButtonsBoundingRect() const;
00221     QGraphicsSimpleTextItem* location;
00222     QGraphicsSimpleTextItem* datetime;
00223     QGraphicsSimpleTextItem* fov;
00224     QGraphicsSimpleTextItem* fps;
00225 
00226     struct ButtonGroup
00227     {
00228         ButtonGroup() : leftMargin(0), rightMargin(0),
00229                         pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
00230                         pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
00232         QList<StelButton*> elems;
00234         int leftMargin;
00236         int rightMargin;
00238         QPixmap* pixBackgroundLeft;
00239         QPixmap* pixBackgroundRight;
00240         QPixmap* pixBackgroundMiddle;
00241         QPixmap* pixBackgroundSingle;
00242     };
00243 
00244     QMap<QString, ButtonGroup> buttonGroups;
00245     QPixmap pixBackgroundLeft;
00246     QPixmap pixBackgroundRight;
00247     QPixmap pixBackgroundMiddle;
00248     QPixmap pixBackgroundSingle;
00249 
00250     bool flagShowTime;
00251     bool flagShowLocation;
00252 
00253     QGraphicsSimpleTextItem* helpLabel;
00254 };
00255 
00256 // The path around the bottom left button bars
00257 class StelBarsPath : public QGraphicsPathItem
00258 {
00259     public:
00260         StelBarsPath(QGraphicsItem* parent);
00261         void updatePath(BottomStelBar* bot, LeftStelBar* lef);
00262         double getRoundSize() const {return roundSize;}
00263         void setBackgroundOpacity(double opacity);
00264     private:
00265         double roundSize;
00266 };
00267 
00268 #endif // _STELGUIITEMS_HPP_