1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * QtInfoBox.cpp
|
---|
25 | *
|
---|
26 | * Created on: Mar 4, 2010
|
---|
27 | * Author: crueger
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "Views/Qt4/QtInfoBox.hpp"
|
---|
36 |
|
---|
37 | #include <iostream>
|
---|
38 | #include <QAbstractItemView>
|
---|
39 |
|
---|
40 | #include "CodePatterns/MemDebug.hpp"
|
---|
41 |
|
---|
42 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
43 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
44 |
|
---|
45 | #include "molecule.hpp"
|
---|
46 | #include "Element/element.hpp"
|
---|
47 | #include "World.hpp"
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | /***************** Basic structure for tab layout ***********/
|
---|
52 |
|
---|
53 | QtInfoBox::QtInfoBox() :
|
---|
54 | QTabWidget(),
|
---|
55 | curAtomId(-1), nextAtomId(-1),
|
---|
56 | curMoleculeId(-1), nextMoleculeId(-1),
|
---|
57 | page_mol(NULL), page_atom(NULL)
|
---|
58 | {
|
---|
59 | timer = new QTimer(this);
|
---|
60 | timer->setSingleShot(true);
|
---|
61 |
|
---|
62 | setMinimumWidth(200);
|
---|
63 | setMinimumHeight(220);
|
---|
64 | currentPage = 0;
|
---|
65 |
|
---|
66 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
---|
67 | }
|
---|
68 |
|
---|
69 | QtInfoBox::~QtInfoBox()
|
---|
70 | {
|
---|
71 | clearTabs();
|
---|
72 | }
|
---|
73 |
|
---|
74 | void QtInfoBox::atomHover(const atomId_t _id)
|
---|
75 | {
|
---|
76 | nextAtomId = _id;
|
---|
77 | timer->start(500);
|
---|
78 | }
|
---|
79 |
|
---|
80 | void QtInfoBox::moleculeHover(const moleculeId_t _id)
|
---|
81 | {
|
---|
82 | nextMoleculeId = _id;
|
---|
83 | timer->start(500);
|
---|
84 | }
|
---|
85 |
|
---|
86 | void QtInfoBox::timerTimeout()
|
---|
87 | {
|
---|
88 | if (nextAtomId != (atomId_t)-1)
|
---|
89 | showAtom(nextAtomId);
|
---|
90 | if (nextMoleculeId != (moleculeId_t)-1)
|
---|
91 | showMolecule(nextMoleculeId);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void QtInfoBox::clearTabs()
|
---|
95 | {
|
---|
96 | if (page_atom){
|
---|
97 | //removeTab(indexOf(page_atom));
|
---|
98 | delete(page_atom);
|
---|
99 | page_atom = NULL;
|
---|
100 | }
|
---|
101 | if (page_mol){
|
---|
102 | //removeTab(indexOf(page_mol));
|
---|
103 | delete(page_mol);
|
---|
104 | page_mol = NULL;
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | void QtInfoBox::showAtom(const atomId_t _id)
|
---|
109 | {
|
---|
110 | currentPage = currentIndex();
|
---|
111 |
|
---|
112 | // Remove old tabs.
|
---|
113 | clearTabs();
|
---|
114 |
|
---|
115 | const atom *curAtom = const_cast<const World &>(World::getInstance()).
|
---|
116 | getAtom(AtomById(_id));
|
---|
117 | curAtomId = curAtom->getId();
|
---|
118 | nextAtomId = -1;
|
---|
119 | nextMoleculeId = -1;
|
---|
120 |
|
---|
121 | // Show new tabs.
|
---|
122 | if (curAtom){
|
---|
123 | page_atom = new QtAtomInfoPage(curAtom, this);
|
---|
124 | addTab(page_atom, "Atom");
|
---|
125 | connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
|
---|
126 |
|
---|
127 | if (curAtom->getMolecule()){
|
---|
128 | page_mol = new QtMoleculeInfoPage(curAtom->getMolecule(), this);
|
---|
129 | addTab(page_mol, "Molecule");
|
---|
130 | connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
|
---|
131 |
|
---|
132 | if (currentPage > 0)
|
---|
133 | setCurrentIndex(currentPage);
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | void QtInfoBox::showMolecule(const moleculeId_t _id)
|
---|
139 | {
|
---|
140 | currentPage = currentIndex();
|
---|
141 |
|
---|
142 | // Remove old tabs.
|
---|
143 | clearTabs();
|
---|
144 |
|
---|
145 | const molecule *curMolecule = const_cast<const World &>(World::getInstance()).
|
---|
146 | getMolecule(MoleculeById(_id));
|
---|
147 | nextAtomId = -1;
|
---|
148 | nextMoleculeId = -1;
|
---|
149 |
|
---|
150 | // Show new tabs.
|
---|
151 | if (curMolecule){
|
---|
152 | page_mol = new QtMoleculeInfoPage(curMolecule, this);
|
---|
153 | addTab(page_mol, "Molecule");
|
---|
154 | connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
|
---|
155 |
|
---|
156 | if (currentPage > 0)
|
---|
157 | setCurrentIndex(currentPage);
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | /************************ Tab for single Atoms ********************/
|
---|
162 |
|
---|
163 | static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
|
---|
164 | {
|
---|
165 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
|
---|
166 | treeItem->setText(0, key);
|
---|
167 | treeItem->setText(1, value);
|
---|
168 | }
|
---|
169 |
|
---|
170 | QtAtomInfoPage::QtAtomInfoPage(const atom *_atom, QWidget *parent) :
|
---|
171 | QTreeWidget(parent),
|
---|
172 | Observer("QTAtomPage"),
|
---|
173 | atomRef(_atom)
|
---|
174 | {
|
---|
175 | atomRef->signOn(this);
|
---|
176 |
|
---|
177 | setColumnCount(2);
|
---|
178 | QStringList header;
|
---|
179 | header << "data";
|
---|
180 | header << "value";
|
---|
181 | setHeaderLabels(header);
|
---|
182 |
|
---|
183 | updatePage();
|
---|
184 | }
|
---|
185 |
|
---|
186 | void QtAtomInfoPage::updatePage()
|
---|
187 | {
|
---|
188 | clear();
|
---|
189 |
|
---|
190 | addInfo(this, "Name", QString(atomRef->getName().c_str()));
|
---|
191 | addInfo(this, "Element", QString(atomRef->getElement().getName().c_str()));
|
---|
192 | addInfo(this, "Mass", QString("%1").arg(atomRef->getMass()));
|
---|
193 | addInfo(this, "Charge", QString("%1").arg(atomRef->getCharge()));
|
---|
194 | addInfo(this, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
|
---|
195 | addInfo(this, "Position x", QString(toString(atomRef->getPosition()[0]).c_str()));
|
---|
196 | addInfo(this, "Position y", QString(toString(atomRef->getPosition()[1]).c_str()));
|
---|
197 | addInfo(this, "Position z", QString(toString(atomRef->getPosition()[2]).c_str()));
|
---|
198 | }
|
---|
199 |
|
---|
200 | QtAtomInfoPage::~QtAtomInfoPage()
|
---|
201 | {
|
---|
202 | if (atomRef)
|
---|
203 | atomRef->signOff(this);
|
---|
204 | }
|
---|
205 |
|
---|
206 | void QtAtomInfoPage::update(Observable *subject)
|
---|
207 | {
|
---|
208 | if (dynamic_cast<atom *>(subject) == atomRef)
|
---|
209 | updatePage();
|
---|
210 | }
|
---|
211 |
|
---|
212 | void QtAtomInfoPage::subjectKilled(Observable *subject){
|
---|
213 | atomRef = NULL;
|
---|
214 | emit atomKilled();
|
---|
215 | }
|
---|
216 |
|
---|
217 | /************************ Tab for single Molecules *****************/
|
---|
218 |
|
---|
219 | QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
|
---|
220 | QTreeWidget(parent),
|
---|
221 | Observer("QTMoleculePage"),
|
---|
222 | mol(_mol)
|
---|
223 | {
|
---|
224 | mol->signOn(this);
|
---|
225 |
|
---|
226 | setColumnCount(2);
|
---|
227 | QStringList header;
|
---|
228 | header << "data";
|
---|
229 | header << "value";
|
---|
230 | setHeaderLabels(header);
|
---|
231 |
|
---|
232 | updatePage();
|
---|
233 | }
|
---|
234 |
|
---|
235 | void QtMoleculeInfoPage::updatePage()
|
---|
236 | {
|
---|
237 | clear();
|
---|
238 |
|
---|
239 | addInfo(this, "Name", QString(mol->getName().c_str()));
|
---|
240 | addInfo(this, "Formula", QString(mol->getFormula().toString().c_str()));
|
---|
241 | addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
---|
242 | addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNoNonHydrogen()));
|
---|
243 | addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
|
---|
244 | const Vector molCenter = mol->DetermineCenterOfAll();
|
---|
245 | addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
|
---|
246 | addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
|
---|
247 | addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
|
---|
248 | }
|
---|
249 |
|
---|
250 | QtMoleculeInfoPage::~QtMoleculeInfoPage(){
|
---|
251 | if (mol)
|
---|
252 | mol->signOff(this);
|
---|
253 | }
|
---|
254 |
|
---|
255 | void QtMoleculeInfoPage::update(Observable *subject){
|
---|
256 | if (dynamic_cast<molecule *>(subject) == mol)
|
---|
257 | updatePage();
|
---|
258 | }
|
---|
259 |
|
---|
260 | void QtMoleculeInfoPage::subjectKilled(Observable *subject){
|
---|
261 | mol = NULL;
|
---|
262 | emit moleculeKilled();
|
---|
263 | }
|
---|