[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 |
|
---|
[4f7473] | 44 | #include "Element/element.hpp"
|
---|
[367489] | 45 | #include "Element/periodentafel.hpp"
|
---|
[e7341e] | 46 | #include "World.hpp"
|
---|
[b47bfc] | 47 |
|
---|
| 48 | using namespace std;
|
---|
| 49 |
|
---|
| 50 | /***************** Basic structure for tab layout ***********/
|
---|
| 51 |
|
---|
[367489] | 52 | QtInfoBox::QtInfoBox(QtObservedInstanceBoard *_board) :
|
---|
[7b6bcfe] | 53 | QTabWidget(),
|
---|
[e7341e] | 54 | curAtomId(-1), nextAtomId(-1),
|
---|
| 55 | curMoleculeId(-1), nextMoleculeId(-1),
|
---|
[367489] | 56 | page_mol(NULL), page_atom(NULL),
|
---|
| 57 | board(_board),
|
---|
| 58 | currentPage(0),
|
---|
| 59 | periode(World::getInstance().getPeriode())
|
---|
[b47bfc] | 60 | {
|
---|
[4a2f3e] | 61 | timer = new QTimer(this);
|
---|
| 62 | timer->setSingleShot(true);
|
---|
[b47bfc] | 63 |
|
---|
[0b2be1] | 64 | setMinimumWidth(200);
|
---|
[5dcb3c] | 65 | setMinimumHeight(220);
|
---|
[0b2be1] | 66 |
|
---|
[4a2f3e] | 67 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
---|
[b47bfc] | 68 | }
|
---|
| 69 |
|
---|
[3c53fa] | 70 | QtInfoBox::~QtInfoBox()
|
---|
[be374a] | 71 | {
|
---|
| 72 | clearTabs();
|
---|
| 73 | }
|
---|
[b47bfc] | 74 |
|
---|
[e7341e] | 75 | void QtInfoBox::atomHover(const atomId_t _id)
|
---|
[4a2f3e] | 76 | {
|
---|
[e7341e] | 77 | nextAtomId = _id;
|
---|
[2b596f] | 78 | timer->start(500);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[e7341e] | 81 | void QtInfoBox::moleculeHover(const moleculeId_t _id)
|
---|
[2b596f] | 82 | {
|
---|
[e7341e] | 83 | nextMoleculeId = _id;
|
---|
[4a2f3e] | 84 | timer->start(500);
|
---|
[b47bfc] | 85 | }
|
---|
| 86 |
|
---|
[3c53fa] | 87 | void QtInfoBox::timerTimeout()
|
---|
[4a2f3e] | 88 | {
|
---|
[e7341e] | 89 | if (nextAtomId != (atomId_t)-1)
|
---|
| 90 | showAtom(nextAtomId);
|
---|
| 91 | if (nextMoleculeId != (moleculeId_t)-1)
|
---|
| 92 | showMolecule(nextMoleculeId);
|
---|
[b47bfc] | 93 | }
|
---|
| 94 |
|
---|
[3c53fa] | 95 | void QtInfoBox::clearTabs()
|
---|
[7b6bcfe] | 96 | {
|
---|
| 97 | if (page_atom){
|
---|
[be374a] | 98 | //removeTab(indexOf(page_atom));
|
---|
[7b6bcfe] | 99 | delete(page_atom);
|
---|
| 100 | page_atom = NULL;
|
---|
| 101 | }
|
---|
| 102 | if (page_mol){
|
---|
[be374a] | 103 | //removeTab(indexOf(page_mol));
|
---|
[7b6bcfe] | 104 | delete(page_mol);
|
---|
| 105 | page_mol = NULL;
|
---|
| 106 | }
|
---|
[be374a] | 107 | }
|
---|
[7b6bcfe] | 108 |
|
---|
[e7341e] | 109 | void QtInfoBox::showAtom(const atomId_t _id)
|
---|
[be374a] | 110 | {
|
---|
[52575c] | 111 | currentPage = currentIndex();
|
---|
| 112 |
|
---|
[be374a] | 113 | // Remove old tabs.
|
---|
| 114 | clearTabs();
|
---|
| 115 |
|
---|
[367489] | 116 | QtObservedAtom::ptr curAtom = board->getObservedAtom(_id);
|
---|
[7b6bcfe] | 117 |
|
---|
| 118 | // Show new tabs.
|
---|
[4a2f3e] | 119 | if (curAtom){
|
---|
[367489] | 120 | curAtomId = curAtom->getAtomIndex();
|
---|
| 121 | nextAtomId = -1;
|
---|
| 122 | nextMoleculeId = -1;
|
---|
[4f7473] | 123 |
|
---|
[367489] | 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 | }
|
---|
[7772aa] | 139 | }
|
---|
[7b6bcfe] | 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[e7341e] | 143 | void QtInfoBox::showMolecule(const moleculeId_t _id)
|
---|
[2b596f] | 144 | {
|
---|
| 145 | currentPage = currentIndex();
|
---|
| 146 |
|
---|
| 147 | // Remove old tabs.
|
---|
| 148 | clearTabs();
|
---|
| 149 |
|
---|
[367489] | 150 | QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(_id);
|
---|
[e7341e] | 151 | nextAtomId = -1;
|
---|
| 152 | nextMoleculeId = -1;
|
---|
[2b596f] | 153 |
|
---|
| 154 | // Show new tabs.
|
---|
| 155 | if (curMolecule){
|
---|
| 156 | page_mol = new QtMoleculeInfoPage(curMolecule, this);
|
---|
| 157 | addTab(page_mol, "Molecule");
|
---|
[367489] | 158 | connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearTabs()));
|
---|
[2b596f] | 159 |
|
---|
| 160 | if (currentPage > 0)
|
---|
| 161 | setCurrentIndex(currentPage);
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[7b6bcfe] | 165 | /************************ Tab for single Atoms ********************/
|
---|
[b47bfc] | 166 |
|
---|
[4f7473] | 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 |
|
---|
[367489] | 174 | QtAtomInfoPage::QtAtomInfoPage(
|
---|
| 175 | QtObservedAtom::ptr &_atom,
|
---|
| 176 | periodentafel *_periode,
|
---|
| 177 | QWidget *parent) :
|
---|
[0b2be1] | 178 | QTreeWidget(parent),
|
---|
[367489] | 179 | atomRef(_atom),
|
---|
| 180 | periode(_periode)
|
---|
[7b6bcfe] | 181 | {
|
---|
[0b2be1] | 182 | setColumnCount(2);
|
---|
[4f7473] | 183 | QStringList header;
|
---|
| 184 | header << "data";
|
---|
| 185 | header << "value";
|
---|
[0b2be1] | 186 | setHeaderLabels(header);
|
---|
[4f7473] | 187 |
|
---|
[4965922] | 188 | updatePage();
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | void QtAtomInfoPage::updatePage()
|
---|
| 192 | {
|
---|
| 193 | clear();
|
---|
| 194 |
|
---|
[2831b3] | 195 | if (atomRef == NULL)
|
---|
| 196 | return;
|
---|
[367489] | 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()));
|
---|
[7b6bcfe] | 206 | }
|
---|
[b47bfc] | 207 |
|
---|
[3c53fa] | 208 | QtAtomInfoPage::~QtAtomInfoPage()
|
---|
[367489] | 209 | {}
|
---|
[b47bfc] | 210 |
|
---|
| 211 | /************************ Tab for single Molecules *****************/
|
---|
| 212 |
|
---|
[367489] | 213 | QtMoleculeInfoPage::QtMoleculeInfoPage(
|
---|
| 214 | QtObservedMolecule::ptr &_mol,
|
---|
| 215 | QWidget *parent) :
|
---|
[0b2be1] | 216 | QTreeWidget(parent),
|
---|
[4f7473] | 217 | mol(_mol)
|
---|
[b47bfc] | 218 | {
|
---|
[0b2be1] | 219 | setColumnCount(2);
|
---|
[4f7473] | 220 | QStringList header;
|
---|
| 221 | header << "data";
|
---|
| 222 | header << "value";
|
---|
[0b2be1] | 223 | setHeaderLabels(header);
|
---|
[4f7473] | 224 |
|
---|
[4965922] | 225 | updatePage();
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void QtMoleculeInfoPage::updatePage()
|
---|
| 229 | {
|
---|
| 230 | clear();
|
---|
| 231 |
|
---|
[2831b3] | 232 | if (mol == NULL)
|
---|
| 233 | return;
|
---|
[367489] | 234 | addInfo(this, "Name", QString(mol->getMolName().c_str()));
|
---|
| 235 | addInfo(this, "Formula", QString(mol->getMolFormula().c_str()));
|
---|
[0b2be1] | 236 | addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
---|
[367489] | 237 | addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNonHydrogenCount()));
|
---|
[0b2be1] | 238 | addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
|
---|
[367489] | 239 | const Vector molCenter = mol->getMolCenter();
|
---|
[5dcb3c] | 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]));
|
---|
[b47bfc] | 243 | }
|
---|
| 244 |
|
---|
[367489] | 245 | QtMoleculeInfoPage::~QtMoleculeInfoPage()
|
---|
| 246 | {}
|
---|