From 8faa96a062f36af3c5e664a1680e2ba092d42a9e Mon Sep 17 00:00:00 2001 From: idotobi <16611056+idotobi@users.noreply.github.com> Date: Sat, 4 Jul 2020 11:02:35 +0200 Subject: [PATCH] Base color selection behaviour on capabilities --- src/control/ToolHandler.cpp | 10 ++++++++-- src/control/ToolHandler.h | 2 +- src/gui/toolbarMenubar/ColorToolItem.cpp | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index a5cdb03d..7479e97d 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -161,7 +161,13 @@ auto ToolHandler::getTool(ToolType type) -> Tool& { return *(this->tools[type - auto ToolHandler::getToolType() -> ToolType { return this->currentTool->type; } -auto ToolHandler::hasCapability(ToolCapabilities cap) -> bool { return (currentTool->capabilities & cap) != 0; } +auto ToolHandler::hasCapability(ToolCapabilities cap, bool mainTool) -> bool { + if (mainTool == false) { + return (currentTool->capabilities & cap) != 0; + } else { + return (toolbarSelectedTool->capabilities & cap) != 0; + } +} auto ToolHandler::getSize() -> ToolSize { return this->currentTool->getSize(); } @@ -261,7 +267,7 @@ void ToolHandler::setLineStyle(const LineStyle& style) { * and therefore should not be applied to a selection */ void ToolHandler::setColor(Color color, bool userSelection) { - if (this->buttonSelectedTool->type == TOOL_ERASER) { + if ((this->buttonSelectedTool->capabilities & TOOL_CAP_COLOR) == 0) { this->toolbarSelectedTool->setColor(color); } this->currentTool->setColor(color); diff --git a/src/control/ToolHandler.h b/src/control/ToolHandler.h index c2957249..0bd71614 100644 --- a/src/control/ToolHandler.h +++ b/src/control/ToolHandler.h @@ -98,7 +98,7 @@ public: EraserType getEraserType(); void eraserTypeChanged(); - bool hasCapability(ToolCapabilities cap); + bool hasCapability(ToolCapabilities cap, bool mainTool = false); void saveSettings(); void loadSettings(); diff --git a/src/gui/toolbarMenubar/ColorToolItem.cpp b/src/gui/toolbarMenubar/ColorToolItem.cpp index 60dea164..56e2da4f 100644 --- a/src/gui/toolbarMenubar/ColorToolItem.cpp +++ b/src/gui/toolbarMenubar/ColorToolItem.cpp @@ -2,6 +2,7 @@ #include +#include "control/ToolEnums.h" #include "gui/toolbarMenubar/icon/ColorSelectImage.h" #include "model/ToolbarColorNames.h" @@ -105,9 +106,10 @@ void ColorToolItem::showColorchooser() { * Enable / Disable the tool item */ void ColorToolItem::enable(bool enabled) { - if (!enabled && toolHandler->getToolType() == TOOL_ERASER) { + if (!enabled && !toolHandler->hasCapability(TOOL_CAP_COLOR) && toolHandler->hasCapability(TOOL_CAP_COLOR, true)) { if (this->icon && toolHandler->triggeredByButton) { - // allow changes in color if eraser only set via stylus + // allow changes if currentTool has no colour capability + // and mainTool has Colour capability icon->setState(COLOR_ICON_STATE_PEN); AbstractToolItem::enable(true); } else {