mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-11 09:10:36 +01:00
Page layout modes
This commit is contained in:
parent
4d7eaf7587
commit
0a28869c94
@ -630,6 +630,15 @@ void PDFDrawWidgetProxy::zoom(PDFReal zoom)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFDrawWidgetProxy::setPageLayout(PageLayout pageLayout)
|
||||||
|
{
|
||||||
|
if (getPageLayout() != pageLayout)
|
||||||
|
{
|
||||||
|
m_controller->setPageLayout(pageLayout);
|
||||||
|
emit pageLayoutChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QRectF PDFDrawWidgetProxy::fromDeviceSpace(const QRectF& rect) const
|
QRectF PDFDrawWidgetProxy::fromDeviceSpace(const QRectF& rect) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(rect.isValid());
|
Q_ASSERT(rect.isValid());
|
||||||
|
@ -167,10 +167,18 @@ public:
|
|||||||
/// and each 1 cm of widget area corresponds to 0.5 cm of the device space area.
|
/// and each 1 cm of widget area corresponds to 0.5 cm of the device space area.
|
||||||
PDFReal getZoom() const { return m_zoom; }
|
PDFReal getZoom() const { return m_zoom; }
|
||||||
|
|
||||||
|
/// Sets the page layout. Page layout can be one of the PDF's page layouts.
|
||||||
|
/// \param pageLayout Page layout
|
||||||
|
void setPageLayout(PageLayout pageLayout);
|
||||||
|
|
||||||
|
/// Returns the page layout
|
||||||
|
PageLayout getPageLayout() const { return m_controller->getPageLayout(); }
|
||||||
|
|
||||||
static constexpr PDFReal ZOOM_STEP = 1.2;
|
static constexpr PDFReal ZOOM_STEP = 1.2;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void drawSpaceChanged();
|
void drawSpaceChanged();
|
||||||
|
void pageLayoutChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct LayoutItem
|
struct LayoutItem
|
||||||
|
@ -75,7 +75,10 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
|
|||||||
setCentralWidget(m_pdfWidget);
|
setCentralWidget(m_pdfWidget);
|
||||||
setFocusProxy(m_pdfWidget);
|
setFocusProxy(m_pdfWidget);
|
||||||
|
|
||||||
|
connect(m_pdfWidget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::pageLayoutChanged, this, &PDFViewerMainWindow::updatePageLayoutActions);
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
updatePageLayoutActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFViewerMainWindow::~PDFViewerMainWindow()
|
PDFViewerMainWindow::~PDFViewerMainWindow()
|
||||||
@ -153,6 +156,41 @@ void PDFViewerMainWindow::updateTitle()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::updatePageLayoutActions()
|
||||||
|
{
|
||||||
|
for (QAction* action : { ui->actionPageLayoutContinuous, ui->actionPageLayoutSinglePage, ui->actionPageLayoutTwoColumns, ui->actionPageLayoutTwoPages })
|
||||||
|
{
|
||||||
|
action->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pdf::PageLayout pageLayout = m_pdfWidget->getDrawWidgetProxy()->getPageLayout();
|
||||||
|
switch (pageLayout)
|
||||||
|
{
|
||||||
|
case pdf::PageLayout::SinglePage:
|
||||||
|
ui->actionPageLayoutSinglePage->setChecked(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::OneColumn:
|
||||||
|
ui->actionPageLayoutContinuous->setChecked(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::TwoColumnLeft:
|
||||||
|
case pdf::PageLayout::TwoColumnRight:
|
||||||
|
ui->actionPageLayoutTwoColumns->setChecked(true);
|
||||||
|
ui->actionFirstPageOnRightSide->setChecked(pageLayout == pdf::PageLayout::TwoColumnRight);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::TwoPagesLeft:
|
||||||
|
case pdf::PageLayout::TwoPagesRight:
|
||||||
|
ui->actionPageLayoutTwoPages->setChecked(true);
|
||||||
|
ui->actionFirstPageOnRightSide->setChecked(pageLayout == pdf::PageLayout::TwoPagesRight);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PDFViewerMainWindow::openDocument(const QString& fileName)
|
void PDFViewerMainWindow::openDocument(const QString& fileName)
|
||||||
{
|
{
|
||||||
// First close old document
|
// First close old document
|
||||||
@ -194,6 +232,11 @@ void PDFViewerMainWindow::closeDocument()
|
|||||||
m_pdfDocument.reset();
|
m_pdfDocument.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::setPageLayout(pdf::PageLayout pageLayout)
|
||||||
|
{
|
||||||
|
m_pdfWidget->getDrawWidgetProxy()->setPageLayout(pageLayout);
|
||||||
|
}
|
||||||
|
|
||||||
void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
|
void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
|
||||||
{
|
{
|
||||||
writeSettings();
|
writeSettings();
|
||||||
@ -201,4 +244,47 @@ void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::on_actionPageLayoutSinglePage_triggered()
|
||||||
|
{
|
||||||
|
setPageLayout(pdf::PageLayout::SinglePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::on_actionPageLayoutContinuous_triggered()
|
||||||
|
{
|
||||||
|
setPageLayout(pdf::PageLayout::OneColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::on_actionPageLayoutTwoPages_triggered()
|
||||||
|
{
|
||||||
|
setPageLayout(ui->actionFirstPageOnRightSide->isChecked() ? pdf::PageLayout::TwoPagesRight : pdf::PageLayout::TwoPagesLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::on_actionPageLayoutTwoColumns_triggered()
|
||||||
|
{
|
||||||
|
setPageLayout(ui->actionFirstPageOnRightSide->isChecked() ? pdf::PageLayout::TwoColumnRight : pdf::PageLayout::TwoColumnLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFViewerMainWindow::on_actionFirstPageOnRightSide_triggered()
|
||||||
|
{
|
||||||
|
switch (m_pdfWidget->getDrawWidgetProxy()->getPageLayout())
|
||||||
|
{
|
||||||
|
case pdf::PageLayout::SinglePage:
|
||||||
|
case pdf::PageLayout::OneColumn:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::TwoColumnLeft:
|
||||||
|
case pdf::PageLayout::TwoColumnRight:
|
||||||
|
on_actionPageLayoutTwoColumns_triggered();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case pdf::PageLayout::TwoPagesLeft:
|
||||||
|
case pdf::PageLayout::TwoPagesRight:
|
||||||
|
on_actionPageLayoutTwoPages_triggered();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Q_ASSERT(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdfviewer
|
} // namespace pdfviewer
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#ifndef PDFVIEWERMAINWINDOW_H
|
#ifndef PDFVIEWERMAINWINDOW_H
|
||||||
#define PDFVIEWERMAINWINDOW_H
|
#define PDFVIEWERMAINWINDOW_H
|
||||||
|
|
||||||
|
#include "pdfcatalog.h"
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
@ -45,6 +47,13 @@ public:
|
|||||||
|
|
||||||
virtual void closeEvent(QCloseEvent* event) override;
|
virtual void closeEvent(QCloseEvent* event) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_actionPageLayoutSinglePage_triggered();
|
||||||
|
void on_actionPageLayoutContinuous_triggered();
|
||||||
|
void on_actionPageLayoutTwoPages_triggered();
|
||||||
|
void on_actionPageLayoutTwoColumns_triggered();
|
||||||
|
void on_actionFirstPageOnRightSide_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onActionOpenTriggered();
|
void onActionOpenTriggered();
|
||||||
void onActionCloseTriggered();
|
void onActionCloseTriggered();
|
||||||
@ -54,11 +63,14 @@ private:
|
|||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
|
void updatePageLayoutActions();
|
||||||
|
|
||||||
void openDocument(const QString& fileName);
|
void openDocument(const QString& fileName);
|
||||||
void setDocument(const pdf::PDFDocument* document);
|
void setDocument(const pdf::PDFDocument* document);
|
||||||
void closeDocument();
|
void closeDocument();
|
||||||
|
|
||||||
|
void setPageLayout(pdf::PageLayout pageLayout);
|
||||||
|
|
||||||
Ui::PDFViewerMainWindow* ui;
|
Ui::PDFViewerMainWindow* ui;
|
||||||
pdf::PDFWidget* m_pdfWidget;
|
pdf::PDFWidget* m_pdfWidget;
|
||||||
QSharedPointer<pdf::PDFDocument> m_pdfDocument;
|
QSharedPointer<pdf::PDFDocument> m_pdfDocument;
|
||||||
|
@ -36,7 +36,25 @@
|
|||||||
<string>Go To</string>
|
<string>Go To</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuView">
|
||||||
|
<property name="title">
|
||||||
|
<string>View</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuPage_Layout">
|
||||||
|
<property name="title">
|
||||||
|
<string>Page Layout</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionPageLayoutSinglePage"/>
|
||||||
|
<addaction name="actionPageLayoutContinuous"/>
|
||||||
|
<addaction name="actionPageLayoutTwoPages"/>
|
||||||
|
<addaction name="actionPageLayoutTwoColumns"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionFirstPageOnRightSide"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuPage_Layout"/>
|
||||||
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
|
<addaction name="menuView"/>
|
||||||
<addaction name="menuGoTo"/>
|
<addaction name="menuGoTo"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="mainToolBar">
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
@ -63,6 +81,64 @@
|
|||||||
<string>Quit</string>
|
<string>Quit</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionPageLayoutSinglePage">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Single Page</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+1</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionPageLayoutContinuous">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Continuous</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+2</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionPageLayoutTwoPages">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Two Pages</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+3</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionPageLayoutTwoColumns">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Two columns</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+4</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionFirstPageOnRightSide">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>First page on right side</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>First page on right side</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+5</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user