3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_PATH_CHOOSER_WIDGET_HPP_INCLUDED
22 #define SCIDE_WIDGETS_PATH_CHOOSER_WIDGET_HPP_INCLUDED
25 #include <QPushButton>
26 #include <QFileDialog>
27 #include <QHBoxLayout>
32 class PathChooserWidget
: public QWidget
38 (QWidget
*parent
= 0, QFileDialog::FileMode mode
= QFileDialog::ExistingFile
):
43 mTextField
= new QLineEdit
;
45 mButton
= new QPushButton
;
46 mButton
->setIcon( QIcon::fromTheme("folder") );
47 mButton
->setFixedWidth( 30 );
48 mButton
->setFlat(true);
49 //setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
51 QHBoxLayout
*box
= new QHBoxLayout(this);
52 box
->addWidget(mTextField
);
53 box
->addWidget(mButton
);
54 box
->setContentsMargins(0,0,0,0);
57 connect(mButton
, SIGNAL(clicked()), this, SLOT(execDialog()), Qt::QueuedConnection
);
60 QString
text() const { return mTextField
->text(); }
62 void setText( const QString
& text
) { mTextField
->setText(text
); }
64 void setFileMode( QFileDialog::FileMode mode
) { mMode
= mode
; }
70 QWidget
*parent
= parentWidget();
71 dialog
= new QFileDialog(parent
? parent
: this);
73 dialog
->setFileMode(mMode
);
74 dialog
->selectFile(mTextField
->text());
76 QPointer
<QLineEdit
> textField
= mTextField
;
77 int result
= dialog
->exec();
78 if (result
== QDialog::Accepted
&& textField
) {
79 QStringList paths
= dialog
->selectedFiles();
80 textField
->setText(paths
.count() ? paths
[0] : "");
85 void textChanged( const QString
& );
88 QLineEdit
*mTextField
;
90 QFileDialog::FileMode mMode
;
96 #endif // SCIDE_WIDGETS_PATH_CHOOSER_WIDGET_HPP_INCLUDED