Home · All Namespaces · All Classes · Functions · Coding Style · 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 <QDebug>
00025 
00026 class QGraphicsSceneMouseEvent;
00027 class QTimeLine;
00028 class QAction;
00029 class QGraphicsTextItem;
00030 class QTimer;
00031 
00032 // Progess bars in the lower right corner
00033 class StelProgressBarMgr : public QObject, public QGraphicsItem
00034 {
00035     Q_OBJECT
00036 public:
00037     StelProgressBarMgr(QGraphicsItem* parent);
00038     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00039     virtual QRectF boundingRect() const;
00040     class QProgressBar* addProgressBar();
00041 private slots:
00042     void oneDestroyed(QObject* obj);
00043 private:
00044     void updateBarsPositions();
00045 };
00046 
00047 // Buttons in the bottom left corner
00048 class CornerButtons : public QObject, public QGraphicsItem
00049 {
00050 Q_OBJECT
00051 public:
00052     CornerButtons(QGraphicsItem* parent=NULL);
00053     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00054     virtual QRectF boundingRect() const;
00055     void setOpacity(double opacity);
00056 private:
00057     mutable double lastOpacity;
00058 };
00059 
00061 class StelButton : public QObject, public QGraphicsPixmapItem
00062 {
00063     friend class BottomStelBar;
00064     friend class LeftStelBar;
00065     Q_OBJECT
00066 public:
00074     StelButton(QGraphicsItem* parent, const QPixmap& pixOn, const QPixmap& pixOff, const QPixmap& pixHover=QPixmap(),
00075                QAction* action=NULL, bool noBackground=false);
00076 
00078     bool isChecked() const {return checked;}
00079 
00081     void setOpacity(double v) {opacity=v; updateIcon();}
00082     
00084     void setRedMode(bool b) {redMode=b; updateIcon();}
00085     
00086 signals:
00088     void toggled(bool);
00090     void triggered();
00093     void hoverChanged(bool b);
00094 
00095 public slots:
00097     void setChecked(bool b);
00098 
00099 protected:
00100     virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
00101     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
00102     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
00103 private slots:
00104     void animValueChanged(qreal value); 
00105 private:
00106     void updateIcon();
00107     
00108     QPixmap pixOn;
00109     QPixmap pixOff;
00110     QPixmap pixHover;
00111     QPixmap pixBackground;
00112     
00113     QPixmap pixOnRed;
00114     QPixmap pixOffRed;
00115     QPixmap pixHoverRed;
00116     QPixmap pixBackgroundRed;
00117     
00118     bool checked;
00119     QTimeLine* timeLine;
00120     QAction* action;
00121     bool noBckground;
00122     double opacity;
00123     double hoverOpacity;
00124     
00125     bool redMode;
00126 };
00127 
00128 // The button bar on the left containing windows toggle buttons
00129 class LeftStelBar : public QObject, public QGraphicsItem
00130 {
00131     Q_OBJECT
00132 public:
00133     LeftStelBar(QGraphicsItem* parent);
00134     ~LeftStelBar();
00135     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00136     virtual QRectF boundingRect() const;
00137     void addButton(StelButton* button);
00138     QRectF boundingRectNoHelpLabel() const;
00140     void setColor(const QColor& c);
00142     void setRedMode(bool b);
00143 private slots:  
00145     void buttonHoverChanged(bool b);
00146 private:
00147     QTimeLine* hideTimeLine;
00148     QGraphicsSimpleTextItem* helpLabel;
00149 };
00150 
00151 // The button bar on the bottom containing actions toggle buttons
00152 class BottomStelBar : public QObject, public QGraphicsItem
00153 {
00154     Q_OBJECT
00155 public:
00156     BottomStelBar(QGraphicsItem* parent, const QPixmap& pixLeft=QPixmap(), const QPixmap& pixRight=QPixmap(), const QPixmap& pixMiddle=QPixmap(), const QPixmap& pixSingle=QPixmap());
00157     virtual ~BottomStelBar();
00158     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00159     virtual QRectF boundingRect() const;
00160     QRectF boundingRectNoHelpLabel() const;
00161             
00166     void addButton(StelButton* button, const QString& groupName="defaultGroup", const QString& beforeActionName="");
00168     StelButton* hideButton(const QString& actionName);
00169     
00171     void setGroupMargin(const QString& groupName, int left, int right);
00172     
00174     void setColor(const QColor& c);
00175     
00177     void setRedMode(bool b);
00178     
00180     void setFlagShowTime(bool b) {flagShowTime=b;}
00182     void setFlagShowLocation(bool b) {flagShowLocation=b;}
00183 
00184 private slots:  
00186     void buttonHoverChanged(bool b);
00187     
00188 private:
00189     void updateText();
00190     void updateButtonsGroups();
00191     QRectF getButtonsBoundingRect() const;
00192     QGraphicsSimpleTextItem* location;
00193     QGraphicsSimpleTextItem* datetime;
00194     QGraphicsSimpleTextItem* fov;
00195     QGraphicsSimpleTextItem* fps;
00196     
00197     struct ButtonGroup
00198     {
00199         ButtonGroup() : leftMargin(0), rightMargin(0) {;}
00201         QList<StelButton*> elems;
00203         int leftMargin;
00205         int rightMargin;
00206     };
00207     
00208     QMap<QString, ButtonGroup> buttonGroups;
00209     QPixmap pixBackgroundLeft;
00210     QPixmap pixBackgroundRight;
00211     QPixmap pixBackgroundMiddle;
00212     QPixmap pixBackgroundSingle;
00213     
00214     bool flagShowTime;
00215     bool flagShowLocation;
00216     
00217     QGraphicsSimpleTextItem* helpLabel;
00218 };
00219 
00220 // The path around the bottom left button bars
00221 class StelBarsPath : public QGraphicsPathItem
00222 {
00223     public:
00224         StelBarsPath(QGraphicsItem* parent);
00225         void updatePath(BottomStelBar* bot, LeftStelBar* lef);
00226         double getRoundSize() const {return roundSize;}
00227     private:
00228         double roundSize;
00229 };
00230 
00231 #endif // _STELGUIITEMS_HPP_

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5