Bugfix: Tool not deactivated when text highlight tool was activated

This commit is contained in:
Jakub Melka 2020-12-13 17:07:01 +01:00
parent 9b9734ffd1
commit 5f13474710
3 changed files with 23 additions and 0 deletions

View File

@ -744,6 +744,8 @@ void PDFToolManager::addTool(PDFWidgetTool* tool)
m_actionsToTools[action] = tool;
connect(action, &QAction::triggered, this, &PDFToolManager::onToolActionTriggered);
}
connect(tool, &PDFWidgetTool::toolActivityChanged, this, &PDFToolManager::onToolActivityChanged);
}
void PDFToolManager::setDocument(const PDFModifiedDocument& document)
@ -885,6 +887,22 @@ const std::optional<QCursor>& PDFToolManager::getCursor() const
return dummy;
}
void PDFToolManager::onToolActivityChanged(bool active)
{
if (active)
{
// When tool is activated outside, we must deactivate old active tool
PDFWidgetTool* tool = qobject_cast<PDFWidgetTool*>(sender());
for (PDFWidgetTool* currentTool : m_tools)
{
if (currentTool->isActive() && currentTool != tool)
{
currentTool->setActive(false);
}
}
}
}
void PDFToolManager::onToolActionTriggered(bool checked)
{
PDFWidgetTool* tool = m_actionsToTools.at(qobject_cast<QAction*>(sender()));

View File

@ -525,6 +525,7 @@ signals:
void documentModified(PDFModifiedDocument document);
private:
void onToolActivityChanged(bool active);
void onToolActionTriggered(bool checked);
std::set<PDFWidgetTool*> m_tools;

View File

@ -265,6 +265,10 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
// Tools
ui->mainToolBar->addAction(ui->actionSelectText);
ui->mainToolBar->addAction(ui->actionCreateTextHighlight);
ui->mainToolBar->addAction(ui->actionCreateTextUnderline);
ui->mainToolBar->addAction(ui->actionCreateTextStrikeout);
ui->mainToolBar->addAction(ui->actionCreateTextSquiggly);
ui->mainToolBar->addAction(ui->actionMagnifier);
ui->mainToolBar->addAction(ui->actionScreenshot);
ui->mainToolBar->addAction(ui->actionExtractImage);