source: ntrip/trunk/GnssCenter/inpedit/selwin.cpp@ 5856

Last change on this file since 5856 was 5117, checked in by mervart, 12 years ago
File size: 2.9 KB
RevLine 
[4876]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
20using namespace std;
[5000]21using namespace GnssCenter;
[4876]22
23// Constructor
24////////////////////////////////////////////////////////////////////////////////
[5114]25t_selWin::t_selWin(t_selWin::Mode mode, QWidget* parent) : QWidget(parent) {
[4876]26
[5114]27 _mode = mode;
28
[4876]29 QHBoxLayout* layout = new QHBoxLayout( this );
30 layout->setMargin(0);
31
32 _lineEdit = new QLineEdit(this);
33 layout->addWidget(_lineEdit);
34
[5117]35 connect(_lineEdit, SIGNAL(textEdited(const QString &)),
36 this, SLOT(slotTextEdited()));
[4876]37
38 _button = new QPushButton("...", this);
39 _button->setFixedWidth(_button->fontMetrics().width(" ... "));
40 layout->addWidget(_button);
41
[5114]42 connect(_button, SIGNAL(clicked()), this, SLOT(slotChooseFile()));
[4876]43 setFocusProxy(_lineEdit);
44}
45
46// Destructor
47////////////////////////////////////////////////////////////////////////////////
48t_selWin::~t_selWin() {
49}
50
51//
52////////////////////////////////////////////////////////////////////////////////
[5114]53void t_selWin::setFileNames(const QStringList& fileNames) {
54 _fileNames = fileNames;
55 setLineEditText();
[4876]56}
57
58//
59////////////////////////////////////////////////////////////////////////////////
[5114]60void t_selWin::setLineEditText() {
61 if (_fileNames.size() == 0) {
62 _lineEdit->setText("");
63 }
64 else if (_fileNames.size() == 1) {
65 _lineEdit->setText(_fileNames[0]);
66 }
67 else if (_fileNames.size() > 1) {
68 _lineEdit->setText(QString("SELECTED (%1 FILES)").arg(_fileNames.size()));
69 }
[4876]70}
71
72//
73////////////////////////////////////////////////////////////////////////////////
[5114]74const QStringList& t_selWin::fileNames() const {
75 return _fileNames;
76}
77
78//
79////////////////////////////////////////////////////////////////////////////////
[5117]80void t_selWin::slotTextEdited() {
81 _fileNames.clear();
82 if (!_lineEdit->text().isEmpty()) {
83 _fileNames << _lineEdit->text();
84 }
85 emit fileNamesChanged();
[5114]86}
87
88//
89////////////////////////////////////////////////////////////////////////////////
90void t_selWin::slotChooseFile() {
[4876]91 if (mode() == File) {
[5114]92 QString fileName = QFileDialog::getOpenFileName(this);
93 if (!fileName.isEmpty()) {
94 _fileNames.clear();
95 _fileNames << fileName;
[5117]96 emit fileNamesChanged();
[5114]97 }
[4876]98 }
99 else if (mode() == Files) {
100 QStringList fileNames = QFileDialog::getOpenFileNames(this);
[5114]101 if (fileNames.size()) {
102 _fileNames = fileNames;
[5117]103 emit fileNamesChanged();
[5114]104 }
[4876]105 }
106 else {
[5114]107 QString dirName = QFileDialog::getExistingDirectory(this);
108 if (!dirName.isEmpty()) {
109 _fileNames.clear();
110 _fileNames << dirName;
[5117]111 emit fileNamesChanged();
[5114]112 }
[4876]113 }
[5114]114 setLineEditText();
115}
[4876]116
Note: See TracBrowser for help on using the repository browser.