1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * QtStatusBar.cpp
|
---|
10 | *
|
---|
11 | * Created on: Feb 17, 2010
|
---|
12 | * Author: crueger
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include <sstream>
|
---|
21 |
|
---|
22 | #include <QtGui/QLabel>
|
---|
23 | #include <QtGui/QBoxLayout>
|
---|
24 | #include <QtGui/QProgressBar>
|
---|
25 |
|
---|
26 | #include "QtStatusBar.hpp"
|
---|
27 |
|
---|
28 | #include "CodePatterns/MemDebug.hpp"
|
---|
29 |
|
---|
30 | #include "World.hpp"
|
---|
31 | #include "Actions/Process.hpp"
|
---|
32 |
|
---|
33 | #define PLURAL_S(v) (((v)==1)?"":"s")
|
---|
34 |
|
---|
35 | using namespace MoleCuilder;
|
---|
36 |
|
---|
37 | QtStatusBar::QtStatusBar(QWidget *_parent) :
|
---|
38 | QStatusBar(_parent),
|
---|
39 | Observer("QtStatusBar"),
|
---|
40 | atomCount(World::getInstance().numAtoms()),
|
---|
41 | moleculeCount(World::getInstance().numMolecules()),
|
---|
42 | parent(_parent)
|
---|
43 | {
|
---|
44 | World::getInstance().signOn(this);
|
---|
45 | Process::AddObserver(this);
|
---|
46 | statusLabel = new QLabel(this);
|
---|
47 | statusLabel->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
|
---|
48 | addPermanentWidget(statusLabel);
|
---|
49 | redrawStatus();
|
---|
50 | }
|
---|
51 |
|
---|
52 | QtStatusBar::~QtStatusBar()
|
---|
53 | {
|
---|
54 | Process::RemoveObserver(this);
|
---|
55 | World::getInstance().signOff(this);
|
---|
56 | }
|
---|
57 |
|
---|
58 | void QtStatusBar::update(Observable *subject){
|
---|
59 | if (subject==World::getPointer()){
|
---|
60 | atomCount = World::getInstance().numAtoms();
|
---|
61 | moleculeCount = World::getInstance().numMolecules();
|
---|
62 | redrawStatus();
|
---|
63 | }
|
---|
64 | else {
|
---|
65 | // we probably have some process
|
---|
66 | Process *proc;
|
---|
67 | if((proc=dynamic_cast<Process*>(subject))){
|
---|
68 | redrawProcess(proc);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | void QtStatusBar::subjectKilled(Observable *subject){
|
---|
74 | // Processes don't notify when they are killed
|
---|
75 | atomCount = World::getInstance().numAtoms();
|
---|
76 | moleculeCount = World::getInstance().numMolecules();
|
---|
77 | World::getInstance().signOn(this);
|
---|
78 | redrawStatus();
|
---|
79 | }
|
---|
80 |
|
---|
81 | void QtStatusBar::redrawStatus(){
|
---|
82 | stringstream sstr;
|
---|
83 | sstr << "You have " << atomCount << " atom" << PLURAL_S(atomCount)
|
---|
84 | <<" in " << moleculeCount << " molecule" << PLURAL_S(moleculeCount);
|
---|
85 | statusLabel->setText(QString(sstr.str().c_str()));
|
---|
86 | }
|
---|
87 |
|
---|
88 | void QtStatusBar::redrawProcess(Process *proc){
|
---|
89 | progressIndicator *ind=0;
|
---|
90 | // see what we have to do with the process
|
---|
91 | if(proc->doesStart()){
|
---|
92 | ind = new progressIndicator(proc->getName());
|
---|
93 | ind->bar->setMaximum(proc->getMaxSteps());
|
---|
94 | progressBars.insert(pair<Process*,progressIndicator*>(proc,ind));
|
---|
95 | }
|
---|
96 | else {
|
---|
97 | ind = progressBars[proc];
|
---|
98 | }
|
---|
99 | if(activeProcess!=proc){
|
---|
100 | addWidget(ind->container);
|
---|
101 | activeProcess = proc;
|
---|
102 | }
|
---|
103 | ind->bar->setValue(proc->getCurrStep());
|
---|
104 | parent->repaint();
|
---|
105 | if(proc->doesStop()){
|
---|
106 | removeWidget(ind->container);
|
---|
107 | activeProcess = 0;
|
---|
108 | progressBars.erase(proc);
|
---|
109 | delete ind;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 | QtStatusBar::progressIndicator::progressIndicator(string name){
|
---|
116 | stringstream sstr;
|
---|
117 | sstr << "Busy (" << name << ")";
|
---|
118 | container = new QWidget();
|
---|
119 | layout = new QHBoxLayout(container);
|
---|
120 | label = new QLabel(QString(sstr.str().c_str()));
|
---|
121 | bar = new QProgressBar();
|
---|
122 |
|
---|
123 | layout->addWidget(label);
|
---|
124 | layout->addWidget(bar);
|
---|
125 | container->setLayout(layout);
|
---|
126 | }
|
---|
127 |
|
---|
128 | QtStatusBar::progressIndicator::~progressIndicator(){
|
---|
129 | delete container;
|
---|
130 | }
|
---|