[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[b47bfc] | 8 | /*
|
---|
[3c53fa] | 9 | * QtInfoBox.cpp
|
---|
[b47bfc] | 10 | *
|
---|
| 11 | * Created on: Mar 4, 2010
|
---|
| 12 | * Author: crueger
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
[bbbad5] | 19 |
|
---|
[3c53fa] | 20 | #include "Views/Qt4/QtInfoBox.hpp"
|
---|
[b47bfc] | 21 |
|
---|
| 22 | #include <iostream>
|
---|
[4f7473] | 23 | #include <QAbstractItemView>
|
---|
[b47bfc] | 24 |
|
---|
[ad011c] | 25 | #include "CodePatterns/MemDebug.hpp"
|
---|
[bbbad5] | 26 |
|
---|
| 27 | #include "molecule.hpp"
|
---|
[4f7473] | 28 | #include "Element/element.hpp"
|
---|
[b47bfc] | 29 |
|
---|
| 30 | using namespace std;
|
---|
| 31 |
|
---|
| 32 | /***************** Basic structure for tab layout ***********/
|
---|
| 33 |
|
---|
[3c53fa] | 34 | QtInfoBox::QtInfoBox() :
|
---|
[7b6bcfe] | 35 | QTabWidget(),
|
---|
[4a2f3e] | 36 | curAtom(NULL), nextAtom(NULL),
|
---|
[7b6bcfe] | 37 | page_mol(NULL), page_atom(NULL)
|
---|
[b47bfc] | 38 | {
|
---|
[4a2f3e] | 39 | timer = new QTimer(this);
|
---|
| 40 | timer->setSingleShot(true);
|
---|
[b47bfc] | 41 |
|
---|
[4a2f3e] | 42 | connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
|
---|
[b47bfc] | 43 | }
|
---|
| 44 |
|
---|
[3c53fa] | 45 | QtInfoBox::~QtInfoBox()
|
---|
[be374a] | 46 | {
|
---|
| 47 | clearTabs();
|
---|
| 48 | }
|
---|
[b47bfc] | 49 |
|
---|
[3c53fa] | 50 | void QtInfoBox::atomHover(const atom *_atom)
|
---|
[4a2f3e] | 51 | {
|
---|
| 52 | nextAtom = _atom;
|
---|
| 53 | timer->start(500);
|
---|
[b47bfc] | 54 | }
|
---|
| 55 |
|
---|
[3c53fa] | 56 | void QtInfoBox::timerTimeout()
|
---|
[4a2f3e] | 57 | {
|
---|
| 58 | if (nextAtom)
|
---|
| 59 | showAtom(nextAtom);
|
---|
[b47bfc] | 60 | }
|
---|
| 61 |
|
---|
[3c53fa] | 62 | void QtInfoBox::clearTabs()
|
---|
[7b6bcfe] | 63 | {
|
---|
| 64 | if (page_atom){
|
---|
[be374a] | 65 | //removeTab(indexOf(page_atom));
|
---|
[7b6bcfe] | 66 | delete(page_atom);
|
---|
| 67 | page_atom = NULL;
|
---|
| 68 | }
|
---|
| 69 | if (page_mol){
|
---|
[be374a] | 70 | //removeTab(indexOf(page_mol));
|
---|
[7b6bcfe] | 71 | delete(page_mol);
|
---|
| 72 | page_mol = NULL;
|
---|
| 73 | }
|
---|
[be374a] | 74 | }
|
---|
[7b6bcfe] | 75 |
|
---|
[3c53fa] | 76 | void QtInfoBox::showAtom(const atom *_atom)
|
---|
[be374a] | 77 | {
|
---|
| 78 | // Remove old tabs.
|
---|
| 79 | clearTabs();
|
---|
| 80 |
|
---|
| 81 | curAtom = _atom;
|
---|
[7b6bcfe] | 82 |
|
---|
| 83 | // Show new tabs.
|
---|
[4a2f3e] | 84 | if (curAtom){
|
---|
[3c53fa] | 85 | page_atom = new QtAtomInfoPage(curAtom);
|
---|
[4f7473] | 86 | addTab(page_atom, "Atom");
|
---|
[be374a] | 87 | connect(page_atom, SIGNAL(atomKilled()), this, SLOT(clearTabs()));
|
---|
[4f7473] | 88 |
|
---|
[7772aa] | 89 | if (curAtom->getMolecule()){
|
---|
[3c53fa] | 90 | page_mol = new QtMoleculeInfoPage(curAtom->getMolecule());
|
---|
[7772aa] | 91 | addTab(page_mol, "Molecule");
|
---|
[be374a] | 92 | connect(page_mol, SIGNAL(moleculeKilled()), this, SLOT(clearTabs()));
|
---|
[7772aa] | 93 | }
|
---|
[7b6bcfe] | 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /************************ Tab for single Atoms ********************/
|
---|
[b47bfc] | 98 |
|
---|
[4f7473] | 99 | static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
|
---|
| 100 | {
|
---|
| 101 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
|
---|
| 102 | treeItem->setText(0, key);
|
---|
| 103 | treeItem->setText(1, value);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[3c53fa] | 106 | QtAtomInfoPage::QtAtomInfoPage(const atom *_atom) :
|
---|
[7b6bcfe] | 107 | Observer("QTAtomPage"),
|
---|
[4f7473] | 108 | atomRef(_atom)
|
---|
[7b6bcfe] | 109 | {
|
---|
| 110 | atomRef->signOn(this);
|
---|
[4f7473] | 111 |
|
---|
| 112 | info = new QTreeWidget(this);
|
---|
| 113 | info->setColumnCount(2);
|
---|
| 114 | QStringList header;
|
---|
| 115 | header << "data";
|
---|
| 116 | header << "value";
|
---|
| 117 | info->setHeaderLabels(header);
|
---|
| 118 |
|
---|
| 119 | addInfo(info, "Element", QString(atomRef->getElement().getName().c_str()));
|
---|
| 120 | addInfo(info, "Mass", QString("%1").arg(atomRef->getMass()));
|
---|
| 121 | addInfo(info, "Charge", QString("%1").arg(atomRef->getCharge()));
|
---|
| 122 | addInfo(info, "Position", QString(toString(atomRef->getPosition()).c_str()));
|
---|
| 123 | addInfo(info, "Bonds", QString("%1").arg(atomRef->getListOfBonds().size()));
|
---|
[7b6bcfe] | 124 | }
|
---|
[b47bfc] | 125 |
|
---|
[3c53fa] | 126 | QtAtomInfoPage::~QtAtomInfoPage()
|
---|
[7b6bcfe] | 127 | {
|
---|
[be374a] | 128 | if (atomRef)
|
---|
| 129 | atomRef->signOff(this);
|
---|
[7b6bcfe] | 130 | }
|
---|
[b47bfc] | 131 |
|
---|
[3c53fa] | 132 | void QtAtomInfoPage::update(Observable *subject){
|
---|
[7b6bcfe] | 133 | /*if(name != atomRef->name){
|
---|
| 134 | name = atomRef->name;
|
---|
| 135 | emit nameChanged(this,name);
|
---|
| 136 | }*/
|
---|
| 137 | }
|
---|
[b47bfc] | 138 |
|
---|
[3c53fa] | 139 | void QtAtomInfoPage::subjectKilled(Observable *subject){
|
---|
[be374a] | 140 | atomRef = NULL;
|
---|
| 141 | emit atomKilled();
|
---|
| 142 | }
|
---|
[b47bfc] | 143 |
|
---|
| 144 | /************************ Tab for single Molecules *****************/
|
---|
| 145 |
|
---|
[3c53fa] | 146 | QtMoleculeInfoPage::QtMoleculeInfoPage(const molecule *_mol) :
|
---|
[b47bfc] | 147 | Observer("QTMoleculePage"),
|
---|
[4f7473] | 148 | mol(_mol)
|
---|
[b47bfc] | 149 | {
|
---|
| 150 | mol->signOn(this);
|
---|
[4f7473] | 151 |
|
---|
| 152 | info = new QTreeWidget(this);
|
---|
| 153 | info->setColumnCount(2);
|
---|
| 154 | QStringList header;
|
---|
| 155 | header << "data";
|
---|
| 156 | header << "value";
|
---|
| 157 | info->setHeaderLabels(header);
|
---|
| 158 |
|
---|
| 159 | addInfo(info, "Name", QString(mol->getName().c_str()));
|
---|
| 160 | addInfo(info, "Formula", QString(mol->getFormula().toString().c_str()));
|
---|
| 161 | addInfo(info, "Atoms", QString("%1").arg(mol->getAtomCount()));
|
---|
| 162 | addInfo(info, "Bonds", QString("%1").arg(mol->getBondCount()));
|
---|
[b47bfc] | 163 | }
|
---|
| 164 |
|
---|
[3c53fa] | 165 | QtMoleculeInfoPage::~QtMoleculeInfoPage(){
|
---|
[be374a] | 166 | if (mol)
|
---|
| 167 | mol->signOff(this);
|
---|
[b47bfc] | 168 | }
|
---|
| 169 |
|
---|
[3c53fa] | 170 | void QtMoleculeInfoPage::update(Observable *subject){ std::cout << "tab mol update\n";
|
---|
[b47bfc] | 171 | }
|
---|
| 172 |
|
---|
[3c53fa] | 173 | void QtMoleculeInfoPage::subjectKilled(Observable *subject){
|
---|
[be374a] | 174 | mol = NULL;
|
---|
| 175 | emit moleculeKilled();
|
---|
| 176 | }
|
---|