scide: implement selectionLength for openDocument
[supercollider.git] / editors / sc-ide / widgets / util / path_chooser_widget.hpp
blobda18211fd44cb5f8d086dba795389e14c6f6b0b9
1 /*
2 SuperCollider Qt IDE
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
24 #include <QLineEdit>
25 #include <QPushButton>
26 #include <QFileDialog>
27 #include <QHBoxLayout>
28 #include <QPointer>
30 namespace ScIDE {
32 class PathChooserWidget : public QWidget
34 Q_OBJECT
36 public:
37 PathChooserWidget
38 (QWidget *parent = 0, QFileDialog::FileMode mode = QFileDialog::ExistingFile ):
39 QWidget(parent),
40 mMode(mode),
41 dialog(0)
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);
55 box->setSpacing(1);
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; }
66 public Q_SLOTS:
67 void execDialog()
69 if(!dialog) {
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] : "");
84 Q_SIGNALS:
85 void textChanged( const QString & );
87 private:
88 QLineEdit *mTextField;
89 QPushButton *mButton;
90 QFileDialog::FileMode mMode;
91 QFileDialog *dialog;
94 } // namespace ScIDE
96 #endif // SCIDE_WIDGETS_PATH_CHOOSER_WIDGET_HPP_INCLUDED