PDF4QT/Pdf4QtLibGui/pdfeditormainwindow.cpp

584 lines
25 KiB
C++
Raw Normal View History

// Copyright (C) 2019-2024 Jakub Melka
2021-09-27 11:14:20 +02:00
//
// This file is part of PDF4QT.
//
// PDF4QT is free software: you can redistribute it and/or modify
// 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
// with the written consent of the copyright owner, any later version.
//
// PDF4QT is distributed in the hope that it will be useful,
// 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
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
2024-03-16 17:02:44 +01:00
#include "pdfeditormainwindow.h"
2024-03-16 17:40:27 +01:00
#include "ui_pdfeditormainwindow.h"
2021-09-27 11:14:20 +02:00
#include "pdfaboutdialog.h"
#include "pdfsidebarwidget.h"
#include "pdfadvancedfindwidget.h"
#include "pdfviewersettingsdialog.h"
#include "pdfdocumentpropertiesdialog.h"
#include "pdfrendertoimagesdialog.h"
#include "pdfdocumentreader.h"
#include "pdfvisitor.h"
#include "pdfstreamfilters.h"
#include "pdfdrawwidget.h"
#include "pdfdrawspacecontroller.h"
#include "pdfrenderingerrorswidget.h"
#include "pdffont.h"
#include "pdfitemmodels.h"
#include "pdfutils.h"
#include "pdfsendmail.h"
#include "pdfexecutionpolicy.h"
#include "pdfwidgetutils.h"
#include "pdfdocumentwriter.h"
#include "pdfsignaturehandler.h"
#include "pdfadvancedtools.h"
#include "pdfwidgetutils.h"
2023-12-25 14:39:47 +01:00
#include "pdfactioncombobox.h"
2021-09-27 11:14:20 +02:00
#include <QPainter>
#include <QFileDialog>
#include <QMessageBox>
#include <QCloseEvent>
#include <QApplication>
#include <QStandardPaths>
#include <QDockWidget>
#include <QTreeView>
#include <QLayout>
#include <QHeaderView>
#include <QInputDialog>
#include <QSpinBox>
#include <QLabel>
#include <QDoubleSpinBox>
#include <QDesktopServices>
#include <QFileDialog>
#include <QLockFile>
#include <QtPrintSupport/QPrinter>
#include <QtPrintSupport/QPrintDialog>
#include <QtConcurrent/QtConcurrent>
#include <QToolButton>
#include <QActionGroup>
#include "pdfdbgheap.h"
2021-09-27 11:14:20 +02:00
#ifdef Q_OS_WIN
#include "Windows.h"
#endif
namespace pdfviewer
{
2024-03-16 17:02:44 +01:00
PDFEditorMainWindow::PDFEditorMainWindow(QWidget* parent) :
2021-09-27 11:14:20 +02:00
QMainWindow(parent),
2024-03-16 17:02:44 +01:00
ui(new Ui::PDFEditorMainWindow),
2021-09-27 11:14:20 +02:00
m_actionManager(new PDFActionManager(this)),
m_programController(new PDFProgramController(this)),
m_sidebarWidget(nullptr),
m_sidebarDockWidget(nullptr),
m_advancedFindWidget(nullptr),
m_advancedFindDockWidget(nullptr),
m_pageNumberSpinBox(nullptr),
m_pageNumberLabel(nullptr),
m_pageZoomSpinBox(nullptr),
m_isLoadingUI(false),
m_progress(new pdf::PDFProgress(this)),
m_progressTaskbarIndicator(new PDFWinTaskBarProgress(this)),
m_progressBarOnStatusBar(nullptr),
m_progressBarLeftLabelOnStatusBar(nullptr),
2021-09-27 11:14:20 +02:00
m_isChangingProgressStep(false)
{
ui->setupUi(this);
setAcceptDrops(true);
// Initialize toolbar icon size
adjustToolbar(ui->mainToolBar);
2022-03-04 19:32:33 +01:00
ui->mainToolBar->setWindowTitle(tr("Standard"));
2021-09-27 11:14:20 +02:00
// Initialize status bar
m_progressBarOnStatusBar = new QProgressBar(this);
m_progressBarOnStatusBar->setHidden(true);
m_progressBarLeftLabelOnStatusBar = new QLabel(this);
m_progressBarLeftLabelOnStatusBar->setHidden(true);
statusBar()->addPermanentWidget(m_progressBarLeftLabelOnStatusBar);
statusBar()->addPermanentWidget(m_progressBarOnStatusBar);
2021-09-27 11:14:20 +02:00
// Initialize actions
m_actionManager->setAction(PDFActionManager::Open, ui->actionOpen);
m_actionManager->setAction(PDFActionManager::Close, ui->actionClose);
2023-09-01 17:33:45 +02:00
m_actionManager->setAction(PDFActionManager::AutomaticDocumentRefresh, ui->actionAutomaticDocumentRefresh);
2021-09-27 11:14:20 +02:00
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);
2023-10-18 20:11:43 +02:00
m_actionManager->setAction(PDFActionManager::CreateRectangle, ui->actionCreateRectangle);
2021-09-27 11:14:20 +02:00
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);
2024-02-10 18:42:58 +01:00
m_actionManager->setAction(PDFActionManager::RenderOptionDisplayRenderTimes, ui->actionRenderOptionDisplayRenderTimes);
2021-09-27 11:14:20 +02:00
m_actionManager->setAction(PDFActionManager::RenderOptionDisplayAnnotations, ui->actionRenderOptionDisplayAnnotations);
m_actionManager->setAction(PDFActionManager::RenderOptionInvertColors, ui->actionColorInvert);
m_actionManager->setAction(PDFActionManager::RenderOptionGrayscale, ui->actionColorGrayscale);
m_actionManager->setAction(PDFActionManager::RenderOptionHighContrast, ui->actionColorHighContrast);
m_actionManager->setAction(PDFActionManager::RenderOptionBitonal, ui->actionColorBitonal);
m_actionManager->setAction(PDFActionManager::RenderOptionCustomColors, ui->actionColorCustom);
2021-09-27 11:14:20 +02:00
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);
m_actionManager->setAction(PDFActionManager::ResetToFactorySettings, ui->actionResetToFactorySettings);
m_actionManager->setAction(PDFActionManager::CertificateManager, ui->actionCertificateManager);
2021-09-27 11:14:20 +02:00
m_actionManager->setAction(PDFActionManager::GetSource, ui->actionGetSource);
2023-10-22 16:07:55 +02:00
m_actionManager->setAction(PDFActionManager::BecomeSponsor, ui->actionBecomeASponsor);
2021-09-27 11:14:20 +02: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);
2023-02-19 18:36:46 +01:00
m_actionManager->setAction(PDFActionManager::Sanitize, ui->actionSanitize);
m_actionManager->setAction(PDFActionManager::CreateBitonalDocument, ui->actionCreateBitonalDocument);
2021-09-27 11:14:20 +02:00
m_actionManager->setAction(PDFActionManager::Encryption, ui->actionEncryption);
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::ToolSelectTable, ui->actionSelectTable);
2021-09-27 11:14:20 +02:00
m_actionManager->setAction(PDFActionManager::ToolMagnifier, ui->actionMagnifier);
m_actionManager->setAction(PDFActionManager::ToolScreenshot, ui->actionScreenshot);
m_actionManager->setAction(PDFActionManager::ToolExtractImage, ui->actionExtractImage);
2023-12-17 18:11:49 +01:00
m_actionManager->setAction(PDFActionManager::BookmarkPage, ui->actionBookmarkPage);
m_actionManager->setAction(PDFActionManager::BookmarkGoToNext, ui->actionGotoNextBookmark);
m_actionManager->setAction(PDFActionManager::BookmarkGoToPrevious, ui->actionGotoPreviousBookmark);
m_actionManager->setAction(PDFActionManager::BookmarkExport, ui->actionBookmarkExport);
m_actionManager->setAction(PDFActionManager::BookmarkImport, ui->actionBookmarkImport);
m_actionManager->setAction(PDFActionManager::BookmarkGenerateAutomatically, ui->actionBookmarkAutoGenerate);
2021-09-27 11:14:20 +02:00
m_actionManager->initActions(pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24)), true);
for (QAction* action : m_programController->getRecentFileManager()->getActions())
{
ui->menuFile->insertAction(ui->actionQuit, action);
}
ui->menuFile->insertSeparator(ui->actionQuit);
2024-03-16 17:02:44 +01:00
connect(ui->actionQuit, &QAction::triggered, this, &PDFEditorMainWindow::onActionQuitTriggered);
2021-09-27 11:14:20 +02:00
m_pageNumberSpinBox = new QSpinBox(this);
m_pageNumberSpinBox->setObjectName("pageNumberSpinBox");
2021-09-27 11:14:20 +02:00
m_pageNumberLabel = new QLabel(this);
m_pageNumberLabel->setObjectName("pageNumberLabel");
2021-09-27 11:14:20 +02:00
m_pageNumberSpinBox->setFixedWidth(pdf::PDFWidgetUtils::scaleDPI_x(m_pageNumberSpinBox, 80));
m_pageNumberSpinBox->setAlignment(Qt::AlignCenter);
2024-03-16 17:02:44 +01:00
connect(m_pageNumberSpinBox, &QSpinBox::editingFinished, this, &PDFEditorMainWindow::onPageNumberSpinboxEditingFinished);
2021-09-27 11:14:20 +02:00
for (QAction* action : m_actionManager->getActionGroup(PDFActionManager::CreateStampGroup)->actions())
{
ui->menuStamp->addAction(action);
}
// Page control
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(ui->actionGoToDocumentStart);
ui->mainToolBar->addAction(ui->actionGoToPreviousPage);
ui->mainToolBar->addWidget(m_pageNumberSpinBox);
ui->mainToolBar->addWidget(m_pageNumberLabel);
ui->mainToolBar->addAction(ui->actionGoToNextPage);
ui->mainToolBar->addAction(ui->actionGoToDocumentEnd);
// Zoom
ui->mainToolBar->addSeparator();
ui->mainToolBar->addAction(ui->actionZoom_In);
ui->mainToolBar->addAction(ui->actionZoom_Out);
m_pageZoomSpinBox = new QDoubleSpinBox(this);
m_pageZoomSpinBox->setObjectName("pageZoomSpinBox");
2021-09-27 11:14:20 +02:00
m_pageZoomSpinBox->setMinimum(pdf::PDFDrawWidgetProxy::getMinZoom() * 100);
m_pageZoomSpinBox->setMaximum(pdf::PDFDrawWidgetProxy::getMaxZoom() * 100);
m_pageZoomSpinBox->setDecimals(2);
m_pageZoomSpinBox->setSuffix(tr("%"));
m_pageZoomSpinBox->setFixedWidth(pdf::PDFWidgetUtils::scaleDPI_x(m_pageNumberSpinBox, 80));
m_pageZoomSpinBox->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
2024-03-16 17:02:44 +01:00
connect(m_pageZoomSpinBox, &QDoubleSpinBox::editingFinished, this, &PDFEditorMainWindow::onPageZoomSpinboxEditingFinished);
2021-09-27 11:14:20 +02:00
ui->mainToolBar->addWidget(m_pageZoomSpinBox);
// Fit page, width, height
ui->mainToolBar->addAction(ui->actionFitPage);
ui->mainToolBar->addAction(ui->actionFitWidth);
ui->mainToolBar->addAction(ui->actionFitHeight);
ui->mainToolBar->addSeparator();
// Tools
ui->mainToolBar->addAction(ui->actionSelectText);
ui->mainToolBar->addAction(ui->actionSelectTable);
2021-09-27 11:14:20 +02:00
ui->mainToolBar->addAction(ui->actionCreateTextHighlight);
ui->mainToolBar->addAction(ui->actionCreateTextUnderline);
ui->mainToolBar->addAction(ui->actionCreateTextStrikeout);
ui->mainToolBar->addAction(ui->actionCreateTextSquiggly);
ui->mainToolBar->addAction(ui->actionMagnifier);
ui->mainToolBar->addAction(ui->actionScreenshot);
ui->mainToolBar->addAction(ui->actionExtractImage);
ui->mainToolBar->addSeparator();
// Special tools
QToolButton* insertStickyNoteButton = m_actionManager->createToolButtonForActionGroup(PDFActionManager::CreateStickyNoteGroup, ui->mainToolBar);
ui->mainToolBar->addWidget(insertStickyNoteButton);
ui->mainToolBar->addSeparator();
m_programController->initialize(PDFProgramController::AllFeatures, this, this, m_actionManager, m_progress);
setCentralWidget(m_programController->getPdfWidget());
setFocusProxy(m_programController->getPdfWidget());
m_sidebarWidget = new PDFSidebarWidget(m_programController->getPdfWidget()->getDrawWidgetProxy(), m_programController->getTextToSpeech(), m_programController->getCertificateStore(), m_programController->getBookmarkManager(), m_programController->getSettings(), true, this);
m_sidebarDockWidget = new QDockWidget(tr("&Sidebar"), this);
2021-09-27 11:14:20 +02:00
m_sidebarDockWidget->setObjectName("SidebarDockWidget");
m_sidebarDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
m_sidebarDockWidget->setWidget(m_sidebarWidget);
addDockWidget(Qt::LeftDockWidgetArea, m_sidebarDockWidget);
m_sidebarDockWidget->hide();
connect(m_sidebarWidget, &PDFSidebarWidget::actionTriggered, m_programController, &PDFProgramController::onActionTriggered);
connect(m_sidebarWidget, &PDFSidebarWidget::documentModified, m_programController, &PDFProgramController::onDocumentModified);
2021-09-27 11:14:20 +02:00
m_advancedFindWidget = new PDFAdvancedFindWidget(m_programController->getPdfWidget()->getDrawWidgetProxy(), this);
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("Ad&vanced Find..."));
2021-09-27 11:14:20 +02:00
toggleAdvancedFindAction->setShortcut(QKeySequence("Ctrl+Shift+F"));
toggleAdvancedFindAction->setIcon(QIcon(":/resources/find-advanced.svg"));
ui->menuEdit->insertAction(nullptr, toggleAdvancedFindAction);
m_actionManager->addAdditionalAction(m_advancedFindDockWidget->toggleViewAction());
ui->menuView->addSeparator();
ui->menuView->addAction(m_sidebarDockWidget->toggleViewAction());
m_sidebarDockWidget->toggleViewAction()->setObjectName("actionSidebar");
m_actionManager->addAdditionalAction(m_sidebarDockWidget->toggleViewAction());
2024-03-16 17:02:44 +01:00
connect(m_progress, &pdf::PDFProgress::progressStarted, this, &PDFEditorMainWindow::onProgressStarted);
connect(m_progress, &pdf::PDFProgress::progressStep, this, &PDFEditorMainWindow::onProgressStep);
connect(m_progress, &pdf::PDFProgress::progressFinished, this, &PDFEditorMainWindow::onProgressFinished);
2021-09-27 11:14:20 +02:00
2023-12-25 14:39:47 +01:00
PDFActionComboBox* actionComboBox = new PDFActionComboBox(this);
menuBar()->setCornerWidget(actionComboBox);
2021-09-27 11:14:20 +02:00
m_programController->finishInitialization();
updateDeveloperMenu();
if (pdf::PDFToolManager* toolManager = m_programController->getToolManager())
{
connect(toolManager, &pdf::PDFToolManager::messageDisplayRequest, statusBar(), &QStatusBar::showMessage);
}
2023-11-26 19:15:20 +01:00
m_actionManager->styleActions();
2023-12-25 14:39:47 +01:00
m_programController->initActionComboBox(actionComboBox);
#ifndef NDEBUG
pdf::PDFWidgetUtils::checkMenuAccessibility(this);
#endif
2021-09-27 11:14:20 +02:00
}
2024-03-16 17:02:44 +01:00
PDFEditorMainWindow::~PDFEditorMainWindow()
2021-09-27 11:14:20 +02:00
{
delete m_programController;
m_programController = nullptr;
delete m_actionManager;
m_actionManager = nullptr;
delete ui;
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::onActionQuitTriggered()
2021-09-27 11:14:20 +02:00
{
close();
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::onPageNumberSpinboxEditingFinished()
2021-09-27 11:14:20 +02:00
{
if (m_isLoadingUI)
{
return;
}
if (m_pageNumberSpinBox->hasFocus())
{
m_programController->getPdfWidget()->setFocus();
}
m_programController->getPdfWidget()->getDrawWidgetProxy()->goToPage(m_pageNumberSpinBox->value() - 1);
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::onPageZoomSpinboxEditingFinished()
2021-09-27 11:14:20 +02:00
{
if (m_isLoadingUI)
{
return;
}
if (m_pageZoomSpinBox->hasFocus())
{
m_programController->getPdfWidget()->setFocus();
}
m_programController->getPdfWidget()->getDrawWidgetProxy()->zoom(m_pageZoomSpinBox->value() / 100.0);
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::onProgressStarted(pdf::ProgressStartupInfo info)
2021-09-27 11:14:20 +02:00
{
m_progressBarLeftLabelOnStatusBar->setText(info.text);
m_progressBarLeftLabelOnStatusBar->setVisible(!info.text.isEmpty());
m_progressBarOnStatusBar->setRange(0, 100);
m_progressBarOnStatusBar->reset();
m_progressBarOnStatusBar->show();
2021-09-27 11:14:20 +02:00
m_progressTaskbarIndicator->setRange(0, 100);
m_progressTaskbarIndicator->reset();
m_progressTaskbarIndicator->show();
m_programController->setIsBusy(true);
m_programController->updateActionsAvailability();
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::onProgressStep(int percentage)
2021-09-27 11:14:20 +02:00
{
if (m_isChangingProgressStep)
{
return;
}
pdf::PDFTemporaryValueChange guard(&m_isChangingProgressStep, true);
m_progressBarOnStatusBar->setValue(percentage);
2021-09-27 11:14:20 +02:00
m_progressTaskbarIndicator->setValue(percentage);
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::onProgressFinished()
2021-09-27 11:14:20 +02:00
{
m_progressBarLeftLabelOnStatusBar->hide();
m_progressBarOnStatusBar->hide();
2021-09-27 11:14:20 +02:00
m_progressTaskbarIndicator->hide();
m_programController->setIsBusy(false);
m_programController->updateActionsAvailability();
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::updateDeveloperMenu()
2021-09-27 11:14:20 +02:00
{
bool isDeveloperMode = m_programController->getSettings()->getSettings().m_allowDeveloperMode;
ui->menuDeveloper->menuAction()->setVisible(isDeveloperMode);
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::updateUI(bool fullUpdate)
2021-09-27 11:14:20 +02:00
{
pdf::PDFTemporaryValueChange guard(&m_isLoadingUI, true);
if (fullUpdate)
{
if (pdf::PDFDocument* document = m_programController->getDocument())
{
size_t pageCount = document->getCatalog()->getPageCount();
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());
}
}
else
{
std::vector<pdf::PDFInteger> currentPages = m_programController->getPdfWidget()->getDrawWidget()->getCurrentPages();
if (!currentPages.empty())
{
m_pageNumberSpinBox->setValue(currentPages.front() + 1);
// Prefetch pages, if it is enabled
if (m_programController->getSettings()->isPagePrefetchingEnabled())
{
m_programController->getPdfWidget()->getDrawWidgetProxy()->prefetchPages(currentPages.back());
}
}
m_sidebarWidget->setCurrentPages(currentPages);
}
m_pageZoomSpinBox->setValue(m_programController->getPdfWidget()->getDrawWidgetProxy()->getZoom() * 100);
}
2024-03-16 17:02:44 +01:00
QMenu* PDFEditorMainWindow::addToolMenu(QString name)
2021-09-27 11:14:20 +02:00
{
return ui->menuTools->addMenu(name);
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::setStatusBarMessage(QString message, int time)
2021-09-27 11:14:20 +02:00
{
statusBar()->showMessage(message, time);
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::setDocument(const pdf::PDFModifiedDocument& document)
2021-09-27 11:14:20 +02:00
{
if (m_sidebarWidget)
{
m_sidebarWidget->setDocument(document, *m_programController->getSignatures());
}
if (m_advancedFindWidget)
{
m_advancedFindWidget->setDocument(document);
}
if (m_sidebarWidget)
{
if (m_sidebarWidget->isEmpty())
{
m_sidebarDockWidget->hide();
}
else if (document.hasReset() && !document.hasPreserveUndoRedo())
2021-09-27 11:14:20 +02:00
{
m_sidebarDockWidget->show();
}
}
if (!document && m_advancedFindDockWidget)
{
m_advancedFindDockWidget->hide();
}
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::adjustToolbar(QToolBar* toolbar)
2021-09-27 11:14:20 +02:00
{
QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(24, 24));
toolbar->setIconSize(iconSize);
}
2024-03-16 17:02:44 +01:00
pdf::PDFTextSelection PDFEditorMainWindow::getSelectedText() const
2021-09-27 11:14:20 +02:00
{
if (!m_advancedFindWidget)
{
return pdf::PDFTextSelection();
}
return m_advancedFindWidget->getSelectedText();
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::closeEvent(QCloseEvent* event)
2021-09-27 11:14:20 +02:00
{
if (!m_programController->canClose())
{
// Jakub Melka: Do not allow to close the application, if document
// reading is running.
event->ignore();
}
else
{
2023-02-26 18:37:27 +01:00
if (!m_programController->askForSaveDocumentBeforeClose())
{
// User cancelled close operation
event->ignore();
return;
}
if (!m_programController->isFactorySettingsBeingRestored())
{
m_programController->writeSettings();
}
2021-09-27 11:14:20 +02:00
m_programController->closeDocument();
event->accept();
}
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::showEvent(QShowEvent* event)
2021-09-27 11:14:20 +02:00
{
QMainWindow::showEvent(event);
m_progressTaskbarIndicator->setWindow(windowHandle());
2021-09-27 11:14:20 +02:00
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::dragEnterEvent(QDragEnterEvent* event)
2021-09-27 11:14:20 +02:00
{
if (event->mimeData()->hasUrls())
{
event->setDropAction(Qt::LinkAction);
event->accept();
}
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::dragMoveEvent(QDragMoveEvent* event)
2021-09-27 11:14:20 +02:00
{
if (event->mimeData()->hasUrls())
{
event->setDropAction(Qt::LinkAction);
event->accept();
}
}
2024-03-16 17:02:44 +01:00
void PDFEditorMainWindow::dropEvent(QDropEvent* event)
2021-09-27 11:14:20 +02:00
{
if (event->mimeData()->hasUrls())
{
QList<QUrl> urls = event->mimeData()->urls();
if (urls.size() == 1)
{
m_programController->openDocument(urls.front().toLocalFile());
event->acceptProposedAction();
}
}
}
} // namespace pdfviewer