| 1 | /* |
| 2 | * File: NewReaderFile.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Aug 7, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This object handles the creation of a new reader file |
| 11 | * |
| 12 | * This program is free software: you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation, either version 3 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include "NewReaderFile.h" |
| 28 | #include "Preferences.h" |
| 29 | |
| 30 | #include <QFileDialog> |
| 31 | |
| 32 | |
| 33 | NewReaderFile::NewReaderFile(QWidget * parent) |
| 34 | : QDialog(parent), |
| 35 | mLabel(this), |
| 36 | mFileName(this), |
| 37 | mBrowseButton(this), |
| 38 | mOKButton(this), |
| 39 | mCancelButton(this) |
| 40 | { |
| 41 | initialize(); |
| 42 | move(parent->x()+50,parent->y()+50); |
| 43 | |
| 44 | connect(&mCancelButton, SIGNAL(pressed()), this, SLOT(doCancel())); |
| 45 | connect(&mOKButton, SIGNAL(pressed()), this, SLOT(doOK())); |
| 46 | connect(&mBrowseButton, SIGNAL(pressed()), this, SLOT(doBrowse())); |
| 47 | } |
| 48 | |
| 49 | NewReaderFile::~NewReaderFile() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | void NewReaderFile::doCancel() |
| 54 | { |
| 55 | this->deleteLater(); |
| 56 | } |
| 57 | |
| 58 | void NewReaderFile::doOK() |
| 59 | { |
| 60 | if (!mFileName.text().isEmpty()) |
| 61 | { |
| 62 | QString str = mFileName.text(); |
| 63 | emit okPressed(str); |
| 64 | } |
| 65 | doCancel(); |
| 66 | } |
| 67 | |
| 68 | void NewReaderFile::doBrowse() |
| 69 | { |
| 70 | std::string s = QFileDialog::getOpenFileName(this, |
| 71 | "Locate reader file(s)", |
| 72 | Preferences::getInstance().configDir().c_str(), |
| 73 | tr("All files(*)")).toUtf8().data(); |
| 74 | mFileName.setText(s.c_str()); |
| 75 | } |
| 76 | |
| 77 | void NewReaderFile::initialize() |
| 78 | { |
| 79 | if (objectName().isEmpty()) |
| 80 | setObjectName(QString::fromUtf8("NewReaderFile")); |
| 81 | |
| 82 | int x = this->geometry().x(); |
| 83 | int y = this->geometry().x(); |
| 84 | this->setGeometry(x, y, 400, 90); |
| 85 | |
| 86 | mLabel.setText("Enter file name to be used as reader file"); |
| 87 | mLabel.setGeometry(5,5,300,12); |
| 88 | |
| 89 | mFileName.setGeometry(5, 30,300,30); |
| 90 | |
| 91 | mBrowseButton.setGeometry(310,40,30,20); |
| 92 | mBrowseButton.setText("..."); |
| 93 | |
| 94 | mOKButton.setGeometry(5,60,50,30); |
| 95 | mOKButton.setText("OK"); |
| 96 | |
| 97 | mCancelButton.setGeometry(310,60,50,30); |
| 98 | mCancelButton.setText("Cancel"); |
| 99 | } |