mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Rendering options
This commit is contained in:
@ -347,7 +347,8 @@ PDFDrawWidgetProxy::PDFDrawWidgetProxy(QObject* parent) :
|
|||||||
m_controller(nullptr),
|
m_controller(nullptr),
|
||||||
m_widget(nullptr),
|
m_widget(nullptr),
|
||||||
m_horizontalScrollbar(nullptr),
|
m_horizontalScrollbar(nullptr),
|
||||||
m_verticalScrollbar(nullptr)
|
m_verticalScrollbar(nullptr),
|
||||||
|
m_features(PDFRenderer::Antialiasing | PDFRenderer::TextAntialiasing)
|
||||||
{
|
{
|
||||||
m_controller = new PDFDrawSpaceController(this);
|
m_controller = new PDFDrawSpaceController(this);
|
||||||
connect(m_controller, &PDFDrawSpaceController::drawSpaceChanged, this, &PDFDrawWidgetProxy::update);
|
connect(m_controller, &PDFDrawSpaceController::drawSpaceChanged, this, &PDFDrawWidgetProxy::update);
|
||||||
@ -549,7 +550,7 @@ void PDFDrawWidgetProxy::draw(QPainter* painter, QRect rect)
|
|||||||
// Clear the page space by white color
|
// Clear the page space by white color
|
||||||
painter->fillRect(placedRect, Qt::white);
|
painter->fillRect(placedRect, Qt::white);
|
||||||
|
|
||||||
PDFRenderer renderer(m_controller->getDocument(), m_controller->getFontCache(), m_controller->getOptionalContentActivity());
|
PDFRenderer renderer(m_controller->getDocument(), m_controller->getFontCache(), m_controller->getOptionalContentActivity(), m_features);
|
||||||
QList<PDFRenderError> errors = renderer.render(painter, placedRect, item.pageIndex);
|
QList<PDFRenderError> errors = renderer.render(painter, placedRect, item.pageIndex);
|
||||||
|
|
||||||
if (!errors.empty())
|
if (!errors.empty())
|
||||||
@ -810,4 +811,18 @@ void PDFDrawWidgetProxy::updateVerticalScrollbarFromOffset()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDFRenderer::Features PDFDrawWidgetProxy::getFeatures() const
|
||||||
|
{
|
||||||
|
return m_features;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFDrawWidgetProxy::setFeatures(PDFRenderer::Features features)
|
||||||
|
{
|
||||||
|
if (m_features != features)
|
||||||
|
{
|
||||||
|
m_features = features;
|
||||||
|
emit repaintNeeded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
@ -213,6 +213,9 @@ public:
|
|||||||
|
|
||||||
static constexpr PDFReal ZOOM_STEP = 1.2;
|
static constexpr PDFReal ZOOM_STEP = 1.2;
|
||||||
|
|
||||||
|
PDFRenderer::Features getFeatures() const;
|
||||||
|
void setFeatures(PDFRenderer::Features features);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void drawSpaceChanged();
|
void drawSpaceChanged();
|
||||||
void pageLayoutChanged();
|
void pageLayoutChanged();
|
||||||
@ -326,6 +329,9 @@ private:
|
|||||||
|
|
||||||
/// Current page layout
|
/// Current page layout
|
||||||
Layout m_layout;
|
Layout m_layout;
|
||||||
|
|
||||||
|
/// Renderer features
|
||||||
|
PDFRenderer::Features m_features;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
@ -1866,6 +1866,23 @@ void PDFPageContentProcessor::operatorPaintXObject(PDFPageContentProcessor::PDFO
|
|||||||
{
|
{
|
||||||
if (m_xobjectDictionary)
|
if (m_xobjectDictionary)
|
||||||
{
|
{
|
||||||
|
// According to the specification, XObjects are skipped entirely, as no operator was invoked.
|
||||||
|
if (m_xobjectDictionary->hasKey("OC"))
|
||||||
|
{
|
||||||
|
const PDFObject& object = m_xobjectDictionary->get("OC");
|
||||||
|
if (object.isReference())
|
||||||
|
{
|
||||||
|
if (isContentSuppressedByOC(object.getReference()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Reference to optional content expected."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const PDFObject& object = m_document->getObject(m_xobjectDictionary->get(name.name));
|
const PDFObject& object = m_document->getObject(m_xobjectDictionary->get(name.name));
|
||||||
if (object.isStream())
|
if (object.isStream())
|
||||||
{
|
{
|
||||||
@ -1969,8 +1986,6 @@ void PDFPageContentProcessor::operatorMarkedContentBegin(PDFOperandName name)
|
|||||||
|
|
||||||
void PDFPageContentProcessor::operatorMarkedContentBeginWithProperties(PDFOperandName name, PDFObject properties)
|
void PDFPageContentProcessor::operatorMarkedContentBeginWithProperties(PDFOperandName name, PDFObject properties)
|
||||||
{
|
{
|
||||||
// TODO: Handle optional content of images/forms
|
|
||||||
|
|
||||||
// Handle the optional content
|
// Handle the optional content
|
||||||
if (name.name == "OC")
|
if (name.name == "OC")
|
||||||
{
|
{
|
||||||
|
@ -406,6 +406,10 @@ protected:
|
|||||||
/// Returns true, if graphic content is suppressed
|
/// Returns true, if graphic content is suppressed
|
||||||
bool isContentSuppressed() const;
|
bool isContentSuppressed() const;
|
||||||
|
|
||||||
|
/// Computes visibility of OCG/OCMD - returns false, if it is not suppressed,
|
||||||
|
/// or true, if it is suppressed.
|
||||||
|
virtual bool isContentSuppressedByOC(PDFObjectReference ocgOrOcmd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Initializes the resources dictionaries
|
/// Initializes the resources dictionaries
|
||||||
void initDictionaries(const PDFObject& resourcesObject);
|
void initDictionaries(const PDFObject& resourcesObject);
|
||||||
@ -665,10 +669,6 @@ private:
|
|||||||
/// Read object from operand stack
|
/// Read object from operand stack
|
||||||
PDFObject readObjectFromOperandStack(size_t startPosition) const;
|
PDFObject readObjectFromOperandStack(size_t startPosition) const;
|
||||||
|
|
||||||
/// Computes visibility of OCG/OCMD - returns false, if it is not suppressed,
|
|
||||||
/// or true, if it is suppressed.
|
|
||||||
bool isContentSuppressedByOC(PDFObjectReference ocgOrOcmd);
|
|
||||||
|
|
||||||
const PDFPage* m_page;
|
const PDFPage* m_page;
|
||||||
const PDFDocument* m_document;
|
const PDFDocument* m_document;
|
||||||
const PDFFontCache* m_fontCache;
|
const PDFFontCache* m_fontCache;
|
||||||
|
@ -81,8 +81,6 @@ void PDFPainter::performPathPainting(const QPainterPath& path, bool stroke, bool
|
|||||||
m_painter->setBrush(Qt::NoBrush);
|
m_painter->setBrush(Qt::NoBrush);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_painter->setRenderHint(QPainter::Antialiasing, m_features.testFlag(PDFRenderer::Antialiasing));
|
|
||||||
|
|
||||||
Q_ASSERT(path.fillRule() == fillRule);
|
Q_ASSERT(path.fillRule() == fillRule);
|
||||||
m_painter->drawPath(path);
|
m_painter->drawPath(path);
|
||||||
}
|
}
|
||||||
@ -162,6 +160,16 @@ void PDFPainter::performRestoreGraphicState(ProcessOrder order)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PDFPainter::isContentSuppressedByOC(PDFObjectReference ocgOrOcmd)
|
||||||
|
{
|
||||||
|
if (m_features.testFlag(PDFRenderer::IgnoreOptionalContent))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PDFPageContentProcessor::isContentSuppressedByOC(ocgOrOcmd);
|
||||||
|
}
|
||||||
|
|
||||||
QPen PDFPainter::getCurrentPenImpl() const
|
QPen PDFPainter::getCurrentPenImpl() const
|
||||||
{
|
{
|
||||||
const PDFPageContentProcessorState* graphicState = getGraphicState();
|
const PDFPageContentProcessorState* graphicState = getGraphicState();
|
||||||
|
@ -57,6 +57,7 @@ protected:
|
|||||||
virtual void performUpdateGraphicsState(const PDFPageContentProcessorState& state) override;
|
virtual void performUpdateGraphicsState(const PDFPageContentProcessorState& state) override;
|
||||||
virtual void performSaveGraphicState(ProcessOrder order) override;
|
virtual void performSaveGraphicState(ProcessOrder order) override;
|
||||||
virtual void performRestoreGraphicState(ProcessOrder order) override;
|
virtual void performRestoreGraphicState(ProcessOrder order) override;
|
||||||
|
virtual bool isContentSuppressedByOC(PDFObjectReference ocgOrOcmd) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Returns current pen
|
/// Returns current pen
|
||||||
|
@ -22,11 +22,11 @@
|
|||||||
namespace pdf
|
namespace pdf
|
||||||
{
|
{
|
||||||
|
|
||||||
PDFRenderer::PDFRenderer(const PDFDocument* document, const PDFFontCache* fontCache, const PDFOptionalContentActivity* optionalContentActivity) :
|
PDFRenderer::PDFRenderer(const PDFDocument* document, const PDFFontCache* fontCache, const PDFOptionalContentActivity* optionalContentActivity, Features features) :
|
||||||
m_document(document),
|
m_document(document),
|
||||||
m_fontCache(fontCache),
|
m_fontCache(fontCache),
|
||||||
m_optionalContentActivity(optionalContentActivity),
|
m_optionalContentActivity(optionalContentActivity),
|
||||||
m_features(Antialiasing | TextAntialiasing)
|
m_features(features)
|
||||||
{
|
{
|
||||||
Q_ASSERT(document);
|
Q_ASSERT(document);
|
||||||
}
|
}
|
||||||
|
@ -32,17 +32,19 @@ class PDFOptionalContentActivity;
|
|||||||
class PDFRenderer
|
class PDFRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PDFRenderer(const PDFDocument* document, const PDFFontCache* fontCache, const PDFOptionalContentActivity* optionalContentActivity);
|
|
||||||
|
|
||||||
enum Feature
|
enum Feature
|
||||||
{
|
{
|
||||||
Antialiasing = 0x0001, ///< Antialiasing for lines, shapes, etc.
|
Antialiasing = 0x0001, ///< Antialiasing for lines, shapes, etc.
|
||||||
TextAntialiasing = 0x0002, ///< Antialiasing for drawing text
|
TextAntialiasing = 0x0002, ///< Antialiasing for drawing text
|
||||||
SmoothImages = 0x0004 ///< Adjust images to the device space using smooth transformation (slower, but better performance quality)
|
SmoothImages = 0x0004, ///< Adjust images to the device space using smooth transformation (slower, but better image quality)
|
||||||
|
IgnoreOptionalContent = 0x0008, ///< Ignore optional content (so all is drawn ignoring settings of optional content)
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS(Features, Feature)
|
Q_DECLARE_FLAGS(Features, Feature)
|
||||||
|
|
||||||
|
explicit PDFRenderer(const PDFDocument* document, const PDFFontCache* fontCache, const PDFOptionalContentActivity* optionalContentActivity, Features features);
|
||||||
|
|
||||||
/// Paints desired page onto the painter. Page is painted in the rectangle using best-fit method.
|
/// Paints desired page onto the painter. Page is painted in the rectangle using best-fit method.
|
||||||
/// If the page doesn't exist, then error is returned. No exception is thrown. Rendering errors
|
/// If the page doesn't exist, then error is returned. No exception is thrown. Rendering errors
|
||||||
/// are reported and returned in the error list. If no error occured, empty list is returned.
|
/// are reported and returned in the error list. If no error occured, empty list is returned.
|
||||||
@ -56,6 +58,9 @@ public:
|
|||||||
/// Rendering errors are reported and returned in the error list. If no error occured, empty list is returned.
|
/// Rendering errors are reported and returned in the error list. If no error occured, empty list is returned.
|
||||||
QList<PDFRenderError> render(QPainter* painter, const QMatrix& matrix, size_t pageIndex) const;
|
QList<PDFRenderError> render(QPainter* painter, const QMatrix& matrix, size_t pageIndex) const;
|
||||||
|
|
||||||
|
/// Returns default renderer features
|
||||||
|
static constexpr Features getDefaultFeatures() { return Antialiasing | TextAntialiasing; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const PDFDocument* m_document;
|
const PDFDocument* m_document;
|
||||||
const PDFFontCache* m_fontCache;
|
const PDFFontCache* m_fontCache;
|
||||||
|
@ -45,6 +45,7 @@ namespace pdfviewer
|
|||||||
PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::PDFViewerMainWindow),
|
ui(new Ui::PDFViewerMainWindow),
|
||||||
|
m_settings(new PDFViewerSettings(this)),
|
||||||
m_pdfWidget(nullptr),
|
m_pdfWidget(nullptr),
|
||||||
m_optionalContentDockWidget(nullptr),
|
m_optionalContentDockWidget(nullptr),
|
||||||
m_optionalContentTreeView(nullptr),
|
m_optionalContentTreeView(nullptr),
|
||||||
@ -97,11 +98,22 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
|||||||
addDockWidget(Qt::LeftDockWidgetArea, m_optionalContentDockWidget);
|
addDockWidget(Qt::LeftDockWidgetArea, m_optionalContentDockWidget);
|
||||||
m_optionalContentDockWidget->hide();
|
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->addSeparator();
|
||||||
ui->menuView->addAction(m_optionalContentDockWidget->toggleViewAction());
|
ui->menuView->addAction(m_optionalContentDockWidget->toggleViewAction());
|
||||||
|
|
||||||
connect(m_pdfWidget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::pageLayoutChanged, this, &PDFViewerMainWindow::updatePageLayoutActions);
|
connect(m_pdfWidget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::pageLayoutChanged, this, &PDFViewerMainWindow::updatePageLayoutActions);
|
||||||
connect(m_pdfWidget, &pdf::PDFWidget::pageRenderingErrorsChanged, this, &PDFViewerMainWindow::onPageRenderingErrorsChanged, Qt::QueuedConnection);
|
connect(m_pdfWidget, &pdf::PDFWidget::pageRenderingErrorsChanged, this, &PDFViewerMainWindow::onPageRenderingErrorsChanged, Qt::QueuedConnection);
|
||||||
|
connect(m_settings, &PDFViewerSettings::settingsChanged, this, &PDFViewerMainWindow::onViewerSettingsChanged);
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
updatePageLayoutActions();
|
updatePageLayoutActions();
|
||||||
@ -114,7 +126,7 @@ PDFViewerMainWindow::~PDFViewerMainWindow()
|
|||||||
|
|
||||||
void PDFViewerMainWindow::onActionOpenTriggered()
|
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())
|
if (!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
openDocument(fileName);
|
openDocument(fileName);
|
||||||
@ -141,7 +153,7 @@ void PDFViewerMainWindow::onPageRenderingErrorsChanged(pdf::PDFInteger pageIndex
|
|||||||
|
|
||||||
void PDFViewerMainWindow::readSettings()
|
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();
|
QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
|
||||||
if (geometry.isEmpty())
|
if (geometry.isEmpty())
|
||||||
@ -162,15 +174,16 @@ void PDFViewerMainWindow::readSettings()
|
|||||||
restoreState(state);
|
restoreState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_directory = settings.value("defaultDirectory", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString();
|
m_settings->readSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFViewerMainWindow::writeSettings()
|
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("geometry", saveGeometry());
|
||||||
settings.setValue("windowState", saveState());
|
settings.setValue("windowState", saveState());
|
||||||
settings.setValue("defaultDirectory", m_directory);
|
|
||||||
|
m_settings->writeSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFViewerMainWindow::updateTitle()
|
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)
|
void PDFViewerMainWindow::openDocument(const QString& fileName)
|
||||||
{
|
{
|
||||||
// First close old document
|
// First close old document
|
||||||
@ -240,7 +278,7 @@ void PDFViewerMainWindow::openDocument(const QString& fileName)
|
|||||||
{
|
{
|
||||||
// Mark current directory as this
|
// Mark current directory as this
|
||||||
QFileInfo fileInfo(fileName);
|
QFileInfo fileInfo(fileName);
|
||||||
m_directory = fileInfo.dir().absolutePath();
|
m_settings->setDirectory(fileInfo.dir().absolutePath());
|
||||||
m_currentFile = fileInfo.fileName();
|
m_currentFile = fileInfo.fileName();
|
||||||
|
|
||||||
m_pdfDocument.reset(new pdf::PDFDocument(std::move(document)));
|
m_pdfDocument.reset(new pdf::PDFDocument(std::move(document)));
|
||||||
@ -297,6 +335,11 @@ void PDFViewerMainWindow::setPageLayout(pdf::PageLayout pageLayout)
|
|||||||
m_pdfWidget->getDrawWidgetProxy()->setPageLayout(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)
|
void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
|
||||||
{
|
{
|
||||||
writeSettings();
|
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
|
} // namespace pdfviewer
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
|
class QSettings;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class PDFViewerMainWindow;
|
class PDFViewerMainWindow;
|
||||||
@ -40,6 +42,35 @@ class PDFOptionalContentTreeItemModel;
|
|||||||
namespace pdfviewer
|
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
|
class PDFViewerMainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -58,7 +89,6 @@ private slots:
|
|||||||
void on_actionFirstPageOnRightSide_triggered();
|
void on_actionFirstPageOnRightSide_triggered();
|
||||||
|
|
||||||
void on_actionRendering_Errors_triggered();
|
void on_actionRendering_Errors_triggered();
|
||||||
|
|
||||||
void on_actionGenerateCMAPrepository_triggered();
|
void on_actionGenerateCMAPrepository_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -72,6 +102,10 @@ private:
|
|||||||
|
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
void updatePageLayoutActions();
|
void updatePageLayoutActions();
|
||||||
|
void updateRenderingOptionActions();
|
||||||
|
|
||||||
|
void onViewerSettingsChanged();
|
||||||
|
void onRenderingOptionTriggered(bool checked);
|
||||||
|
|
||||||
void openDocument(const QString& fileName);
|
void openDocument(const QString& fileName);
|
||||||
void setDocument(const pdf::PDFDocument* document);
|
void setDocument(const pdf::PDFDocument* document);
|
||||||
@ -79,10 +113,12 @@ private:
|
|||||||
|
|
||||||
void setPageLayout(pdf::PageLayout pageLayout);
|
void setPageLayout(pdf::PageLayout pageLayout);
|
||||||
|
|
||||||
|
std::vector<QAction*> getRenderingOptionActions() const;
|
||||||
|
|
||||||
Ui::PDFViewerMainWindow* ui;
|
Ui::PDFViewerMainWindow* ui;
|
||||||
|
PDFViewerSettings* m_settings;
|
||||||
pdf::PDFWidget* m_pdfWidget;
|
pdf::PDFWidget* m_pdfWidget;
|
||||||
QSharedPointer<pdf::PDFDocument> m_pdfDocument;
|
QSharedPointer<pdf::PDFDocument> m_pdfDocument;
|
||||||
QString m_directory;
|
|
||||||
QString m_currentFile;
|
QString m_currentFile;
|
||||||
QDockWidget* m_optionalContentDockWidget;
|
QDockWidget* m_optionalContentDockWidget;
|
||||||
QTreeView* m_optionalContentTreeView;
|
QTreeView* m_optionalContentTreeView;
|
||||||
|
@ -51,7 +51,17 @@
|
|||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionFirstPageOnRightSide"/>
|
<addaction name="actionFirstPageOnRightSide"/>
|
||||||
</widget>
|
</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="menuPage_Layout"/>
|
||||||
|
<addaction name="menuRendering_Options"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuTools">
|
<widget class="QMenu" name="menuTools">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@ -166,6 +176,38 @@
|
|||||||
<string>Generate CMAP repository</string>
|
<string>Generate CMAP repository</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Reference in New Issue
Block a user