mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Thumbnails finishing
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user