Commit 230a68d5 authored by Simone Gaiarin's avatar Simone Gaiarin Committed by Albert Astals Cid
Browse files

Uncheck mouse mode action when annotation tool selected

When the annotation is unchecked the previous mouse mode is restored.

The slot slotMouseNormalToggled is changed back to its original version
of slotSetMouseNormal given that we needed to pass the checked state
only to detach the annotations, and we do it in the lambda now.

BUG: 398108

BUG: 437377

FIXED-IN: 21.08
parent 67a54bd8
Pipeline #66617 passed with stage
in 12 minutes and 56 seconds
......@@ -184,37 +184,43 @@ void AnnotationToolBarTest::testAnnotationToolBar()
QTest::keyClick(part->widget(), Qt::Key_3);
QTRY_VERIFY2(!annToolBar->isVisible(), "ToolBar shown when triggering quick annotation using shortcut.");
// set mouse mode to browse before starting the tests on the annotation actions
QAction *aMouseNormal = part->actionCollection()->action(QStringLiteral("mouse_drag"));
QVERIFY(aMouseNormal);
aMouseNormal->trigger();
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
// Click an annotation action to enable it
QAction *aPopupNote = part->actionCollection()->action(QStringLiteral("annotation_popup_note"));
QVERIFY(aPopupNote);
aPopupNote->trigger();
int mouseX = 350;
int mouseY = 100;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
QTRY_COMPARE(aMouseNormal->isChecked(), false);
// Click again the same annotation action to disable it
aPopupNote->trigger();
mouseY = 150;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), false);
QTRY_COMPARE(aMouseNormal->isChecked(), true);
// Trigger the action using a shortcut
QTest::keyClick(part->widget(), Qt::Key_7, Qt::AltModifier);
mouseY = 200;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
QTRY_COMPARE(aMouseNormal->isChecked(), false);
// Click Esc to disable all annotations
QTest::keyClick(pageView(part), Qt::Key_Escape);
mouseY = 250;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), false);
QTRY_COMPARE(aMouseNormal->isChecked(), true);
// Trigger the action using a quick annotation shortcut
QTest::keyClick(part->widget(), Qt::Key_6);
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
QTRY_COMPARE(aMouseNormal->isChecked(), false);
// Test pin/continuous mode action
QVERIFY(aContinuousMode->isEnabled());
......
......@@ -657,7 +657,7 @@ void PageView::setupViewerActions(KActionCollection *ac)
d->mouseModeActionGroup->setExclusive(true);
d->aMouseNormal = new QAction(QIcon::fromTheme(QStringLiteral("transform-browse")), i18n("&Browse"), this);
ac->addAction(QStringLiteral("mouse_drag"), d->aMouseNormal);
connect(d->aMouseNormal, &QAction::toggled, this, &PageView::slotMouseNormalToggled);
connect(d->aMouseNormal, &QAction::triggered, this, &PageView::slotSetMouseNormal);
d->aMouseNormal->setCheckable(true);
ac->setDefaultShortcut(d->aMouseNormal, QKeySequence(Qt::CTRL | Qt::Key_1));
d->aMouseNormal->setActionGroup(d->mouseModeActionGroup);
......@@ -816,8 +816,36 @@ void PageView::setupActions(KActionCollection *ac)
kredo->setEnabled(false);
d->annotator = new PageViewAnnotator(this, d->document);
connect(d->annotator, &PageViewAnnotator::toolSelected, d->aMouseNormal, &QAction::trigger);
connect(d->annotator, &PageViewAnnotator::toolSelected, d->mouseAnnotation, &MouseAnnotation::reset);
connect(d->annotator, &PageViewAnnotator::toolActive, this, [&](bool selected) {
if (selected) {
QAction *aMouseMode = d->mouseModeActionGroup->checkedAction();
if (aMouseMode) {
aMouseMode->setChecked(false);
}
} else {
switch (d->mouseMode) {
case Okular::Settings::EnumMouseMode::Browse:
d->aMouseNormal->setChecked(true);
break;
case Okular::Settings::EnumMouseMode::Zoom:
d->aMouseZoom->setChecked(true);
break;
case Okular::Settings::EnumMouseMode::RectSelect:
d->aMouseSelect->setChecked(true);
break;
case Okular::Settings::EnumMouseMode::TableSelect:
d->aMouseTableSelect->setChecked(true);
break;
case Okular::Settings::EnumMouseMode::Magnifier:
d->aMouseMagnifier->setChecked(true);
break;
case Okular::Settings::EnumMouseMode::TextSelect:
d->aMouseTextSelect->setChecked(true);
break;
}
}
});
connect(d->annotator, &PageViewAnnotator::toolActive, d->mouseAnnotation, &MouseAnnotation::reset);
connect(d->annotator, &PageViewAnnotator::requestOpenFile, this, &PageView::requestOpenFile);
d->annotator->setupActions(ac);
}
......@@ -4763,19 +4791,16 @@ void PageView::slotUpdateReadingDirectionAction()
d->aReadingDirection->setChecked(Okular::Settings::rtlReadingDirection());
}
void PageView::slotMouseNormalToggled(bool checked)
void PageView::slotSetMouseNormal()
{
if (checked) {
d->mouseMode = Okular::Settings::EnumMouseMode::Browse;
Okular::Settings::setMouseMode(d->mouseMode);
// hide the messageWindow
d->messageWindow->hide();
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
} else {
d->annotator->detachAnnotation();
}
d->mouseMode = Okular::Settings::EnumMouseMode::Browse;
Okular::Settings::setMouseMode(d->mouseMode);
// hide the messageWindow
d->messageWindow->hide();
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
d->annotator->detachAnnotation();
}
void PageView::slotSetMouseZoom()
......@@ -4787,6 +4812,7 @@ void PageView::slotSetMouseZoom()
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
d->annotator->detachAnnotation();
}
void PageView::slotSetMouseMagnifier()
......@@ -4798,6 +4824,7 @@ void PageView::slotSetMouseMagnifier()
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
d->annotator->detachAnnotation();
}
void PageView::slotSetMouseSelect()
......@@ -4809,6 +4836,7 @@ void PageView::slotSetMouseSelect()
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
d->annotator->detachAnnotation();
}
void PageView::slotSetMouseTextSelect()
......@@ -4820,6 +4848,7 @@ void PageView::slotSetMouseTextSelect()
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
d->annotator->detachAnnotation();
}
void PageView::slotSetMouseTableSelect()
......@@ -4831,6 +4860,7 @@ void PageView::slotSetMouseTableSelect()
// force an update of the cursor
updateCursor();
Okular::Settings::self()->save();
d->annotator->detachAnnotation();
}
void PageView::slotSignature()
......
......@@ -262,7 +262,7 @@ private Q_SLOTS:
void slotContinuousToggled();
void slotReadingDirectionToggled(bool leftToRight);
void slotUpdateReadingDirectionAction();
void slotMouseNormalToggled(bool);
void slotSetMouseNormal();
void slotSetMouseZoom();
void slotSetMouseMagnifier();
void slotSetMouseSelect();
......
......@@ -1198,6 +1198,7 @@ void PageViewAnnotator::selectTool(AnnotationTools *toolsDefinition, int toolId,
if (toolId == -1) {
m_pageView->displayMessage(QString());
m_pageView->updateCursor();
emit toolActive(false);
return;
}
......@@ -1265,8 +1266,7 @@ void PageViewAnnotator::selectTool(AnnotationTools *toolsDefinition, int toolId,
m_pageView->updateCursor();
}
if (toolId > 0)
emit toolSelected();
emit toolActive(true);
}
void PageViewAnnotator::selectLastTool()
......
......@@ -137,7 +137,10 @@ public Q_SLOTS:
void slotAdvancedSettings();
Q_SIGNALS:
void toolSelected();
/**
* This signal is emitted whenever an annotation tool is activated or all the tools get deactivated
*/
void toolActive(bool active);
void requestOpenFile(const QString &filePath, int pageNumber);
private:
......
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