Settings dialog

This commit is contained in:
Jakub Melka 2019-09-07 19:01:54 +02:00
parent 4058a25bab
commit 6f0c586c90
7 changed files with 142 additions and 23 deletions

View File

@ -456,8 +456,11 @@ void PDFViewerMainWindow::on_actionGenerateCMAPrepository_triggered()
void PDFViewerMainWindow::on_actionOptions_triggered()
{
PDFViewerSettingsDialog dialog(this);
dialog.exec();
PDFViewerSettingsDialog dialog(m_settings->getSettings(), this);
if (dialog.exec() == QDialog::Accepted)
{
m_settings->setSettings(dialog.getSettings());
}
}
} // namespace pdfviewer

View File

@ -214,6 +214,9 @@
<property name="text">
<string>Options...</string>
</property>
<property name="shortcut">
<string>Ctrl+K</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>

View File

@ -3,6 +3,12 @@
namespace pdfviewer
{
void PDFViewerSettings::setSettings(const PDFViewerSettings::Settings& settings)
{
m_settings = settings;
emit settingsChanged();
}
void PDFViewerSettings::readSettings(QSettings& settings)
{
settings.beginGroup("ViewerSettings");

View File

@ -19,6 +19,27 @@ public:
}
struct Settings
{
Settings() :
m_features(pdf::PDFRenderer::getDefaultFeatures()),
m_rendererEngine(pdf::RendererEngine::OpenGL),
m_multisampleAntialiasing(true),
m_rendererSamples(16)
{
}
pdf::PDFRenderer::Features m_features;
QString m_directory;
pdf::RendererEngine m_rendererEngine;
bool m_multisampleAntialiasing;
int m_rendererSamples;
};
const Settings& getSettings() const { return m_settings; }
void setSettings(const Settings& settings);
void readSettings(QSettings& settings);
void writeSettings(QSettings& settings);
@ -38,22 +59,6 @@ signals:
void settingsChanged();
private:
struct Settings
{
Settings() :
m_features(pdf::PDFRenderer::getDefaultFeatures()),
m_rendererEngine(pdf::RendererEngine::OpenGL),
m_rendererSamples(16)
{
}
pdf::PDFRenderer::Features m_features;
QString m_directory;
pdf::RendererEngine m_rendererEngine;
int m_rendererSamples;
};
Settings m_settings;
};

View File

@ -1,14 +1,19 @@
#include "pdfviewersettingsdialog.h"
#include "ui_pdfviewersettingsdialog.h"
#include "pdfglobal.h"
#include "pdfutils.h"
#include <QListWidgetItem>
namespace pdfviewer
{
PDFViewerSettingsDialog::PDFViewerSettingsDialog(QWidget *parent) :
PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settings& settings, QWidget *parent) :
QDialog(parent),
ui(new Ui::PDFViewerSettingsDialog)
ui(new Ui::PDFViewerSettingsDialog),
m_settings(settings),
m_isLoadingData(false)
{
ui->setupUi(this);
@ -21,8 +26,26 @@ PDFViewerSettingsDialog::PDFViewerSettingsDialog(QWidget *parent) :
for (int i : { 1, 2, 4, 8, 16 })
{
ui->multisampleAntialiasingSamplesCountComboBox->addItem(QString::number(i));
ui->multisampleAntialiasingSamplesCountComboBox->addItem(QString::number(i), i);
}
for (QWidget* widget : { ui->engineInfoLabel, ui->renderingInfoLabel })
{
widget->setMinimumWidth(widget->sizeHint().width());
}
for (QCheckBox* checkBox : { ui->multisampleAntialiasingCheckBox, ui->antialiasingCheckBox, ui->textAntialiasingCheckBox, ui->smoothPicturesCheckBox, ui->ignoreOptionalContentCheckBox, ui->clipToCropBoxCheckBox })
{
connect(checkBox, &QCheckBox::clicked, this, &PDFViewerSettingsDialog::saveData);
}
for (QComboBox* comboBox : { ui->renderingEngineComboBox, ui->multisampleAntialiasingSamplesCountComboBox })
{
connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PDFViewerSettingsDialog::saveData);
}
ui->optionsPagesWidget->setCurrentRow(0);
adjustSize();
loadData();
}
PDFViewerSettingsDialog::~PDFViewerSettingsDialog()
@ -54,4 +77,76 @@ void PDFViewerSettingsDialog::on_optionsPagesWidget_currentItemChanged(QListWidg
}
}
void PDFViewerSettingsDialog::loadData()
{
pdf::PDFTemporaryValueChange guard(&m_isLoadingData, true);
ui->renderingEngineComboBox->setCurrentIndex(ui->renderingEngineComboBox->findData(static_cast<int>(m_settings.m_rendererEngine)));
if (m_settings.m_rendererEngine == pdf::RendererEngine::OpenGL)
{
ui->multisampleAntialiasingCheckBox->setEnabled(true);
ui->multisampleAntialiasingCheckBox->setChecked(m_settings.m_multisampleAntialiasing);
ui->multisampleAntialiasingSamplesCountComboBox->setEnabled(true);
ui->multisampleAntialiasingSamplesCountComboBox->setCurrentIndex(ui->multisampleAntialiasingSamplesCountComboBox->findData(m_settings.m_rendererSamples));
}
else
{
ui->multisampleAntialiasingCheckBox->setEnabled(false);
ui->multisampleAntialiasingCheckBox->setChecked(false);
ui->multisampleAntialiasingSamplesCountComboBox->setEnabled(false);
ui->multisampleAntialiasingSamplesCountComboBox->setCurrentIndex(-1);
}
ui->antialiasingCheckBox->setChecked(m_settings.m_features.testFlag(pdf::PDFRenderer::Antialiasing));
ui->textAntialiasingCheckBox->setChecked(m_settings.m_features.testFlag(pdf::PDFRenderer::TextAntialiasing));
ui->smoothPicturesCheckBox->setChecked(m_settings.m_features.testFlag(pdf::PDFRenderer::SmoothImages));
ui->ignoreOptionalContentCheckBox->setChecked(m_settings.m_features.testFlag(pdf::PDFRenderer::IgnoreOptionalContent));
ui->clipToCropBoxCheckBox->setChecked(m_settings.m_features.testFlag(pdf::PDFRenderer::ClipToCropBox));
}
void PDFViewerSettingsDialog::saveData()
{
if (m_isLoadingData)
{
return;
}
QObject* sender = this->sender();
if (sender == ui->renderingEngineComboBox)
{
m_settings.m_rendererEngine = static_cast<pdf::RendererEngine>(ui->renderingEngineComboBox->currentData().toInt());
}
else if (sender == ui->multisampleAntialiasingCheckBox)
{
m_settings.m_multisampleAntialiasing = ui->multisampleAntialiasingCheckBox->isChecked();
}
else if (sender == ui->multisampleAntialiasingSamplesCountComboBox)
{
m_settings.m_rendererSamples = ui->multisampleAntialiasingSamplesCountComboBox->currentData().toInt();
}
else if (sender == ui->antialiasingCheckBox)
{
m_settings.m_features.setFlag(pdf::PDFRenderer::Antialiasing, ui->antialiasingCheckBox->isChecked());
}
else if (sender == ui->textAntialiasingCheckBox)
{
m_settings.m_features.setFlag(pdf::PDFRenderer::TextAntialiasing, ui->textAntialiasingCheckBox->isChecked());
}
else if (sender == ui->smoothPicturesCheckBox)
{
m_settings.m_features.setFlag(pdf::PDFRenderer::SmoothImages, ui->smoothPicturesCheckBox->isChecked());
}
else if (sender == ui->ignoreOptionalContentCheckBox)
{
m_settings.m_features.setFlag(pdf::PDFRenderer::IgnoreOptionalContent, ui->ignoreOptionalContentCheckBox->isChecked());
}
else if (sender == ui->clipToCropBoxCheckBox)
{
m_settings.m_features.setFlag(pdf::PDFRenderer::ClipToCropBox, ui->clipToCropBoxCheckBox->isChecked());
}
loadData();
}
} // namespace pdfviewer

View File

@ -20,7 +20,7 @@ class PDFViewerSettingsDialog : public QDialog
Q_OBJECT
public:
explicit PDFViewerSettingsDialog(QWidget* parent);
explicit PDFViewerSettingsDialog(const PDFViewerSettings::Settings& settings, QWidget* parent);
virtual ~PDFViewerSettingsDialog() override;
enum Page : int
@ -30,11 +30,18 @@ public:
ShadingSettings
};
const PDFViewerSettings::Settings& getSettings() const { return m_settings; }
private slots:
void on_optionsPagesWidget_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);
private:
void loadData();
void saveData();
Ui::PDFViewerSettingsDialog* ui;
PDFViewerSettings::Settings m_settings;
bool m_isLoadingData;
};
} // namespace pdfviewer

View File

@ -26,7 +26,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="enginePage">
<layout class="QVBoxLayout" name="enginePageLayout">