|
Quantum GIS API Documentation
master-693a1fe
|
00001 /*************************************************************************** 00002 qgsmessagebar.h - description 00003 ------------------- 00004 begin : June 2012 00005 copyright : (C) 2012 by Giuseppe Sucameli 00006 email : sucameli at faunalia dot it 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 #ifndef QGSMESSAGEBAR_H 00018 #define QGSMESSAGEBAR_H 00019 00020 #include <qgisgui.h> 00021 00022 #include <QString> 00023 #include <QFrame> 00024 #include <QIcon> 00025 #include <QColor> 00026 #include <QList> 00027 00028 class QWidget; 00029 class QGridLayout; 00030 class QMenu; 00031 class QProgressBar; 00032 class QToolButton; 00033 class QLabel; 00034 class QAction; 00035 class QTimer; 00036 00041 class GUI_EXPORT QgsMessageBar: public QFrame 00042 { 00043 Q_OBJECT 00044 00045 public: 00046 enum MessageLevel 00047 { 00048 INFO = 0, 00049 WARNING = 1, 00050 CRITICAL = 2 00051 }; 00052 00053 QgsMessageBar( QWidget *parent = 0 ); 00054 ~QgsMessageBar(); 00055 00062 void pushWidget( QWidget *widget, MessageLevel level = INFO, int duration = 0 ); 00063 00069 bool popWidget( QWidget *widget ); 00070 00072 static QWidget* createMessage( const QString &text, QWidget *parent = 0 ) { return createMessage( QString::null, text, QIcon(), parent ); } 00074 static QWidget* createMessage( const QString &text, const QIcon &icon, QWidget *parent = 0 ) { return createMessage( QString::null, text, icon, parent ); } 00076 static QWidget* createMessage( const QString &title, const QString &text, QWidget *parent = 0 ) { return createMessage( title, text, QIcon(), parent ); } 00078 static QWidget* createMessage( const QString &title, const QString &text, const QIcon &icon, QWidget *parent = 0 ); 00079 00081 void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 ) { pushMessage( QString::null, text, level, duration ); } 00083 void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 ); 00084 00085 signals: 00087 void widgetAdded( QWidget *widget ); 00088 00090 void widgetRemoved( QWidget *widget ); 00091 00092 public slots: 00097 bool popWidget(); 00098 00102 bool clearWidgets(); 00103 00104 protected: 00105 void mousePressEvent( QMouseEvent * e ); 00106 00107 private: 00108 class QgsMessageBarItem 00109 { 00110 public: 00111 QgsMessageBarItem( QWidget *widget, const QString &styleSheet, int duration = 0 ): 00112 mWidget( widget ), mStyleSheet( styleSheet ), mDuration( duration ) {} 00113 ~QgsMessageBarItem() {} 00114 00115 QWidget* widget() const { return mWidget; } 00116 QString styleSheet() const { return mStyleSheet; } 00117 int duration() const { return mDuration; } 00118 00119 private: 00120 QWidget *mWidget; 00121 QString mStyleSheet; 00122 int mDuration; // 0 value indicates no timeout duration 00123 }; 00124 00125 void pushWidget( QWidget *widget, const QString &styleSheet, int duration = 0 ); 00126 00127 void popItem( QgsMessageBarItem *item ); 00128 void pushItem( QgsMessageBarItem *item ); 00129 00130 QgsMessageBarItem *mCurrentItem; 00131 QList<QgsMessageBarItem *> mList; 00132 QMenu *mCloseMenu; 00133 QToolButton *mCloseBtn; 00134 QGridLayout *mLayout; 00135 QLabel *mItemCount; 00136 QAction *mActionCloseAll; 00137 QTimer *mCountdownTimer; 00138 QProgressBar *mCountProgress; 00139 QString mCountStyleSheet; 00140 00141 private slots: 00143 void updateItemCount(); 00144 00146 void updateCountdown(); 00147 void resetCountdown(); 00148 }; 00149 00150 #endif