1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * RTNet GUI
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: t_selWin
|
---|
7 | *
|
---|
8 | * Purpose: Widget for File/Directory Selection
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 08-Jan-2013
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include "selwin.h"
|
---|
19 |
|
---|
20 | using namespace std;
|
---|
21 | using namespace GnssCenter;
|
---|
22 |
|
---|
23 | // Constructor
|
---|
24 | ////////////////////////////////////////////////////////////////////////////////
|
---|
25 | t_selWin::t_selWin(QWidget* parent, t_selWin::Mode mode) :
|
---|
26 | QWidget(parent), _mode(mode) {
|
---|
27 |
|
---|
28 | QHBoxLayout* layout = new QHBoxLayout( this );
|
---|
29 | layout->setMargin(0);
|
---|
30 |
|
---|
31 | _lineEdit = new QLineEdit(this);
|
---|
32 | layout->addWidget(_lineEdit);
|
---|
33 |
|
---|
34 | connect(_lineEdit, SIGNAL(textChanged(const QString &)),
|
---|
35 | this, SIGNAL(fileNameChanged(const QString &)));
|
---|
36 |
|
---|
37 | _button = new QPushButton("...", this);
|
---|
38 | _button->setFixedWidth(_button->fontMetrics().width(" ... "));
|
---|
39 | layout->addWidget(_button);
|
---|
40 |
|
---|
41 | connect(_button, SIGNAL(clicked()), this, SLOT(chooseFile()));
|
---|
42 | setFocusProxy(_lineEdit);
|
---|
43 | }
|
---|
44 |
|
---|
45 | // Destructor
|
---|
46 | ////////////////////////////////////////////////////////////////////////////////
|
---|
47 | t_selWin::~t_selWin() {
|
---|
48 | }
|
---|
49 |
|
---|
50 | //
|
---|
51 | ////////////////////////////////////////////////////////////////////////////////
|
---|
52 | void t_selWin::setFileName(const QString& fileName) {
|
---|
53 | _lineEdit->setText(fileName);
|
---|
54 | }
|
---|
55 |
|
---|
56 | //
|
---|
57 | ////////////////////////////////////////////////////////////////////////////////
|
---|
58 | QString t_selWin::fileName() const {
|
---|
59 | return _lineEdit->text();
|
---|
60 | }
|
---|
61 |
|
---|
62 | //
|
---|
63 | ////////////////////////////////////////////////////////////////////////////////
|
---|
64 | void t_selWin::chooseFile() {
|
---|
65 | QString fileName;
|
---|
66 | if (mode() == File) {
|
---|
67 | fileName = QFileDialog::getOpenFileName(this);
|
---|
68 | }
|
---|
69 | else if (mode() == Files) {
|
---|
70 | QStringList fileNames = QFileDialog::getOpenFileNames(this);
|
---|
71 | fileName = fileNames.join(",");
|
---|
72 | }
|
---|
73 | else {
|
---|
74 | fileName = QFileDialog::getExistingDirectory(this);
|
---|
75 | }
|
---|
76 |
|
---|
77 | if (!fileName.isEmpty()) {
|
---|
78 | _lineEdit->setText(fileName);
|
---|
79 | emit fileNameChanged(fileName);
|
---|
80 | }
|
---|
81 | }
|
---|