From 93a4b4733291bfcbfb65e3b1ac2fbbf71910938f Mon Sep 17 00:00:00 2001 From: Simone Gaiarin Date: Wed, 28 Oct 2020 07:33:28 +0100 Subject: [PATCH] Remember last used quick annotation tool A limitation of the current implementation is that when the quick annotation tools are modified by the user, the first quick annotation tool is selected. This because the order of the quick annotation tools may be changed and some tools may have been deleted. --- conf/okular.kcfg | 3 +++ part/annotationactionhandler.cpp | 23 +++++++++++++++++++++-- part/pageviewannotator.cpp | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/conf/okular.kcfg b/conf/okular.kcfg index 873b231e9..f5d37333f 100644 --- a/conf/okular.kcfg +++ b/conf/okular.kcfg @@ -163,6 +163,9 @@ true + + 0 + diff --git a/part/annotationactionhandler.cpp b/part/annotationactionhandler.cpp index 7d46590ad..196d28596 100644 --- a/part/annotationactionhandler.cpp +++ b/part/annotationactionhandler.cpp @@ -32,6 +32,7 @@ #include "guiutils.h" #include "pageview.h" #include "pageviewannotator.h" +#include "settings.h" #include "toggleactionmenu.h" class AnnotationActionHandlerPrivate @@ -353,6 +354,7 @@ void AnnotationActionHandlerPrivate::populateQuickAnnotations() q->deselectAllAnnotationActions(); } + const bool isFirstTimePopulated = quickTools->count() == 0; for (auto action : *quickTools) { action->setShortcut(QKeySequence()); aQuickTools->removeAction(action); @@ -388,9 +390,24 @@ void AnnotationActionHandlerPrivate::populateQuickAnnotations() favToolElement = annotator->quickTool(++favToolId); } - if (!quickTools->isEmpty()) { - aQuickTools->setDefaultAction(quickTools->at(0)); + + if (quickTools->isEmpty()) { + aQuickTools->setDefaultAction(aQuickTools); + Okular::Settings::setQuickAnnotationDefaultAction(0); + Okular::Settings::self()->save(); + } else { + int defaultAction = Okular::Settings::quickAnnotationDefaultAction(); + if (isFirstTimePopulated && defaultAction < quickTools->count()) { + // we can reach here also if no quick tools were defined before, in that case defaultAction is correctly equal to zero + aQuickTools->setDefaultAction(quickTools->at(defaultAction)); + } else { + // if the quick tools have been modified we cannot restore the previous default action + aQuickTools->setDefaultAction(quickTools->at(0)); + Okular::Settings::setQuickAnnotationDefaultAction(0); + Okular::Settings::self()->save(); + } } + QAction *separator = new QAction(); separator->setSeparator(true); aQuickTools->addAction(separator); @@ -467,6 +484,8 @@ void AnnotationActionHandlerPrivate::slotQuickToolSelected(int favToolId) annotator->selectQuickTool(favToolId); selectedBuiltinTool = -1; updateConfigActions(); + Okular::Settings::setQuickAnnotationDefaultAction(favToolId - 1); + Okular::Settings::self()->save(); } void AnnotationActionHandlerPrivate::slotSetColor(AnnotationColor colorType, const QColor &color) diff --git a/part/pageviewannotator.cpp b/part/pageviewannotator.cpp index a805e0e99..a6d55bdc9 100644 --- a/part/pageviewannotator.cpp +++ b/part/pageviewannotator.cpp @@ -890,7 +890,7 @@ PageViewAnnotator::PageViewAnnotator(PageView *parent, Okular::Document *storage reparseBuiltinToolsConfig(); reparseQuickToolsConfig(); connect(Okular::Settings::self(), &Okular::Settings::builtinAnnotationToolsChanged, this, &PageViewAnnotator::reparseBuiltinToolsConfig); - connect(Okular::Settings::self(), &Okular::Settings::quickAnnotationToolsChanged, this, &PageViewAnnotator::reparseQuickToolsConfig); + connect(Okular::Settings::self(), &Okular::Settings::quickAnnotationToolsChanged, this, &PageViewAnnotator::reparseQuickToolsConfig, Qt::QueuedConnection); } void PageViewAnnotator::reparseConfig()