[8df74d] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[8df74d] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * FileQtQuery.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Oct 25, 2010
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include <Qt/qboxlayout.h>
|
---|
| 36 | #include <Qt/qlabel.h>
|
---|
| 37 | #include <Qt/qlineedit.h>
|
---|
| 38 | #include <Qt/qpushbutton.h>
|
---|
[69f38a] | 39 | #include <Qt/qstringlist.h>
|
---|
[7c9921] | 40 | #include <QtGui/QFileDialog>
|
---|
[8df74d] | 41 |
|
---|
[ad011c] | 42 | #include "CodePatterns/MemDebug.hpp"
|
---|
[8df74d] | 43 |
|
---|
[308aa4] | 44 | #include "UIElements/Qt4/Query/QtQuery.hpp"
|
---|
[8df74d] | 45 |
|
---|
[69f38a] | 46 | #include "Parser/ParserTypes.hpp"
|
---|
| 47 | #include "Parser/FormatParserStorage.hpp"
|
---|
[8df74d] | 48 |
|
---|
[7dfd07] | 49 | QtDialog::FileQtQuery::FileQtQuery(Parameter<boost::filesystem::path> &_param, std::string _title, QBoxLayout *_parent, Dialog *_dialog) :
|
---|
[852ea3] | 50 | QtQuery<boost::filesystem::path>(_param, _title),
|
---|
[7c9921] | 51 | parent(_parent),
|
---|
| 52 | dialog(_dialog)
|
---|
[8df74d] | 53 | {
|
---|
[7dfd07] | 54 | filenameLineEdit = new QLineEdit();
|
---|
[8df74d] | 55 | filenameLineEdit->setText(QString());
|
---|
| 56 | filenameLineEdit->setReadOnly(true);
|
---|
| 57 |
|
---|
| 58 | filenameLabel = new QLabel(QString("Input file:"));
|
---|
| 59 | filenameLabel->setBuddy(filenameLineEdit);
|
---|
| 60 |
|
---|
[7dfd07] | 61 | filedialogButton = new QPushButton("&Choose");
|
---|
[7c9921] | 62 | theFileDialog = NULL;
|
---|
[8df74d] | 63 |
|
---|
| 64 | thisLayout = new QHBoxLayout();
|
---|
| 65 | parent->addLayout(thisLayout);
|
---|
| 66 | thisLayout->addWidget(filenameLabel);
|
---|
| 67 | thisLayout->addWidget(filenameLineEdit);
|
---|
| 68 | thisLayout->addWidget(filedialogButton);
|
---|
| 69 |
|
---|
[7c9921] | 70 | QObject::connect(filedialogButton,SIGNAL(clicked()),this,SLOT(showFileDialog()));
|
---|
[8df74d] | 71 | }
|
---|
| 72 |
|
---|
| 73 | QtDialog::FileQtQuery::~FileQtQuery()
|
---|
| 74 | {
|
---|
[7c9921] | 75 | if (theFileDialog != NULL)
|
---|
| 76 | delete theFileDialog;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void QtDialog::FileQtQuery::onUpdate() {
|
---|
| 80 | QStringList ListOfFilenames = theFileDialog->selectedFiles();
|
---|
| 81 | std::cout << "Selected File is " << ListOfFilenames.at(0).toStdString() << std::endl;
|
---|
| 82 | temp = ListOfFilenames.at(0).toStdString();
|
---|
| 83 | filenameLineEdit->setText(QString::fromStdString(temp.string()));
|
---|
| 84 | dialog->update();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | void QtDialog::FileQtQuery::showFileDialog() {
|
---|
| 88 | filedialogButton->setFlat(true);
|
---|
| 89 | if (theFileDialog == NULL) {
|
---|
[69f38a] | 90 | theFileDialog = new QFileDialog(NULL, tr("Open input file"), QString());
|
---|
| 91 | // gather all possible suffixes
|
---|
| 92 | QStringList filters;
|
---|
| 93 | std::stringstream parsersuffixes;
|
---|
| 94 | parsersuffixes << std::string("Config files (");
|
---|
| 95 | for (ParserTypes t = ParserTypes_begin; t < ParserTypes_end; ++t){
|
---|
| 96 | if (t != ParserTypes_begin)
|
---|
| 97 | parsersuffixes << std::string(" ");
|
---|
| 98 | parsersuffixes << std::string("*.") <<
|
---|
| 99 | FormatParserStorage::getInstance().getSuffixFromType(t);
|
---|
| 100 | }
|
---|
| 101 | parsersuffixes << std::string(")");
|
---|
| 102 | filters << tr(parsersuffixes.str().c_str());
|
---|
| 103 | filters << tr("Data files (*.dat)");
|
---|
| 104 | filters << tr("Any files (*)");
|
---|
| 105 | theFileDialog->setNameFilters(filters);
|
---|
[7c9921] | 106 | theFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
|
---|
| 107 | theFileDialog->setFileMode(QFileDialog::AnyFile);
|
---|
| 108 | theFileDialog->setViewMode(QFileDialog::List);
|
---|
| 109 | }
|
---|
| 110 | theFileDialog->exec();
|
---|
| 111 |
|
---|
| 112 | onUpdate();
|
---|
| 113 | filedialogButton->setFlat(false);
|
---|
[8df74d] | 114 | }
|
---|
| 115 |
|
---|