Page layout modes

This commit is contained in:
Jakub Melka
2019-02-03 13:57:37 +01:00
parent 4d7eaf7587
commit 0a28869c94
5 changed files with 191 additions and 0 deletions

View File

@ -75,7 +75,10 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget *parent) :
setCentralWidget(m_pdfWidget);
setFocusProxy(m_pdfWidget);
connect(m_pdfWidget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::pageLayoutChanged, this, &PDFViewerMainWindow::updatePageLayoutActions);
readSettings();
updatePageLayoutActions();
}
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)
{
// First close old document
@ -194,6 +232,11 @@ void PDFViewerMainWindow::closeDocument()
m_pdfDocument.reset();
}
void PDFViewerMainWindow::setPageLayout(pdf::PageLayout pageLayout)
{
m_pdfWidget->getDrawWidgetProxy()->setPageLayout(pageLayout);
}
void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
{
writeSettings();
@ -201,4 +244,47 @@ void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
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