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 "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
43 |
|
---|
44 | #include "Element/element.hpp"
|
---|
45 | #include "Element/periodentafel.hpp"
|
---|
46 | #include "World.hpp"
|
---|
47 |
|
---|
48 | using namespace std;
|
---|
49 |
|
---|
50 | /***************** Basic structure for tab layout ***********/
|
---|
51 |
|
---|
52 | QtInfoBox::QtInfoBox(QtObservedInstanceBoard *_board) :
|
---|
53 | QTabWidget(),
|
---|
54 | curAtomId(-1), nextAtomId(-1),
|
---|
55 | curMoleculeId(-1), nextMoleculeId(-1),
|
---|
56 | page_mol(NULL), page_atom(NULL),
|
---|
57 | board(_board),
|
---|
58 | currentPage(0),
|
---|
59 | periode(World::getInstance().getPeriode())
|
---|
60 | {
|
---|
61 | timer = new QTimer(this);
|
---|
62 | timer->setSingleShot(true);
|
---|
63 |
|
---|
64 | setMinimumWidth(200);
|
---|
65 | setMinimumHeight(220);
|
---|
66 |
|
---|
67 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
---|
68 | }
|
---|
69 |
|
---|
70 | QtInfoBox::~QtInfoBox()
|
---|
71 | {
|
---|
72 | clearTabs();
|
---|
73 | }
|
---|
74 |
|
---|
75 | void QtInfoBox::atomHover(const atomId_t _id)
|
---|
76 | {
|
---|
77 | nextAtomId = _id;
|
---|
78 | timer->start(500);
|
---|
79 | }
|
---|
80 |
|
---|
81 | void QtInfoBox::moleculeHover(const moleculeId_t _id)
|
---|
82 | {
|
---|
83 | nextMoleculeId = _id;
|
---|
84 | timer->start(500);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void QtInfoBox::timerTimeout()
|
---|
88 | {
|
---|
89 | if (nextAtomId != (atomId_t)-1)
|
---|
90 | showAtom(nextAtomId);
|
---|
91 | if (nextMoleculeId != (moleculeId_t)-1)
|
---|
92 | showMolecule(nextMoleculeId);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void QtInfoBox::clearTabs()
|
---|
96 | {
|
---|
97 | if (page_atom){
|
---|
98 | //removeTab(indexOf(page_atom));
|
---|
99 | delete(page_atom);
|
---|
100 | page_atom = NULL;
|
---|
101 | }
|
---|
102 | if (page_mol){
|
---|
103 | //removeTab(indexOf(page_mol));
|
---|
104 | delete(page_mol);
|
---|
105 | page_mol = NULL;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | void QtInfoBox::showAtom(const atomId_t _id)
|
---|
110 | {
|
---|
111 | currentPage = currentIndex();
|
---|
112 |
|
---|
113 | // Remove old tabs.
|
---|
114 | clearTabs();
|
---|
115 |
|
---|
116 | QtObservedAtom::ptr curAtom = board->getObservedAtom(_id);
|
---|
117 |
|
---|
118 | // Show new tabs.
|
---|
119 | if (curAtom){
|
---|
120 | curAtomId = curAtom->getAtomIndex();
|
---|
121 | nextAtomId = -1;
|
---|
122 | nextMoleculeId = -1;
|
---|
123 |
|
---|
124 | page_atom = new QtAtomInfoPage(curAtom, periode, this);
|
---|
125 | addTab(page_atom, "Atom");
|
---|
126 | connect(curAtom.get(), SIGNAL(atomRemoved()), this, SLOT(clearTabs()));
|
---|
127 |
|
---|
128 | const moleculeId_t molid = curAtom->getAtomMoleculeIndex();
|
---|
129 | if (molid != (moleculeId_t)-1) {
|
---|
130 | QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(molid);
|
---|
131 | if (curMolecule) {
|
---|
132 | page_mol = new QtMoleculeInfoPage(curMolecule, this);
|
---|
133 | addTab(page_mol, "Molecule");
|
---|
134 | connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
|
---|
135 |
|
---|
136 | if (currentPage > 0)
|
---|
137 | setCurrentIndex(currentPage);
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | void QtInfoBox::showMolecule(const moleculeId_t _id)
|
---|
144 | {
|
---|
145 | currentPage = currentIndex();
|
---|
146 |
|
---|
147 | // Remove old tabs.
|
---|
148 | clearTabs();
|
---|
149 |
|
---|
150 | QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(_id);
|
---|
151 | nextAtomId = -1;
|
---|
152 | nextMoleculeId = -1;
|
---|
153 |
|
---|
154 | // Show new tabs.
|
---|
155 | if (curMolecule){
|
---|
156 | page_mol = new QtMoleculeInfoPage(curMolecule, this);
|
---|
157 | addTab(page_mol, "Molecule");
|
---|
158 | connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearTabs()));
|
---|
159 |
|
---|
160 | if (currentPage > 0)
|
---|
161 | setCurrentIndex(currentPage);
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | /************************ Tab for single Atoms ********************/
|
---|
166 |
|
---|
167 | static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
|
---|
168 | {
|
---|
169 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
|
---|
170 | treeItem->setText(0, key);
|
---|
171 | treeItem->setText(1, value);
|
---|
172 | }
|
---|
173 |
|
---|
174 | QtAtomInfoPage::QtAtomInfoPage(
|
---|
175 | QtObservedAtom::ptr &_atom,
|
---|
176 | periodentafel *_periode,
|
---|
177 | QWidget *parent) :
|
---|
178 | QTreeWidget(parent),
|
---|
179 | atomRef(_atom),
|
---|
180 | periode(_periode)
|
---|
181 | {
|
---|
182 | setColumnCount(2);
|
---|
183 | QStringList header;
|
---|
184 | header << "data";
|
---|
185 | header << "value";
|
---|
186 | setHeaderLabels(header);
|
---|
187 |
|
---|
188 | updatePage();
|
---|
189 | }
|
---|
190 |
|
---|
191 | void QtAtomInfoPage::updatePage()
|
---|
192 | {
|
---|
193 | clear();
|
---|
194 |
|
---|
195 | if (atomRef == NULL)
|
---|
196 | return;
|
---|
197 | const element * const _element = periode->FindElement(atomRef->getAtomElement());
|
---|
198 | addInfo(this, "Name", QString(atomRef->getAtomName().c_str()));
|
---|
199 | addInfo(this, "Element", QString(_element->getName().c_str()));
|
---|
200 | addInfo(this, "Mass", QString("%1").arg(_element->getMass()));
|
---|
201 | addInfo(this, "Charge", QString("%1").arg(_element->getCharge()));
|
---|
202 | addInfo(this, "Bonds", QString("%1").arg(atomRef->getAtomBonds().size()));
|
---|
203 | addInfo(this, "Position x", QString(toString(atomRef->getAtomPosition()[0]).c_str()));
|
---|
204 | addInfo(this, "Position y", QString(toString(atomRef->getAtomPosition()[1]).c_str()));
|
---|
205 | addInfo(this, "Position z", QString(toString(atomRef->getAtomPosition()[2]).c_str()));
|
---|
206 | }
|
---|
207 |
|
---|
208 | QtAtomInfoPage::~QtAtomInfoPage()
|
---|
209 | {}
|
---|
210 |
|
---|
211 | /************************ Tab for single Molecules *****************/
|
---|
212 |
|
---|
213 | QtMoleculeInfoPage::QtMoleculeInfoPage(
|
---|
214 | QtObservedMolecule::ptr &_mol,
|
---|
215 | QWidget *parent) :
|
---|
216 | QTreeWidget(parent),
|
---|
217 | mol(_mol)
|
---|
218 | {
|
---|
219 | setColumnCount(2);
|
---|
220 | QStringList header;
|
---|
221 | header << "data";
|
---|
222 | header << "value";
|
---|
223 | setHeaderLabels(header);
|
---|
224 |
|
---|
225 | updatePage();
|
---|
226 | }
|
---|
227 |
|
---|
228 | void QtMoleculeInfoPage::updatePage()
|
---|
229 | {
|
---|
230 | clear();
|
---|
231 |
|
---|
232 | if (mol == NULL)
|
---|
233 | return;
|
---|
234 | addInfo(this, "Name", QString(mol->getMolName().c_str()));
|
---|
235 | addInfo(this, "Formula", QString(mol->getMolFormula().c_str()));
|
---|
236 | addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
---|
237 | addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNonHydrogenCount()));
|
---|
238 | addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
|
---|
239 | const Vector molCenter = mol->getMolCenter();
|
---|
240 | addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
|
---|
241 | addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
|
---|
242 | addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
|
---|
243 | }
|
---|
244 |
|
---|
245 | QtMoleculeInfoPage::~QtMoleculeInfoPage()
|
---|
246 | {}
|
---|