mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Thumbnails finishing
This commit is contained in:
@ -659,6 +659,7 @@ std::vector<PDFInteger> PDFDrawWidgetProxy::getPagesIntersectingRect(QRect rect)
|
|||||||
pages.push_back(item.pageIndex);
|
pages.push_back(item.pageIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qSort(pages);
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
@ -981,6 +982,7 @@ void PDFDrawWidgetProxy::setFeatures(PDFRenderer::Features features)
|
|||||||
if (m_features != features)
|
if (m_features != features)
|
||||||
{
|
{
|
||||||
m_features = features;
|
m_features = features;
|
||||||
|
emit pageImageChanged(true, { });
|
||||||
emit repaintNeeded();
|
emit repaintNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -990,6 +992,7 @@ void PDFDrawWidgetProxy::setPreferredMeshResolutionRatio(PDFReal ratio)
|
|||||||
if (m_meshQualitySettings.preferredMeshResolutionRatio != ratio)
|
if (m_meshQualitySettings.preferredMeshResolutionRatio != ratio)
|
||||||
{
|
{
|
||||||
m_meshQualitySettings.preferredMeshResolutionRatio = ratio;
|
m_meshQualitySettings.preferredMeshResolutionRatio = ratio;
|
||||||
|
emit pageImageChanged(true, { });
|
||||||
emit repaintNeeded();
|
emit repaintNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -999,6 +1002,7 @@ void PDFDrawWidgetProxy::setMinimalMeshResolutionRatio(PDFReal ratio)
|
|||||||
if (m_meshQualitySettings.minimalMeshResolutionRatio != ratio)
|
if (m_meshQualitySettings.minimalMeshResolutionRatio != ratio)
|
||||||
{
|
{
|
||||||
m_meshQualitySettings.minimalMeshResolutionRatio = ratio;
|
m_meshQualitySettings.minimalMeshResolutionRatio = ratio;
|
||||||
|
emit pageImageChanged(true, { });
|
||||||
emit repaintNeeded();
|
emit repaintNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1008,6 +1012,7 @@ void PDFDrawWidgetProxy::setColorTolerance(PDFReal colorTolerance)
|
|||||||
if (m_meshQualitySettings.tolerance != colorTolerance)
|
if (m_meshQualitySettings.tolerance != colorTolerance)
|
||||||
{
|
{
|
||||||
m_meshQualitySettings.tolerance = colorTolerance;
|
m_meshQualitySettings.tolerance = colorTolerance;
|
||||||
|
emit pageImageChanged(true, { });
|
||||||
emit repaintNeeded();
|
emit repaintNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,6 +742,11 @@ void PDFThumbnailsItemModel::setDocument(const PDFDocument* document)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDFInteger PDFThumbnailsItemModel::getPageIndex(const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
return index.row();
|
||||||
|
}
|
||||||
|
|
||||||
void PDFThumbnailsItemModel::onPageImageChanged(bool all, const std::vector<PDFInteger>& pages)
|
void PDFThumbnailsItemModel::onPageImageChanged(bool all, const std::vector<PDFInteger>& pages)
|
||||||
{
|
{
|
||||||
Q_UNUSED(all);
|
Q_UNUSED(all);
|
||||||
|
@ -240,6 +240,8 @@ public:
|
|||||||
/// Sets the extra item width/height for size hint. This space will be added to the size hint (pixmap size)
|
/// 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; }
|
void setExtraItemSizeHint(int width, int height) { m_extraItemWidthHint = width; m_extraItemHeighHint = height; }
|
||||||
|
|
||||||
|
PDFInteger getPageIndex(const QModelIndex& index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "pdfdocument.h"
|
#include "pdfdocument.h"
|
||||||
#include "pdfitemmodels.h"
|
#include "pdfitemmodels.h"
|
||||||
#include "pdfexception.h"
|
#include "pdfexception.h"
|
||||||
|
#include "pdfdrawspacecontroller.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
@ -41,9 +42,10 @@ constexpr const char* STYLESHEET =
|
|||||||
"QWidget#thumbnailsToolbarWidget { background-color: #F0F0F0 }"
|
"QWidget#thumbnailsToolbarWidget { background-color: #F0F0F0 }"
|
||||||
"QWidget#PDFSidebarWidget { background-color: #404040; background: green;}";
|
"QWidget#PDFSidebarWidget { background-color: #404040; background: green;}";
|
||||||
|
|
||||||
PDFSidebarWidget::PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget* parent) :
|
PDFSidebarWidget::PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy, QWidget* parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::PDFSidebarWidget),
|
ui(new Ui::PDFSidebarWidget),
|
||||||
|
m_proxy(proxy),
|
||||||
m_outlineTreeModel(nullptr),
|
m_outlineTreeModel(nullptr),
|
||||||
m_thumbnailsModel(nullptr),
|
m_thumbnailsModel(nullptr),
|
||||||
m_optionalContentTreeModel(nullptr),
|
m_optionalContentTreeModel(nullptr),
|
||||||
@ -69,6 +71,7 @@ PDFSidebarWidget::PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget
|
|||||||
m_thumbnailsModel->setExtraItemSizeHint(2 * thumbnailsMargin, thumbnailsMargin + thumbnailsFontSize);
|
m_thumbnailsModel->setExtraItemSizeHint(2 * thumbnailsMargin, thumbnailsMargin + thumbnailsFontSize);
|
||||||
ui->thumbnailsListView->setModel(m_thumbnailsModel);
|
ui->thumbnailsListView->setModel(m_thumbnailsModel);
|
||||||
connect(ui->thumbnailsSizeSlider, &QSlider::valueChanged, this, &PDFSidebarWidget::onThumbnailsSizeChanged);
|
connect(ui->thumbnailsSizeSlider, &QSlider::valueChanged, this, &PDFSidebarWidget::onThumbnailsSizeChanged);
|
||||||
|
connect(ui->thumbnailsListView, &QListView::clicked, this, &PDFSidebarWidget::onThumbnailClicked);
|
||||||
onThumbnailsSizeChanged(ui->thumbnailsSizeSlider->value());
|
onThumbnailsSizeChanged(ui->thumbnailsSizeSlider->value());
|
||||||
|
|
||||||
// Optional content
|
// Optional content
|
||||||
@ -258,6 +261,31 @@ std::vector<PDFSidebarWidget::Page> PDFSidebarWidget::getValidPages() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFSidebarWidget::setCurrentPages(const std::vector<pdf::PDFInteger>& currentPages)
|
||||||
|
{
|
||||||
|
if (!currentPages.empty() && ui->synchronizeThumbnailsButton->isChecked())
|
||||||
|
{
|
||||||
|
QModelIndex index = m_thumbnailsModel->index(currentPages.front(), 0, QModelIndex());
|
||||||
|
if (index.isValid())
|
||||||
|
{
|
||||||
|
ui->thumbnailsListView->scrollTo(index, QListView::EnsureVisible);
|
||||||
|
|
||||||
|
// Try to examine, if we have to switch the current index
|
||||||
|
QModelIndex currentIndex = ui->thumbnailsListView->currentIndex();
|
||||||
|
if (currentIndex.isValid())
|
||||||
|
{
|
||||||
|
const pdf::PDFInteger currentPageIndex = m_thumbnailsModel->getPageIndex(currentIndex);
|
||||||
|
Q_ASSERT(std::is_sorted(currentPages.cbegin(), currentPages.cend()));
|
||||||
|
if (std::binary_search(currentPages.cbegin(), currentPages.cend(), currentPageIndex))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ui->thumbnailsListView->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PDFSidebarWidget::updateGUI(Page preferredPage)
|
void PDFSidebarWidget::updateGUI(Page preferredPage)
|
||||||
{
|
{
|
||||||
if (preferredPage != Invalid && !isEmpty(preferredPage))
|
if (preferredPage != Invalid && !isEmpty(preferredPage))
|
||||||
@ -369,6 +397,14 @@ void PDFSidebarWidget::onAttachmentCustomContextMenuRequested(const QPoint& pos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFSidebarWidget::onThumbnailClicked(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
if (index.isValid())
|
||||||
|
{
|
||||||
|
m_proxy->goToPage(m_thumbnailsModel->getPageIndex(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PDFSidebarWidget::paintEvent(QPaintEvent* event)
|
void PDFSidebarWidget::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#ifndef PDFSIDEBARWIDGET_H
|
#ifndef PDFSIDEBARWIDGET_H
|
||||||
#define PDFSIDEBARWIDGET_H
|
#define PDFSIDEBARWIDGET_H
|
||||||
|
|
||||||
|
#include "pdfglobal.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
@ -49,7 +51,7 @@ class PDFSidebarWidget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget* parent = nullptr);
|
explicit PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy, QWidget* parent = nullptr);
|
||||||
virtual ~PDFSidebarWidget() override;
|
virtual ~PDFSidebarWidget() override;
|
||||||
|
|
||||||
virtual void paintEvent(QPaintEvent* event) override;
|
virtual void paintEvent(QPaintEvent* event) override;
|
||||||
@ -79,6 +81,9 @@ public:
|
|||||||
/// Returns list of valid pages (nonempty pages)
|
/// Returns list of valid pages (nonempty pages)
|
||||||
std::vector<Page> getValidPages() const;
|
std::vector<Page> getValidPages() const;
|
||||||
|
|
||||||
|
/// Sets current pages (for example, selects the correct thumbnail)
|
||||||
|
void setCurrentPages(const std::vector<pdf::PDFInteger>& currentPages);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void actionTriggered(const pdf::PDFAction* action);
|
void actionTriggered(const pdf::PDFAction* action);
|
||||||
|
|
||||||
@ -90,6 +95,7 @@ private:
|
|||||||
void onOutlineItemClicked(const QModelIndex& index);
|
void onOutlineItemClicked(const QModelIndex& index);
|
||||||
void onThumbnailsSizeChanged(int size);
|
void onThumbnailsSizeChanged(int size);
|
||||||
void onAttachmentCustomContextMenuRequested(const QPoint& pos);
|
void onAttachmentCustomContextMenuRequested(const QPoint& pos);
|
||||||
|
void onThumbnailClicked(const QModelIndex& index);
|
||||||
|
|
||||||
struct PageInfo
|
struct PageInfo
|
||||||
{
|
{
|
||||||
@ -98,6 +104,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ui::PDFSidebarWidget* ui;
|
Ui::PDFSidebarWidget* ui;
|
||||||
|
pdf::PDFDrawWidgetProxy* m_proxy;
|
||||||
pdf::PDFOutlineTreeItemModel* m_outlineTreeModel;
|
pdf::PDFOutlineTreeItemModel* m_outlineTreeModel;
|
||||||
pdf::PDFThumbnailsItemModel* m_thumbnailsModel;
|
pdf::PDFThumbnailsItemModel* m_thumbnailsModel;
|
||||||
pdf::PDFOptionalContentTreeItemModel* m_optionalContentTreeModel;
|
pdf::PDFOptionalContentTreeItemModel* m_optionalContentTreeModel;
|
||||||
|
@ -631,6 +631,8 @@ void PDFViewerMainWindow::updateUI(bool fullUpdate)
|
|||||||
{
|
{
|
||||||
m_pageNumberSpinBox->setValue(currentPages.front() + 1);
|
m_pageNumberSpinBox->setValue(currentPages.front() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_sidebarWidget->setCurrentPages(currentPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pageZoomSpinBox->setValue(m_pdfWidget->getDrawWidgetProxy()->getZoom() * 100);
|
m_pageZoomSpinBox->setValue(m_pdfWidget->getDrawWidgetProxy()->getZoom() * 100);
|
||||||
|
Reference in New Issue
Block a user