diff --git a/src/control/LastSelectedTool.cpp b/src/control/LastSelectedTool.cpp index 6d240f5b..24ae14a4 100644 --- a/src/control/LastSelectedTool.cpp +++ b/src/control/LastSelectedTool.cpp @@ -14,3 +14,7 @@ auto LastSelectedTool::restoreAndGet() -> Tool* { return tool; } + +auto LastSelectedTool::getToolType() -> ToolType { return this->tool->getToolType(); } + +void LastSelectedTool::setColor(int color) { this->tool->setColor(color); } \ No newline at end of file diff --git a/src/control/LastSelectedTool.h b/src/control/LastSelectedTool.h index e219178b..55f82e7f 100644 --- a/src/control/LastSelectedTool.h +++ b/src/control/LastSelectedTool.h @@ -30,6 +30,10 @@ public: */ Tool* restoreAndGet(); + ToolType getToolType(); + + void setColor(int color); + private: /** * The last tool diff --git a/src/control/Tool.cpp b/src/control/Tool.cpp index 489e4471..0616d39b 100644 --- a/src/control/Tool.cpp +++ b/src/control/Tool.cpp @@ -30,3 +30,5 @@ void Tool::setCapability(int capability, bool enabled) { auto Tool::hasCapability(ToolCapabilities cap) const -> bool { return (this->capabilities & cap) != 0; } auto Tool::getThickness(ToolSize size) -> double { return this->thickness[size - TOOL_SIZE_VERY_FINE]; } + +auto Tool::getToolType() -> ToolType { return this->type; } diff --git a/src/control/Tool.h b/src/control/Tool.h index 5e8c4728..e38ec340 100644 --- a/src/control/Tool.h +++ b/src/control/Tool.h @@ -29,6 +29,8 @@ public: double getThickness(ToolSize size); + ToolType getToolType(); + protected: void setCapability(int capability, bool enabled); diff --git a/src/control/ToolBase.cpp b/src/control/ToolBase.cpp index 822c8b28..2b9b90d0 100644 --- a/src/control/ToolBase.cpp +++ b/src/control/ToolBase.cpp @@ -8,7 +8,7 @@ ToolBase::~ToolBase() = default; * Apply data from another ToolBase or any extending class */ void ToolBase::applyFrom(const ToolBase* t) { - this->color = t->color; + // this->color = t->color; this->size = t->size; this->drawingType = t->drawingType; this->fill = t->fill; diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index 14c4c8e1..3858d205 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -138,6 +138,13 @@ void ToolHandler::selectTool(ToolType type, bool fireToolChanged) { g_warning("unknown tool selected: %i\n", type); return; } + // if lastSelectedTool is set then eraser was only set + // temporarily using the stylus buttons + if (type == TOOL_ERASER && this->lastSelectedTool) { + this->triggeredByStylusButton = true; + } else { + this->triggeredByStylusButton = false; + } this->current = tools[type - TOOL_PEN].get(); if (fireToolChanged) { @@ -252,6 +259,13 @@ void ToolHandler::setLineStyle(const LineStyle& style) { * and therefore should not be applied to a selection */ void ToolHandler::setColor(Color color, bool userSelection) { + // TODO: execption rased when switching to eraser in the menu bar + // - Cause: lastSelectedTool not set + if (this->current->type == TOOL_ERASER && this->lastSelectedTool) { + this->lastSelectedTool->setColor(color); + this->listener->toolColorChanged(userSelection); + this->listener->setCustomColorSelected(); + } this->current->setColor(color); this->listener->toolColorChanged(userSelection); this->listener->setCustomColorSelected(); diff --git a/src/control/ToolHandler.h b/src/control/ToolHandler.h index dd35d363..eb31f7e6 100644 --- a/src/control/ToolHandler.h +++ b/src/control/ToolHandler.h @@ -123,6 +123,8 @@ public: */ bool isSinglePageTool(); + bool triggeredByStylusButton = false; + protected: void initTools(); diff --git a/src/gui/toolbarMenubar/ColorToolItem.cpp b/src/gui/toolbarMenubar/ColorToolItem.cpp index 86ddaa77..8df7758d 100644 --- a/src/gui/toolbarMenubar/ColorToolItem.cpp +++ b/src/gui/toolbarMenubar/ColorToolItem.cpp @@ -106,15 +106,18 @@ void ColorToolItem::showColorchooser() { */ void ColorToolItem::enable(bool enabled) { if (!enabled && toolHandler->getToolType() == TOOL_ERASER) { - if (this->icon) { + if (this->icon && toolHandler->triggeredByStylusButton) { + // allow changes in color if eraser only set via stylus icon->setState(COLOR_ICON_STATE_PEN); + AbstractToolItem::enable(true); + } else { + // disallow changes in color + icon->setState(COLOR_ICON_STATE_DISABLED); + AbstractToolItem::enable(false); } - AbstractToolItem::enable(true); - switchToPen = true; return; } - switchToPen = false; AbstractToolItem::enable(enabled); if (this->icon) { if (enabled) { @@ -126,10 +129,6 @@ void ColorToolItem::enable(bool enabled) { } void ColorToolItem::activated(GdkEvent* event, GtkMenuItem* menuitem, GtkToolButton* toolbutton) { - if (switchToPen) { - toolHandler->selectTool(TOOL_PEN, true); - } - if (inUpdate) { return; } diff --git a/src/gui/toolbarMenubar/ColorToolItem.h b/src/gui/toolbarMenubar/ColorToolItem.h index aadc76a7..0cfce063 100644 --- a/src/gui/toolbarMenubar/ColorToolItem.h +++ b/src/gui/toolbarMenubar/ColorToolItem.h @@ -75,11 +75,6 @@ private: */ ColorSelectImage* icon = nullptr; - /** - * Switch to pen if the color icon is pressed - */ - bool switchToPen = false; - GtkWindow* parent = nullptr; ToolHandler* toolHandler = nullptr;