51 #include <QHBoxLayout>
53 #include <QPushButton>
55 #include "filenameWidget.hh"
72 mode_ (QFileDialog::AcceptOpen),
73 filter_ (
"Any File (*)"),
77 QHBoxLayout *hL =
new QHBoxLayout;
79 line_ =
new QLineEdit;
81 if (_hints.contains (
"default"))
82 default_ = _hints[
"default"];
84 line_->setText (default_);
86 hL->addWidget (line_);
88 selectButton_ =
new QPushButton (
"Select");
90 connect (selectButton_, SIGNAL (pressed ()),
this, SLOT (showDialog ()));
91 hL->addWidget (selectButton_);
95 if (_typeName ==
"Directory")
98 if (_hints.contains (
"mode") && _hints[
"mode"] ==
"Save")
99 mode_ = QFileDialog::AcceptSave;
101 if (_hints.contains (
"filter"))
102 filter_ = _hints[
"filter"];
104 if (_hints.contains (
"default_suffix"))
105 defaultSuffix_ = _hints[
"default_suffix"];
121 return "\"" + line_->text () +
"\"";
129 if (_from.isEmpty ())
136 _from.remove (_from.length () - 1, 1);
138 line_->setText (_from);
146 line_->setText (default_);
152 void FilenameWidget::showDialog()
155 QFileDialog d (
this, tr(
"Select File"), QString() , filter_);
156 d.setAcceptMode (mode_);
157 d.setDefaultSuffix (defaultSuffix_);
160 d.setFileMode (QFileDialog::Directory);
161 d.setOption (QFileDialog::ShowDirsOnly,
true);
164 if (QDialog::Accepted == d.exec ())
165 line_->setText (d.selectedFiles ()[0]);
FilenameWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
QString toValue()
Convert current value to string.
void toDefault()
Reset to default.
void fromValue(QString _from)
Read value from string.
~FilenameWidget()
Destructor.