PDF4QT/PdfForQtViewer/pdfviewersettingsdialog.cpp

186 lines
7.2 KiB
C++
Raw Normal View History

2019-09-06 19:07:52 +02:00
#include "pdfviewersettingsdialog.h"
#include "ui_pdfviewersettingsdialog.h"
2019-09-07 19:01:54 +02:00
#include "pdfglobal.h"
#include "pdfutils.h"
2019-09-28 18:26:31 +02:00
#include <QMessageBox>
2019-09-06 19:07:52 +02:00
#include <QListWidgetItem>
namespace pdfviewer
{
2019-09-07 19:01:54 +02:00
PDFViewerSettingsDialog::PDFViewerSettingsDialog(const PDFViewerSettings::Settings& settings, QWidget *parent) :
2019-09-06 19:07:52 +02:00
QDialog(parent),
2019-09-07 19:01:54 +02:00
ui(new Ui::PDFViewerSettingsDialog),
m_settings(settings),
m_isLoadingData(false)
2019-09-06 19:07:52 +02:00
{
ui->setupUi(this);
new QListWidgetItem(QIcon(":/resources/engine.svg"), tr("Engine"), ui->optionsPagesWidget, EngineSettings);
new QListWidgetItem(QIcon(":/resources/rendering.svg"), tr("Rendering"), ui->optionsPagesWidget, RenderingSettings);
new QListWidgetItem(QIcon(":/resources/shading.svg"), tr("Shading"), ui->optionsPagesWidget, ShadingSettings);
ui->renderingEngineComboBox->addItem(tr("Software"), static_cast<int>(pdf::RendererEngine::Software));
ui->renderingEngineComboBox->addItem(tr("Hardware accelerated (OpenGL)"), static_cast<int>(pdf::RendererEngine::OpenGL));
for (int i : { 1, 2, 4, 8, 16 })
{
2019-09-07 19:01:54 +02:00
ui->multisampleAntialiasingSamplesCountComboBox->addItem(QString::number(i), i);
}
for (QWidget* widget : { ui->engineInfoLabel, ui->renderingInfoLabel })
{
widget->setMinimumWidth(widget->sizeHint().width());
2019-09-06 19:07:52 +02:00
}
2019-09-07 19:01:54 +02:00
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);
}
2019-09-28 18:26:31 +02:00
for (QDoubleSpinBox* spinBox : { ui->preferredMeshResolutionEdit, ui->minimalMeshResolutionEdit, ui->colorToleranceEdit })
{
connect(spinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &PDFViewerSettingsDialog::saveData);
}
2019-09-07 19:01:54 +02:00
ui->optionsPagesWidget->setCurrentRow(0);
adjustSize();
loadData();
2019-09-06 19:07:52 +02:00
}
PDFViewerSettingsDialog::~PDFViewerSettingsDialog()
{
delete ui;
}
void PDFViewerSettingsDialog::on_optionsPagesWidget_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous)
{
Q_UNUSED(previous);
switch (current->type())
{
case EngineSettings:
ui->stackedWidget->setCurrentWidget(ui->enginePage);
break;
case RenderingSettings:
ui->stackedWidget->setCurrentWidget(ui->renderingPage);
break;
case ShadingSettings:
ui->stackedWidget->setCurrentWidget(ui->shadingPage);
break;
default:
Q_ASSERT(false);
break;
}
}
2019-09-07 19:01:54 +02:00
void PDFViewerSettingsDialog::loadData()
{
pdf::PDFTemporaryValueChange guard(&m_isLoadingData, true);
ui->renderingEngineComboBox->setCurrentIndex(ui->renderingEngineComboBox->findData(static_cast<int>(m_settings.m_rendererEngine)));
2019-09-28 18:26:31 +02:00
// Engine
2019-09-07 19:01:54 +02:00
if (m_settings.m_rendererEngine == pdf::RendererEngine::OpenGL)
{
ui->multisampleAntialiasingCheckBox->setEnabled(true);
ui->multisampleAntialiasingCheckBox->setChecked(m_settings.m_multisampleAntialiasing);
2019-09-08 11:13:59 +02:00
if (m_settings.m_multisampleAntialiasing)
{
ui->multisampleAntialiasingSamplesCountComboBox->setEnabled(true);
ui->multisampleAntialiasingSamplesCountComboBox->setCurrentIndex(ui->multisampleAntialiasingSamplesCountComboBox->findData(m_settings.m_rendererSamples));
}
else
{
ui->multisampleAntialiasingSamplesCountComboBox->setEnabled(false);
ui->multisampleAntialiasingSamplesCountComboBox->setCurrentIndex(-1);
}
2019-09-07 19:01:54 +02:00
}
else
{
ui->multisampleAntialiasingCheckBox->setEnabled(false);
ui->multisampleAntialiasingCheckBox->setChecked(false);
ui->multisampleAntialiasingSamplesCountComboBox->setEnabled(false);
ui->multisampleAntialiasingSamplesCountComboBox->setCurrentIndex(-1);
}
2019-09-28 18:26:31 +02:00
// Rendering
2019-09-07 19:01:54 +02:00
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));
2019-09-28 18:26:31 +02:00
// Shading
ui->preferredMeshResolutionEdit->setValue(m_settings.m_preferredMeshResolutionRatio);
ui->minimalMeshResolutionEdit->setValue(m_settings.m_minimalMeshResolutionRatio);
ui->colorToleranceEdit->setValue(m_settings.m_colorTolerance);
2019-09-07 19:01:54 +02:00
}
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());
}
2019-09-28 18:26:31 +02:00
else if (sender == ui->preferredMeshResolutionEdit)
{
m_settings.m_preferredMeshResolutionRatio = ui->preferredMeshResolutionEdit->value();
}
else if (sender == ui->minimalMeshResolutionEdit)
{
m_settings.m_minimalMeshResolutionRatio = ui->minimalMeshResolutionEdit->value();
}
else if (sender == ui->colorToleranceEdit)
{
m_settings.m_colorTolerance = ui->colorToleranceEdit->value();
}
2019-09-07 19:01:54 +02:00
loadData();
}
2019-09-06 19:07:52 +02:00
} // namespace pdfviewer