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