Thumbnails - first part

This commit is contained in:
Jakub Melka 2019-12-07 17:59:03 +01:00
parent 99ba0a0c09
commit 1be4aea954
17 changed files with 792 additions and 9 deletions

View File

@ -49,7 +49,7 @@ void PDFDrawSpaceController::setDocument(const PDFDocument* document, const PDFO
m_document = document;
m_fontCache.setDocument(document);
m_optionalContentActivity = optionalContentActivity;
connect(m_optionalContentActivity, &PDFOptionalContentActivity::optionalContentGroupStateChanged, this, &PDFDrawSpaceController::repaintNeeded);
connect(m_optionalContentActivity, &PDFOptionalContentActivity::optionalContentGroupStateChanged, this, &PDFDrawSpaceController::onOptionalContentGroupStateChanged);
recalculate();
}
}
@ -133,6 +133,12 @@ QSizeF PDFDrawSpaceController::getReferenceBoundingBox() const
return rect.size();
}
void PDFDrawSpaceController::onOptionalContentGroupStateChanged()
{
emit pageImageChanged(true, { });
emit repaintNeeded();
}
void PDFDrawSpaceController::recalculate()
{
if (!m_document)
@ -393,6 +399,7 @@ PDFDrawWidgetProxy::PDFDrawWidgetProxy(QObject* parent) :
m_controller = new PDFDrawSpaceController(this);
connect(m_controller, &PDFDrawSpaceController::drawSpaceChanged, this, &PDFDrawWidgetProxy::update);
connect(m_controller, &PDFDrawSpaceController::repaintNeeded, this, &PDFDrawWidgetProxy::repaintNeeded);
connect(m_controller, &PDFDrawSpaceController::pageImageChanged, this, &PDFDrawWidgetProxy::pageImageChanged);
}
PDFDrawWidgetProxy::~PDFDrawWidgetProxy()
@ -603,6 +610,36 @@ void PDFDrawWidgetProxy::draw(QPainter* painter, QRect rect)
}
}
QImage PDFDrawWidgetProxy::drawThumbnailImage(PDFInteger pageIndex, int pixelSize) const
{
QImage image;
if (!m_controller->getDocument())
{
// No thumbnail - return empty image
return image;
}
if (const PDFPage* page = m_controller->getDocument()->getCatalog()->getPage(pageIndex))
{
QRectF pageRect = page->getRotatedMediaBox();
QSizeF pageSize = pageRect.size();
pageSize.scale(pixelSize, pixelSize, Qt::KeepAspectRatio);
QSize imageSize = pageSize.toSize();
if (imageSize.isValid())
{
image = QImage(imageSize, QImage::Format_RGBA8888_Premultiplied);
image.fill(Qt::white);
QPainter painter(&image);
PDFRenderer renderer(m_controller->getDocument(), m_controller->getFontCache(), m_controller->getOptionalContentActivity(), m_features, m_meshQualitySettings);
renderer.render(&painter, QRect(QPoint(0, 0), imageSize), pageIndex);
}
}
return image;
}
std::vector<PDFInteger> PDFDrawWidgetProxy::getPagesIntersectingRect(QRect rect) const
{
std::vector<PDFInteger> pages;

View File

@ -113,8 +113,11 @@ public:
signals:
void drawSpaceChanged();
void repaintNeeded();
void pageImageChanged(bool all, const std::vector<PDFInteger>& pages);
private:
void onOptionalContentGroupStateChanged();
/// Recalculates the draw space. Preserves setted page rotation.
void recalculate();
@ -176,6 +179,12 @@ public:
/// \param rect Rectangle in which the content is painted
void draw(QPainter* painter, QRect rect);
/// Draws thumbnail image of the given size (so larger of the page size
/// width or height equals to pixel size and the latter size is rescaled
/// using the aspect ratio)
/// \param pixelSize Pixel size
QImage drawThumbnailImage(PDFInteger pageIndex, int pixelSize) const;
enum Operation
{
ZoomIn,
@ -260,6 +269,7 @@ signals:
void pageLayoutChanged();
void renderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
void repaintNeeded();
void pageImageChanged(bool all, const std::vector<PDFInteger>& pages);
private:
struct LayoutItem

View File

@ -17,6 +17,7 @@
#include "pdfitemmodels.h"
#include "pdfdocument.h"
#include "pdfdrawspacecontroller.h"
#include <QFont>
#include <QStyle>
@ -614,4 +615,160 @@ const PDFFileSpecification* PDFAttachmentsTreeItemModel::getFileSpecification(co
return nullptr;
}
PDFThumbnailsItemModel::PDFThumbnailsItemModel(const PDFDrawWidgetProxy* proxy, QObject* parent) :
QAbstractItemModel(parent),
m_proxy(proxy),
m_thumbnailSize(100),
m_extraItemWidthHint(0),
m_extraItemHeighHint(0),
m_pageCount(0),
m_document(nullptr)
{
connect(proxy, &PDFDrawWidgetProxy::pageImageChanged, this, &PDFThumbnailsItemModel::onPageImageChanged);
}
bool PDFThumbnailsItemModel::isEmpty() const
{
return rowCount(QModelIndex()) == 0;
}
QModelIndex PDFThumbnailsItemModel::index(int row, int column, const QModelIndex& parent) const
{
if (parent.isValid())
{
return QModelIndex();
}
return createIndex(row, column, nullptr);
}
QModelIndex PDFThumbnailsItemModel::parent(const QModelIndex& child) const
{
Q_UNUSED(child);
return QModelIndex();
}
int PDFThumbnailsItemModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
{
return 0;
}
return m_pageCount;
}
int PDFThumbnailsItemModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
return 1;
}
QVariant PDFThumbnailsItemModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || !m_document)
{
return QVariant();
}
const int page = index.row();
switch (role)
{
case Qt::DisplayRole:
return QString::number(page + 1);
case Qt::DecorationRole:
{
QString key = getKey(index.row());
QPixmap pixmap;
if (!m_thumbnailCache.find(key, pixmap))
{
QImage thumbnail = m_proxy->drawThumbnailImage(index.row(), m_thumbnailSize);
if (!thumbnail.isNull())
{
pixmap = QPixmap::fromImage(qMove(thumbnail));
m_thumbnailCache.insert(key, pixmap);
}
}
return pixmap;
}
case Qt::TextAlignmentRole:
{
return int(Qt::AlignHCenter | Qt::AlignBottom);
}
case Qt::SizeHintRole:
{
const PDFPage* page = m_document->getCatalog()->getPage(index.row());
QSizeF pageSize = page->getRotatedMediaBox().size();
pageSize.scale(m_thumbnailSize, m_thumbnailSize, Qt::KeepAspectRatio);
return pageSize.toSize() + QSize(m_extraItemWidthHint, m_extraItemHeighHint);
break;
}
default:
break;
}
return QVariant();
}
void PDFThumbnailsItemModel::setThumbnailsSize(int size)
{
if (m_thumbnailSize != size)
{
emit layoutAboutToBeChanged();
m_thumbnailSize = size;
m_thumbnailCache.clear();
emit layoutChanged();
}
}
void PDFThumbnailsItemModel::setDocument(const PDFDocument* document)
{
if (m_document != document)
{
m_thumbnailCache.clear();
m_document = document;
m_pageCount = 0;
if (m_document)
{
m_pageCount = static_cast<int>(m_document->getCatalog()->getPageCount());
}
}
}
void PDFThumbnailsItemModel::onPageImageChanged(bool all, const std::vector<PDFInteger>& pages)
{
Q_UNUSED(all);
Q_UNUSED(pages);
if (all)
{
m_thumbnailCache.clear();
emit dataChanged(index(0, 0, QModelIndex()), index(rowCount(QModelIndex()) - 1, 0, QModelIndex()));
}
else
{
const int rowCount = this->rowCount(QModelIndex());
for (const PDFInteger pageIndex : pages)
{
if (pageIndex < rowCount)
{
m_thumbnailCache.remove(getKey(pageIndex));
emit dataChanged(index(pageIndex, 0, QModelIndex()), index(pageIndex, 0, QModelIndex()));
}
}
}
}
QString PDFThumbnailsItemModel::getKey(int pageIndex) const
{
return QString("PDF_THUMBNAIL_%1").arg(pageIndex);
}
} // namespace pdf

View File

@ -22,6 +22,7 @@
#include "pdfobject.h"
#include <QIcon>
#include <QPixmapCache>
#include <QAbstractItemModel>
namespace pdf
@ -31,6 +32,7 @@ class PDFDocument;
class PDFOutlineItem;
class PDFFileSpecification;
class PDFOptionalContentActivity;
class PDFDrawWidgetProxy;
/// Represents tree item in the GUI tree
class PDFTreeItem
@ -217,6 +219,42 @@ public:
const PDFFileSpecification* getFileSpecification(const QModelIndex& index) const;
};
class PDFFORQTLIBSHARED_EXPORT PDFThumbnailsItemModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit inline PDFThumbnailsItemModel(const PDFDrawWidgetProxy* proxy, QObject* parent);
bool isEmpty() const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
virtual QModelIndex parent(const QModelIndex& child) const override;
virtual int rowCount(const QModelIndex& parent) const override;
virtual int columnCount(const QModelIndex& parent) const override;
virtual QVariant data(const QModelIndex& index, int role) const override;
void setThumbnailsSize(int size);
void setDocument(const PDFDocument* document);
/// Sets the extra item width/height for size hint. This space will be added to the size hint (pixmap size)
void setExtraItemSizeHint(int width, int height) { m_extraItemWidthHint = width; m_extraItemHeighHint = height; }
private:
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
/// Returns generated key for page index
QString getKey(int pageIndex) const;
const PDFDrawWidgetProxy* m_proxy;
int m_thumbnailSize;
int m_extraItemWidthHint;
int m_extraItemHeighHint;
int m_pageCount;
const PDFDocument* m_document;
QPixmapCache m_thumbnailCache;
};
} // namespace pdf
#endif // PDFITEMMODELS_H

View File

@ -38,14 +38,16 @@ SOURCES += \
pdfsidebarwidget.cpp \
pdfviewermainwindow.cpp \
pdfviewersettings.cpp \
pdfviewersettingsdialog.cpp
pdfviewersettingsdialog.cpp \
pdfwidgetutils.cpp
HEADERS += \
pdfaboutdialog.h \
pdfsidebarwidget.h \
pdfviewermainwindow.h \
pdfviewersettings.h \
pdfviewersettingsdialog.h
pdfviewersettingsdialog.h \
pdfwidgetutils.h
FORMS += \
pdfaboutdialog.ui \

View File

@ -21,5 +21,6 @@
<file>resources/zoom-fit.svg</file>
<file>resources/zoom-fit-horizontal.svg</file>
<file>resources/zoom-fit-vertical.svg</file>
<file>resources/synchronize.svg</file>
</qresource>
</RCC>

View File

@ -18,6 +18,8 @@
#include "pdfsidebarwidget.h"
#include "ui_pdfsidebarwidget.h"
#include "pdfwidgetutils.h"
#include "pdfdocument.h"
#include "pdfitemmodels.h"
#include "pdfexception.h"
@ -36,12 +38,14 @@ constexpr const char* STYLESHEET =
"QPushButton { background-color: #404040; color: #FFFFFF; }"
"QPushButton:disabled { background-color: #404040; color: #000000; }"
"QPushButton:checked { background-color: #808080; color: #FFFFFF; }"
"QWidget#thumbnailsToolbarWidget { background-color: #F0F0F0 }"
"QWidget#PDFSidebarWidget { background-color: #404040; background: green;}";
PDFSidebarWidget::PDFSidebarWidget(QWidget* parent) :
PDFSidebarWidget::PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget* parent) :
QWidget(parent),
ui(new Ui::PDFSidebarWidget),
m_outlineTreeModel(nullptr),
m_thumbnailsModel(nullptr),
m_optionalContentTreeModel(nullptr),
m_document(nullptr),
m_optionalContentActivity(nullptr),
@ -58,6 +62,15 @@ PDFSidebarWidget::PDFSidebarWidget(QWidget* parent) :
ui->bookmarksTreeView->header()->hide();
connect(ui->bookmarksTreeView, &QTreeView::clicked, this, &PDFSidebarWidget::onOutlineItemClicked);
// Thumbnails
m_thumbnailsModel = new pdf::PDFThumbnailsItemModel(proxy, this);
int thumbnailsMargin = ui->thumbnailsListView->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr, ui->thumbnailsListView) + 1;
int thumbnailsFontSize = QFontMetrics(ui->thumbnailsListView->font()).lineSpacing();
m_thumbnailsModel->setExtraItemSizeHint(2 * thumbnailsMargin, thumbnailsMargin + thumbnailsFontSize);
ui->thumbnailsListView->setModel(m_thumbnailsModel);
connect(ui->thumbnailsSizeSlider, &QSlider::valueChanged, this, &PDFSidebarWidget::onThumbnailsSizeChanged);
onThumbnailsSizeChanged(ui->thumbnailsSizeSlider->value());
// Optional content
ui->optionalContentTreeView->header()->hide();
m_optionalContentTreeModel = new pdf::PDFOptionalContentTreeItemModel(this);
@ -78,6 +91,14 @@ PDFSidebarWidget::PDFSidebarWidget(QWidget* parent) :
m_pageInfo[Thumbnails] = { ui->thumbnailsButton, ui->thumbnailsPage };
m_pageInfo[Attachments] = { ui->attachmentsButton, ui->attachmentsPage };
for (const auto& pageInfo : m_pageInfo)
{
if (pageInfo.second.button)
{
connect(pageInfo.second.button, &QPushButton::clicked, this, &PDFSidebarWidget::onPageButtonClicked);
}
}
selectPage(Invalid);
updateButtons();
}
@ -95,6 +116,9 @@ void PDFSidebarWidget::setDocument(const pdf::PDFDocument* document, pdf::PDFOpt
// Update outline
m_outlineTreeModel->setDocument(document);
// Thumbnails
m_thumbnailsModel->setDocument(document);
// Update optional content
m_optionalContentTreeModel->setDocument(document);
m_optionalContentTreeModel->setActivity(m_optionalContentActivity);
@ -127,6 +151,30 @@ void PDFSidebarWidget::setDocument(const pdf::PDFDocument* document, pdf::PDFOpt
preferred = Attachments;
break;
case pdf::PageMode::Fullscreen:
{
pdf::PDFViewerPreferences::NonFullScreenPageMode nonFullscreenPageMode = m_document->getCatalog()->getViewerPreferences()->getNonFullScreenPageMode();
switch (nonFullscreenPageMode)
{
case pdf::PDFViewerPreferences::NonFullScreenPageMode::UseOutline:
preferred = Bookmarks;
break;
case pdf::PDFViewerPreferences::NonFullScreenPageMode::UseThumbnails:
preferred = Thumbnails;
break;
case pdf::PDFViewerPreferences::NonFullScreenPageMode::UseOptionalContent:
preferred = OptionalContent;
break;
default:
break;
}
break;
}
default:
break;
}
@ -161,7 +209,7 @@ bool PDFSidebarWidget::isEmpty(Page page) const
return m_outlineTreeModel->isEmpty();
case Thumbnails:
return true;
return m_thumbnailsModel->isEmpty();
case OptionalContent:
return m_optionalContentTreeModel->isEmpty();
@ -242,6 +290,21 @@ void PDFSidebarWidget::updateButtons()
}
}
void PDFSidebarWidget::onPageButtonClicked()
{
QObject* pushButton = sender();
for (const auto& pageInfo : m_pageInfo)
{
if (pageInfo.second.button == pushButton)
{
Q_ASSERT(!isEmpty(pageInfo.first));
selectPage(pageInfo.first);
break;
}
}
}
void PDFSidebarWidget::onOutlineItemClicked(const QModelIndex& index)
{
if (const pdf::PDFAction* action = m_outlineTreeModel->getAction(index))
@ -250,6 +313,13 @@ void PDFSidebarWidget::onOutlineItemClicked(const QModelIndex& index)
}
}
void PDFSidebarWidget::onThumbnailsSizeChanged(int size)
{
const int thumbnailsSize = PDFWidgetUtils::getPixelSize(this, size * 10.0);
Q_ASSERT(thumbnailsSize > 0);
m_thumbnailsModel->setThumbnailsSize(thumbnailsSize);
}
void PDFSidebarWidget::onAttachmentCustomContextMenuRequested(const QPoint& pos)
{
if (const pdf::PDFFileSpecification* fileSpecification = m_attachmentsTreeModel->getFileSpecification(ui->attachmentsTreeView->indexAt(pos)))

View File

@ -33,7 +33,9 @@ namespace pdf
{
class PDFAction;
class PDFDocument;
class PDFDrawWidgetProxy;
class PDFOutlineTreeItemModel;
class PDFThumbnailsItemModel;
class PDFAttachmentsTreeItemModel;
class PDFOptionalContentActivity;
class PDFOptionalContentTreeItemModel;
@ -47,7 +49,7 @@ class PDFSidebarWidget : public QWidget
Q_OBJECT
public:
explicit PDFSidebarWidget(QWidget* parent = nullptr);
explicit PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget* parent = nullptr);
virtual ~PDFSidebarWidget() override;
virtual void paintEvent(QPaintEvent* event) override;
@ -84,7 +86,9 @@ private:
void updateGUI(Page preferredPage);
void updateButtons();
void onPageButtonClicked();
void onOutlineItemClicked(const QModelIndex& index);
void onThumbnailsSizeChanged(int size);
void onAttachmentCustomContextMenuRequested(const QPoint& pos);
struct PageInfo
@ -95,6 +99,7 @@ private:
Ui::PDFSidebarWidget* ui;
pdf::PDFOutlineTreeItemModel* m_outlineTreeModel;
pdf::PDFThumbnailsItemModel* m_thumbnailsModel;
pdf::PDFOptionalContentTreeItemModel* m_optionalContentTreeModel;
const pdf::PDFDocument* m_document;
pdf::PDFOptionalContentActivity* m_optionalContentActivity;

View File

@ -98,7 +98,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="emptyPage"/>
<widget class="QWidget" name="bookmarksPage">
@ -125,6 +125,9 @@
</widget>
<widget class="QWidget" name="thumbnailsPage">
<layout class="QVBoxLayout" name="thumbnailsLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
@ -137,6 +140,45 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="thumbnailsToolbarWidget" native="true">
<layout class="QHBoxLayout" name="thumbnailsToolbarLayout">
<item>
<widget class="QToolButton" name="synchronizeThumbnailsButton">
<property name="toolTip">
<string>Synchronize thumbnails with current page</string>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<normaloff>:/resources/synchronize.svg</normaloff>:/resources/synchronize.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="thumbnailsSizeSlider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>6</number>
</property>
<property name="value">
<number>3</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QListView" name="thumbnailsListView">
<property name="movement">
@ -148,6 +190,9 @@
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="itemAlignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
</layout>
@ -197,6 +242,8 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="pdfforqtviewer.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -152,7 +152,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
setCentralWidget(m_pdfWidget);
setFocusProxy(m_pdfWidget);
m_sidebarWidget = new PDFSidebarWidget(this);
m_sidebarWidget = new PDFSidebarWidget(m_pdfWidget->getDrawWidgetProxy(), this);
m_sidebarDockWidget = new QDockWidget(tr("Sidebar"), this);
m_sidebarDockWidget->setObjectName("SidebarDockWidget");
m_sidebarDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);

View File

@ -1,3 +1,20 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfviewersettings.h"
namespace pdfviewer

View File

@ -1,3 +1,20 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFVIEWERSETTINGS_H
#define PDFVIEWERSETTINGS_H

View File

@ -1,3 +1,20 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfviewersettingsdialog.h"
#include "ui_pdfviewersettingsdialog.h"

View File

@ -1,3 +1,20 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFVIEWERSETTINGSDIALOG_H
#define PDFVIEWERSETTINGSDIALOG_H

View File

@ -0,0 +1,39 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfwidgetutils.h"
namespace pdfviewer
{
int PDFWidgetUtils::getPixelSize(QWidget* widget, pdf::PDFReal sizeMM)
{
const int width = widget->width();
const int height = widget->height();
if (width > height)
{
return pdf::PDFReal(width) * sizeMM / pdf::PDFReal(widget->widthMM());
}
else
{
return pdf::PDFReal(height) * sizeMM / pdf::PDFReal(widget->heightMM());
}
}
} // namespace pdfviewer

View File

@ -0,0 +1,39 @@
// Copyright (C) 2019 Jakub Melka
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#ifndef PDFWIDGETUTILS_H
#define PDFWIDGETUTILS_H
#include "pdfglobal.h"
#include <QWidget>
namespace pdfviewer
{
class PDFWidgetUtils
{
public:
PDFWidgetUtils() = delete;
/// Converts size in MM to pixel size
static int getPixelSize(QWidget* widget, pdf::PDFReal sizeMM);
};
} // namespace pdfviewer
#endif // PDFWIDGETUTILS_H

View File

@ -0,0 +1,270 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg5291"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="synchronize.svg">
<defs
id="defs5285">
<inkscape:path-effect
effect="bspline"
id="path-effect1207"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<marker
inkscape:stockid="Arrow2Lend"
orient="auto"
refY="0.0"
refX="0.0"
id="Arrow2Lend"
style="overflow:visible;"
inkscape:isstock="true">
<path
id="path898"
style="fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round;stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1"
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
transform="scale(1.1) rotate(180) translate(1,0)" />
</marker>
<inkscape:path-effect
effect="bspline"
id="path-effect1183"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="bspline"
id="path-effect1179"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<marker
inkscape:stockid="TriangleOutL"
orient="auto"
refY="0.0"
refX="0.0"
id="TriangleOutL"
style="overflow:visible"
inkscape:isstock="true">
<path
id="path1019"
d="M 5.77,0.0 L -2.88,5.0 L -2.88,-5.0 L 5.77,0.0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
transform="scale(0.8)" />
</marker>
<inkscape:path-effect
effect="bspline"
id="path-effect875"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="bspline"
id="path-effect861"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="bspline"
id="path-effect857"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="bspline"
id="path-effect853"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="bspline"
id="path-effect849"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="bspline"
id="path-effect845"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
<inkscape:path-effect
effect="skeletal"
id="path-effect837"
is_visible="true"
pattern="M 0,5 C 0,2.24 2.24,0 5,0 7.76,0 10,2.24 10,5 10,7.76 7.76,10 5,10 2.24,10 0,7.76 0,5 Z"
copytype="single_stretched"
prop_scale="0.26458333"
scale_y_rel="false"
spacing="0"
normal_offset="0"
tang_offset="0"
prop_units="false"
vertical_pattern="false"
fuse_tolerance="0" />
<marker
inkscape:stockid="Arrow2Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow2Lend-5"
style="overflow:visible"
inkscape:isstock="true">
<path
inkscape:connector-curvature="0"
id="path898-1"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="matrix(-1.1,0,0,-1.1,-1.1,0)" />
</marker>
<inkscape:path-effect
effect="bspline"
id="path-effect1183-5"
is_visible="true"
weight="33.333333"
steps="2"
helper_size="0"
apply_no_weight="true"
apply_with_weight="true"
only_selected="false" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="11.2"
inkscape:cx="120.53309"
inkscape:cy="11.77171"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2035"
inkscape:window-x="-13"
inkscape:window-y="-13"
inkscape:window-maximized="1" />
<metadata
id="metadata5288">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Vrstva 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-267)">
<ellipse
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path867"
cx="15.270238"
cy="282.03217"
rx="11.670015"
ry="11.292038" />
<g
id="g8785">
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.80000001;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 15.901303,286.40781 -0.01563,0.80078 3.474608,0.0664 0.01563,-0.80078 z"
id="path1181"
inkscape:connector-curvature="0" />
<path
d="m 10.884926,283.16137 9.545034,3.71976 -9.680958,3.35013 c 1.575879,-2.05751 1.621928,-4.91309 0.135924,-7.06989 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.55000001;stroke-linejoin:round;stroke-opacity:1"
id="path8791"
inkscape:connector-curvature="0" />
</g>
<g
id="g8752">
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.80000001;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 14.787663,278.32079 0.01563,-0.80078 -3.474609,-0.0664 -0.01563,0.80078 z"
id="path1181-5"
inkscape:connector-curvature="0" />
<path
d="m 19.804039,281.56723 -9.545033,-3.71976 9.680958,-3.35013 c -1.57588,2.0575 -1.621928,4.91309 -0.135925,7.06989 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.55000001;stroke-linejoin:round;stroke-opacity:1"
id="path8758"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB