mirror of https://github.com/JakubMelka/PDF4QT.git
Thumbnails finishing
This commit is contained in:
parent
1be4aea954
commit
7bcbd512a8
|
@ -659,6 +659,7 @@ std::vector<PDFInteger> PDFDrawWidgetProxy::getPagesIntersectingRect(QRect rect)
|
|||
pages.push_back(item.pageIndex);
|
||||
}
|
||||
}
|
||||
qSort(pages);
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
@ -981,6 +982,7 @@ void PDFDrawWidgetProxy::setFeatures(PDFRenderer::Features features)
|
|||
if (m_features != features)
|
||||
{
|
||||
m_features = features;
|
||||
emit pageImageChanged(true, { });
|
||||
emit repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
@ -990,6 +992,7 @@ void PDFDrawWidgetProxy::setPreferredMeshResolutionRatio(PDFReal ratio)
|
|||
if (m_meshQualitySettings.preferredMeshResolutionRatio != ratio)
|
||||
{
|
||||
m_meshQualitySettings.preferredMeshResolutionRatio = ratio;
|
||||
emit pageImageChanged(true, { });
|
||||
emit repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
@ -999,6 +1002,7 @@ void PDFDrawWidgetProxy::setMinimalMeshResolutionRatio(PDFReal ratio)
|
|||
if (m_meshQualitySettings.minimalMeshResolutionRatio != ratio)
|
||||
{
|
||||
m_meshQualitySettings.minimalMeshResolutionRatio = ratio;
|
||||
emit pageImageChanged(true, { });
|
||||
emit repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
@ -1008,6 +1012,7 @@ void PDFDrawWidgetProxy::setColorTolerance(PDFReal colorTolerance)
|
|||
if (m_meshQualitySettings.tolerance != colorTolerance)
|
||||
{
|
||||
m_meshQualitySettings.tolerance = colorTolerance;
|
||||
emit pageImageChanged(true, { });
|
||||
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)
|
||||
{
|
||||
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)
|
||||
void setExtraItemSizeHint(int width, int height) { m_extraItemWidthHint = width; m_extraItemHeighHint = height; }
|
||||
|
||||
PDFInteger getPageIndex(const QModelIndex& index) const;
|
||||
|
||||
private:
|
||||
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "pdfdocument.h"
|
||||
#include "pdfitemmodels.h"
|
||||
#include "pdfexception.h"
|
||||
#include "pdfdrawspacecontroller.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
@ -41,9 +42,10 @@ constexpr const char* STYLESHEET =
|
|||
"QWidget#thumbnailsToolbarWidget { background-color: #F0F0F0 }"
|
||||
"QWidget#PDFSidebarWidget { background-color: #404040; background: green;}";
|
||||
|
||||
PDFSidebarWidget::PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget* parent) :
|
||||
PDFSidebarWidget::PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::PDFSidebarWidget),
|
||||
m_proxy(proxy),
|
||||
m_outlineTreeModel(nullptr),
|
||||
m_thumbnailsModel(nullptr),
|
||||
m_optionalContentTreeModel(nullptr),
|
||||
|
@ -69,6 +71,7 @@ PDFSidebarWidget::PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget
|
|||
m_thumbnailsModel->setExtraItemSizeHint(2 * thumbnailsMargin, thumbnailsMargin + thumbnailsFontSize);
|
||||
ui->thumbnailsListView->setModel(m_thumbnailsModel);
|
||||
connect(ui->thumbnailsSizeSlider, &QSlider::valueChanged, this, &PDFSidebarWidget::onThumbnailsSizeChanged);
|
||||
connect(ui->thumbnailsListView, &QListView::clicked, this, &PDFSidebarWidget::onThumbnailClicked);
|
||||
onThumbnailsSizeChanged(ui->thumbnailsSizeSlider->value());
|
||||
|
||||
// Optional content
|
||||
|
@ -258,6 +261,31 @@ std::vector<PDFSidebarWidget::Page> PDFSidebarWidget::getValidPages() const
|
|||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef PDFSIDEBARWIDGET_H
|
||||
#define PDFSIDEBARWIDGET_H
|
||||
|
||||
#include "pdfglobal.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QPushButton;
|
||||
|
@ -49,7 +51,7 @@ class PDFSidebarWidget : public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PDFSidebarWidget(const pdf::PDFDrawWidgetProxy* proxy, QWidget* parent = nullptr);
|
||||
explicit PDFSidebarWidget(pdf::PDFDrawWidgetProxy* proxy, QWidget* parent = nullptr);
|
||||
virtual ~PDFSidebarWidget() override;
|
||||
|
||||
virtual void paintEvent(QPaintEvent* event) override;
|
||||
|
@ -79,6 +81,9 @@ public:
|
|||
/// Returns list of valid pages (nonempty pages)
|
||||
std::vector<Page> getValidPages() const;
|
||||
|
||||
/// Sets current pages (for example, selects the correct thumbnail)
|
||||
void setCurrentPages(const std::vector<pdf::PDFInteger>& currentPages);
|
||||
|
||||
signals:
|
||||
void actionTriggered(const pdf::PDFAction* action);
|
||||
|
||||
|
@ -90,6 +95,7 @@ private:
|
|||
void onOutlineItemClicked(const QModelIndex& index);
|
||||
void onThumbnailsSizeChanged(int size);
|
||||
void onAttachmentCustomContextMenuRequested(const QPoint& pos);
|
||||
void onThumbnailClicked(const QModelIndex& index);
|
||||
|
||||
struct PageInfo
|
||||
{
|
||||
|
@ -98,6 +104,7 @@ private:
|
|||
};
|
||||
|
||||
Ui::PDFSidebarWidget* ui;
|
||||
pdf::PDFDrawWidgetProxy* m_proxy;
|
||||
pdf::PDFOutlineTreeItemModel* m_outlineTreeModel;
|
||||
pdf::PDFThumbnailsItemModel* m_thumbnailsModel;
|
||||
pdf::PDFOptionalContentTreeItemModel* m_optionalContentTreeModel;
|
||||
|
|
|
@ -631,6 +631,8 @@ void PDFViewerMainWindow::updateUI(bool fullUpdate)
|
|||
{
|
||||
m_pageNumberSpinBox->setValue(currentPages.front() + 1);
|
||||
}
|
||||
|
||||
m_sidebarWidget->setCurrentPages(currentPages);
|
||||
}
|
||||
|
||||
m_pageZoomSpinBox->setValue(m_pdfWidget->getDrawWidgetProxy()->getZoom() * 100);
|
||||
|
|
Loading…
Reference in New Issue