| [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 |
|
|---|
| [3027f8] | 8 | /*
|
|---|
| [4cf323d] | 9 | * QtMainWindow.cpp
|
|---|
| [3027f8] | 10 | *
|
|---|
| 11 | * Created on: Jan 14, 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 "QtMainWindow.hpp"
|
|---|
| [3027f8] | 21 |
|
|---|
| [8f67e2] | 22 | #include<Qt/qapplication.h>
|
|---|
| [fa27ed] | 23 | #include<Qt/qlabel.h>
|
|---|
| 24 | #include<Qt/qstring.h>
|
|---|
| 25 | #include<Qt/qmenubar.h>
|
|---|
| [cef1d7] | 26 | #include<Qt/qsplitter.h>
|
|---|
| [7641d4] | 27 | #include<Qt/qtoolbar.h>
|
|---|
| [b82101] | 28 | #include<Qt/qsettings.h>
|
|---|
| [22d01e] | 29 | #include<Qt/qmessagebox.h>
|
|---|
| 30 | #include<Qt/qevent.h>
|
|---|
| [8f67e2] | 31 |
|
|---|
| [3027f8] | 32 | #include<iostream>
|
|---|
| [b2531f] | 33 | #include<map>
|
|---|
| 34 |
|
|---|
| [fa27ed] | 35 | #include<boost/bind.hpp>
|
|---|
| 36 |
|
|---|
| [a08d3c0] | 37 | #include "Menu/Qt4/QtMenu.hpp"
|
|---|
| [0eb7bf3] | 38 | #include "Views/Qt4/QtMoleculeList.hpp"
|
|---|
| [0e6156] | 39 | #include "Views/Qt4/QtElementList.hpp"
|
|---|
| [3c53fa] | 40 | #include "Views/Qt4/QtInfoBox.hpp"
|
|---|
| [a08d3c0] | 41 | #include "Views/Qt4/QtStatusBar.hpp"
|
|---|
| [7641d4] | 42 | #include "Views/Qt4/QtToolBar.hpp"
|
|---|
| [04f017] | 43 | #include "Views/Qt4/Qt3D/GLWorldView.hpp"
|
|---|
| [a08d3c0] | 44 |
|
|---|
| [ad011c] | 45 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| [bbbad5] | 46 |
|
|---|
| [6f0841] | 47 | #include "Atom/atom.hpp"
|
|---|
| [fa27ed] | 48 | #include "molecule.hpp"
|
|---|
| [ad011c] | 49 | #include "CodePatterns/Verbose.hpp"
|
|---|
| [b2531f] | 50 | #include "Actions/Action.hpp"
|
|---|
| 51 | #include "Actions/ActionRegistry.hpp"
|
|---|
| [22d01e] | 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;
|
|---|
| [3027f8] | 58 |
|
|---|
| [4cf323d] | 59 | QtMainWindow::QtMainWindow(QApplication *_theApp) :
|
|---|
| [8f67e2] | 60 | theApp(_theApp)
|
|---|
| [fa27ed] | 61 | {
|
|---|
| [b82101] | 62 | QCoreApplication::setOrganizationName("ins");
|
|---|
| 63 | QCoreApplication::setOrganizationDomain("ins.uni-bonn.de");
|
|---|
| 64 | QCoreApplication::setApplicationName("MoleCuilder");
|
|---|
| [cef1d7] | 65 | QSplitter *splitter1 = new QSplitter (Qt::Horizontal, this );
|
|---|
| 66 | QSplitter *splitter2 = new QSplitter (Qt::Vertical, splitter1 );
|
|---|
| [244f81] | 67 | QTabWidget *worldTab = new QTabWidget(splitter2);
|
|---|
| [cef1d7] | 68 |
|
|---|
| [0eb7bf3] | 69 | moleculeList = new QtMoleculeList(worldTab);
|
|---|
| [0e6156] | 70 | elementList = new QtElementList(worldTab);
|
|---|
| [cef1d7] | 71 |
|
|---|
| [3c53fa] | 72 | infoBox = new QtInfoBox();
|
|---|
| [0eb7bf3] | 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));
|
|---|
| [cef1d7] | 78 |
|
|---|
| [b59da6] | 79 | MainMenu = new QtMenu<QMenuBar>(menuBar(), "");
|
|---|
| 80 | MainMenu->init();
|
|---|
| [b80021] | 81 |
|
|---|
| [7641d4] | 82 | toolbar = new QtToolBar(this);
|
|---|
| [0eb7bf3] | 83 | glWorldView->addToolBarActions(toolbar);
|
|---|
| [7641d4] | 84 | addToolBar(toolbar);
|
|---|
| 85 |
|
|---|
| [cef1d7] | 86 | setCentralWidget(splitter1);
|
|---|
| 87 | splitter1->addWidget(splitter2);
|
|---|
| [3c53fa] | 88 | splitter1->addWidget(infoBox);
|
|---|
| [0eb7bf3] | 89 | splitter2->addWidget(glWorldView);
|
|---|
| [244f81] | 90 | splitter2->addWidget(worldTab);
|
|---|
| [0eb7bf3] | 91 | worldTab->addTab(moleculeList, "Molecules");
|
|---|
| [0e6156] | 92 | worldTab->addTab(elementList, "All Elements");
|
|---|
| [cef1d7] | 93 |
|
|---|
| [4cf323d] | 94 | statusBar = new QtStatusBar(this);
|
|---|
| [326a43b] | 95 | setStatusBar(statusBar);
|
|---|
| [fa27ed] | 96 |
|
|---|
| [b82101] | 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 |
|
|---|
| [3c53fa] | 105 | connect(glWorldView,SIGNAL(hoverChanged(const atom*)), infoBox,SLOT(atomHover(const atom*)));
|
|---|
| [fa27ed] | 106 | }
|
|---|
| [3027f8] | 107 |
|
|---|
| [4cf323d] | 108 | QtMainWindow::~QtMainWindow()
|
|---|
| [992fd7] | 109 | {
|
|---|
| [b82101] | 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 |
|
|---|
| [992fd7] | 117 | menuBar()->clear();
|
|---|
| [da8f97] | 118 | delete MainMenu;
|
|---|
| [992fd7] | 119 | }
|
|---|
| [3027f8] | 120 |
|
|---|
| [4cf323d] | 121 | void QtMainWindow::display() {
|
|---|
| [8f67e2] | 122 | this->show();
|
|---|
| 123 | theApp->exec();
|
|---|
| [3027f8] | 124 | }
|
|---|
| [b2531f] | 125 |
|
|---|
| [5125f6] | 126 | void QtMainWindow::closeEvent(QCloseEvent *event)
|
|---|
| 127 | {
|
|---|
| [22d01e] | 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 | }
|
|---|
| [5125f6] | 152 | QMainWindow::closeEvent(event);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|