[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 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/>.
|
---|
[bcf653] | 21 | */
|
---|
| 22 |
|
---|
[b47bfc] | 23 | /*
|
---|
[3c53fa] | 24 | * QtInfoBox.cpp
|
---|
[b47bfc] | 25 | *
|
---|
| 26 | * Created on: Mar 4, 2010
|
---|
| 27 | * Author: crueger
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[bf3817] | 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
[bbbad5] | 34 |
|
---|
[3c53fa] | 35 | #include "Views/Qt4/QtInfoBox.hpp"
|
---|
[b47bfc] | 36 |
|
---|
| 37 | #include <iostream>
|
---|
[4f7473] | 38 | #include <QAbstractItemView>
|
---|
[b47bfc] | 39 |
|
---|
[ad011c] | 40 | #include "CodePatterns/MemDebug.hpp"
|
---|
[bbbad5] | 41 |
|
---|
[367489] | 42 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
[e7341e] | 43 |
|
---|
[cf9287] | 44 | #include <boost/thread/locks.hpp>
|
---|
| 45 |
|
---|
[4f7473] | 46 | #include "Element/element.hpp"
|
---|
[367489] | 47 | #include "Element/periodentafel.hpp"
|
---|
[e7341e] | 48 | #include "World.hpp"
|
---|
[b47bfc] | 49 |
|
---|
| 50 | using namespace std;
|
---|
| 51 |
|
---|
| 52 | /***************** Basic structure for tab layout ***********/
|
---|
| 53 |
|
---|
[b2c2e4] | 54 | QtInfoBox::QtInfoBox(QtObservedInstanceBoard *_board, QWidget *_parent) :
|
---|
| 55 | QTabWidget(_parent),
|
---|
[e7341e] | 56 | curAtomId(-1), nextAtomId(-1),
|
---|
| 57 | curMoleculeId(-1), nextMoleculeId(-1),
|
---|
[367489] | 58 | page_mol(NULL), page_atom(NULL),
|
---|
| 59 | board(_board),
|
---|
| 60 | currentPage(0),
|
---|
| 61 | periode(World::getInstance().getPeriode())
|
---|
[b47bfc] | 62 | {
|
---|
[4a2f3e] | 63 | timer = new QTimer(this);
|
---|
| 64 | timer->setSingleShot(true);
|
---|
[b47bfc] | 65 |
|
---|
[0b2be1] | 66 | setMinimumWidth(200);
|
---|
[5dcb3c] | 67 | setMinimumHeight(220);
|
---|
[0b2be1] | 68 |
|
---|
[4a2f3e] | 69 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
---|
[b47bfc] | 70 | }
|
---|
| 71 |
|
---|
[3c53fa] | 72 | QtInfoBox::~QtInfoBox()
|
---|
[be374a] | 73 | {
|
---|
[cf9287] | 74 | clearAtomTab();
|
---|
| 75 | clearMoleculeTab();
|
---|
[be374a] | 76 | }
|
---|
[b47bfc] | 77 |
|
---|
[e7341e] | 78 | void QtInfoBox::atomHover(const atomId_t _id)
|
---|
[4a2f3e] | 79 | {
|
---|
[e7341e] | 80 | nextAtomId = _id;
|
---|
[2b596f] | 81 | timer->start(500);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[e7341e] | 84 | void QtInfoBox::moleculeHover(const moleculeId_t _id)
|
---|
[2b596f] | 85 | {
|
---|
[e7341e] | 86 | nextMoleculeId = _id;
|
---|
[4a2f3e] | 87 | timer->start(500);
|
---|
[b47bfc] | 88 | }
|
---|
| 89 |
|
---|
[3c53fa] | 90 | void QtInfoBox::timerTimeout()
|
---|
[4a2f3e] | 91 | {
|
---|
[e7341e] | 92 | if (nextAtomId != (atomId_t)-1)
|
---|
| 93 | showAtom(nextAtomId);
|
---|
| 94 | if (nextMoleculeId != (moleculeId_t)-1)
|
---|
| 95 | showMolecule(nextMoleculeId);
|
---|
[b47bfc] | 96 | }
|
---|
| 97 |
|
---|
[cf9287] | 98 | void QtInfoBox::clearAtomTab()
|
---|
[7b6bcfe] | 99 | {
|
---|
[cf9287] | 100 | boost::recursive_mutex::scoped_lock lock(tabs_mutex);
|
---|
[7b6bcfe] | 101 | if (page_atom){
|
---|
[42d7dc] | 102 | disconnect(page_atom->getAtom().get(), SIGNAL(atomRemoved()), this, SLOT(clearAtomTab()));
|
---|
[be374a] | 103 | //removeTab(indexOf(page_atom));
|
---|
[7b6bcfe] | 104 | delete(page_atom);
|
---|
| 105 | page_atom = NULL;
|
---|
| 106 | }
|
---|
[cf9287] | 107 | }
|
---|
| 108 |
|
---|
| 109 | void QtInfoBox::clearMoleculeTab()
|
---|
| 110 | {
|
---|
| 111 | boost::recursive_mutex::scoped_lock lock(tabs_mutex);
|
---|
[7b6bcfe] | 112 | if (page_mol){
|
---|
[42d7dc] | 113 | disconnect(page_mol->getMolecule().get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
|
---|
[be374a] | 114 | //removeTab(indexOf(page_mol));
|
---|
[7b6bcfe] | 115 | delete(page_mol);
|
---|
| 116 | page_mol = NULL;
|
---|
| 117 | }
|
---|
[be374a] | 118 | }
|
---|
[7b6bcfe] | 119 |
|
---|
[e7341e] | 120 | void QtInfoBox::showAtom(const atomId_t _id)
|
---|
[be374a] | 121 | {
|
---|
[52575c] | 122 | currentPage = currentIndex();
|
---|
| 123 |
|
---|
[be374a] | 124 | // Remove old tabs.
|
---|
[cf9287] | 125 | clearAtomTab();
|
---|
| 126 | clearMoleculeTab();
|
---|
[be374a] | 127 |
|
---|
[367489] | 128 | QtObservedAtom::ptr curAtom = board->getObservedAtom(_id);
|
---|
[7b6bcfe] | 129 |
|
---|
| 130 | // Show new tabs.
|
---|
[4a2f3e] | 131 | if (curAtom){
|
---|
[367489] | 132 | curAtomId = curAtom->getAtomIndex();
|
---|
| 133 | nextAtomId = -1;
|
---|
| 134 | nextMoleculeId = -1;
|
---|
[4f7473] | 135 |
|
---|
[cf9287] | 136 | boost::recursive_mutex::scoped_lock lock(tabs_mutex);
|
---|
[367489] | 137 | page_atom = new QtAtomInfoPage(curAtom, periode, this);
|
---|
| 138 | addTab(page_atom, "Atom");
|
---|
[cf9287] | 139 | connect(curAtom.get(), SIGNAL(atomRemoved()), this, SLOT(clearAtomTab()));
|
---|
[367489] | 140 |
|
---|
| 141 | const moleculeId_t molid = curAtom->getAtomMoleculeIndex();
|
---|
| 142 | if (molid != (moleculeId_t)-1) {
|
---|
| 143 | QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(molid);
|
---|
| 144 | if (curMolecule) {
|
---|
| 145 | page_mol = new QtMoleculeInfoPage(curMolecule, this);
|
---|
| 146 | addTab(page_mol, "Molecule");
|
---|
| 147 | connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
|
---|
| 148 |
|
---|
| 149 | if (currentPage > 0)
|
---|
| 150 | setCurrentIndex(currentPage);
|
---|
| 151 | }
|
---|
[7772aa] | 152 | }
|
---|
[7b6bcfe] | 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[e7341e] | 156 | void QtInfoBox::showMolecule(const moleculeId_t _id)
|
---|
[2b596f] | 157 | {
|
---|
| 158 | currentPage = currentIndex();
|
---|
| 159 |
|
---|
| 160 | // Remove old tabs.
|
---|
[cf9287] | 161 | clearAtomTab();
|
---|
| 162 | clearMoleculeTab();
|
---|
[2b596f] | 163 |
|
---|
[367489] | 164 | QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(_id);
|
---|
[e7341e] | 165 | nextAtomId = -1;
|
---|
| 166 | nextMoleculeId = -1;
|
---|
[2b596f] | 167 |
|
---|
| 168 | // Show new tabs.
|
---|
| 169 | if (curMolecule){
|
---|
[cf9287] | 170 | boost::recursive_mutex::scoped_lock lock(tabs_mutex);
|
---|
[2b596f] | 171 | page_mol = new QtMoleculeInfoPage(curMolecule, this);
|
---|
| 172 | addTab(page_mol, "Molecule");
|
---|
[cf9287] | 173 | connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
|
---|
[2b596f] | 174 |
|
---|
| 175 | if (currentPage > 0)
|
---|
| 176 | setCurrentIndex(currentPage);
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[7b6bcfe] | 180 | /************************ Tab for single Atoms ********************/
|
---|
[b47bfc] | 181 |
|
---|
[4f7473] | 182 | static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
|
---|
| 183 | {
|
---|
| 184 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
|
---|
| 185 | treeItem->setText(0, key);
|
---|
| 186 | treeItem->setText(1, value);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[367489] | 189 | QtAtomInfoPage::QtAtomInfoPage(
|
---|
| 190 | QtObservedAtom::ptr &_atom,
|
---|
| 191 | periodentafel *_periode,
|
---|
| 192 | QWidget *parent) :
|
---|
[0b2be1] | 193 | QTreeWidget(parent),
|
---|
[367489] | 194 | atomRef(_atom),
|
---|
| 195 | periode(_periode)
|
---|
[7b6bcfe] | 196 | {
|
---|
[0b2be1] | 197 | setColumnCount(2);
|
---|
[4f7473] | 198 | QStringList header;
|
---|
| 199 | header << "data";
|
---|
| 200 | header << "value";
|
---|
[0b2be1] | 201 | setHeaderLabels(header);
|
---|
[4f7473] | 202 |
|
---|
[4965922] | 203 | updatePage();
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | void QtAtomInfoPage::updatePage()
|
---|
| 207 | {
|
---|
| 208 | clear();
|
---|
| 209 |
|
---|
[2831b3] | 210 | if (atomRef == NULL)
|
---|
| 211 | return;
|
---|
[367489] | 212 | const element * const _element = periode->FindElement(atomRef->getAtomElement());
|
---|
| 213 | addInfo(this, "Name", QString(atomRef->getAtomName().c_str()));
|
---|
| 214 | addInfo(this, "Element", QString(_element->getName().c_str()));
|
---|
| 215 | addInfo(this, "Mass", QString("%1").arg(_element->getMass()));
|
---|
| 216 | addInfo(this, "Charge", QString("%1").arg(_element->getCharge()));
|
---|
| 217 | addInfo(this, "Bonds", QString("%1").arg(atomRef->getAtomBonds().size()));
|
---|
| 218 | addInfo(this, "Position x", QString(toString(atomRef->getAtomPosition()[0]).c_str()));
|
---|
| 219 | addInfo(this, "Position y", QString(toString(atomRef->getAtomPosition()[1]).c_str()));
|
---|
| 220 | addInfo(this, "Position z", QString(toString(atomRef->getAtomPosition()[2]).c_str()));
|
---|
[7b6bcfe] | 221 | }
|
---|
[b47bfc] | 222 |
|
---|
[3c53fa] | 223 | QtAtomInfoPage::~QtAtomInfoPage()
|
---|
[367489] | 224 | {}
|
---|
[b47bfc] | 225 |
|
---|
| 226 | /************************ Tab for single Molecules *****************/
|
---|
| 227 |
|
---|
[367489] | 228 | QtMoleculeInfoPage::QtMoleculeInfoPage(
|
---|
| 229 | QtObservedMolecule::ptr &_mol,
|
---|
| 230 | QWidget *parent) :
|
---|
[0b2be1] | 231 | QTreeWidget(parent),
|
---|
[4f7473] | 232 | mol(_mol)
|
---|
[b47bfc] | 233 | {
|
---|
[0b2be1] | 234 | setColumnCount(2);
|
---|
[4f7473] | 235 | QStringList header;
|
---|
| 236 | header << "data";
|
---|
| 237 | header << "value";
|
---|
[0b2be1] | 238 | setHeaderLabels(header);
|
---|
[4f7473] | 239 |
|
---|
[4965922] | 240 | updatePage();
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | void QtMoleculeInfoPage::updatePage()
|
---|
| 244 | {
|
---|
| 245 | clear();
|
---|
| 246 |
|
---|
[2831b3] | 247 | if (mol == NULL)
|
---|
| 248 | return;
|
---|
[367489] | 249 | addInfo(this, "Name", QString(mol->getMolName().c_str()));
|
---|
| 250 | addInfo(this, "Formula", QString(mol->getMolFormula().c_str()));
|
---|
[0b2be1] | 251 | addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
---|
[367489] | 252 | addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNonHydrogenCount()));
|
---|
[0b2be1] | 253 | addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
|
---|
[367489] | 254 | const Vector molCenter = mol->getMolCenter();
|
---|
[5dcb3c] | 255 | addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
|
---|
| 256 | addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
|
---|
| 257 | addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
|
---|
[b47bfc] | 258 | }
|
---|
| 259 |
|
---|
[367489] | 260 | QtMoleculeInfoPage::~QtMoleculeInfoPage()
|
---|
| 261 | {}
|
---|