NCL Composer  0.1.5
 All Classes Functions Variables Pages
FileChooser.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "FileChooser.h"
20 #include "ui_FileChooser.h"
21 
22 #include <QFileDialog>
23 
24 FileChooser::FileChooser(const QString &label,
25  FileChooser::FILECHOOSER_TYPE fctype,
26  const QString &caption,
27  const QString &filter,
28  QWidget *parent) :
29  QWidget(parent),
30  ui(new Ui::FileChooser),
31  fctype(fctype),
32  filter(filter),
33  caption(caption)
34 {
35  ui->setupUi(this);
36  ui->label->setText(label);
37 }
38 
39 FileChooser::~FileChooser()
40 {
41  delete ui;
42 }
43 
44 void FileChooser::on_pushButton_pressed()
45 {
46  QString location;
47 
48  switch(fctype)
49  {
50  case OPEN_FILENAME:
51  location = QFileDialog::getOpenFileName(NULL, caption, "", filter);
52  break;
53  case SAVE_FILENAME:
54  location = QFileDialog::getSaveFileName(NULL, caption, "", filter);
55  break;
56  case GET_EXISTINGDIRECTORY:
57  location = QFileDialog::getExistingDirectory(NULL, caption, "");
58  break;
59  //case OPEN_FILENAMES:
60  // location = QFileDialog::getOpenFileNames(NULL, caption, "", filter);
61  // break;
62  default:
63  location = QFileDialog::getOpenFileName(NULL, caption, "", filter);
64  break;
65  }
66 
67  ui->lineEdit->setText(location);
68 }
69 
70 QString FileChooser::getText()
71 {
72  return ui->lineEdit->text();
73 }
74 
75 void FileChooser::setText(const QString &value)
76 {
77  ui->lineEdit->setText(value);
78 }