| 1 | /* | 
|---|
| 2 | * QtStatusBar.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Feb 17, 2010 | 
|---|
| 5 | *      Author: crueger | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef QTSTATUSBAR_HPP_ | 
|---|
| 9 | #define QTSTATUSBAR_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | #include <map> | 
|---|
| 18 | #include <utility> | 
|---|
| 19 | #include <string> | 
|---|
| 20 | #include <QtGui/QStatusBar> | 
|---|
| 21 |  | 
|---|
| 22 | #include <boost/thread/recursive_mutex.hpp> | 
|---|
| 23 |  | 
|---|
| 24 | #include "CodePatterns/Observer/Observer.hpp" | 
|---|
| 25 |  | 
|---|
| 26 | class QBoxLayout; | 
|---|
| 27 | class QLabel; | 
|---|
| 28 | class QProgressBar; | 
|---|
| 29 | class QTimer; | 
|---|
| 30 |  | 
|---|
| 31 | namespace MoleCuilder { | 
|---|
| 32 | class ActionStatusList; | 
|---|
| 33 | class Process; | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | class QtStatusBar : public QStatusBar, public Observer | 
|---|
| 37 | { | 
|---|
| 38 | Q_OBJECT | 
|---|
| 39 |  | 
|---|
| 40 | struct progressIndicator{ | 
|---|
| 41 | progressIndicator(const std::string &name); | 
|---|
| 42 | ~progressIndicator(); | 
|---|
| 43 | QLabel *label; | 
|---|
| 44 | QProgressBar *bar; | 
|---|
| 45 | QBoxLayout *layout; | 
|---|
| 46 | QWidget *container; | 
|---|
| 47 | }; | 
|---|
| 48 | public: | 
|---|
| 49 | QtStatusBar(QWidget *parent=0); | 
|---|
| 50 | virtual ~QtStatusBar(); | 
|---|
| 51 |  | 
|---|
| 52 | void update(Observable *subject); | 
|---|
| 53 | void subjectKilled(Observable *subject); | 
|---|
| 54 | void recieveNotification(Observable *_publisher, Notification *_notification); | 
|---|
| 55 | virtual void paintEvent(QPaintEvent * event); | 
|---|
| 56 |  | 
|---|
| 57 | private slots: | 
|---|
| 58 | void updateProgressBar( | 
|---|
| 59 | const std::string name, | 
|---|
| 60 | const unsigned int maxsteps, | 
|---|
| 61 | const unsigned int currentstep, | 
|---|
| 62 | const bool StopStatus); | 
|---|
| 63 | void updateStatusMessage(); | 
|---|
| 64 |  | 
|---|
| 65 | signals: | 
|---|
| 66 | void redrawProgressBar( | 
|---|
| 67 | const std::string name, | 
|---|
| 68 | const unsigned int maxsteps, | 
|---|
| 69 | const unsigned int currentstep, | 
|---|
| 70 | const bool StopStatus); | 
|---|
| 71 |  | 
|---|
| 72 | private: | 
|---|
| 73 | void redrawStatus(); | 
|---|
| 74 |  | 
|---|
| 75 | void startTimer(); | 
|---|
| 76 | void stopTimer(); | 
|---|
| 77 |  | 
|---|
| 78 | int atomCount; | 
|---|
| 79 | int moleculeCount; | 
|---|
| 80 |  | 
|---|
| 81 | QLabel *statusLabel; | 
|---|
| 82 | QWidget *parent; | 
|---|
| 83 | typedef std::map<std::string,progressIndicator*> progressBars_t; | 
|---|
| 84 | progressBars_t progressBars; | 
|---|
| 85 | std::string activeProcess; | 
|---|
| 86 | //!> reference to the StatusList we are signed on | 
|---|
| 87 | MoleCuilder::ActionStatusList& StatusList; | 
|---|
| 88 | //!> indicates whether we are currently signed on | 
|---|
| 89 | bool StatusList_signedOn; | 
|---|
| 90 | //!> QTimer instance that causes regular updates of status messages | 
|---|
| 91 | QTimer *timer; | 
|---|
| 92 | //!> time interval in milliseconds | 
|---|
| 93 | const int timer_interval; | 
|---|
| 94 |  | 
|---|
| 95 | mutable boost::recursive_mutex refill_mutex; | 
|---|
| 96 | }; | 
|---|
| 97 |  | 
|---|
| 98 | #endif /* QTSTATUSBAR_HPP_ */ | 
|---|