6 #include <QApplication>
7 #include <QFontMetrics>
8 #include "fileselectwidget.h"
11 FileSelectWidget::FileSelectWidget(QWidget
*parent
) : QWidget(parent
)
13 _edit
= new QLineEdit();
15 _edit
->setDisabled(true);
17 QFontMetrics
fm(QApplication::font());
18 _edit
->setMinimumWidth(fm
.averageCharWidth() * (QDir::homePath().length()
20 #endif // Q_OS_ANDROID
22 _button
= new QPushButton("...");
23 _button
->setMaximumWidth(_button
->sizeHint().width() / 2);
25 _button
= new QToolButton();
26 _button
->setText("...");
28 connect(_button
, &QToolButton::clicked
, this, &FileSelectWidget::browse
);
30 QHBoxLayout
*layout
= new QHBoxLayout();
31 layout
->setContentsMargins(QMargins());
32 layout
->addWidget(_edit
);
33 layout
->addWidget(_button
);
36 QSizePolicy
p(QSizePolicy::MinimumExpanding
, QSizePolicy::Fixed
);
40 void FileSelectWidget::browse()
43 _fileName
= QFileDialog::getSaveFileName(this, tr("Select file"));
44 if (!_fileName
.isEmpty())
45 _edit
->setText(Util::displayName(_fileName
));
47 QFileInfo
fi(_edit
->text());
48 QString fileName
= QFileDialog::getSaveFileName(this, tr("Select file"),
49 fi
.dir().absolutePath(), _filter
);
50 if (!fileName
.isEmpty())
51 _edit
->setText(fileName
);
52 #endif // Q_OS_ANDROID
55 bool FileSelectWidget::checkFile(QString
&error
) const
57 if (file().isEmpty()) {
58 error
= tr("No output file selected.");
64 bool exists
= fi
.exists();
67 if (exists
&& fi
.isDir()) {
68 error
= tr("%1 is a directory.").arg(f
.fileName());
70 } else if ((exists
&& !fi
.isWritable())
71 || !(opened
= f
.open(QFile::Append
))) {
72 error
= tr("%1 is not writable.").arg(f
.fileName());