[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[d103d3] | 4 | * Copyright (C) 2010-2011 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 | /*
|
---|
[4cf323d] | 9 | * QtMoleculeView.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 |
|
---|
[4cf323d] | 20 | #include "Views/Qt4/QtMoleculeView.hpp"
|
---|
[b47bfc] | 21 |
|
---|
| 22 | #include <iostream>
|
---|
| 23 |
|
---|
[ad011c] | 24 | #include "CodePatterns/MemDebug.hpp"
|
---|
[bbbad5] | 25 |
|
---|
| 26 | #include "molecule.hpp"
|
---|
[b47bfc] | 27 |
|
---|
| 28 | using namespace std;
|
---|
| 29 |
|
---|
| 30 | /***************** Basic structure for tab layout ***********/
|
---|
| 31 |
|
---|
[4cf323d] | 32 | QtMoleculeView::QtMoleculeView() :
|
---|
[b47bfc] | 33 | QTabWidget()
|
---|
| 34 | {
|
---|
| 35 | allPage = new QTAllMoleculePage();
|
---|
| 36 | addTab(allPage,QString("All Molecules"));
|
---|
| 37 |
|
---|
| 38 | connect(this,SIGNAL(addMolecule(molecule*)),allPage,SLOT(addMolecule(molecule*)));
|
---|
| 39 | connect(this,SIGNAL(removeMolecule(molecule*)),allPage,SLOT(removeMolecule(molecule*)));
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[4cf323d] | 42 | QtMoleculeView::~QtMoleculeView()
|
---|
[b47bfc] | 43 | {}
|
---|
| 44 |
|
---|
[4cf323d] | 45 | void QtMoleculeView::moleculeSelected(molecule *mol){
|
---|
[b47bfc] | 46 | if(!pages.count(mol)){
|
---|
[fa60dd] | 47 | string molName = mol->name;
|
---|
[b47bfc] | 48 | QTMoleculePage *molPage = new QTMoleculePage(mol,molName);
|
---|
| 49 | addTab(molPage,QString(molName.c_str()));
|
---|
| 50 | pages[mol] = molPage;
|
---|
| 51 |
|
---|
| 52 | connect(molPage,SIGNAL(nameChanged(QTMoleculePage*,std::string)),this,SLOT(nameChanged(QTMoleculePage*,std::string)));
|
---|
| 53 |
|
---|
| 54 | emit addMolecule(mol);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[4cf323d] | 58 | void QtMoleculeView::moleculeUnSelected(molecule *mol){
|
---|
[b47bfc] | 59 | if(pages.count(mol)){
|
---|
| 60 | QTMoleculePage *molPage = pages[mol];
|
---|
| 61 | removeTab(indexOf(molPage));
|
---|
| 62 | pages.erase(mol);
|
---|
| 63 | delete molPage;
|
---|
| 64 | emit removeMolecule(mol);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[4cf323d] | 68 | void QtMoleculeView::nameChanged(QTMoleculePage *page, std::string name){
|
---|
[b47bfc] | 69 | setTabText(indexOf(page),QString(name.c_str()));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /************************ Tab for all Molecules ********************/
|
---|
| 73 |
|
---|
| 74 | QTAllMoleculePage::QTAllMoleculePage() :
|
---|
| 75 | Observer("QTAllMoleculePage")
|
---|
| 76 | {}
|
---|
| 77 |
|
---|
| 78 | void QTAllMoleculePage::addMolecule(molecule *mol){}
|
---|
| 79 |
|
---|
| 80 | void QTAllMoleculePage::removeMolecule(molecule *mol){}
|
---|
| 81 |
|
---|
| 82 | void QTAllMoleculePage::update(Observable *subject){}
|
---|
| 83 |
|
---|
| 84 | void QTAllMoleculePage::subjectKilled(Observable *subject){}
|
---|
| 85 |
|
---|
| 86 | /************************ Tab for single Molecules *****************/
|
---|
| 87 |
|
---|
| 88 | QTMoleculePage::QTMoleculePage(molecule *_mol, string _name) :
|
---|
| 89 | Observer("QTMoleculePage"),
|
---|
| 90 | mol(_mol), name(_name)
|
---|
| 91 | {
|
---|
| 92 | mol->signOn(this);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | QTMoleculePage::~QTMoleculePage(){
|
---|
| 96 | mol->signOff(this);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | void QTMoleculePage::update(Observable *subject){
|
---|
[fa60dd] | 100 | if(name != mol->name){
|
---|
| 101 | name = mol->name;
|
---|
[b47bfc] | 102 | emit nameChanged(this,name);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void QTMoleculePage::subjectKilled(Observable *subject){}
|
---|