mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Page navigation and zoom
This commit is contained in:
@ -100,6 +100,8 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
||||
m_pageNumberSpinBox = new QSpinBox(this);
|
||||
m_pageNumberLabel = new QLabel(this);
|
||||
m_pageNumberSpinBox->setFixedWidth(adjustDpiX(80));
|
||||
m_pageNumberSpinBox->setAlignment(Qt::AlignCenter);
|
||||
connect(m_pageNumberSpinBox, &QSpinBox::editingFinished, this, &PDFViewerMainWindow::onPageNumberSpinboxEditingFinished);
|
||||
|
||||
// Page control
|
||||
ui->mainToolBar->addSeparator();
|
||||
@ -121,6 +123,8 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
||||
m_pageZoomSpinBox->setDecimals(2);
|
||||
m_pageZoomSpinBox->setSuffix(tr("%"));
|
||||
m_pageZoomSpinBox->setFixedWidth(adjustDpiX(80));
|
||||
m_pageZoomSpinBox->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
|
||||
connect(m_pageZoomSpinBox, &QDoubleSpinBox::editingFinished, this, &PDFViewerMainWindow::onPageZoomSpinboxEditingFinished);
|
||||
ui->mainToolBar->addWidget(m_pageZoomSpinBox);
|
||||
|
||||
connect(ui->actionZoom_In, &QAction::triggered, this, [this] { m_pdfWidget->getDrawWidgetProxy()->performOperation(pdf::PDFDrawWidgetProxy::ZoomIn); });
|
||||
@ -208,6 +212,36 @@ void PDFViewerMainWindow::onPageLayoutChanged()
|
||||
updatePageLayoutActions();
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::onPageNumberSpinboxEditingFinished()
|
||||
{
|
||||
if (m_isLoadingUI)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pageNumberSpinBox->hasFocus())
|
||||
{
|
||||
m_pdfWidget->setFocus();
|
||||
}
|
||||
|
||||
m_pdfWidget->getDrawWidgetProxy()->goToPage(m_pageNumberSpinBox->value() - 1);
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::onPageZoomSpinboxEditingFinished()
|
||||
{
|
||||
if (m_isLoadingUI)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_pageZoomSpinBox->hasFocus())
|
||||
{
|
||||
m_pdfWidget->setFocus();
|
||||
}
|
||||
|
||||
m_pdfWidget->getDrawWidgetProxy()->zoom(m_pageZoomSpinBox->value() / 100.0);
|
||||
}
|
||||
|
||||
void PDFViewerMainWindow::readSettings()
|
||||
{
|
||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
|
||||
@ -324,6 +358,14 @@ void PDFViewerMainWindow::updateUI(bool fullUpdate)
|
||||
m_pageNumberLabel->setText(QString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<pdf::PDFInteger> currentPages = m_pdfWidget->getDrawWidget()->getCurrentPages();
|
||||
if (!currentPages.empty())
|
||||
{
|
||||
m_pageNumberSpinBox->setValue(currentPages.front() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
m_pageZoomSpinBox->setValue(m_pdfWidget->getDrawWidgetProxy()->getZoom() * 100);
|
||||
}
|
||||
|
Reference in New Issue
Block a user