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