| 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 | * QtMainWindow.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Jan 14, 2010
|
|---|
| 12 | * Author: crueger
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "QtMainWindow.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include<Qt/qapplication.h>
|
|---|
| 23 | #include<Qt/qlabel.h>
|
|---|
| 24 | #include<Qt/qstring.h>
|
|---|
| 25 | #include<Qt/qmenubar.h>
|
|---|
| 26 | #include<Qt/qsplitter.h>
|
|---|
| 27 | #include<Qt/qtoolbar.h>
|
|---|
| 28 | #include<Qt/qsettings.h>
|
|---|
| 29 | #include<Qt/qmessagebox.h>
|
|---|
| 30 | #include<Qt/qevent.h>
|
|---|
| 31 |
|
|---|
| 32 | #include<iostream>
|
|---|
| 33 | #include<map>
|
|---|
| 34 |
|
|---|
| 35 | #include<boost/bind.hpp>
|
|---|
| 36 |
|
|---|
| 37 | #include "Menu/Qt4/QtMenu.hpp"
|
|---|
| 38 | #include "Views/Qt4/QtMoleculeList.hpp"
|
|---|
| 39 | #include "Views/Qt4/QtElementList.hpp"
|
|---|
| 40 | #include "Views/Qt4/QtInfoBox.hpp"
|
|---|
| 41 | #include "Views/Qt4/QtStatusBar.hpp"
|
|---|
| 42 | #include "Views/Qt4/QtToolBar.hpp"
|
|---|
| 43 | #include "Views/Qt4/Qt3D/GLWorldView.hpp"
|
|---|
| 44 |
|
|---|
| 45 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 46 |
|
|---|
| 47 | #include "Atom/atom.hpp"
|
|---|
| 48 | #include "molecule.hpp"
|
|---|
| 49 | #include "CodePatterns/Verbose.hpp"
|
|---|
| 50 | #include "Actions/Action.hpp"
|
|---|
| 51 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 52 | #include "Parser/ChangeTracker.hpp"
|
|---|
| 53 | #include "Parser/FormatParserStorage.hpp"
|
|---|
| 54 | #include "Actions/WorldAction/OutputAction.hpp"
|
|---|
| 55 | #include "Actions/WorldAction/OutputAsAction.hpp"
|
|---|
| 56 |
|
|---|
| 57 | using namespace MoleCuilder;
|
|---|
| 58 |
|
|---|
| 59 | QtMainWindow::QtMainWindow(QApplication *_theApp) :
|
|---|
| 60 | theApp(_theApp)
|
|---|
| 61 | {
|
|---|
| 62 | QCoreApplication::setOrganizationName("ins");
|
|---|
| 63 | QCoreApplication::setOrganizationDomain("ins.uni-bonn.de");
|
|---|
| 64 | QCoreApplication::setApplicationName("MoleCuilder");
|
|---|
| 65 | QSplitter *splitter1 = new QSplitter (Qt::Horizontal, this );
|
|---|
| 66 | QSplitter *splitter2 = new QSplitter (Qt::Vertical, splitter1 );
|
|---|
| 67 | QTabWidget *worldTab = new QTabWidget(splitter2);
|
|---|
| 68 |
|
|---|
| 69 | moleculeList = new QtMoleculeList(worldTab);
|
|---|
| 70 | elementList = new QtElementList(worldTab);
|
|---|
| 71 |
|
|---|
| 72 | infoBox = new QtInfoBox();
|
|---|
| 73 | glWorldView = new GLWorldView(this);
|
|---|
| 74 | // glWorldView->setSizePolicy( QSizePolicy::Minimum,QSizePolicy::Minimum);
|
|---|
| 75 | glWorldView->setMinimumSize( QSize(640,480) );
|
|---|
| 76 | // glWorldView->setFocus();
|
|---|
| 77 | glWorldView->camera()->setEye( QVector3D(0,3,10));
|
|---|
| 78 |
|
|---|
| 79 | MainMenu = new QtMenu<QMenuBar>(menuBar(), "");
|
|---|
| 80 | MainMenu->init();
|
|---|
| 81 |
|
|---|
| 82 | toolbar = new QtToolBar(this);
|
|---|
| 83 | glWorldView->addToolBarActions(toolbar);
|
|---|
| 84 | addToolBar(toolbar);
|
|---|
| 85 |
|
|---|
| 86 | setCentralWidget(splitter1);
|
|---|
| 87 | splitter1->addWidget(splitter2);
|
|---|
| 88 | splitter1->addWidget(infoBox);
|
|---|
| 89 | splitter2->addWidget(glWorldView);
|
|---|
| 90 | splitter2->addWidget(worldTab);
|
|---|
| 91 | worldTab->addTab(moleculeList, "Molecules");
|
|---|
| 92 | worldTab->addTab(elementList, "All Elements");
|
|---|
| 93 |
|
|---|
| 94 | statusBar = new QtStatusBar(this);
|
|---|
| 95 | setStatusBar(statusBar);
|
|---|
| 96 |
|
|---|
| 97 | QSettings settings;
|
|---|
| 98 | settings.beginGroup("MainWindow");
|
|---|
| 99 | resize(settings.value("size", QSize(400, 400)).toSize());
|
|---|
| 100 | move(settings.value("position", QPoint(200, 200)).toPoint());
|
|---|
| 101 | if (settings.value("maximized", false).toBool())
|
|---|
| 102 | showMaximized();
|
|---|
| 103 | settings.endGroup();
|
|---|
| 104 |
|
|---|
| 105 | connect(glWorldView,SIGNAL(hoverChanged(const atom*)), infoBox,SLOT(atomHover(const atom*)));
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | QtMainWindow::~QtMainWindow()
|
|---|
| 109 | {
|
|---|
| 110 | QSettings settings;
|
|---|
| 111 | settings.beginGroup("MainWindow");
|
|---|
| 112 | settings.setValue("size", size());
|
|---|
| 113 | settings.setValue("position", pos());
|
|---|
| 114 | settings.setValue("maximized", isMaximized());
|
|---|
| 115 | settings.endGroup();
|
|---|
| 116 |
|
|---|
| 117 | menuBar()->clear();
|
|---|
| 118 | delete MainMenu;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | void QtMainWindow::display() {
|
|---|
| 122 | this->show();
|
|---|
| 123 | theApp->exec();
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | void QtMainWindow::closeEvent(QCloseEvent *event)
|
|---|
| 127 | {
|
|---|
| 128 | if (ChangeTracker::getInstance().hasChanged()){
|
|---|
| 129 | int ret = QMessageBox::question(this, tr("MoleCuilder"),
|
|---|
| 130 | tr("The world has been modified.\n"
|
|---|
| 131 | "Do you want to save your changes?"),
|
|---|
| 132 | QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
|
|---|
| 133 | QMessageBox::Save);
|
|---|
| 134 | switch(ret){
|
|---|
| 135 | case QMessageBox::Cancel:
|
|---|
| 136 | event->ignore();
|
|---|
| 137 | return;
|
|---|
| 138 | case QMessageBox::Save:
|
|---|
| 139 | if (FormatParserStorage::getInstance().isAbleToSave())
|
|---|
| 140 | MoleCuilder::WorldOutput();
|
|---|
| 141 | else{
|
|---|
| 142 | Action* action = ActionRegistry::getInstance().getActionByName("output-as");
|
|---|
| 143 | try{
|
|---|
| 144 | action->call();
|
|---|
| 145 | }catch(...){
|
|---|
| 146 | ELOG(1, "Action failed or cancelled");
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 | break;
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 | QMainWindow::closeEvent(event);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|