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