[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 |
|
---|
| 42 | #include "molecule.hpp"
|
---|
[4f7473] | 43 | #include "Element/element.hpp"
|
---|
[b47bfc] | 44 |
|
---|
| 45 | using namespace std;
|
---|
| 46 |
|
---|
| 47 | /***************** Basic structure for tab layout ***********/
|
---|
| 48 |
|
---|
[3c53fa] | 49 | QtInfoBox::QtInfoBox() :
|
---|
[7b6bcfe] | 50 | QTabWidget(),
|
---|
[4a2f3e] | 51 | curAtom(NULL), nextAtom(NULL),
|
---|
[7b6bcfe] | 52 | page_mol(NULL), page_atom(NULL)
|
---|
[b47bfc] | 53 | {
|
---|
[4a2f3e] | 54 | timer = new QTimer(this);
|
---|
| 55 | timer->setSingleShot(true);
|
---|
[b47bfc] | 56 |
|
---|
[0b2be1] | 57 | setMinimumWidth(200);
|
---|
[4458b0] | 58 | setMinimumHeight(200);
|
---|
[52575c] | 59 | currentPage = 0;
|
---|
[0b2be1] | 60 |
|
---|
[4a2f3e] | 61 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
---|
[b47bfc] | 62 | }
|
---|
| 63 |
|
---|
[3c53fa] | 64 | QtInfoBox::~QtInfoBox()
|
---|
[be374a] | 65 | {
|
---|
| 66 | clearTabs();
|
---|
| 67 | }
|
---|
[b47bfc] | 68 |
|
---|
[3c53fa] | 69 | void QtInfoBox::atomHover(const atom *_atom)
|
---|
[4a2f3e] | 70 | {
|
---|
| 71 | nextAtom = _atom;
|
---|
| 72 | timer->start(500);
|
---|
[b47bfc] | 73 | }
|
---|
| 74 |
|
---|
[3c53fa] | 75 | void QtInfoBox::timerTimeout()
|
---|
[4a2f3e] | 76 | {
|
---|
| 77 | if (nextAtom)
|
---|
| 78 | showAtom(nextAtom);
|
---|
[b47bfc] | 79 | }
|
---|
| 80 |
|
---|
[3c53fa] | 81 | void QtInfoBox::clearTabs()
|
---|
[7b6bcfe] | 82 | {
|
---|
| 83 | if (page_atom){
|
---|
[be374a] | 84 | //removeTab(indexOf(page_atom));
|
---|
[7b6bcfe] | 85 | delete(page_atom);
|
---|
| 86 | page_atom = NULL;
|
---|
| 87 | }
|
---|
| 88 | if (page_mol){
|
---|
[be374a] | 89 | //removeTab(indexOf(page_mol));
|
---|
[7b6bcfe] | 90 | delete(page_mol);
|
---|
| 91 | page_mol = NULL;
|
---|
| 92 | }
|
---|
[be374a] | 93 | }
|
---|
[7b6bcfe] | 94 |
|
---|
[3c53fa] | 95 | void QtInfoBox::showAtom(const atom *_atom)
|
---|
[be374a] | 96 | {
|
---|
[52575c] | 97 | currentPage = currentIndex();
|
---|
| 98 |
|
---|
[be374a] | 99 | // Remove old tabs.
|
---|
| 100 | clearTabs();
|
---|
| 101 |
|
---|
| 102 | curAtom = _atom;
|
---|
[7b6bcfe] | 103 |
|
---|
| 104 | // Show new tabs.
|
---|
[4a2f3e] | 105 | if (curAtom){
|
---|
[0b2be1] | 106 | page_atom = new QtAtomInfoPage(curAtom, this);
|
---|
[4f7473] | 107 | addTab(page_atom, "Atom");
|
---|
[be374a] | 108 | connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
|
---|
[4f7473] | 109 |
|
---|
[7772aa] | 110 | if (curAtom->getMolecule()){
|
---|
[0b2be1] | 111 | page_mol = new QtMoleculeInfoPage(curAtom->getMolecule(), this);
|
---|
[7772aa] | 112 | addTab(page_mol, "Molecule");
|
---|
[be374a] | 113 | connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
|
---|
[52575c] | 114 |
|
---|
| 115 | if (currentPage > 0)
|
---|
| 116 | setCurrentIndex(currentPage);
|
---|
[7772aa] | 117 | }
|
---|
[7b6bcfe] | 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /************************ Tab for single Atoms ********************/
|
---|
[b47bfc] | 122 |
|
---|
[4f7473] | 123 | static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
|
---|
| 124 | {
|
---|
| 125 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
|
---|
| 126 | treeItem->setText(0, key);
|
---|
| 127 | treeItem->setText(1, value);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[0b2be1] | 130 | QtAtomInfoPage::QtAtomInfoPage(const atom *_atom, QWidget *parent) :
|
---|
| 131 | QTreeWidget(parent),
|
---|
[7b6bcfe] | 132 | Observer("QTAtomPage"),
|
---|
[4f7473] | 133 | atomRef(_atom)
|
---|
[7b6bcfe] | 134 | {
|
---|
| 135 | atomRef->signOn(this);
|
---|
[4f7473] | 136 |
|
---|
[0b2be1] | 137 | setColumnCount(2);
|
---|
[4f7473] | 138 | QStringList header;
|
---|
| 139 | header << "data";
|
---|
| 140 | header << "value";
|
---|
[0b2be1] | 141 | setHeaderLabels(header);
|
---|
[4f7473] | 142 |
|
---|
[5e4bfd] | 143 | addInfo(this, "Name", QString(atomRef->getName().c_str()));
|
---|
[0b2be1] | 144 | addInfo(this, "Element", QString(atomRef->getElement().getName().c_str()));
|
---|
| 145 | addInfo(this, "Mass", QString("%1").arg(atomRef->getMass()));
|
---|
| 146 | addInfo(this, "Charge", QString("%1").arg(atomRef->getCharge()));
|
---|
| 147 | addInfo(this, "Position", QString(toString(atomRef->getPosition()).c_str()));
|
---|
| 148 | addInfo(this, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
|
---|
[7b6bcfe] | 149 | }
|
---|
[b47bfc] | 150 |
|
---|
[3c53fa] | 151 | QtAtomInfoPage::~QtAtomInfoPage()
|
---|
[7b6bcfe] | 152 | {
|
---|
[be374a] | 153 | if (atomRef)
|
---|
| 154 | atomRef->signOff(this);
|
---|
[7b6bcfe] | 155 | }
|
---|
[b47bfc] | 156 |
|
---|
[3c53fa] | 157 | void QtAtomInfoPage::update(Observable *subject){
|
---|
[7b6bcfe] | 158 | /*if(name != atomRef->name){
|
---|
| 159 | name = atomRef->name;
|
---|
| 160 | emit nameChanged(this,name);
|
---|
| 161 | }*/
|
---|
| 162 | }
|
---|
[b47bfc] | 163 |
|
---|
[3c53fa] | 164 | void QtAtomInfoPage::subjectKilled(Observable *subject){
|
---|
[be374a] | 165 | atomRef = NULL;
|
---|
| 166 | emit atomKilled();
|
---|
| 167 | }
|
---|
[b47bfc] | 168 |
|
---|
| 169 | /************************ Tab for single Molecules *****************/
|
---|
| 170 |
|
---|
[0b2be1] | 171 | QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
|
---|
| 172 | QTreeWidget(parent),
|
---|
[b47bfc] | 173 | Observer("QTMoleculePage"),
|
---|
[4f7473] | 174 | mol(_mol)
|
---|
[b47bfc] | 175 | {
|
---|
| 176 | mol->signOn(this);
|
---|
[4f7473] | 177 |
|
---|
[0b2be1] | 178 | setColumnCount(2);
|
---|
[4f7473] | 179 | QStringList header;
|
---|
| 180 | header << "data";
|
---|
| 181 | header << "value";
|
---|
[0b2be1] | 182 | setHeaderLabels(header);
|
---|
[4f7473] | 183 |
|
---|
[0b2be1] | 184 | addInfo(this, "Name", QString(mol->getName().c_str()));
|
---|
| 185 | addInfo(this, "Formula", QString(mol->getFormula().toString().c_str()));
|
---|
| 186 | addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
---|
| 187 | addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
|
---|
[b47bfc] | 188 | }
|
---|
| 189 |
|
---|
[3c53fa] | 190 | QtMoleculeInfoPage::~QtMoleculeInfoPage(){
|
---|
[be374a] | 191 | if (mol)
|
---|
| 192 | mol->signOff(this);
|
---|
[b47bfc] | 193 | }
|
---|
| 194 |
|
---|
[3c53fa] | 195 | void QtMoleculeInfoPage::update(Observable *subject){ std::cout << "tab mol update\n";
|
---|
[b47bfc] | 196 | }
|
---|
| 197 |
|
---|
[3c53fa] | 198 | void QtMoleculeInfoPage::subjectKilled(Observable *subject){
|
---|
[be374a] | 199 | mol = NULL;
|
---|
| 200 | emit moleculeKilled();
|
---|
| 201 | }
|
---|