Commit 6b61909a authored by Simone Gaiarin's avatar Simone Gaiarin
Browse files

Select quick tool directly without proxying a builtin annotation

parent 3f18367e
......@@ -68,7 +68,7 @@ public:
, currentInnerColor(QColor())
, currentFont(QFont())
, currentWidth(-1)
, selectedTool(-1)
, selectedBuiltinTool(-1)
, textToolsEnabled(false)
{
}
......@@ -133,7 +133,7 @@ public:
QFont currentFont;
int currentWidth;
int selectedTool;
int selectedBuiltinTool;
bool textToolsEnabled;
};
......@@ -425,7 +425,7 @@ const QIcon AnnotationActionHandlerPrivate::stampIcon(const QString &stampIconNa
void AnnotationActionHandlerPrivate::selectTool(int toolId)
{
selectedTool = toolId;
selectedBuiltinTool = toolId;
annotator->selectBuiltinTool(toolId, PageViewAnnotator::ShowTip::Yes);
parseTool(toolId);
}
......@@ -433,44 +433,15 @@ void AnnotationActionHandlerPrivate::selectTool(int toolId)
void AnnotationActionHandlerPrivate::slotStampToolSelected(const QString &stamp)
{
KMessageBox::information(nullptr, i18nc("@info", "Stamps inserted in PDF documents are not visible in PDF readers other than Okular"), i18nc("@title:window", "Experimental feature"), QStringLiteral("stampAnnotationWarning"));
selectedTool = PageViewAnnotator::STAMP_TOOL_ID;
selectedBuiltinTool = PageViewAnnotator::STAMP_TOOL_ID;
annotator->selectStampTool(stamp); // triggers a reparsing thus calling parseTool
}
void AnnotationActionHandlerPrivate::slotQuickToolSelected(int favToolId)
{
int toolId = annotator->setQuickTool(favToolId); // always triggers an unuseful reparsing
if (toolId == -1) {
qWarning("Corrupted configuration for quick annotation tool with id: %d", favToolId);
return;
}
int indexOfActionInGroup = toolId - 1;
if (toolId == PageViewAnnotator::STAMP_TOOL_ID) {
// if the quick tool is a stamp we need to find its corresponding built-in tool action and select it
QDomElement favToolElement = annotator->quickTool(favToolId);
QDomElement engineElement = favToolElement.firstChildElement(QStringLiteral("engine"));
QDomElement annotationElement = engineElement.firstChildElement(QStringLiteral("annotation"));
QString stampIconName = annotationElement.attribute(QStringLiteral("icon"));
const auto defaultStamps = StampAnnotationWidget::defaultStamps();
auto it = std::find_if(defaultStamps.begin(), defaultStamps.end(), [&stampIconName](const QPair<QString, QString> &element) { return element.second == stampIconName; });
if (it != defaultStamps.end()) {
int stampActionIndex = std::distance(defaultStamps.begin(), it);
indexOfActionInGroup = PageViewAnnotator::STAMP_TOOL_ID + stampActionIndex - 1;
} else {
maybeUpdateCustomStampAction(stampIconName);
indexOfActionInGroup = agTools->actions().size() - 1;
}
}
QAction *favToolAction = agTools->actions().at(indexOfActionInGroup);
if (!favToolAction->isChecked()) {
// action group workaround: activates the action slot calling selectTool
// when new tool if different from the selected one
favToolAction->trigger();
} else {
selectTool(toolId);
}
aShowToolBar->setChecked(true);
annotator->selectQuickTool(favToolId);
selectedBuiltinTool = -1;
updateConfigActions();
}
void AnnotationActionHandlerPrivate::slotSetColor(AnnotationColor colorType, const QColor &color)
......@@ -741,7 +712,7 @@ void AnnotationActionHandler::setupAnnotationToolBarVisibilityAction()
void AnnotationActionHandler::reparseBuiltinToolsConfig()
{
d->parseTool(d->selectedTool);
d->parseTool(d->selectedBuiltinTool);
}
void AnnotationActionHandler::reparseQuickToolsConfig()
......
......@@ -882,6 +882,7 @@ PageViewAnnotator::PageViewAnnotator(PageView *parent, Okular::Document *storage
, m_continuousMode(true)
, m_constrainRatioAndAngle(false)
, m_signatureMode(false)
, m_lastToolsDefinition(nullptr)
, m_lastToolId(-1)
, m_lockedItem(nullptr)
{
......@@ -1154,6 +1155,11 @@ void PageViewAnnotator::selectBuiltinTool(int toolId, ShowTip showTip)
selectTool(m_builtinToolsDefinition, toolId, showTip);
}
void PageViewAnnotator::selectQuickTool(int toolId)
{
selectTool(m_quickToolsDefinition, toolId, ShowTip::Yes);
}
void PageViewAnnotator::selectTool(AnnotationTools *toolsDefinition, int toolId, ShowTip showTip)
{
// ask for Author's name if not already set
......@@ -1189,6 +1195,7 @@ void PageViewAnnotator::selectTool(AnnotationTools *toolsDefinition, int toolId,
// store current tool for later usage
m_lastToolId = toolId;
m_lastToolsDefinition = toolsDefinition;
// handle tool deselection
if (toolId == -1) {
......@@ -1267,7 +1274,7 @@ void PageViewAnnotator::selectTool(AnnotationTools *toolsDefinition, int toolId,
void PageViewAnnotator::selectLastTool()
{
selectBuiltinTool(m_lastToolId, ShowTip::No);
selectTool(m_lastToolsDefinition, m_lastToolId, ShowTip::No);
}
void PageViewAnnotator::selectStampTool(const QString &stampSymbol)
......@@ -1510,21 +1517,6 @@ void PageViewAnnotator::saveBuiltinAnnotationTools()
Okular::Settings::self()->save();
}
int PageViewAnnotator::setQuickTool(int favToolId)
{
int toolId = -1;
QDomElement favToolElement = m_quickToolsDefinition->tool(favToolId);
if (!favToolElement.isNull()) {
toolId = m_builtinToolsDefinition->findToolId(favToolElement.attribute(QStringLiteral("type")));
if (toolId == -1) {
return -1;
}
if (m_builtinToolsDefinition->updateTool(favToolElement, toolId))
saveBuiltinAnnotationTools();
}
return toolId;
}
QDomElement PageViewAnnotator::builtinTool(int toolId)
{
return m_builtinToolsDefinition->tool(toolId);
......
......@@ -110,8 +110,8 @@ public:
void selectBuiltinTool(int toolId, ShowTip showTip);
// selects a stamp tool and sets the stamp symbol
void selectStampTool(const QString &stampSymbol);
// makes a quick annotation the active tool
int setQuickTool(int toolId);
// selects the active quick tool
void selectQuickTool(int toolId);
// selects the last used tool
void selectLastTool();
// deselects the tool and uncheck all the annotation actions
......@@ -167,6 +167,7 @@ private:
bool m_signatureMode;
// creation related variables
AnnotationTools *m_lastToolsDefinition;
int m_lastToolId;
QRect m_lastDrawnRect;
PageViewItem *m_lockedItem;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment