| 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 "molecule.hpp"
|
|---|
| 43 | #include "Element/element.hpp"
|
|---|
| 44 |
|
|---|
| 45 | using namespace std;
|
|---|
| 46 |
|
|---|
| 47 | /***************** Basic structure for tab layout ***********/
|
|---|
| 48 |
|
|---|
| 49 | QtInfoBox::QtInfoBox() :
|
|---|
| 50 | QTabWidget(),
|
|---|
| 51 | curAtom(NULL), nextAtom(NULL),
|
|---|
| 52 | page_mol(NULL), page_atom(NULL)
|
|---|
| 53 | {
|
|---|
| 54 | timer = new QTimer(this);
|
|---|
| 55 | timer->setSingleShot(true);
|
|---|
| 56 |
|
|---|
| 57 | setMinimumWidth(200);
|
|---|
| 58 | currentPage = 0;
|
|---|
| 59 |
|
|---|
| 60 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | QtInfoBox::~QtInfoBox()
|
|---|
| 64 | {
|
|---|
| 65 | clearTabs();
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void QtInfoBox::atomHover(const atom *_atom)
|
|---|
| 69 | {
|
|---|
| 70 | nextAtom = _atom;
|
|---|
| 71 | timer->start(500);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void QtInfoBox::timerTimeout()
|
|---|
| 75 | {
|
|---|
| 76 | if (nextAtom)
|
|---|
| 77 | showAtom(nextAtom);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | void QtInfoBox::clearTabs()
|
|---|
| 81 | {
|
|---|
| 82 | if (page_atom){
|
|---|
| 83 | //removeTab(indexOf(page_atom));
|
|---|
| 84 | delete(page_atom);
|
|---|
| 85 | page_atom = NULL;
|
|---|
| 86 | }
|
|---|
| 87 | if (page_mol){
|
|---|
| 88 | //removeTab(indexOf(page_mol));
|
|---|
| 89 | delete(page_mol);
|
|---|
| 90 | page_mol = NULL;
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | void QtInfoBox::showAtom(const atom *_atom)
|
|---|
| 95 | {
|
|---|
| 96 | currentPage = currentIndex();
|
|---|
| 97 |
|
|---|
| 98 | // Remove old tabs.
|
|---|
| 99 | clearTabs();
|
|---|
| 100 |
|
|---|
| 101 | curAtom = _atom;
|
|---|
| 102 |
|
|---|
| 103 | // Show new tabs.
|
|---|
| 104 | if (curAtom){
|
|---|
| 105 | page_atom = new QtAtomInfoPage(curAtom, this);
|
|---|
| 106 | addTab(page_atom, "Atom");
|
|---|
| 107 | connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
|
|---|
| 108 |
|
|---|
| 109 | if (curAtom->getMolecule()){
|
|---|
| 110 | page_mol = new QtMoleculeInfoPage(curAtom->getMolecule(), this);
|
|---|
| 111 | addTab(page_mol, "Molecule");
|
|---|
| 112 | connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
|
|---|
| 113 |
|
|---|
| 114 | if (currentPage > 0)
|
|---|
| 115 | setCurrentIndex(currentPage);
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | /************************ Tab for single Atoms ********************/
|
|---|
| 121 |
|
|---|
| 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 |
|
|---|
| 129 | QtAtomInfoPage::QtAtomInfoPage(const atom *_atom, QWidget *parent) :
|
|---|
| 130 | QTreeWidget(parent),
|
|---|
| 131 | Observer("QTAtomPage"),
|
|---|
| 132 | atomRef(_atom)
|
|---|
| 133 | {
|
|---|
| 134 | atomRef->signOn(this);
|
|---|
| 135 |
|
|---|
| 136 | setColumnCount(2);
|
|---|
| 137 | QStringList header;
|
|---|
| 138 | header << "data";
|
|---|
| 139 | header << "value";
|
|---|
| 140 | setHeaderLabels(header);
|
|---|
| 141 |
|
|---|
| 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()));
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | QtAtomInfoPage::~QtAtomInfoPage()
|
|---|
| 150 | {
|
|---|
| 151 | if (atomRef)
|
|---|
| 152 | atomRef->signOff(this);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | void QtAtomInfoPage::update(Observable *subject){
|
|---|
| 156 | /*if(name != atomRef->name){
|
|---|
| 157 | name = atomRef->name;
|
|---|
| 158 | emit nameChanged(this,name);
|
|---|
| 159 | }*/
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | void QtAtomInfoPage::subjectKilled(Observable *subject){
|
|---|
| 163 | atomRef = NULL;
|
|---|
| 164 | emit atomKilled();
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /************************ Tab for single Molecules *****************/
|
|---|
| 168 |
|
|---|
| 169 | QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol, QWidget *parent) :
|
|---|
| 170 | QTreeWidget(parent),
|
|---|
| 171 | Observer("QTMoleculePage"),
|
|---|
| 172 | mol(_mol)
|
|---|
| 173 | {
|
|---|
| 174 | mol->signOn(this);
|
|---|
| 175 |
|
|---|
| 176 | setColumnCount(2);
|
|---|
| 177 | QStringList header;
|
|---|
| 178 | header << "data";
|
|---|
| 179 | header << "value";
|
|---|
| 180 | setHeaderLabels(header);
|
|---|
| 181 |
|
|---|
| 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()));
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | QtMoleculeInfoPage::~QtMoleculeInfoPage(){
|
|---|
| 189 | if (mol)
|
|---|
| 190 | mol->signOff(this);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | void QtMoleculeInfoPage::update(Observable *subject){ std::cout << "tab mol update\n";
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | void QtMoleculeInfoPage::subjectKilled(Observable *subject){
|
|---|
| 197 | mol = NULL;
|
|---|
| 198 | emit moleculeKilled();
|
|---|
| 199 | }
|
|---|