| [8df74d] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [8df74d] | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | /*
 | 
|---|
 | 9 |  * FileQtQuery.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Oct 25, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | #include <Qt/qboxlayout.h>
 | 
|---|
 | 21 | #include <Qt/qlabel.h>
 | 
|---|
 | 22 | #include <Qt/qlineedit.h>
 | 
|---|
 | 23 | #include <Qt/qpushbutton.h>
 | 
|---|
| [7c9921] | 24 | #include <QtGui/QFileDialog>
 | 
|---|
| [8df74d] | 25 | 
 | 
|---|
| [ad011c] | 26 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [8df74d] | 27 | 
 | 
|---|
| [308aa4] | 28 | #include "UIElements/Qt4/Query/QtQuery.hpp"
 | 
|---|
| [8df74d] | 29 | 
 | 
|---|
 | 30 | 
 | 
|---|
| [7dfd07] | 31 | QtDialog::FileQtQuery::FileQtQuery(Parameter<boost::filesystem::path> &_param, std::string _title, QBoxLayout *_parent, Dialog *_dialog) :
 | 
|---|
| [b3a54d] | 32 |     Dialog::FileQuery(_param, _title),
 | 
|---|
| [7c9921] | 33 |     parent(_parent),
 | 
|---|
 | 34 |     dialog(_dialog)
 | 
|---|
| [8df74d] | 35 | {
 | 
|---|
 | 36 | 
 | 
|---|
| [7dfd07] | 37 |   filenameLineEdit = new QLineEdit();
 | 
|---|
| [8df74d] | 38 |   filenameLineEdit->setText(QString());
 | 
|---|
 | 39 |   filenameLineEdit->setReadOnly(true);
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 |   filenameLabel = new QLabel(QString("Input file:"));
 | 
|---|
 | 42 |   filenameLabel->setBuddy(filenameLineEdit);
 | 
|---|
 | 43 | 
 | 
|---|
| [7dfd07] | 44 |   filedialogButton = new QPushButton("&Choose");
 | 
|---|
| [7c9921] | 45 |   theFileDialog = NULL;
 | 
|---|
| [8df74d] | 46 | 
 | 
|---|
 | 47 |   thisLayout = new QHBoxLayout();
 | 
|---|
 | 48 |   parent->addLayout(thisLayout);
 | 
|---|
 | 49 |   thisLayout->addWidget(filenameLabel);
 | 
|---|
 | 50 |   thisLayout->addWidget(filenameLineEdit);
 | 
|---|
 | 51 |   thisLayout->addWidget(filedialogButton);
 | 
|---|
 | 52 | 
 | 
|---|
| [7c9921] | 53 |   QObject::connect(filedialogButton,SIGNAL(clicked()),this,SLOT(showFileDialog()));
 | 
|---|
| [8df74d] | 54 | }
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | QtDialog::FileQtQuery::~FileQtQuery()
 | 
|---|
 | 57 | {
 | 
|---|
| [7c9921] | 58 |   if (theFileDialog != NULL)
 | 
|---|
 | 59 |     delete theFileDialog;
 | 
|---|
 | 60 | }
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 | void QtDialog::FileQtQuery::onUpdate() {
 | 
|---|
 | 63 |   QStringList ListOfFilenames = theFileDialog->selectedFiles();
 | 
|---|
 | 64 |   std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl;
 | 
|---|
 | 65 |   temp = ListOfFilenames.at(0).toStdString();
 | 
|---|
 | 66 |   filenameLineEdit->setText(QString::fromStdString(temp.string()));
 | 
|---|
 | 67 |   dialog->update();
 | 
|---|
 | 68 | }
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | void QtDialog::FileQtQuery::showFileDialog() {
 | 
|---|
 | 71 |   filedialogButton->setFlat(true);
 | 
|---|
 | 72 |   if (theFileDialog == NULL) {
 | 
|---|
 | 73 |     theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString(), tr("ParallelCarParrinello (*.conf);;MassivelyParallelQuantumChemistry (*.mpqc);;ParticleDataBase (*.pdb);;XYZ (*.xyz)"));
 | 
|---|
 | 74 |     theFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
 | 
|---|
 | 75 |     theFileDialog->setFileMode(QFileDialog::AnyFile);
 | 
|---|
 | 76 |     theFileDialog->setViewMode(QFileDialog::List);
 | 
|---|
 | 77 |   }
 | 
|---|
 | 78 |   theFileDialog->exec();
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 |   onUpdate();
 | 
|---|
 | 81 |   filedialogButton->setFlat(false);
 | 
|---|
| [8df74d] | 82 | }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | bool QtDialog::FileQtQuery::handle(){
 | 
|---|
| [9d5531] | 85 |   if (param.isValid(temp)){
 | 
|---|
 | 86 |     param.set(temp);
 | 
|---|
 | 87 |     return true;
 | 
|---|
 | 88 |   }
 | 
|---|
 | 89 |   return false;
 | 
|---|
| [8df74d] | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|