mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Issue #54: Finishing of bookmarking
This commit is contained in:
@ -210,6 +210,9 @@ void PDFActionManager::initActions(QSize iconSize, bool initializeStampActions)
|
||||
setShortcut(GoToPreviousPage, QKeySequence::MoveToPreviousPage);
|
||||
setShortcut(GoToNextLine, QKeySequence::MoveToNextLine);
|
||||
setShortcut(GoToPreviousLine, QKeySequence::MoveToPreviousLine);
|
||||
setShortcut(BookmarkPage, QKeySequence("Ctrl+M"));
|
||||
setShortcut(BookmarkGoToNext, QKeySequence("Ctrl+."));
|
||||
setShortcut(BookmarkGoToPrevious, QKeySequence("Ctrl+,"));
|
||||
|
||||
if (hasActions({ CreateStickyNoteComment, CreateStickyNoteHelp, CreateStickyNoteInsert, CreateStickyNoteKey, CreateStickyNoteNewParagraph, CreateStickyNoteNote, CreateStickyNoteParagraph }))
|
||||
{
|
||||
@ -403,6 +406,8 @@ void PDFProgramController::initializeFormManager()
|
||||
void PDFProgramController::initializeBookmarkManager()
|
||||
{
|
||||
m_bookmarkManager = new PDFBookmarkManager(this);
|
||||
connect(m_bookmarkManager, &PDFBookmarkManager::bookmarkActivated, this, &PDFProgramController::onBookmarkActivated);
|
||||
updateBookmarkSettings();
|
||||
}
|
||||
|
||||
void PDFProgramController::initialize(Features features,
|
||||
@ -581,6 +586,30 @@ void PDFProgramController::initialize(Features features,
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionAutomaticDocumentRefresh);
|
||||
}
|
||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkPage))
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionBookmarkPage);
|
||||
}
|
||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkGoToNext))
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionBookmarkGoToNext);
|
||||
}
|
||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkGoToPrevious))
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionBookmarkGoToPrevious);
|
||||
}
|
||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkExport))
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionBookmarkExport);
|
||||
}
|
||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkImport))
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionBookmarkImport);
|
||||
}
|
||||
if (QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkGenerateAutomatically))
|
||||
{
|
||||
connect(action, &QAction::triggered, this, &PDFProgramController::onActionBookmarkGenerateAutomatically);
|
||||
}
|
||||
|
||||
if (m_recentFileManager)
|
||||
{
|
||||
@ -1559,6 +1588,8 @@ void PDFProgramController::readSettings(Settings settingsFlags)
|
||||
{
|
||||
m_formManager->setAppearanceFlags(m_settings->getSettings().m_formAppearanceFlags);
|
||||
}
|
||||
|
||||
updateBookmarkSettings();
|
||||
}
|
||||
|
||||
if (settingsFlags.testFlag(PluginsSettings))
|
||||
@ -1712,6 +1743,13 @@ void PDFProgramController::onFileChanged(const QString& fileName)
|
||||
}
|
||||
}
|
||||
|
||||
void PDFProgramController::onBookmarkActivated(int index, PDFBookmarkManager::Bookmark bookmark)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
|
||||
m_pdfWidget->getDrawWidgetProxy()->goToPage(bookmark.pageIndex);
|
||||
}
|
||||
|
||||
void PDFProgramController::updateFileInfo(const QString& fileName)
|
||||
{
|
||||
QFileInfo fileInfo(fileName);
|
||||
@ -1996,6 +2034,22 @@ void PDFProgramController::updateRenderingOptionActions()
|
||||
}
|
||||
}
|
||||
|
||||
void PDFProgramController::updateBookmarkSettings()
|
||||
{
|
||||
const bool enable = m_settings->getSettings().m_autoGenerateBookmarks;
|
||||
|
||||
if (m_bookmarkManager)
|
||||
{
|
||||
m_bookmarkManager->setGenerateBookmarksAutomatically(enable);
|
||||
}
|
||||
|
||||
QAction* action = m_actionManager->getAction(PDFActionManager::BookmarkGenerateAutomatically);
|
||||
if (action)
|
||||
{
|
||||
action->setChecked(enable);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFProgramController::updateTitle()
|
||||
{
|
||||
if (m_pdfDocument)
|
||||
@ -2550,6 +2604,53 @@ void PDFProgramController::onActionAutomaticDocumentRefresh()
|
||||
updateFileWatcher();
|
||||
}
|
||||
|
||||
void PDFProgramController::onActionBookmarkPage()
|
||||
{
|
||||
std::vector<pdf::PDFInteger> currentPages = m_pdfWidget->getDrawWidget()->getCurrentPages();
|
||||
if (!currentPages.empty())
|
||||
{
|
||||
m_bookmarkManager->toggleBookmark(currentPages.front());
|
||||
}
|
||||
}
|
||||
|
||||
void PDFProgramController::onActionBookmarkGoToNext()
|
||||
{
|
||||
m_bookmarkManager->goToNextBookmark();
|
||||
}
|
||||
|
||||
void PDFProgramController::onActionBookmarkGoToPrevious()
|
||||
{
|
||||
m_bookmarkManager->goToPreviousBookmark();
|
||||
}
|
||||
|
||||
void PDFProgramController::onActionBookmarkExport()
|
||||
{
|
||||
QFileInfo fileInfo(m_fileInfo.originalFileName);
|
||||
QString saveFileName = QFileDialog::getSaveFileName(m_mainWindow, tr("Export Bookmarks As"), fileInfo.dir().absoluteFilePath(m_fileInfo.originalFileName).replace(".pdf", ".json"), tr("JSON (*.json);;All files (*.*)"));
|
||||
if (!saveFileName.isEmpty())
|
||||
{
|
||||
m_bookmarkManager->saveToFile(saveFileName);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFProgramController::onActionBookmarkImport()
|
||||
{
|
||||
QFileInfo fileInfo(m_fileInfo.originalFileName);
|
||||
QString fileName = QFileDialog::getOpenFileName(m_mainWindow, tr("Select PDF document"), fileInfo.dir().absolutePath(), tr("JSON (*.json)"));
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
m_bookmarkManager->loadFromFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
void PDFProgramController::onActionBookmarkGenerateAutomatically(bool checked)
|
||||
{
|
||||
auto settings = m_settings->getSettings();
|
||||
settings.m_autoGenerateBookmarks = checked;
|
||||
m_settings->setSettings(settings);
|
||||
m_bookmarkManager->setGenerateBookmarksAutomatically(checked);
|
||||
}
|
||||
|
||||
void PDFProgramController::onPageRenderingErrorsChanged(pdf::PDFInteger pageIndex, int errorsCount)
|
||||
{
|
||||
if (errorsCount > 0)
|
||||
|
Reference in New Issue
Block a user