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

Last change on this file since 10576 was 10524, checked in by stuerze, 3 months ago

replacement of obsolete qt-class members

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////////////////////////////////////////////////////////////////////////////////
[10524]26qtFileChooser::qtFileChooser(QWidget* parent, qtFileChooser::Mode mode) :
[3825]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);
[10524]39 _button->setFixedWidth(_button->fontMetrics().horizontalAdvance(" ... "));
[3601]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
[10524]51//
[3601]52////////////////////////////////////////////////////////////////////////////////
53void qtFileChooser::setFileName(const QString& fileName) {
54 _lineEdit->setText(fileName);
55}
56
[10524]57//
[3601]58////////////////////////////////////////////////////////////////////////////////
59QString qtFileChooser::fileName() const {
60 return _lineEdit->text();
61}
62
[10524]63//
[3601]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.