From 10445d12ab675c3c1fc43a84f2dff1b2636e5058 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Wed, 19 Dec 2018 19:43:08 +0100 Subject: [PATCH] Should fix unexpected color change fixes #558 --- .settings/language.settings.xml | 2 +- src/control/Control.cpp | 14 +++++++-- src/control/Control.h | 13 ++++++-- src/control/ToolHandler.cpp | 17 +++++++--- src/control/ToolHandler.h | 13 ++++++-- src/control/settings/ButtonConfig.cpp | 40 +++++++++++++----------- src/gui/toolbarMenubar/ColorToolItem.cpp | 8 ++--- 7 files changed, 72 insertions(+), 35 deletions(-) diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 85c30f84..ca7c0739 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/src/control/Control.cpp b/src/control/Control.cpp index 81146149..73636c35 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -1687,7 +1687,7 @@ void Control::toolChanged() // Update color if (toolHandler->isEnableColor()) { - toolColorChanged(); + toolColorChanged(false); } ActionType rulerAction = ACTION_NOT_SELECTED; @@ -1833,14 +1833,22 @@ void Control::toolSizeChanged() } } -void Control::toolColorChanged() +/** + * Select the color for the tool + * + * @param userSelection + * true if the user selected the color + * false if the color is selected by a tool change + * and therefore should not be applied to a selection + */ +void Control::toolColorChanged(bool userSelection) { XOJ_CHECK_TYPE(Control); fireActionSelected(GROUP_COLOR, ACTION_SELECT_COLOR); getCursor()->updateCursor(); - if (this->win && toolHandler->getColor() != -1) + if (userSelection && this->win && toolHandler->getColor() != -1) { EditSelection* sel = this->win->getXournal()->getSelection(); if (sel) diff --git a/src/control/Control.h b/src/control/Control.h index 9bbef8e8..0e4ebdb5 100644 --- a/src/control/Control.h +++ b/src/control/Control.h @@ -49,7 +49,8 @@ class PageTypeHandler; class PageTypeMenu; class BaseExportJob; -class Control : public ActionHandler, +class Control : + public ActionHandler, public ToolListener, public DocumentHandler, public RecentManagerListener, @@ -90,7 +91,15 @@ public: virtual void actionPerformed(ActionType type, ActionGroup group, GdkEvent* event, GtkMenuItem* menuitem, GtkToolButton* toolbutton, bool enabled); - virtual void toolColorChanged(); + /** + * Select the color for the tool + * + * @param userSelection + * true if the user selected the color + * false if the color is selected by a tool change + * and therefore should not be applied to a selection + */ + virtual void toolColorChanged(bool userSelection); virtual void setCustomColorSelected(); virtual void toolChanged(); virtual void toolSizeChanged(); diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index bea95440..8f166266 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -339,14 +339,23 @@ void ToolHandler::setSize(ToolSize size) this->listener->toolSizeChanged(); } -void ToolHandler::setColor(int color) +/** + * Select the color for the tool + * + * @param color Color + * @param userSelection + * true if the user selected the color + * false if the color is selected by a tool change + * and therefore should not be applied to a selection + */ +void ToolHandler::setColor(int color, bool userSelection) { XOJ_CHECK_TYPE(ToolHandler); this->colorFound = false; this->current->color = color; - this->listener->toolColorChanged(); + this->listener->toolColorChanged(userSelection); if (!colorFound) { @@ -544,7 +553,7 @@ void ToolHandler::restoreLastConfig() delete this->lastSelectedTool; this->lastSelectedTool = NULL; - this->listener->toolColorChanged(); + this->listener->toolColorChanged(false); this->listener->toolSizeChanged(); this->fireToolChanged(); } @@ -574,7 +583,7 @@ void ToolHandler::setSelectionEditTools(bool setColor, bool setSize) this->current->type == TOOL_SELECT_OBJECT || this->current->type == TOOL_PLAY_OBJECT) { - this->listener->toolColorChanged(); + this->listener->toolColorChanged(false); this->listener->toolSizeChanged(); this->fireToolChanged(); } diff --git a/src/control/ToolHandler.h b/src/control/ToolHandler.h index 1748ab30..ced59bc1 100644 --- a/src/control/ToolHandler.h +++ b/src/control/ToolHandler.h @@ -22,7 +22,7 @@ class LastSelectedTool; class ToolListener { public: - virtual void toolColorChanged() = 0; + virtual void toolColorChanged(bool userSelection) = 0; virtual void setCustomColorSelected() = 0; virtual void toolSizeChanged() = 0; virtual void toolChanged() = 0; @@ -38,7 +38,16 @@ public: ToolHandler(ToolListener* listener, ActionHandler* actionHandler, Settings* settings); virtual ~ToolHandler(); - void setColor(int color); + /** + * Select the color for the tool + * + * @param color Color + * @param userSelection + * true if the user selected the color + * false if the color is selected by a tool change + * and therefore should not be applied to a selection + */ + void setColor(int color, bool userSelection); int getColor(); DrawingType getDrawingType(); diff --git a/src/control/settings/ButtonConfig.cpp b/src/control/settings/ButtonConfig.cpp index 8d581e71..1cd42a90 100644 --- a/src/control/settings/ButtonConfig.cpp +++ b/src/control/settings/ButtonConfig.cpp @@ -44,34 +44,36 @@ void ButtonConfig::acceptActions(ToolHandler* toolHandler) { XOJ_CHECK_TYPE(ButtonConfig); - if (this->action != TOOL_NONE) + if (this->action == TOOL_NONE) { - toolHandler->selectTool(this->action, false); - - if (this->action == TOOL_PEN || this->action == TOOL_HILIGHTER) - { + return; + } - if (this->drawingType != DRAWING_TYPE_DONT_CHANGE) - { - toolHandler->setDrawingType(this->drawingType); - } + toolHandler->selectTool(this->action, false); - if (this->size != TOOL_SIZE_NONE) - { - toolHandler->setSize(this->size); - } - } + if (this->action == TOOL_PEN || this->action == TOOL_HILIGHTER) + { - if (this->action == TOOL_PEN || this->action == TOOL_HILIGHTER || this->action == TOOL_TEXT) + if (this->drawingType != DRAWING_TYPE_DONT_CHANGE) { - toolHandler->setColor(this->color); + toolHandler->setDrawingType(this->drawingType); } - if (this->action == TOOL_ERASER && this->eraserMode != ERASER_TYPE_NONE) + if (this->size != TOOL_SIZE_NONE) { - toolHandler->setEraserType(this->eraserMode); + toolHandler->setSize(this->size); } + } - toolHandler->fireToolChanged(); + if (this->action == TOOL_PEN || this->action == TOOL_HILIGHTER || this->action == TOOL_TEXT) + { + toolHandler->setColor(this->color, false); } + + if (this->action == TOOL_ERASER && this->eraserMode != ERASER_TYPE_NONE) + { + toolHandler->setEraserType(this->eraserMode); + } + + toolHandler->fireToolChanged(); } diff --git a/src/gui/toolbarMenubar/ColorToolItem.cpp b/src/gui/toolbarMenubar/ColorToolItem.cpp index 99ade4ca..e456d200 100644 --- a/src/gui/toolbarMenubar/ColorToolItem.cpp +++ b/src/gui/toolbarMenubar/ColorToolItem.cpp @@ -10,8 +10,8 @@ bool ColorToolItem::inUpdate = false; -ColorToolItem::ColorToolItem(ActionHandler* handler, ToolHandler* toolHandler, GtkWindow* parent, int color, bool selektor) : - AbstractToolItem("", handler, selektor ? ACTION_SELECT_COLOR_CUSTOM : ACTION_SELECT_COLOR) +ColorToolItem::ColorToolItem(ActionHandler* handler, ToolHandler* toolHandler, GtkWindow* parent, int color, bool selektor) + : AbstractToolItem("", handler, selektor ? ACTION_SELECT_COLOR_CUSTOM : ACTION_SELECT_COLOR) { XOJ_INIT_TYPE(ColorToolItem); @@ -97,7 +97,7 @@ void ColorToolItem::enableColor(int color) // Only equals more ore less, so we will set it exact to the default color if (this->color != color) { - this->toolHandler->setColor(this->color); + this->toolHandler->setColor(this->color, true); } } @@ -185,7 +185,7 @@ void ColorToolItem::activated(GdkEvent* event, GtkMenuItem* menuitem, GtkToolBut showColorchooser(); } - toolHandler->setColor(this->color); + toolHandler->setColor(this->color, true); inUpdate = false; }