source: ntrip/trunk/BNC/src/qtfilechooser.cpp@ 9484

Last change on this file since 9484 was 8252, checked in by stoecker, 7 years ago

see #105 - reenable Qt4 build options, drop generic version dependend includes, replace by direct requirements, remaining QtCore lines should also be replaced

File size: 2.2 KB
RevLine 
[3601]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
[8252]17#include <QFileDialog>
18#include <QHBoxLayout>
19#include <QLineEdit>
20#include <QPushButton>
21
[3601]22#include "qtfilechooser.h"
23
24// Constructor
25////////////////////////////////////////////////////////////////////////////////
[3825]26qtFileChooser::qtFileChooser(QWidget* parent, qtFileChooser::Mode mode) :
27 QWidget(parent), _mode(mode) {
[3601]28
29 QHBoxLayout* layout = new QHBoxLayout( this );
30 layout->setMargin(0);
31
32 _lineEdit = new QLineEdit(this);
33 layout->addWidget(_lineEdit);
34
35 connect(_lineEdit, SIGNAL(textChanged(const QString &)),
36 this, SIGNAL(fileNameChanged(const QString &)));
37
38 _button = new QPushButton("...", this);
39 _button->setFixedWidth(_button->fontMetrics().width(" ... "));
40 layout->addWidget(_button);
41
42 connect(_button, SIGNAL(clicked()), this, SLOT(chooseFile()));
43 setFocusProxy(_lineEdit);
44}
45
46// Destructor
47////////////////////////////////////////////////////////////////////////////////
48qtFileChooser::~qtFileChooser() {
49}
50
51//
52////////////////////////////////////////////////////////////////////////////////
53void qtFileChooser::setFileName(const QString& fileName) {
54 _lineEdit->setText(fileName);
55}
56
57//
58////////////////////////////////////////////////////////////////////////////////
59QString qtFileChooser::fileName() const {
60 return _lineEdit->text();
61}
62
63//
64////////////////////////////////////////////////////////////////////////////////
65void qtFileChooser::chooseFile() {
66 QString fileName;
[3825]67 if (mode() == File) {
[3601]68 fileName = QFileDialog::getOpenFileName(this);
69 }
[3825]70 else if (mode() == Files) {
71 QStringList fileNames = QFileDialog::getOpenFileNames(this);
72 fileName = fileNames.join(",");
73 }
[3601]74 else {
75 fileName = QFileDialog::getExistingDirectory(this);
76 }
77
78 if (!fileName.isEmpty()) {
79 _lineEdit->setText(fileName);
80 emit fileNameChanged(fileName);
81 }
82}
Note: See TracBrowser for help on using the repository browser.