| 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 | addInfo(this, "Name", QString(atomRef->getName().c_str()));
|
|---|
| 184 | addInfo(this, "Element", QString(atomRef->getElement().getName().c_str()));
|
|---|
| 185 | addInfo(this, "Mass", QString("%1").arg(atomRef->getMass()));
|
|---|
| 186 | addInfo(this, "Charge", QString("%1").arg(atomRef->getCharge()));
|
|---|
| 187 | addInfo(this, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
|
|---|
| 188 | addInfo(this, "Position x", QString(toString(atomRef->getPosition()[0]).c_str()));
|
|---|
| 189 | addInfo(this, "Position y", QString(toString(atomRef->getPosition()[1]).c_str()));
|
|---|
| 190 | addInfo(this, "Position z", QString(toString(atomRef->getPosition()[2]).c_str()));
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | QtAtomInfoPage::~QtAtomInfoPage()
|
|---|
| 194 | {
|
|---|
| 195 | if (atomRef)
|
|---|
| 196 | atomRef->signOff(this);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | void QtAtomInfoPage::update(Observable *subject){
|
|---|
| 200 | /*if(name != atomRef->name){
|
|---|
| 201 | name = atomRef->name;
|
|---|
| 202 | emit nameChanged(this,name);
|
|---|
| 203 | }*/
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | void QtAtomInfoPage::subjectKilled(Observable *subject){
|
|---|
| 207 | atomRef = NULL;
|
|---|
| 208 | emit atomKilled();
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /************************ Tab for single Molecules *****************/
|
|---|
| 212 |
|
|---|
| 213 | QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
|
|---|
| 214 | QTreeWidget(parent),
|
|---|
| 215 | Observer("QTMoleculePage"),
|
|---|
| 216 | mol(_mol)
|
|---|
| 217 | {
|
|---|
| 218 | mol->signOn(this);
|
|---|
| 219 |
|
|---|
| 220 | setColumnCount(2);
|
|---|
| 221 | QStringList header;
|
|---|
| 222 | header << "data";
|
|---|
| 223 | header << "value";
|
|---|
| 224 | setHeaderLabels(header);
|
|---|
| 225 |
|
|---|
| 226 | addInfo(this, "Name", QString(mol->getName().c_str()));
|
|---|
| 227 | addInfo(this, "Formula", QString(mol->getFormula().toString().c_str()));
|
|---|
| 228 | addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
|---|
| 229 | addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNoNonHydrogen()));
|
|---|
| 230 | addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
|
|---|
| 231 | const Vector molCenter = mol->DetermineCenterOfAll();
|
|---|
| 232 | addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
|
|---|
| 233 | addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
|
|---|
| 234 | addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | QtMoleculeInfoPage::~QtMoleculeInfoPage(){
|
|---|
| 238 | if (mol)
|
|---|
| 239 | mol->signOff(this);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | void QtMoleculeInfoPage::update(Observable *subject){ std::cout << "tab mol update\n";
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | void QtMoleculeInfoPage::subjectKilled(Observable *subject){
|
|---|
| 246 | mol = NULL;
|
|---|
| 247 | emit moleculeKilled();
|
|---|
| 248 | }
|
|---|