45 #include <QHBoxLayout> 47 #include <QPushButton> 49 #include "filenameWidget.hh" 66 mode_ (QFileDialog::AcceptOpen),
67 filter_ (
"Any File (*)"),
71 QHBoxLayout *hL =
new QHBoxLayout;
73 line_ =
new QLineEdit;
75 if (_hints.contains (
"default"))
76 default_ = _hints[
"default"];
78 line_->setText (default_);
80 hL->addWidget (line_);
82 selectButton_ =
new QPushButton (
"Select");
84 connect (selectButton_, SIGNAL (pressed ()),
this, SLOT (showDialog ()));
85 hL->addWidget (selectButton_);
89 if (_typeName ==
"Directory")
92 if (_hints.contains (
"mode") && _hints[
"mode"] ==
"Save")
93 mode_ = QFileDialog::AcceptSave;
95 if (_hints.contains (
"filter"))
96 filter_ = _hints[
"filter"];
98 if (_hints.contains (
"default_suffix"))
99 defaultSuffix_ = _hints[
"default_suffix"];
106 FilenameWidget::~ FilenameWidget()
115 return "\"" + line_->text () +
"\"";
123 if (_from.isEmpty ())
130 _from.remove (_from.length () - 1, 1);
132 line_->setText (_from);
140 line_->setText (default_);
146 void FilenameWidget::showDialog()
149 QFileDialog d (
this, tr(
"Select File"), QString() , filter_);
150 d.setAcceptMode (mode_);
151 d.setDefaultSuffix (defaultSuffix_);
154 d.setFileMode (QFileDialog::Directory);
155 d.setOption (QFileDialog::ShowDirsOnly,
true);
158 if (QDialog::Accepted == d.exec ())
159 line_->setText (d.selectedFiles ()[0]);
FilenameWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
void fromValue(QString _from)
Read value from string.
QString toValue()
Convert current value to string.
void toDefault()
Reset to default.