PDF4QT/Pdf4QtViewer/pdfviewermainwindow.cpp

545 lines
22 KiB
C++
Raw Normal View History

2021-04-30 20:12:10 +02:00
// Copyright (C) 2019-2021 Jakub Melka
2019-01-27 17:55:22 +01:00
//
2021-08-10 19:22:56 +02:00
// This file is part of PDF4QT.
2019-01-27 17:55:22 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is free software: you can redistribute it and/or modify
2019-01-27 17:55:22 +01:00
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
2021-04-30 20:12:10 +02:00
// with the written consent of the copyright owner, any later version.
2019-01-27 17:55:22 +01:00
//
2021-08-10 19:22:56 +02:00
// PDF4QT is distributed in the hope that it will be useful,
2019-01-27 17:55:22 +01:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
2021-08-10 19:22:56 +02:00
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
2019-01-27 17:55:22 +01:00
2018-11-21 19:30:15 +01:00
#include "pdfviewermainwindow.h"
#include "ui_pdfviewermainwindow.h"
2019-11-10 14:17:54 +01:00
#include "pdfaboutdialog.h"
2019-11-28 18:20:32 +01:00
#include "pdfsidebarwidget.h"
2020-01-03 18:11:03 +01:00
#include "pdfadvancedfindwidget.h"
2019-12-20 18:56:03 +01:00
#include "pdfviewersettingsdialog.h"
#include "pdfdocumentpropertiesdialog.h"
2020-02-08 18:09:46 +01:00
#include "pdfrendertoimagesdialog.h"
2020-05-31 18:31:59 +02:00
#include "pdfoptimizedocumentdialog.h"
2019-09-06 19:07:52 +02:00
2018-11-21 19:30:15 +01:00
#include "pdfdocumentreader.h"
2018-12-01 11:36:07 +01:00
#include "pdfvisitor.h"
2019-01-20 17:55:06 +01:00
#include "pdfstreamfilters.h"
2019-01-27 17:55:22 +01:00
#include "pdfdrawwidget.h"
2019-02-02 18:10:00 +01:00
#include "pdfdrawspacecontroller.h"
2019-02-24 19:42:00 +01:00
#include "pdfrenderingerrorswidget.h"
2019-04-27 14:14:07 +02:00
#include "pdffont.h"
2019-07-01 19:53:38 +02:00
#include "pdfitemmodels.h"
2019-11-06 18:25:46 +01:00
#include "pdfutils.h"
2019-12-22 18:03:19 +01:00
#include "pdfsendmail.h"
2020-01-18 14:55:26 +01:00
#include "pdfexecutionpolicy.h"
2020-01-25 17:36:25 +01:00
#include "pdfwidgetutils.h"
2020-06-07 17:46:49 +02:00
#include "pdfdocumentwriter.h"
2020-06-14 18:40:42 +02:00
#include "pdfsignaturehandler.h"
#include "pdfadvancedtools.h"
2020-12-20 16:36:07 +01:00
#include "pdfwidgetutils.h"
2018-11-21 19:30:15 +01:00
2020-02-03 19:45:17 +01:00
#include <QPainter>
2019-01-27 17:55:22 +01:00
#include <QSettings>
2018-11-21 19:30:15 +01:00
#include <QFileDialog>
#include <QMessageBox>
2019-01-27 17:55:22 +01:00
#include <QCloseEvent>
#include <QApplication>
#include <QDesktopWidget>
#include <QStandardPaths>
2019-07-01 19:53:38 +02:00
#include <QDockWidget>
#include <QTreeView>
#include <QLayout>
#include <QHeaderView>
#include <QInputDialog>
2019-11-06 18:25:46 +01:00
#include <QSpinBox>
#include <QLabel>
#include <QDoubleSpinBox>
2019-11-30 16:26:32 +01:00
#include <QDesktopServices>
2020-06-07 17:46:49 +02:00
#include <QFileDialog>
2020-06-28 18:55:09 +02:00
#include <QLockFile>
2020-02-03 19:45:17 +01:00
#include <QtPrintSupport/QPrinter>
#include <QtPrintSupport/QPrintDialog>
2019-12-23 15:58:40 +01:00
#include <QtConcurrent/QtConcurrent>
2020-11-17 18:28:34 +01:00
#include <QPluginLoader>
2020-11-21 16:56:10 +01:00
#include <QToolButton>
#include <QActionGroup>
2019-11-30 16:26:32 +01:00
#ifdef Q_OS_WIN
#include "Windows.h"
#endif
2018-11-21 19:30:15 +01:00
namespace pdfviewer
{
PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
2018-11-21 19:30:15 +01:00
QMainWindow(parent),
2019-01-27 17:55:22 +01:00
ui(new Ui::PDFViewerMainWindow),
2020-12-20 16:36:07 +01:00
m_actionManager(new PDFActionManager(this)),
m_programController(new PDFProgramController(this)),
2020-01-03 18:11:03 +01:00
m_sidebarWidget(nullptr),
2019-11-28 18:20:32 +01:00
m_sidebarDockWidget(nullptr),
2020-01-03 18:11:03 +01:00
m_advancedFindWidget(nullptr),
m_advancedFindDockWidget(nullptr),
2019-11-06 18:25:46 +01:00
m_pageNumberSpinBox(nullptr),
m_pageNumberLabel(nullptr),
m_pageZoomSpinBox(nullptr),
m_isLoadingUI(false),
m_progress(new pdf::PDFProgress(this)),
m_taskbarButton(new QWinTaskbarButton(this)),
m_progressTaskbarIndicator(nullptr),
m_progressDialog(nullptr),
2020-12-20 16:36:07 +01:00
m_isChangingProgressStep(false)
2018-11-21 19:30:15 +01:00
{
ui->setupUi(this);
setAcceptDrops(true);
2020-01-25 17:36:25 +01:00
// Initialize toolbar icon size
2020-12-20 16:36:07 +01:00
adjustToolbar(ui->mainToolBar);
2020-01-25 17:36:25 +01:00
// Initialize task bar progress
m_progressTaskbarIndicator = m_taskbarButton->progress();
2020-12-20 16:36:07 +01:00
// Initialize actions
m_actionManager->setAction(PDFActionManager::Open, ui->actionOpen);
m_actionManager->setAction(PDFActionManager::Close, ui->actionClose);
m_actionManager->setAction(PDFActionManager::Quit, ui->actionQuit);
m_actionManager->setAction(PDFActionManager::ZoomIn, ui->actionZoom_In);
m_actionManager->setAction(PDFActionManager::ZoomOut, ui->actionZoom_Out);
m_actionManager->setAction(PDFActionManager::Find, ui->actionFind);
m_actionManager->setAction(PDFActionManager::FindPrevious, ui->actionFindPrevious);
m_actionManager->setAction(PDFActionManager::FindNext, ui->actionFindNext);
m_actionManager->setAction(PDFActionManager::SelectTextAll, ui->actionSelectTextAll);
m_actionManager->setAction(PDFActionManager::DeselectText, ui->actionDeselectText);
m_actionManager->setAction(PDFActionManager::CopyText, ui->actionCopyText);
m_actionManager->setAction(PDFActionManager::RotateRight, ui->actionRotateRight);
m_actionManager->setAction(PDFActionManager::RotateLeft, ui->actionRotateLeft);
m_actionManager->setAction(PDFActionManager::Print, ui->actionPrint);
m_actionManager->setAction(PDFActionManager::Undo, ui->actionUndo);
m_actionManager->setAction(PDFActionManager::Redo, ui->actionRedo);
m_actionManager->setAction(PDFActionManager::Save, ui->actionSave);
m_actionManager->setAction(PDFActionManager::SaveAs, ui->actionSave_As);
m_actionManager->setAction(PDFActionManager::GoToDocumentStart, ui->actionGoToDocumentStart);
m_actionManager->setAction(PDFActionManager::GoToDocumentEnd, ui->actionGoToDocumentEnd);
m_actionManager->setAction(PDFActionManager::GoToNextPage, ui->actionGoToNextPage);
m_actionManager->setAction(PDFActionManager::GoToPreviousPage, ui->actionGoToPreviousPage);
m_actionManager->setAction(PDFActionManager::GoToNextLine, ui->actionGoToNextLine);
m_actionManager->setAction(PDFActionManager::GoToPreviousLine, ui->actionGoToPreviousLine);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteComment, ui->actionStickyNoteComment);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteHelp, ui->actionStickyNoteHelp);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteInsert, ui->actionStickyNoteInsert);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteKey, ui->actionStickyNoteKey);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteNewParagraph, ui->actionStickyNoteNewParagraph);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteNote, ui->actionStickyNoteNote);
m_actionManager->setAction(PDFActionManager::CreateStickyNoteParagraph, ui->actionStickyNoteParagraph);
m_actionManager->setAction(PDFActionManager::CreateTextHighlight, ui->actionCreateTextHighlight);
m_actionManager->setAction(PDFActionManager::CreateTextUnderline, ui->actionCreateTextUnderline);
m_actionManager->setAction(PDFActionManager::CreateTextStrikeout, ui->actionCreateTextStrikeout);
m_actionManager->setAction(PDFActionManager::CreateTextSquiggly, ui->actionCreateTextSquiggly);
m_actionManager->setAction(PDFActionManager::CreateHyperlink, ui->actionCreateHyperlink);
m_actionManager->setAction(PDFActionManager::CreateInlineText, ui->actionInlineText);
m_actionManager->setAction(PDFActionManager::CreateStraightLine, ui->actionCreateStraightLine);
m_actionManager->setAction(PDFActionManager::CreatePolyline, ui->actionCreatePolyline);
m_actionManager->setAction(PDFActionManager::CreatePolygon, ui->actionCreatePolygon);
m_actionManager->setAction(PDFActionManager::CreateEllipse, ui->actionCreateEllipse);
m_actionManager->setAction(PDFActionManager::CreateFreehandCurve, ui->actionCreateFreehandCurve);
m_actionManager->setAction(PDFActionManager::RenderOptionAntialiasing, ui->actionRenderOptionAntialiasing);
m_actionManager->setAction(PDFActionManager::RenderOptionTextAntialiasing, ui->actionRenderOptionTextAntialiasing);
m_actionManager->setAction(PDFActionManager::RenderOptionSmoothPictures, ui->actionRenderOptionSmoothPictures);
m_actionManager->setAction(PDFActionManager::RenderOptionIgnoreOptionalContentSettings, ui->actionRenderOptionIgnoreOptionalContentSettings);
m_actionManager->setAction(PDFActionManager::RenderOptionDisplayAnnotations, ui->actionRenderOptionDisplayAnnotations);
m_actionManager->setAction(PDFActionManager::RenderOptionInvertColors, ui->actionInvertColors);
m_actionManager->setAction(PDFActionManager::RenderOptionShowTextBlocks, ui->actionShow_Text_Blocks);
m_actionManager->setAction(PDFActionManager::RenderOptionShowTextLines, ui->actionShow_Text_Lines);
m_actionManager->setAction(PDFActionManager::Properties, ui->actionProperties);
m_actionManager->setAction(PDFActionManager::Options, ui->actionOptions);
2021-05-03 18:37:27 +02:00
m_actionManager->setAction(PDFActionManager::GetSource, ui->actionGetSource);
2020-12-20 16:36:07 +01:00
m_actionManager->setAction(PDFActionManager::About, ui->actionAbout);
m_actionManager->setAction(PDFActionManager::SendByMail, ui->actionSend_by_E_Mail);
m_actionManager->setAction(PDFActionManager::RenderToImages, ui->actionRender_to_Images);
m_actionManager->setAction(PDFActionManager::Optimize, ui->actionOptimize);
2021-05-21 19:00:25 +02:00
m_actionManager->setAction(PDFActionManager::Encryption, ui->actionEncryption);
2020-12-20 16:36:07 +01:00
m_actionManager->setAction(PDFActionManager::FitPage, ui->actionFitPage);
m_actionManager->setAction(PDFActionManager::FitWidth, ui->actionFitWidth);
m_actionManager->setAction(PDFActionManager::FitHeight, ui->actionFitHeight);
m_actionManager->setAction(PDFActionManager::ShowRenderingErrors, ui->actionRendering_Errors);
m_actionManager->setAction(PDFActionManager::PageLayoutSinglePage, ui->actionPageLayoutSinglePage);
m_actionManager->setAction(PDFActionManager::PageLayoutContinuous, ui->actionPageLayoutContinuous);
m_actionManager->setAction(PDFActionManager::PageLayoutTwoPages, ui->actionPageLayoutTwoPages);
m_actionManager->setAction(PDFActionManager::PageLayoutTwoColumns, ui->actionPageLayoutTwoColumns);
m_actionManager->setAction(PDFActionManager::PageLayoutFirstPageOnRightSide, ui->actionFirstPageOnRightSide);
m_actionManager->setAction(PDFActionManager::ToolSelectText, ui->actionSelectText);
m_actionManager->setAction(PDFActionManager::ToolMagnifier, ui->actionMagnifier);
m_actionManager->setAction(PDFActionManager::ToolScreenshot, ui->actionScreenshot);
m_actionManager->setAction(PDFActionManager::ToolExtractImage, ui->actionExtractImage);
2021-04-25 18:33:41 +02:00
m_actionManager->setAction(PDFActionManager::DeveloperCreateInstaller, ui->actionDeveloperCreateInstaller);
2020-12-20 16:36:07 +01:00
m_actionManager->initActions(pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)), true);
for (QAction* action : m_programController->getRecentFileManager()->getActions())
2020-02-01 11:56:40 +01:00
{
ui->menuFile->insertAction(ui->actionQuit, action);
}
ui->menuFile->insertSeparator(ui->actionQuit);
2019-01-27 17:55:22 +01:00
connect(ui->actionQuit, &QAction::triggered, this, &PDFViewerMainWindow::onActionQuitTriggered);
2019-11-06 18:25:46 +01:00
m_pageNumberSpinBox = new QSpinBox(this);
m_pageNumberLabel = new QLabel(this);
2020-12-20 16:36:07 +01:00
m_pageNumberSpinBox->setFixedWidth(pdf::PDFWidgetUtils::scaleDPI_x(m_pageNumberSpinBox, 80));
2019-11-09 15:11:57 +01:00
m_pageNumberSpinBox->setAlignment(Qt::AlignCenter);
connect(m_pageNumberSpinBox, &QSpinBox::editingFinished, this, &PDFViewerMainWindow::onPageNumberSpinboxEditingFinished);
2019-11-06 18:25:46 +01:00
2020-12-20 16:36:07 +01:00
for (QAction* action : m_actionManager->getActionGroup(PDFActionManager::CreateStampGroup)->actions())
2020-12-10 19:27:26 +01:00
{
ui->menuStamp->addAction(action);
}
2019-11-06 18:25:46 +01:00
// Page control
ui->mainToolBar->addSeparator();
2020-12-20 16:36:07 +01:00
ui->mainToolBar->addAction(ui->actionGoToDocumentStart);
ui->mainToolBar->addAction(ui->actionGoToPreviousPage);
2019-11-06 18:25:46 +01:00
ui->mainToolBar->addWidget(m_pageNumberSpinBox);
ui->mainToolBar->addWidget(m_pageNumberLabel);
2020-12-20 16:36:07 +01:00
ui->mainToolBar->addAction(ui->actionGoToNextPage);
ui->mainToolBar->addAction(ui->actionGoToDocumentEnd);
2019-11-06 18:25:46 +01:00
// Zoom
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(ui->actionZoom_In);
ui->mainToolBar->addAction(ui->actionZoom_Out);
m_pageZoomSpinBox = new QDoubleSpinBox(this);
m_pageZoomSpinBox->setMinimum(pdf::PDFDrawWidgetProxy::getMinZoom() * 100);
m_pageZoomSpinBox->setMaximum(pdf::PDFDrawWidgetProxy::getMaxZoom() * 100);
m_pageZoomSpinBox->setDecimals(2);
m_pageZoomSpinBox->setSuffix(tr("%"));
2020-12-20 16:36:07 +01:00
m_pageZoomSpinBox->setFixedWidth(pdf::PDFWidgetUtils::scaleDPI_x(m_pageNumberSpinBox, 80));
2019-11-09 15:11:57 +01:00
m_pageZoomSpinBox->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
connect(m_pageZoomSpinBox, &QDoubleSpinBox::editingFinished, this, &PDFViewerMainWindow::onPageZoomSpinboxEditingFinished);
2019-11-06 18:25:46 +01:00
ui->mainToolBar->addWidget(m_pageZoomSpinBox);
2019-12-01 13:02:25 +01:00
// Fit page, width, height
ui->mainToolBar->addAction(ui->actionFitPage);
ui->mainToolBar->addAction(ui->actionFitWidth);
ui->mainToolBar->addAction(ui->actionFitHeight);
2020-01-25 17:36:25 +01:00
ui->mainToolBar->addSeparator();
// Tools
ui->mainToolBar->addAction(ui->actionSelectText);
ui->mainToolBar->addAction(ui->actionCreateTextHighlight);
ui->mainToolBar->addAction(ui->actionCreateTextUnderline);
ui->mainToolBar->addAction(ui->actionCreateTextStrikeout);
ui->mainToolBar->addAction(ui->actionCreateTextSquiggly);
2020-02-22 18:27:33 +01:00
ui->mainToolBar->addAction(ui->actionMagnifier);
2020-02-23 18:59:54 +01:00
ui->mainToolBar->addAction(ui->actionScreenshot);
2020-02-29 14:26:36 +01:00
ui->mainToolBar->addAction(ui->actionExtractImage);
ui->mainToolBar->addSeparator();
// Special tools
2020-12-20 16:36:07 +01:00
QToolButton* insertStickyNoteButton = m_actionManager->createToolButtonForActionGroup(PDFActionManager::CreateStickyNoteGroup, ui->mainToolBar);
ui->mainToolBar->addWidget(insertStickyNoteButton);
ui->mainToolBar->addSeparator();
2019-12-01 13:02:25 +01:00
2020-12-20 16:36:07 +01:00
m_programController->initialize(PDFProgramController::AllFeatures, this, this, m_actionManager, m_progress);
setCentralWidget(m_programController->getPdfWidget());
setFocusProxy(m_programController->getPdfWidget());
2019-09-08 11:13:59 +02:00
2020-12-20 16:36:07 +01:00
m_sidebarWidget = new PDFSidebarWidget(m_programController->getPdfWidget()->getDrawWidgetProxy(), m_programController->getTextToSpeech(), m_programController->getCertificateStore(), m_programController->getSettings(), this);
2019-11-28 18:20:32 +01:00
m_sidebarDockWidget = new QDockWidget(tr("Sidebar"), this);
m_sidebarDockWidget->setObjectName("SidebarDockWidget");
m_sidebarDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
m_sidebarDockWidget->setWidget(m_sidebarWidget);
addDockWidget(Qt::LeftDockWidgetArea, m_sidebarDockWidget);
m_sidebarDockWidget->hide();
2020-12-20 16:36:07 +01:00
connect(m_sidebarWidget, &PDFSidebarWidget::actionTriggered, m_programController, &PDFProgramController::onActionTriggered);
2019-07-01 19:53:38 +02:00
2020-12-20 16:36:07 +01:00
m_advancedFindWidget = new PDFAdvancedFindWidget(m_programController->getPdfWidget()->getDrawWidgetProxy(), this);
2020-01-03 18:11:03 +01:00
m_advancedFindDockWidget = new QDockWidget(tr("Advanced find"), this);
m_advancedFindDockWidget->setObjectName("AdvancedFind");
m_advancedFindDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
m_advancedFindDockWidget->setWidget(m_advancedFindWidget);
addDockWidget(Qt::BottomDockWidgetArea, m_advancedFindDockWidget);
m_advancedFindDockWidget->hide();
QAction* toggleAdvancedFindAction = m_advancedFindDockWidget->toggleViewAction();
toggleAdvancedFindAction->setObjectName("actionAdvancedFind");
toggleAdvancedFindAction->setText(tr("Advanced Find"));
toggleAdvancedFindAction->setShortcut(QKeySequence("Ctrl+Shift+F"));
2020-01-12 18:46:59 +01:00
toggleAdvancedFindAction->setIcon(QIcon(":/resources/find-advanced.svg"));
2020-01-03 18:11:03 +01:00
ui->menuEdit->insertAction(nullptr, toggleAdvancedFindAction);
2020-12-20 16:36:07 +01:00
m_actionManager->addAdditionalAction(m_advancedFindDockWidget->toggleViewAction());
2019-07-06 15:55:37 +02:00
2019-07-01 19:53:38 +02:00
ui->menuView->addSeparator();
2019-11-28 18:20:32 +01:00
ui->menuView->addAction(m_sidebarDockWidget->toggleViewAction());
2019-12-16 19:46:29 +01:00
m_sidebarDockWidget->toggleViewAction()->setObjectName("actionSidebar");
2020-12-20 16:36:07 +01:00
m_actionManager->addAdditionalAction(m_sidebarDockWidget->toggleViewAction());
2019-07-01 19:53:38 +02:00
connect(m_progress, &pdf::PDFProgress::progressStarted, this, &PDFViewerMainWindow::onProgressStarted);
connect(m_progress, &pdf::PDFProgress::progressStep, this, &PDFViewerMainWindow::onProgressStep);
connect(m_progress, &pdf::PDFProgress::progressFinished, this, &PDFViewerMainWindow::onProgressFinished);
2020-11-17 18:28:34 +01:00
2020-12-20 16:36:07 +01:00
m_programController->finishInitialization();
2021-05-04 18:40:51 +02:00
updateDeveloperMenu();
2020-11-17 18:28:34 +01:00
2020-12-20 16:36:07 +01:00
if (pdf::PDFToolManager* toolManager = m_programController->getToolManager())
2020-11-17 18:28:34 +01:00
{
2020-12-20 16:36:07 +01:00
connect(toolManager, &pdf::PDFToolManager::messageDisplayRequest, statusBar(), &QStatusBar::showMessage);
2020-11-17 18:28:34 +01:00
}
2018-11-21 19:30:15 +01:00
}
PDFViewerMainWindow::~PDFViewerMainWindow()
{
2020-12-20 16:36:07 +01:00
delete m_programController;
m_programController = nullptr;
2020-04-22 20:00:44 +02:00
2020-12-20 16:36:07 +01:00
delete m_actionManager;
m_actionManager = nullptr;
2020-03-07 17:38:50 +01:00
2018-11-21 19:30:15 +01:00
delete ui;
}
2019-01-27 17:55:22 +01:00
void PDFViewerMainWindow::onActionQuitTriggered()
{
close();
}
2019-01-20 17:55:06 +01:00
2019-11-09 15:11:57 +01:00
void PDFViewerMainWindow::onPageNumberSpinboxEditingFinished()
{
if (m_isLoadingUI)
{
return;
}
if (m_pageNumberSpinBox->hasFocus())
{
2020-12-20 16:36:07 +01:00
m_programController->getPdfWidget()->setFocus();
2019-11-09 15:11:57 +01:00
}
2020-12-20 16:36:07 +01:00
m_programController->getPdfWidget()->getDrawWidgetProxy()->goToPage(m_pageNumberSpinBox->value() - 1);
2019-11-09 15:11:57 +01:00
}
void PDFViewerMainWindow::onPageZoomSpinboxEditingFinished()
{
if (m_isLoadingUI)
{
return;
}
if (m_pageZoomSpinBox->hasFocus())
{
2020-12-20 16:36:07 +01:00
m_programController->getPdfWidget()->setFocus();
2019-11-09 15:11:57 +01:00
}
2020-12-20 16:36:07 +01:00
m_programController->getPdfWidget()->getDrawWidgetProxy()->zoom(m_pageZoomSpinBox->value() / 100.0);
2019-11-29 19:10:29 +01:00
}
void PDFViewerMainWindow::onProgressStarted(pdf::ProgressStartupInfo info)
{
Q_ASSERT(!m_progressDialog);
if (info.showDialog)
{
m_progressDialog = new QProgressDialog(info.text, QString(), 0, 100, this);
m_progressDialog->setWindowModality(Qt::WindowModal);
m_progressDialog->setCancelButton(nullptr);
}
m_progressTaskbarIndicator->setRange(0, 100);
m_progressTaskbarIndicator->reset();
m_progressTaskbarIndicator->show();
2020-12-20 16:36:07 +01:00
m_programController->setIsBusy(true);
m_programController->updateActionsAvailability();
}
void PDFViewerMainWindow::onProgressStep(int percentage)
{
if (m_isChangingProgressStep)
{
return;
}
pdf::PDFTemporaryValueChange guard(&m_isChangingProgressStep, true);
if (m_progressDialog)
{
m_progressDialog->setValue(percentage);
}
m_progressTaskbarIndicator->setValue(percentage);
}
void PDFViewerMainWindow::onProgressFinished()
{
if (m_progressDialog)
{
m_progressDialog->hide();
m_progressDialog->deleteLater();
m_progressDialog = nullptr;
}
m_progressTaskbarIndicator->hide();
2020-12-20 16:36:07 +01:00
m_programController->setIsBusy(false);
m_programController->updateActionsAvailability();
2019-07-06 15:55:37 +02:00
}
2021-05-04 18:40:51 +02:00
void PDFViewerMainWindow::updateDeveloperMenu()
{
bool isDeveloperMode = m_programController->getSettings()->getSettings().m_allowDeveloperMode;
ui->menuDeveloper->menuAction()->setVisible(isDeveloperMode);
}
2019-11-06 18:25:46 +01:00
void PDFViewerMainWindow::updateUI(bool fullUpdate)
{
pdf::PDFTemporaryValueChange guard(&m_isLoadingUI, true);
if (fullUpdate)
{
2020-12-20 16:36:07 +01:00
if (pdf::PDFDocument* document = m_programController->getDocument())
2019-11-06 18:25:46 +01:00
{
2020-12-20 16:36:07 +01:00
size_t pageCount = document->getCatalog()->getPageCount();
2019-11-06 18:25:46 +01:00
m_pageNumberSpinBox->setMinimum(1);
m_pageNumberSpinBox->setMaximum(static_cast<int>(pageCount));
m_pageNumberSpinBox->setEnabled(true);
m_pageNumberLabel->setText(tr(" / %1").arg(pageCount));
}
else
{
m_pageNumberSpinBox->setEnabled(false);
m_pageNumberLabel->setText(QString());
}
}
2019-11-09 15:11:57 +01:00
else
{
2020-12-20 16:36:07 +01:00
std::vector<pdf::PDFInteger> currentPages = m_programController->getPdfWidget()->getDrawWidget()->getCurrentPages();
2019-11-09 15:11:57 +01:00
if (!currentPages.empty())
{
m_pageNumberSpinBox->setValue(currentPages.front() + 1);
2019-12-15 17:46:58 +01:00
// Prefetch pages, if it is enabled
2020-12-20 16:36:07 +01:00
if (m_programController->getSettings()->isPagePrefetchingEnabled())
2019-12-15 17:46:58 +01:00
{
2020-12-20 16:36:07 +01:00
m_programController->getPdfWidget()->getDrawWidgetProxy()->prefetchPages(currentPages.back());
2019-12-15 17:46:58 +01:00
}
2019-11-09 15:11:57 +01:00
}
2019-12-08 19:20:36 +01:00
m_sidebarWidget->setCurrentPages(currentPages);
2019-11-09 15:11:57 +01:00
}
2019-11-06 18:25:46 +01:00
2020-12-20 16:36:07 +01:00
m_pageZoomSpinBox->setValue(m_programController->getPdfWidget()->getDrawWidgetProxy()->getZoom() * 100);
2019-07-06 15:55:37 +02:00
}
2020-12-20 16:36:07 +01:00
QMenu* PDFViewerMainWindow::addToolMenu(QString name)
2019-07-06 15:55:37 +02:00
{
2020-12-20 16:36:07 +01:00
return ui->menuTools->addMenu(name);
2019-07-06 15:55:37 +02:00
}
2020-12-20 16:36:07 +01:00
void PDFViewerMainWindow::setStatusBarMessage(QString message, int time)
2019-01-27 17:55:22 +01:00
{
2020-12-20 16:36:07 +01:00
statusBar()->showMessage(message, time);
2020-06-07 17:46:49 +02:00
}
2020-12-20 16:36:07 +01:00
void PDFViewerMainWindow::setDocument(const pdf::PDFModifiedDocument& document)
2020-06-07 17:46:49 +02:00
{
2020-12-20 16:36:07 +01:00
if (m_sidebarWidget)
{
2020-12-20 16:36:07 +01:00
m_sidebarWidget->setDocument(document, *m_programController->getSignatures());
}
2020-05-30 18:31:50 +02:00
2020-12-20 16:36:07 +01:00
if (m_advancedFindWidget)
2019-01-27 17:55:22 +01:00
{
2020-12-20 16:36:07 +01:00
m_advancedFindWidget->setDocument(document);
2018-11-21 19:30:15 +01:00
}
2020-05-03 18:52:22 +02:00
2020-12-20 16:36:07 +01:00
if (m_sidebarWidget)
2019-07-02 16:20:12 +02:00
{
2020-12-20 16:36:07 +01:00
if (m_sidebarWidget->isEmpty())
{
2020-12-20 16:36:07 +01:00
m_sidebarDockWidget->hide();
}
2020-12-20 16:36:07 +01:00
else
{
2020-12-20 16:36:07 +01:00
m_sidebarDockWidget->show();
}
}
2019-07-01 19:53:38 +02:00
2020-12-20 16:36:07 +01:00
if (!document && m_advancedFindDockWidget)
2020-01-03 18:11:03 +01:00
{
m_advancedFindDockWidget->hide();
}
2019-01-27 17:55:22 +01:00
}
2020-12-20 16:36:07 +01:00
void PDFViewerMainWindow::adjustToolbar(QToolBar* toolbar)
2019-02-03 13:57:37 +01:00
{
2020-12-20 16:36:07 +01:00
QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24));
toolbar->setIconSize(iconSize);
2019-11-06 18:25:46 +01:00
}
2020-12-30 18:26:45 +01:00
pdf::PDFTextSelection PDFViewerMainWindow::getSelectedText() const
{
if (!m_advancedFindWidget)
{
return pdf::PDFTextSelection();
}
return m_advancedFindWidget->getSelectedText();
}
2019-01-27 17:55:22 +01:00
void PDFViewerMainWindow::closeEvent(QCloseEvent* event)
{
2020-12-20 16:36:07 +01:00
if (!m_programController->canClose())
2019-12-23 15:58:40 +01:00
{
// Jakub Melka: Do not allow to close the application, if document
// reading is running.
event->ignore();
}
else
{
2020-12-20 16:36:07 +01:00
m_programController->writeSettings();
m_programController->closeDocument();
2019-12-23 15:58:40 +01:00
event->accept();
}
2019-01-27 17:55:22 +01:00
}
void PDFViewerMainWindow::showEvent(QShowEvent* event)
{
Q_UNUSED(event);
m_taskbarButton->setWindow(windowHandle());
}
void PDFViewerMainWindow::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls())
{
event->setDropAction(Qt::LinkAction);
event->accept();
}
}
void PDFViewerMainWindow::dragMoveEvent(QDragMoveEvent* event)
{
if (event->mimeData()->hasUrls())
{
event->setDropAction(Qt::LinkAction);
event->accept();
}
}
void PDFViewerMainWindow::dropEvent(QDropEvent* event)
{
if (event->mimeData()->hasUrls())
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.size() == 1)
{
2020-12-20 16:36:07 +01:00
m_programController->openDocument(urls.front().toLocalFile());
event->acceptProposedAction();
}
}
}
2020-06-07 17:46:49 +02:00
} // namespace pdfviewer