QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsmessagebar.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmessagebar.h - description
3  -------------------
4  begin : June 2012
5  copyright : (C) 2012 by Giuseppe Sucameli
6  email : sucameli at faunalia dot it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSMESSAGEBAR_H
18 #define QGSMESSAGEBAR_H
19 
20 #include <qgisgui.h>
21 
22 #include <QString>
23 #include <QFrame>
24 #include <QIcon>
25 #include <QColor>
26 #include <QList>
27 
28 class QWidget;
29 class QGridLayout;
30 class QMenu;
31 class QProgressBar;
32 class QToolButton;
33 class QLabel;
34 class QAction;
35 class QTimer;
36 
37 class QgsMessageBarItem;
38 
42 class GUI_EXPORT QgsMessageBar: public QFrame
43 {
44  Q_OBJECT
45 
46  public:
48  {
49  INFO = 0,
50  WARNING = 1,
51  CRITICAL = 2,
52  SUCCESS = 3
53  };
54 
55  QgsMessageBar( QWidget *parent = 0 );
56  ~QgsMessageBar();
57 
62  void pushItem( QgsMessageBarItem *item );
63 
70  QgsMessageBarItem *pushWidget( QWidget *widget, MessageLevel level = INFO, int duration = 0 );
71 
77  bool popWidget( QgsMessageBarItem *item );
78 
80  static QgsMessageBarItem* createMessage( const QString &text, QWidget *parent = 0 );
82  static QgsMessageBarItem* createMessage( const QString &title, const QString &text, QWidget *parent = 0 );
84  static QgsMessageBarItem* createMessage( QWidget *widget, QWidget *parent = 0 );
85 
87  void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 ) { return pushMessage( QString::null, text, level, duration ); }
89  void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );
90 
91  signals:
93  void widgetAdded( QgsMessageBarItem *item );
94 
96  void widgetRemoved( QgsMessageBarItem *item );
97 
98  public slots:
103  bool popWidget();
104 
108  bool clearWidgets();
109 
115  void pushSuccess( const QString& title, const QString& message );
116 
122  void pushInfo( const QString& title, const QString& message );
123 
129  void pushWarning( const QString& title, const QString& message );
130 
136  void pushCritical( const QString& title, const QString& message );
137 
138  protected:
139  void mousePressEvent( QMouseEvent * e ) override;
140 
141  private:
142  void popItem( QgsMessageBarItem *item );
143  void showItem( QgsMessageBarItem *item );
144  QgsMessageBarItem *mCurrentItem;
145  QList<QgsMessageBarItem *> mItems;
146  QMenu *mCloseMenu;
147  QToolButton *mCloseBtn;
148  QGridLayout *mLayout;
149  QLabel *mItemCount;
150  QAction *mActionCloseAll;
151  QTimer *mCountdownTimer;
152  QProgressBar *mCountProgress;
153  QString mCountStyleSheet;
154 
155  private slots:
157  void updateItemCount();
158 
160  void updateCountdown();
161  void resetCountdown();
162 };
163 
164 #endif
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=0)
convenience method for pushing a message to the bar
Definition: qgsmessagebar.h:87
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:42