| 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 | * 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>
|
|---|
| 24 | #include <QtGui/QFileDialog>
|
|---|
| 25 |
|
|---|
| 26 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include "UIElements/Qt4/Query/QtQuery.hpp"
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | QtDialog::FileQtQuery::FileQtQuery(Parameter<boost::filesystem::path> &_param, std::string _title, QBoxLayout *_parent, Dialog *_dialog) :
|
|---|
| 32 | QtQuery<boost::filesystem::path>(_param, _title),
|
|---|
| 33 | parent(_parent),
|
|---|
| 34 | dialog(_dialog)
|
|---|
| 35 | {
|
|---|
| 36 |
|
|---|
| 37 | filenameLineEdit = new QLineEdit();
|
|---|
| 38 | filenameLineEdit->setText(QString());
|
|---|
| 39 | filenameLineEdit->setReadOnly(true);
|
|---|
| 40 |
|
|---|
| 41 | filenameLabel = new QLabel(QString("Input file:"));
|
|---|
| 42 | filenameLabel->setBuddy(filenameLineEdit);
|
|---|
| 43 |
|
|---|
| 44 | filedialogButton = new QPushButton("&Choose");
|
|---|
| 45 | theFileDialog = NULL;
|
|---|
| 46 |
|
|---|
| 47 | thisLayout = new QHBoxLayout();
|
|---|
| 48 | parent->addLayout(thisLayout);
|
|---|
| 49 | thisLayout->addWidget(filenameLabel);
|
|---|
| 50 | thisLayout->addWidget(filenameLineEdit);
|
|---|
| 51 | thisLayout->addWidget(filedialogButton);
|
|---|
| 52 |
|
|---|
| 53 | QObject::connect(filedialogButton,SIGNAL(clicked()),this,SLOT(showFileDialog()));
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | QtDialog::FileQtQuery::~FileQtQuery()
|
|---|
| 57 | {
|
|---|
| 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);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|