Change color selection behaviour if tool is Eraser

New Behaviour:

 - Eraser selected from toolbar:
   No change of color possible anymoer as eraser does not have color and
   it's not obvious for which other tool to set the color
 - Eraser selected via stylus:
   Allow change of color in the toolbar. This color will actually set
   the tools color which was active before the button press. This makes
   sense as upon release of the eraser button this tool will be selected
   again.
master
tobidot 6 years ago committed by idotobi
parent 9417fca2c5
commit 387bde19ad
  1. 4
      src/control/LastSelectedTool.cpp
  2. 4
      src/control/LastSelectedTool.h
  3. 2
      src/control/Tool.cpp
  4. 2
      src/control/Tool.h
  5. 2
      src/control/ToolBase.cpp
  6. 14
      src/control/ToolHandler.cpp
  7. 2
      src/control/ToolHandler.h
  8. 15
      src/gui/toolbarMenubar/ColorToolItem.cpp
  9. 5
      src/gui/toolbarMenubar/ColorToolItem.h

@ -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); }

@ -30,6 +30,10 @@ public:
*/
Tool* restoreAndGet();
ToolType getToolType();
void setColor(int color);
private:
/**
* The last tool

@ -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; }

@ -29,6 +29,8 @@ public:
double getThickness(ToolSize size);
ToolType getToolType();
protected:
void setCapability(int capability, bool enabled);

@ -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;

@ -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();

@ -123,6 +123,8 @@ public:
*/
bool isSinglePageTool();
bool triggeredByStylusButton = false;
protected:
void initTools();

@ -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;
}

@ -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;

Loading…
Cancel
Save