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.
remotes/origin/work/spdx
Simone Gaiarin 5 years ago
parent 3d55184116
commit 93a4b47332
  1. 3
      conf/okular.kcfg
  2. 23
      part/annotationactionhandler.cpp
  3. 2
      part/pageviewannotator.cpp

@ -163,6 +163,9 @@
<entry key="AnnotationContinuousMode" type="Bool">
<default>true</default>
</entry>
<entry key="QuickAnnotationDefaultAction" type="UInt">
<default>0</default>
</entry>
</group>
<group name="Zoom">
<entry key="ZoomMode" type="UInt" >

@ -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)

@ -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()

Loading…
Cancel
Save