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