source: ntrip/trunk/BNC/qtfilechooser.cpp@ 3837

Last change on this file since 3837 was 3825, checked in by mervart, 13 years ago
File size: 2.1 KB
Line 
1/* -------------------------------------------------------------------------
2 * Generally useful widget
3 * -------------------------------------------------------------------------
4 *
5 * Class: qtFileChooser
6 *
7 * Purpose: Widget for selecting a file or directory
8 *
9 * Author: L. Mervart
10 *
11 * Created: 10-May-2011
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include "qtfilechooser.h"
18
19// Constructor
20////////////////////////////////////////////////////////////////////////////////
21qtFileChooser::qtFileChooser(QWidget* parent, qtFileChooser::Mode mode) :
22 QWidget(parent), _mode(mode) {
23
24 QHBoxLayout* layout = new QHBoxLayout( this );
25 layout->setMargin(0);
26
27 _lineEdit = new QLineEdit(this);
28 layout->addWidget(_lineEdit);
29
30 connect(_lineEdit, SIGNAL(textChanged(const QString &)),
31 this, SIGNAL(fileNameChanged(const QString &)));
32
33 _button = new QPushButton("...", this);
34 _button->setFixedWidth(_button->fontMetrics().width(" ... "));
35 layout->addWidget(_button);
36
37 connect(_button, SIGNAL(clicked()), this, SLOT(chooseFile()));
38 setFocusProxy(_lineEdit);
39}
40
41// Destructor
42////////////////////////////////////////////////////////////////////////////////
43qtFileChooser::~qtFileChooser() {
44}
45
46//
47////////////////////////////////////////////////////////////////////////////////
48void qtFileChooser::setFileName(const QString& fileName) {
49 _lineEdit->setText(fileName);
50}
51
52//
53////////////////////////////////////////////////////////////////////////////////
54QString qtFileChooser::fileName() const {
55 return _lineEdit->text();
56}
57
58//
59////////////////////////////////////////////////////////////////////////////////
60void qtFileChooser::chooseFile() {
61 QString fileName;
62 if (mode() == File) {
63 fileName = QFileDialog::getOpenFileName(this);
64 }
65 else if (mode() == Files) {
66 QStringList fileNames = QFileDialog::getOpenFileNames(this);
67 fileName = fileNames.join(",");
68 }
69 else {
70 fileName = QFileDialog::getExistingDirectory(this);
71 }
72
73 if (!fileName.isEmpty()) {
74 _lineEdit->setText(fileName);
75 emit fileNameChanged(fileName);
76 }
77}
Note: See TracBrowser for help on using the repository browser.