Stellarium 0.11.3
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., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, 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 
00093     int getButtonPixmapWidth() const {return pixOn.width();}
00094 
00096     void setOpacity(double v) {opacity=v; updateIcon();}
00097 
00099     void setRedMode(bool b) {redMode=b; updateIcon();}
00100 
00104     void setBackgroundPixmap(const QPixmap& newBackground);
00105 
00107     static QPixmap makeRed(const QPixmap& p);
00108 
00109 signals:
00111     void toggled(bool);
00113     void triggered();
00116     void hoverChanged(bool b);
00117 
00118 public slots:
00120     void setChecked(int b);
00121     void setChecked(bool b) { setChecked((int)b); }
00122 
00123 protected:
00124     virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
00125     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
00126     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
00127     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00128 private slots:
00129     void animValueChanged(qreal value);
00130 private:
00131     void updateIcon();
00132     int toggleChecked(int);
00133 
00134     QPixmap pixOn;
00135     QPixmap pixOff;
00136     QPixmap pixNoChange;
00137     QPixmap pixHover;
00138     QPixmap pixBackground;
00139 
00140     QPixmap pixOnRed;
00141     QPixmap pixOffRed;
00142     QPixmap pixNoChangeRed;
00143     QPixmap pixHoverRed;
00144     QPixmap pixBackgroundRed;
00145 
00146     int checked;
00147 
00148     QTimeLine* timeLine;
00149     QAction* action;
00150     bool noBckground;
00151     bool isTristate_;
00152     double opacity;
00153     double hoverOpacity;
00154 
00155     bool redMode;
00156 };
00157 
00158 // The button bar on the left containing windows toggle buttons
00159 class LeftStelBar : public QObject, public QGraphicsItem
00160 {
00161     Q_OBJECT
00162     Q_INTERFACES(QGraphicsItem);
00163 public:
00164     LeftStelBar(QGraphicsItem* parent);
00165     ~LeftStelBar();
00166     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00167     virtual QRectF boundingRect() const;
00168     void addButton(StelButton* button);
00169     QRectF boundingRectNoHelpLabel() const;
00171     void setColor(const QColor& c);
00173     void setRedMode(bool b);
00174 private slots:
00176     void buttonHoverChanged(bool b);
00177 private:
00178     QTimeLine* hideTimeLine;
00179     QGraphicsSimpleTextItem* helpLabel;
00180 };
00181 
00182 // The button bar on the bottom containing actions toggle buttons
00183 class BottomStelBar : public QObject, public QGraphicsItem
00184 {
00185     Q_OBJECT
00186     Q_INTERFACES(QGraphicsItem);
00187 public:
00188     BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
00189     virtual ~BottomStelBar();
00190     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00191     virtual QRectF boundingRect() const;
00192     QRectF boundingRectNoHelpLabel() const;
00193 
00198     void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
00200     StelButton* hideButton(const QString& actionName);
00201 
00203     void setGroupMargin(const QString& groupName, int left, int right);
00204 
00206     void setGroupBackground(const QString& groupName, const QPixmap& pixLeft=QPixmap(),
00207                             const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(),
00208                             const QPixmap& pixSingle=QPixmap());
00209 
00211     void setColor(const QColor& c);
00212 
00214     void setRedMode(bool b);
00215 
00217     void setFlagShowTime(bool b) {flagShowTime=b;}
00219     void setFlagShowLocation(bool b) {flagShowLocation=b;}
00220 
00221 
00222 private slots:
00224     void buttonHoverChanged(bool b);
00225 
00226 private:
00227     void updateText(bool forceUpdatePos=false);
00228     void updateButtonsGroups();
00229     QRectF getButtonsBoundingRect() const;
00230     QGraphicsSimpleTextItem* location;
00231     QGraphicsSimpleTextItem* datetime;
00232     QGraphicsSimpleTextItem* fov;
00233     QGraphicsSimpleTextItem* fps;
00234 
00235     struct ButtonGroup
00236     {
00237         ButtonGroup() : leftMargin(0), rightMargin(0),
00238                         pixBackgroundLeft(NULL), pixBackgroundRight(NULL),
00239                         pixBackgroundMiddle(NULL), pixBackgroundSingle(NULL) {;}
00241         QList<StelButton*> elems;
00243         int leftMargin;
00245         int rightMargin;
00247         QPixmap* pixBackgroundLeft;
00248         QPixmap* pixBackgroundRight;
00249         QPixmap* pixBackgroundMiddle;
00250         QPixmap* pixBackgroundSingle;
00251     };
00252 
00253     QMap<QString, ButtonGroup> buttonGroups;
00254     QPixmap pixBackgroundLeft;
00255     QPixmap pixBackgroundRight;
00256     QPixmap pixBackgroundMiddle;
00257     QPixmap pixBackgroundSingle;
00258 
00259     bool flagShowTime;
00260     bool flagShowLocation;
00261 
00262     QGraphicsSimpleTextItem* helpLabel;
00263 };
00264 
00265 // The path around the bottom left button bars
00266 class StelBarsPath : public QGraphicsPathItem
00267 {
00268     public:
00269         StelBarsPath(QGraphicsItem* parent);
00270         void updatePath(BottomStelBar* bot, LeftStelBar* lef);
00271         double getRoundSize() const {return roundSize;}
00272         void setBackgroundOpacity(double opacity);
00273     private:
00274         double roundSize;
00275 };
00276 
00277 #endif // _STELGUIITEMS_HPP_
Generated on Thu May 31 10:37:19 2012 for Stellarium by  doxygen 1.6.3