New option "Don't use the native file dialog".

This commit is contained in:
Roman Telezhynskyi 2020-12-17 18:43:15 +02:00
parent 0ab76dd6b9
commit 58cae6f66c
18 changed files with 120 additions and 92 deletions

View File

@ -4,6 +4,7 @@
- Fix a regression in tool Segment a spline path.
- Fix invalid visualization for tool Point of intersection circles.
- New warning. Warn about empty measurements dimension value when preparing placeholders.
- New option "Don't use the native file dialog".
# Version 0.7.41 Dec 4, 2020
- Bug fixes.

View File

@ -53,7 +53,10 @@ TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *pare
ui->osOptionCheck->setChecked(qApp->TapeSettings()->GetOsSeparator());
// Theme
ui->darkModeCheck->setChecked(qApp->TapeSettings()->GetDarkMode());
ui->darkModeCheck->setChecked(qApp->TapeSettings()->GetDarkMode());
// Native dialogs
ui->checkBoxDontUseNativeDialog->setChecked(qApp->TapeSettings()->IsDontUseNativeDialog());
//---------------------- Pattern making system
ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing());
@ -106,6 +109,11 @@ QStringList TapePreferencesConfigurationPage::Apply()
preferences.append(tr("dark mode"));
}
if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked())
{
settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked());
}
if (m_langChanged || m_systemChanged)
{
const QString locale = qvariant_cast<QString>(ui->langCombo->currentData());

View File

@ -170,19 +170,22 @@
<property name="title">
<string>User Interface</string>
</property>
<widget class="QCheckBox" name="darkModeCheck">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>351</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Activate dark mode</string>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QCheckBox" name="darkModeCheck">
<property name="text">
<string>Activate dark mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDontUseNativeDialog">
<property name="text">
<string>Don't use the native file dialog</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>

View File

@ -149,8 +149,9 @@ void TapePreferencesPathPage::EditPath()
usedNotExistedDir = directory.mkpath(QChar('.'));
}
const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
const QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), path,
qApp->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
if (dir.isEmpty())
{
if (usedNotExistedDir)

View File

@ -520,7 +520,8 @@ void TMainWindow::CreateFromExisting()
usedNotExistedDir = directory.mkpath(QChar('.'));
}
const QString mPath = QFileDialog::getOpenFileName(this, tr("Select file"), pathTo, filter);
const QString mPath = QFileDialog::getOpenFileName(this, tr("Select file"), pathTo, filter, nullptr,
qApp->NativeFileDialog());
if (not mPath.isEmpty())
{
@ -889,7 +890,8 @@ bool TMainWindow::FileSaveAs()
usedNotExistedDir = directory.mkpath(QChar('.'));
}
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters);
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters, nullptr,
qApp->NativeFileDialog());
auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]()
{
@ -997,11 +999,8 @@ void TMainWindow::ImportDataFromCSV()
const QString filters = tr("Comma-Separated Values") + QStringLiteral(" (*.csv)");
const QString suffix = QStringLiteral("csv");
QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr,
qApp->NativeFileDialog());
if (fileName.isEmpty())
{
@ -1471,7 +1470,8 @@ void TMainWindow::ImportFromPattern()
//Use standard path to individual measurements
QString pathTo = qApp->TapeSettings()->GetPathPattern();
const QString mPath = QFileDialog::getOpenFileName(this, tr("Import from a pattern"), pathTo, filter);
const QString mPath = QFileDialog::getOpenFileName(this, tr("Import from a pattern"), pathTo, filter, nullptr,
qApp->NativeFileDialog());
if (mPath.isEmpty())
{
return;
@ -2189,7 +2189,7 @@ void TMainWindow::ExportToIndividual()
QString filters = tr("Individual measurements") + QStringLiteral(" (*.vit)");
QString fName = tr("measurements.vit");
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to individual"), dir + QChar('/') + fName,
filters);
filters, nullptr, qApp->NativeFileDialog());
auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]()
{
@ -3358,7 +3358,8 @@ bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::Open(const QString &pathTo, const QString &filter)
{
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter);
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter, nullptr,
qApp->NativeFileDialog());
if (not mPath.isEmpty())
{

View File

@ -130,6 +130,9 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent)
// Tool panel
ui->checkBoxToolPanelScaling->setChecked(settings->GetToolPanelScaling());
// Native dialogs
ui->checkBoxDontUseNativeDialog->setChecked(settings->IsDontUseNativeDialog());
// Tab Scrolling
ui->spinBoxDuration->setMinimum(VSettings::scrollingDurationMin);
ui->spinBoxDuration->setMaximum(VSettings::scrollingDurationMax);
@ -186,6 +189,11 @@ QStringList PreferencesConfigurationPage::Apply()
settings->SetToolPanelScaling(ui->checkBoxToolPanelScaling->isChecked());
}
if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked())
{
settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked());
}
settings->SetFreeCurveMode(ui->checkBoxFreeCurve->isChecked());
settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked());

View File

@ -33,9 +33,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-161</y>
<y>-189</y>
<width>624</width>
<height>717</height>
<height>745</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -283,6 +283,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDontUseNativeDialog">
<property name="text">
<string>Don't use the native file dialog</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -166,13 +166,9 @@ void PreferencesPathPage::EditPath()
usedNotExistedDir = directory.mkpath(QChar('.'));
}
const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks
#ifdef Q_OS_LINUX
| QFileDialog::DontUseNativeDialog
#endif
);
const QString dir = QFileDialog::getExistingDirectory(
this, tr("Open Directory"), path,
qApp->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
if (dir.isEmpty())
{
if (usedNotExistedDir)

View File

@ -411,11 +411,8 @@ void DialogPatternProperties::InitImage()
void DialogPatternProperties::ChangeImage()
{
const QString filter = tr("Images") + QLatin1String(" (*.png *.jpg *.jpeg *.bmp)");
const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), filter, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), filter, nullptr,
qApp->NativeFileDialog());
if (not fileName.isEmpty())
{
QImage image;
@ -456,11 +453,8 @@ void DialogPatternProperties::SaveImage()
QByteArray ba = QByteArray::fromBase64(byteArray);
const QString extension = doc->GetImageExtension().prepend(QChar('.'));
QString filter = tr("Images") + QStringLiteral(" (*") + extension + QChar(')');
QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter,
qApp->NativeFileDialog());
if (not filename.isEmpty())
{
if (not filename.endsWith(extension.toUpper()))

View File

@ -127,13 +127,9 @@ DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName
usedNotExistedDir = directory.mkpath(QChar('.'));
}
const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"), dirPath,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks
#ifdef Q_OS_LINUX
| QFileDialog::DontUseNativeDialog
#endif
);
const QString dir = QFileDialog::getExistingDirectory(
this, tr("Select folder"), dirPath,
qApp->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks));
if (not dir.isEmpty())
{// If paths equal the signal will not be called, we will do this manually
dir == ui->lineEditPath->text() ? PathChanged(dir) : ui->lineEditPath->setText(dir);

View File

@ -1769,11 +1769,8 @@ void MainWindow::LoadIndividual()
usedNotExistedDir = directory.mkpath(QChar('.'));
}
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr,
qApp->NativeFileDialog());
if (not mPath.isEmpty())
{
@ -1810,11 +1807,8 @@ void MainWindow::LoadMultisize()
//Use standard path to multisize measurements
QString path = qApp->ValentinaSettings()->GetPathMultisizeMeasurements();
path = VCommonSettings::PrepareMultisizeTables(path);
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr,
qApp->NativeFileDialog());
if (not mPath.isEmpty())
{
@ -2034,7 +2028,8 @@ void MainWindow::LoadWatermark()
const QString filter(tr("Watermark files") + QLatin1String(" (*.vwm)"));
QString dir = QDir::homePath();
qDebug("Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr);
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr,
qApp->NativeFileDialog());
if (filePath.isEmpty())
{
return;
@ -3108,11 +3103,7 @@ bool MainWindow::on_actionSaveAs_triggered()
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"),
dir + QLatin1String("/") + tr("pattern") + QLatin1String(".val"),
filters, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
filters, nullptr, qApp->NativeFileDialog());
auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]()
{
@ -3305,11 +3296,8 @@ void MainWindow::on_actionOpen_triggered()
dir = QFileInfo(files.first()).absolutePath();
}
qCDebug(vMainWindow, "Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr,
qApp->NativeFileDialog());
if (filePath.isEmpty())
{
return;
@ -4762,7 +4750,7 @@ void MainWindow::CreateActions()
QString fileName =
QFileDialog::getSaveFileName(this, tr("Export recipe"),
QDir::homePath() + '/' + tr("recipe") + QStringLiteral(".vpr"),
filters, nullptr);
filters, nullptr, qApp->NativeFileDialog());
if (fileName.isEmpty())
{
return;
@ -5569,6 +5557,7 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS
QFileDialog dialog(this, tr("Open file"), dirPath, filter);
dialog.selectFile(selectedName);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setOption(QFileDialog::DontUseNativeDialog, qApp->Settings()->IsDontUseNativeDialog());
if (dialog.exec() == QDialog::Accepted)
{
mPath = dialog.selectedFiles().value(0);

View File

@ -93,7 +93,7 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) :
{
const QString filter = tr("Images") + QLatin1String(" (*.png *.jpg *.jpeg *.bmp)");
const QString fileName = QFileDialog::getOpenFileName(this, tr("Watermark image"), QString(), filter,
nullptr);
nullptr, qApp->NativeFileDialog());
if (not fileName.isEmpty())
{
ui->lineEditPath->setText(fileName);
@ -284,7 +284,7 @@ bool WatermarkWindow::on_actionSaveAs_triggered()
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"),
dir + QLatin1String("/") + tr("watermark") + QLatin1String(".vwm"),
filters, nullptr);
filters, nullptr, qApp->NativeFileDialog());
if (fileName.isEmpty())
{
@ -426,7 +426,8 @@ void WatermarkWindow::on_actionOpen_triggered()
const QString filter(tr("Watermark files") + QLatin1String(" (*.vwm)"));
QString dir = QDir::homePath();
qDebug("Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr);
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr,
qApp->NativeFileDialog());
if (filePath.isEmpty())
{
return;

View File

@ -313,3 +313,14 @@ bool VAbstractApplication::IsWarningMessage(const QString &message) const
{
return VAbstractApplication::ClearMessage(message).startsWith(warningMessageSignature);
}
//---------------------------------------------------------------------------------------------------------------------
QFileDialog::Options VAbstractApplication::NativeFileDialog(QFileDialog::Options options) const
{
if (settings->IsDontUseNativeDialog())
{
options |= QFileDialog::DontUseNativeDialog;
}
return options;
}

View File

@ -39,6 +39,7 @@
#include <QString>
#include <QtGlobal>
#include <QTranslator>
#include <QFileDialog>
#include "../vmisc/def.h"
#include "../vpatterndb/vtranslatevars.h"
@ -82,6 +83,8 @@ public:
static const QString warningMessageSignature;
bool IsWarningMessage(const QString &message) const;
QFileDialog::Options NativeFileDialog(QFileDialog::Options options = QFileDialog::Options()) const;
#if defined(Q_OS_WIN)
static void WinAttachConsole();
#endif

View File

@ -66,6 +66,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmFormatRewrit
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationToolBarStyle, (QLatin1String("configuration/tool_bar_style")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationFreeCurveMode, (QLatin1String("configuration/freeCurveMode")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDoubleClickZoomFitBestCurrentPP, (QLatin1String("configuration/doubleClickZoomFitBestCurrentPP")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDontUseNativeDialog, (QLatin1String("configuration/dontUseNativeDialog")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUndo, (QLatin1String("pattern/undo")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForbidFlipping, (QLatin1String("pattern/forbidFlipping")))
@ -1170,6 +1171,21 @@ void VCommonSettings::SetPieceShowMainPath(bool value)
setValue(*settingPatternPieceShowMainPath, pieceShowMainPath);
}
//---------------------------------------------------------------------------------------------------------------------
bool VCommonSettings::IsDontUseNativeDialog() const
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
return settings.value(*settingConfigurationDontUseNativeDialog, false).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetDontUseNativeDialog(bool value)
{
QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename);
settings.setValue(*settingConfigurationDontUseNativeDialog, value);
settings.sync();
}
//---------------------------------------------------------------------------------------------------------------------
qreal VCommonSettings::GetLineWidth() const
{

View File

@ -214,6 +214,9 @@ public:
bool IsPieceShowMainPath() const;
void SetPieceShowMainPath(bool value);
bool IsDontUseNativeDialog() const;
void SetDontUseNativeDialog(bool value);
static qreal DefaultLineWidth();
static qreal MinimalLineWidth();
static qreal MaximalLineWidth();

View File

@ -300,11 +300,7 @@ void DialogEditLabel::ExportTemplate()
QString fileName = QFileDialog::getSaveFileName(this, tr("Export label template"),
path + QLatin1String("/") + tr("template") + QLatin1String(".xml"),
filters, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
filters, nullptr, qApp->NativeFileDialog());
if (fileName.isEmpty())
{
@ -353,11 +349,8 @@ void DialogEditLabel::ImportTemplate()
QString filter(tr("Label template") + QLatin1String(" (*.xml)"));
//Use standard path to label templates
const QString path = VCommonSettings::PrepareLabelTemplates(qApp->Settings()->GetPathLabelTemplate());
const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr,
qApp->NativeFileDialog());
if (fileName.isEmpty())
{
return;

View File

@ -180,11 +180,8 @@ QString VAbstractMainWindow::CSVFilePath()
const QString suffix("csv");
const QString path = QDir::homePath() + QChar('/') + tr("values") + QChar('.') + suffix;
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters, nullptr
#ifdef Q_OS_LINUX
, QFileDialog::DontUseNativeDialog
#endif
);
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters, nullptr,
qApp->NativeFileDialog());
if (fileName.isEmpty())
{