mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Rendering options
This commit is contained in:
@ -45,6 +45,7 @@ namespace pdfviewer
|
||||
PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::PDFViewerMainWindow),
|
||||
m_settings(new PDFViewerSettings(this)),
|
||||
m_pdfWidget(nullptr),
|
||||
m_optionalContentDockWidget(nullptr),
|
||||
m_optionalContentTreeView(nullptr),
|
||||
@ -97,11 +98,22 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_optionalContentDockWidget);
|
||||
m_optionalContentDockWidget->hide();
|
||||
|
||||
ui->actionRenderOptionAntialiasing->setData(pdf::PDFRenderer::Antialiasing);
|
||||
ui->actionRenderOptionTextAntialiasing->setData(pdf::PDFRenderer::TextAntialiasing);
|
||||
ui->actionRenderOptionSmoothPictures->setData(pdf::PDFRenderer::SmoothImages);
|
||||
ui->actionRenderOptionIgnoreOptionalContentSettings->setData(pdf::PDFRenderer::IgnoreOptionalContent);
|
||||
|
||||
for (QAction* action : getRenderingOptionActions())
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFViewerMainWindow::onRenderingOptionTriggered);
|
||||
}
|
||||
|
||||
ui->menuView->addSeparator();
|
||||
ui->menuView->addAction(m_optionalContentDockWidget->toggleViewAction());
|
||||
|
||||
connect(m_pdfWidget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::pageLayoutChanged, this, &PDFViewerMainWindow::updatePageLayoutActions);
|
||||
connect(m_pdfWidget, &pdf::PDFWidget::pageRenderingErrorsChanged, this, &PDFViewerMainWindow::onPageRenderingErrorsChanged, Qt::QueuedConnection);
|
||||
connect(m_settings, &PDFViewerSettings::settingsChanged, this, &PDFViewerMainWindow::onViewerSettingsChanged);
|
||||
|
||||
readSettings();
|
||||
updatePageLayoutActions();
|
||||
@ -114,7 +126,7 @@ PDFViewerMainWindow::~PDFViewerMainWindow()
|
||||
|
||||
void PDFViewerMainWindow::onActionOpenTriggered()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_directory, tr("PDF document (*.pdf)"));
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Select PDF document"), m_settings->getDirectory(), tr("PDF document (*.pdf)"));
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
openDocument(fileName);
|
||||
@ -141,7 +153,7 @@ void PDFViewerMainWindow::onPageRenderingErrorsChanged(pdf::PDFInteger pageIndex
|
||||
|
||||
void PDFViewerMainWindow::readSettings()
|
||||
{
|
||||
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
|
||||
QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
|
||||
if (geometry.isEmpty())
|
||||
@ -162,15 +174,16 @@ void PDFViewerMainWindow::readSettings()
|
||||
restoreState(state);
|
||||
}
|
||||
|
||||
m_directory = settings.value("defaultDirectory", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString();
|
||||
m_settings->readSettings(settings);
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::writeSettings()
|
||||
{
|
||||
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
settings.setValue("geometry", saveGeometry());
|
||||
settings.setValue("windowState", saveState());
|
||||
settings.setValue("defaultDirectory", m_directory);
|
||||
|
||||
m_settings->writeSettings(settings);
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::updateTitle()
|
||||
@ -225,6 +238,31 @@ void PDFViewerMainWindow::updatePageLayoutActions()
|
||||
}
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::updateRenderingOptionActions()
|
||||
{
|
||||
const pdf::PDFRenderer::Features features = m_settings->getFeatures();
|
||||
for (QAction* action : getRenderingOptionActions())
|
||||
{
|
||||
action->setChecked(features.testFlag(static_cast<pdf::PDFRenderer::Feature>(action->data().toInt())));
|
||||
}
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::onViewerSettingsChanged()
|
||||
{
|
||||
m_pdfWidget->getDrawWidgetProxy()->setFeatures(m_settings->getFeatures());
|
||||
updateRenderingOptionActions();
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::onRenderingOptionTriggered(bool checked)
|
||||
{
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
Q_ASSERT(action);
|
||||
|
||||
pdf::PDFRenderer::Features features = m_settings->getFeatures();
|
||||
features.setFlag(static_cast<pdf::PDFRenderer::Feature>(action->data().toInt()), checked);
|
||||
m_settings->setFeatures(features);
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::openDocument(const QString& fileName)
|
||||
{
|
||||
// First close old document
|
||||
@ -240,7 +278,7 @@ void PDFViewerMainWindow::openDocument(const QString& fileName)
|
||||
{
|
||||
// Mark current directory as this
|
||||
QFileInfo fileInfo(fileName);
|
||||
m_directory = fileInfo.dir().absolutePath();
|
||||
m_settings->setDirectory(fileInfo.dir().absolutePath());
|
||||
m_currentFile = fileInfo.fileName();
|
||||
|
||||
m_pdfDocument.reset(new pdf::PDFDocument(std::move(document)));
|
||||
@ -297,6 +335,11 @@ void PDFViewerMainWindow::setPageLayout(pdf::PageLayout pageLayout)
|
||||
m_pdfWidget->getDrawWidgetProxy()->setPageLayout(pageLayout);
|
||||
}
|
||||
|
||||
std::vector<QAction*> PDFViewerMainWindow::getRenderingOptionActions() const
|
||||
{
|
||||
return { ui->actionRenderOptionAntialiasing, ui->actionRenderOptionTextAntialiasing, ui->actionRenderOptionSmoothPictures, ui->actionRenderOptionIgnoreOptionalContentSettings };
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
writeSettings();
|
||||
@ -393,4 +436,50 @@ void PDFViewerMainWindow::on_actionGenerateCMAPrepository_triggered()
|
||||
}
|
||||
}
|
||||
|
||||
void PDFViewerSettings::readSettings(QSettings& settings)
|
||||
{
|
||||
settings.beginGroup("ViewerSettings");
|
||||
m_directory = settings.value("defaultDirectory", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString();
|
||||
m_features = static_cast<pdf::PDFRenderer::Features>(settings.value("rendererFeatures", static_cast<int>(pdf::PDFRenderer::getDefaultFeatures())).toInt());
|
||||
settings.endGroup();
|
||||
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
||||
void PDFViewerSettings::writeSettings(QSettings& settings)
|
||||
{
|
||||
settings.beginGroup("ViewerSettings");
|
||||
settings.setValue("defaultDirectory", m_directory);
|
||||
settings.setValue("rendererFeatures", static_cast<int>(m_features));
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
QString PDFViewerSettings::getDirectory() const
|
||||
{
|
||||
return m_directory;
|
||||
}
|
||||
|
||||
void PDFViewerSettings::setDirectory(const QString& directory)
|
||||
{
|
||||
if (m_directory != directory)
|
||||
{
|
||||
m_directory = directory;
|
||||
emit settingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
pdf::PDFRenderer::Features PDFViewerSettings::getFeatures() const
|
||||
{
|
||||
return m_features;
|
||||
}
|
||||
|
||||
void PDFViewerSettings::setFeatures(const pdf::PDFRenderer::Features& features)
|
||||
{
|
||||
if (m_features != features)
|
||||
{
|
||||
m_features = features;
|
||||
emit settingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pdfviewer
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include <QMainWindow>
|
||||
#include <QSharedPointer>
|
||||
|
||||
class QSettings;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class PDFViewerMainWindow;
|
||||
@ -40,6 +42,35 @@ class PDFOptionalContentTreeItemModel;
|
||||
namespace pdfviewer
|
||||
{
|
||||
|
||||
class PDFViewerSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
inline explicit PDFViewerSettings(QObject* parent) :
|
||||
QObject(parent),
|
||||
m_features(pdf::PDFRenderer::Antialiasing | pdf::PDFRenderer::TextAntialiasing)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void readSettings(QSettings& settings);
|
||||
void writeSettings(QSettings& settings);
|
||||
|
||||
QString getDirectory() const;
|
||||
void setDirectory(const QString& directory);
|
||||
|
||||
pdf::PDFRenderer::Features getFeatures() const;
|
||||
void setFeatures(const pdf::PDFRenderer::Features& features);
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
|
||||
private:
|
||||
pdf::PDFRenderer::Features m_features;
|
||||
QString m_directory;
|
||||
};
|
||||
|
||||
class PDFViewerMainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -58,7 +89,6 @@ private slots:
|
||||
void on_actionFirstPageOnRightSide_triggered();
|
||||
|
||||
void on_actionRendering_Errors_triggered();
|
||||
|
||||
void on_actionGenerateCMAPrepository_triggered();
|
||||
|
||||
private:
|
||||
@ -72,6 +102,10 @@ private:
|
||||
|
||||
void updateTitle();
|
||||
void updatePageLayoutActions();
|
||||
void updateRenderingOptionActions();
|
||||
|
||||
void onViewerSettingsChanged();
|
||||
void onRenderingOptionTriggered(bool checked);
|
||||
|
||||
void openDocument(const QString& fileName);
|
||||
void setDocument(const pdf::PDFDocument* document);
|
||||
@ -79,10 +113,12 @@ private:
|
||||
|
||||
void setPageLayout(pdf::PageLayout pageLayout);
|
||||
|
||||
std::vector<QAction*> getRenderingOptionActions() const;
|
||||
|
||||
Ui::PDFViewerMainWindow* ui;
|
||||
PDFViewerSettings* m_settings;
|
||||
pdf::PDFWidget* m_pdfWidget;
|
||||
QSharedPointer<pdf::PDFDocument> m_pdfDocument;
|
||||
QString m_directory;
|
||||
QString m_currentFile;
|
||||
QDockWidget* m_optionalContentDockWidget;
|
||||
QTreeView* m_optionalContentTreeView;
|
||||
|
@ -51,7 +51,17 @@
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionFirstPageOnRightSide"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuRendering_Options">
|
||||
<property name="title">
|
||||
<string>Rendering Options</string>
|
||||
</property>
|
||||
<addaction name="actionRenderOptionAntialiasing"/>
|
||||
<addaction name="actionRenderOptionTextAntialiasing"/>
|
||||
<addaction name="actionRenderOptionSmoothPictures"/>
|
||||
<addaction name="actionRenderOptionIgnoreOptionalContentSettings"/>
|
||||
</widget>
|
||||
<addaction name="menuPage_Layout"/>
|
||||
<addaction name="menuRendering_Options"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuTools">
|
||||
<property name="title">
|
||||
@ -166,6 +176,38 @@
|
||||
<string>Generate CMAP repository</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRenderOptionAntialiasing">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Antialiasing</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRenderOptionTextAntialiasing">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Text Antialiasing</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRenderOptionSmoothPictures">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Smooth Pictures</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRenderOptionIgnoreOptionalContentSettings">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ignore Optional Content Settings</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
Reference in New Issue
Block a user