From 8cd2fdb85017d396893597ec24e64bee2f19ab6a Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Mon, 24 Dec 2018 23:00:09 +0100 Subject: [PATCH] Fill implementation --- src/control/Actions.h | 9 ++ src/control/Control.cpp | 49 ++++++++ src/control/Control.h | 2 + src/control/Tool.cpp | 50 +++++--- src/control/Tool.h | 32 +++-- src/control/ToolHandler.cpp | 140 +++++++++++++++++---- src/control/ToolHandler.h | 19 ++- src/control/tools/InputHandler.cpp | 1 + src/gui/dialog/AboutDialog.cpp | 3 +- src/gui/dialog/AboutDialog.h | 2 - src/gui/dialog/ButtonConfigGui.h | 2 - src/gui/dialog/ExportDialog.h | 1 - src/gui/dialog/FillTransparencyDialog.cpp | 85 +++++++++++++ src/gui/dialog/FillTransparencyDialog.h | 34 +++++ src/gui/dialog/FormatDialog.h | 2 - src/gui/dialog/GotoDialog.h | 1 - src/gui/dialog/LatexDialog.h | 2 - src/gui/dialog/PageTemplateDialog.h | 2 - src/gui/dialog/SettingsDialog.h | 2 - src/gui/dialog/ToolbarManageDialog.cpp | 4 +- src/gui/dialog/ToolbarManageDialog.h | 2 - src/gui/toolbarMenubar/ToolMenuHandler.cpp | 6 + src/util/XournalTypeList.h | 1 + ui/fillTransparency.glade | 139 ++++++++++++++++++++ ui/main.glade | 48 ++++++- 25 files changed, 565 insertions(+), 73 deletions(-) create mode 100644 src/gui/dialog/FillTransparencyDialog.cpp create mode 100644 src/gui/dialog/FillTransparencyDialog.h create mode 100644 ui/fillTransparency.glade diff --git a/src/control/Actions.h b/src/control/Actions.h index 2420cc01..f8252988 100644 --- a/src/control/Actions.h +++ b/src/control/Actions.h @@ -107,9 +107,16 @@ enum ActionType ACTION_TOOL_PEN_SIZE_THICK, ACTION_TOOL_PEN_SIZE_VERY_THICK, + ACTION_TOOL_PEN_FILL, + ACTION_TOOL_PEN_FILL_TRANSPARENCY, + ACTION_TOOL_HILIGHTER_SIZE_FINE, ACTION_TOOL_HILIGHTER_SIZE_MEDIUM, ACTION_TOOL_HILIGHTER_SIZE_THICK, + + ACTION_TOOL_HILIGHTER_FILL, + ACTION_TOOL_HILIGHTER_FILL_TRANSPARENCY, + ACTION_ROTATION_SNAPPING, ACTION_GRID_SNAPPING, @@ -155,7 +162,9 @@ enum ActionGroup GROUP_ERASER_MODE, GROUP_ERASER_SIZE, GROUP_PEN_SIZE, + GROUP_PEN_FILL, GROUP_HILIGHTER_SIZE, + GROUP_HILIGHTER_FILL, // Need group for toggle button, this is the first Toggle Group GROUP_TOGGLE_GROUP, diff --git a/src/control/Control.cpp b/src/control/Control.cpp index 1c7edffa..494958e3 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -8,6 +8,7 @@ #include "gui/dialog/AboutDialog.h" #include "gui/dialog/GotoDialog.h" +#include "gui/dialog/FillTransparencyDialog.h" #include "gui/dialog/FormatDialog.h" #include "gui/dialog/PageTemplateDialog.h" #include "gui/dialog/SettingsDialog.h" @@ -745,6 +746,14 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even penSizeChanged(); } break; + case ACTION_TOOL_PEN_FILL: + this->toolHandler->setPenFillEnabled(enabled); + break; + case ACTION_TOOL_PEN_FILL_TRANSPARENCY: + selectFillAlpha(true); + break; + + case ACTION_TOOL_HILIGHTER_SIZE_FINE: if (enabled) { @@ -766,6 +775,12 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even hilighterSizeChanged(); } break; + case ACTION_TOOL_HILIGHTER_FILL: + this->toolHandler->setHilighterFillEnabled(enabled); + break; + case ACTION_TOOL_HILIGHTER_FILL_TRANSPARENCY: + selectFillAlpha(false); + break; case ACTION_FONT_BUTTON_CHANGED: fontChanged(); @@ -905,6 +920,40 @@ bool Control::paste() return this->clipboardHandler->paste(); } +void Control::selectFillAlpha(bool pen) +{ + XOJ_CHECK_TYPE(Control); + + int alpha = 0; + + if (pen) + { + alpha = toolHandler->getPenFill(); + } + else + { + alpha = toolHandler->getHilighterFill(); + } + + FillTransparencyDialog dlg(gladeSearchPath, alpha); + dlg.show(getGtkWindow()); + + if (dlg.getResultAlpha() == -1) + { + return; + } + + + if (pen) + { + toolHandler->setPenFill(dlg.getResultAlpha()); + } + else + { + toolHandler->setHilighterFill(dlg.getResultAlpha()); + } +} + void Control::clearSelectionEndText() { XOJ_CHECK_TYPE(Control); diff --git a/src/control/Control.h b/src/control/Control.h index 1a92a064..963a1ddc 100644 --- a/src/control/Control.h +++ b/src/control/Control.h @@ -218,6 +218,8 @@ public: void help(); + void selectFillAlpha(bool pen); + public: // UndoRedoListener interface void undoRedoChanged(); diff --git a/src/control/Tool.cpp b/src/control/Tool.cpp index 5ad6a8b9..313e71ff 100644 --- a/src/control/Tool.cpp +++ b/src/control/Tool.cpp @@ -1,8 +1,6 @@ #include "Tool.h" -Tool::Tool(string name, ToolType type, int color, bool enableColor, bool enableSize, bool enableRuler, - bool enableRectangle, bool enableCircle, bool enableArrow, bool enableShapreRecognizer, - double* thickness) +Tool::Tool(string name, ToolType type, int color, int capabilities, double* thickness) { XOJ_INIT_TYPE(Tool); @@ -10,18 +8,15 @@ Tool::Tool(string name, ToolType type, int color, bool enableColor, bool enableS this->type = type; this->thickness = thickness; - this->enableColor = enableColor; - this->enableSize = enableSize; - this->enableShapeRecognizer = enableShapreRecognizer; - this->enableRuler = enableRuler; - this->enableRectangle = enableRectangle; - this->enableCircle = enableCircle; - this->enableArrow = enableArrow; + this->capabilities = capabilities; this->drawingType = DRAWING_TYPE_DEFAULT; this->color = color; this->size = TOOL_SIZE_MEDIUM; + + this->fill = false; + this->fillAlpha = 128; } Tool::~Tool() @@ -69,53 +64,74 @@ void Tool::setSize(ToolSize size) this->size = size; } +void Tool::setCapability(int capability, bool enabled) +{ + XOJ_CHECK_TYPE(Tool); + + if (enabled) + { + this->capabilities |= capability; + } + else + { + this->capabilities &= ~capability; + } +} + bool Tool::isEnableColor() { XOJ_CHECK_TYPE(Tool); - return this->enableColor; + return this->capabilities & TOOL_CAP_COLOR != 0; } bool Tool::isEnableSize() { XOJ_CHECK_TYPE(Tool); - return this->enableSize; + return this->capabilities & TOOL_CAP_SIZE != 0; } bool Tool::isEnableRuler() { XOJ_CHECK_TYPE(Tool); - return this->enableRuler; + return this->capabilities & TOOL_CAP_RULER != 0; } bool Tool::isEnableRectangle() { XOJ_CHECK_TYPE(Tool); - return this->enableRectangle; + return this->capabilities & TOOL_CAP_RECTANGLE != 0; } bool Tool::isEnableCircle() { XOJ_CHECK_TYPE(Tool); - return this->enableCircle; + return this->capabilities & TOOL_CAP_CIRCLE != 0; } bool Tool::isEnableArrow() { XOJ_CHECK_TYPE(Tool); - return this->enableArrow; + return this->capabilities & TOOL_CAP_ARROW != 0; } bool Tool::isEnableShapeRecognizer() { XOJ_CHECK_TYPE(Tool); - return this->enableShapeRecognizer; + return this->capabilities & TOOL_CAP_RECOGNIZER != 0; +} + +bool Tool::isEnableFill() +{ + XOJ_CHECK_TYPE(Tool); + + return this->capabilities & TOOL_CAP_FILL != 0; } DrawingType Tool::getDrawingType() diff --git a/src/control/Tool.h b/src/control/Tool.h index 4cb4186d..3cc7d158 100644 --- a/src/control/Tool.h +++ b/src/control/Tool.h @@ -89,12 +89,23 @@ enum DrawingType string drawingTypeToString(DrawingType type); DrawingType drawingTypeFromString(string type); +enum ToolCapabilities +{ + TOOL_CAP_NONE = 0, + TOOL_CAP_COLOR = 1 << 0, + TOOL_CAP_SIZE = 1 << 1, + TOOL_CAP_RULER = 1 << 2, + TOOL_CAP_RECTANGLE = 1 << 3, + TOOL_CAP_CIRCLE = 1 << 4, + TOOL_CAP_ARROW = 1 << 5, + TOOL_CAP_RECOGNIZER = 1 << 6, + TOOL_CAP_FILL = 1 << 7 +}; + class Tool { public: - Tool(string name, ToolType tool, int color, bool enableColor, bool enableSize, - bool enableRuler, bool enableRectangle, bool enableCircle, bool enableArrow, - bool enableShapreRecognizer, double* thickness); + Tool(string name, ToolType tool, int color, int capabilities, double* thickness); virtual ~Tool(); string getName(); @@ -115,9 +126,13 @@ public: bool isEnableCircle(); bool isEnableArrow(); bool isEnableShapeRecognizer(); + bool isEnableFill(); double getThickness(ToolSize size); +protected: + void setCapability(int capability, bool enabled); + private: Tool(const Tool& t); void operator=(const Tool& t); @@ -132,15 +147,12 @@ private: ToolSize size; double* thickness; + bool fill; + int fillAlpha; + DrawingType drawingType; - bool enableColor; - bool enableSize; - bool enableRuler; - bool enableRectangle; - bool enableCircle; - bool enableArrow; - bool enableShapeRecognizer; + int capabilities; friend class ToolHandler; }; diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index 8f166266..f2976f19 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -43,7 +43,10 @@ void ToolHandler::initTools() thickness[TOOL_SIZE_MEDIUM] = 1.41; thickness[TOOL_SIZE_THICK] = 2.26; thickness[TOOL_SIZE_VERY_THICK] = 5.67; - t = new Tool("pen", TOOL_PEN, 0x3333CC, true, true, true, true, true, true, true, thickness); + t = new Tool("pen", TOOL_PEN, 0x3333CC, + TOOL_CAP_COLOR | TOOL_CAP_SIZE | TOOL_CAP_RULER | TOOL_CAP_RECTANGLE | + TOOL_CAP_CIRCLE | TOOL_CAP_ARROW | TOOL_CAP_RECOGNIZER | TOOL_CAP_FILL, + thickness); tools[TOOL_PEN - TOOL_PEN] = t; thickness = new double[5]; @@ -52,7 +55,7 @@ void ToolHandler::initTools() thickness[TOOL_SIZE_MEDIUM] = 8.50; thickness[TOOL_SIZE_THICK] = 19.84; thickness[TOOL_SIZE_VERY_THICK] = 19.84; - t = new Tool("eraser", TOOL_ERASER, 0x000000, false, true, false, false, false, false, false, thickness); + t = new Tool("eraser", TOOL_ERASER, 0x000000, TOOL_CAP_SIZE, thickness); tools[TOOL_ERASER - TOOL_PEN] = t; // highlighter thicknesses = 1, 3, 7 mm @@ -62,40 +65,43 @@ void ToolHandler::initTools() thickness[TOOL_SIZE_MEDIUM] = 8.50; thickness[TOOL_SIZE_THICK] = 19.84; thickness[TOOL_SIZE_VERY_THICK] = 19.84; - t = new Tool("hilighter", TOOL_HILIGHTER, 0xFFFF00, true, true, true, true, true, true, true, thickness); + t = new Tool("hilighter", TOOL_HILIGHTER, 0xFFFF00, + TOOL_CAP_COLOR | TOOL_CAP_SIZE | TOOL_CAP_RULER | TOOL_CAP_RECTANGLE | + TOOL_CAP_CIRCLE | TOOL_CAP_ARROW | TOOL_CAP_RECOGNIZER | TOOL_CAP_FILL, + thickness); tools[TOOL_HILIGHTER - TOOL_PEN] = t; - t = new Tool("text", TOOL_TEXT, 0x000000, true, false, false, false, false, false, false, NULL); + t = new Tool("text", TOOL_TEXT, 0x000000, TOOL_CAP_COLOR, NULL); tools[TOOL_TEXT - TOOL_PEN] = t; - t = new Tool("image", TOOL_IMAGE, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("image", TOOL_IMAGE, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_IMAGE - TOOL_PEN] = t; - t = new Tool("selectRect", TOOL_SELECT_RECT, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("selectRect", TOOL_SELECT_RECT, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_SELECT_RECT - TOOL_PEN] = t; - t = new Tool("selectRegion", TOOL_SELECT_REGION, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("selectRegion", TOOL_SELECT_REGION, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_SELECT_REGION - TOOL_PEN] = t; - t = new Tool("selectObject", TOOL_SELECT_OBJECT, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("selectObject", TOOL_SELECT_OBJECT, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_SELECT_OBJECT - TOOL_PEN] = t; - t = new Tool("verticalSpace", TOOL_VERTICAL_SPACE, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("verticalSpace", TOOL_VERTICAL_SPACE, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_VERTICAL_SPACE - TOOL_PEN] = t; - t = new Tool("hand", TOOL_HAND, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("hand", TOOL_HAND, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_HAND - TOOL_PEN] = t; - t = new Tool("playObject", TOOL_PLAY_OBJECT, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("playObject", TOOL_PLAY_OBJECT, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_PLAY_OBJECT - TOOL_PEN] = t; - t = new Tool("drawRect", TOOL_DRAW_RECT, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("drawRect", TOOL_DRAW_RECT, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_DRAW_RECT - TOOL_PEN] = t; - t = new Tool("drawCircle", TOOL_DRAW_CIRCLE, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("drawCircle", TOOL_DRAW_CIRCLE, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_DRAW_CIRCLE - TOOL_PEN] = t; - t = new Tool("drawArrow", TOOL_DRAW_ARROW, 0x000000, false, false, false, false, false, false, false, NULL); + t = new Tool("drawArrow", TOOL_DRAW_ARROW, 0x000000, TOOL_CAP_NONE, NULL); tools[TOOL_DRAW_ARROW - TOOL_PEN] = t; selectTool(TOOL_PEN); @@ -185,7 +191,7 @@ void ToolHandler::fireToolChanged() } } -Tool &ToolHandler::getTool(ToolType type) +Tool& ToolHandler::getTool(ToolType type) { return *(this->tools[type - TOOL_PEN]); } @@ -201,49 +207,49 @@ bool ToolHandler::isEnableColor() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableColor; + return current->capabilities & TOOL_CAP_COLOR != 0; } bool ToolHandler::isEnableSize() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableSize; + return current->capabilities & TOOL_CAP_SIZE != 0; } bool ToolHandler::isEnableRuler() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableRuler; + return current->capabilities & TOOL_CAP_RULER != 0; } bool ToolHandler::isEnableRectangle() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableRectangle; + return current->capabilities & TOOL_CAP_RECTANGLE != 0; } bool ToolHandler::isEnableCircle() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableCircle; + return current->capabilities & TOOL_CAP_CIRCLE != 0; } bool ToolHandler::isEnableArrow() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableArrow; + return current->capabilities & TOOL_CAP_ARROW != 0; } bool ToolHandler::isEnableShapreRecognizer() { XOJ_CHECK_TYPE(ToolHandler); - return current->enableShapeRecognizer; + return current->capabilities & TOOL_CAP_RECOGNIZER != 0; } ToolSize ToolHandler::getSize() @@ -310,6 +316,74 @@ void ToolHandler::setHilighterSize(ToolSize size) } } +void ToolHandler::setPenFillEnabled(bool fill) +{ + XOJ_CHECK_TYPE(ToolHandler); + + this->tools[TOOL_PEN - TOOL_PEN]->fill = fill; + + // TODO: Currently no toolbar event to send, but if there is a toolbar, here the event should be sent +// if (this->current->type == TOOL_PEN) +// { +// this->listener->toolSizeChanged(); +// } +} + +bool ToolHandler::getPenFillEnabled() +{ + XOJ_CHECK_TYPE(ToolHandler); + + return this->tools[TOOL_PEN - TOOL_PEN]->fill; +} + +void ToolHandler::setPenFill(int alpha) +{ + XOJ_CHECK_TYPE(ToolHandler); + + this->tools[TOOL_PEN - TOOL_PEN]->fillAlpha = alpha; +} + +int ToolHandler::getPenFill() +{ + XOJ_CHECK_TYPE(ToolHandler); + + return this->tools[TOOL_PEN - TOOL_PEN]->fillAlpha; +} + +void ToolHandler::setHilighterFillEnabled(bool fill) +{ + XOJ_CHECK_TYPE(ToolHandler); + + this->tools[TOOL_HILIGHTER - TOOL_PEN]->fill = fill; + + // TODO: Currently no toolbar event to send, but if there is a toolbar, here the event should be sent +// if (this->current->type == TOOL_HILIGHTER) +// { +// this->listener->toolSizeChanged(); +// } +} + +bool ToolHandler::getHilighterFillEnabled() +{ + XOJ_CHECK_TYPE(ToolHandler); + + return this->tools[TOOL_HILIGHTER - TOOL_PEN]->fill; +} + +void ToolHandler::setHilighterFill(int alpha) +{ + XOJ_CHECK_TYPE(ToolHandler); + + this->tools[TOOL_HILIGHTER - TOOL_PEN]->fillAlpha = alpha; +} + +int ToolHandler::getHilighterFill() +{ + XOJ_CHECK_TYPE(ToolHandler); + + return this->tools[TOOL_HILIGHTER - TOOL_PEN]->fillAlpha; +} + double ToolHandler::getThickness() { XOJ_CHECK_TYPE(ToolHandler); @@ -370,6 +444,21 @@ int ToolHandler::getColor() return current->color; } +/** + * @return -1 if fill is disabled, else the fill alpha value + */ +int ToolHandler::getFill() +{ + XOJ_CHECK_TYPE(ToolHandler); + + if (!current->fill) + { + return -1; + } + + return current->fillAlpha; +} + DrawingType ToolHandler::getDrawingType() { XOJ_CHECK_TYPE(ToolHandler); @@ -565,6 +654,9 @@ const double* ToolHandler::getToolThickness(ToolType type) return this->tools[type - TOOL_PEN]->thickness; } +/** + * Change the selection tools capabilities, depending on the selected elements + */ void ToolHandler::setSelectionEditTools(bool setColor, bool setSize) { XOJ_CHECK_TYPE(ToolHandler); @@ -572,8 +664,8 @@ void ToolHandler::setSelectionEditTools(bool setColor, bool setSize) for (int i = TOOL_SELECT_RECT - TOOL_PEN; i <= TOOL_SELECT_OBJECT - TOOL_PEN; i++) { Tool* t = tools[i]; - t->enableColor = setColor; - t->enableSize = setSize; + t->setCapability(TOOL_CAP_COLOR, setColor); + t->setCapability(TOOL_CAP_SIZE, setSize); t->size = TOOL_SIZE_NONE; t->color = -1; } diff --git a/src/control/ToolHandler.h b/src/control/ToolHandler.h index ced59bc1..2c267ce6 100644 --- a/src/control/ToolHandler.h +++ b/src/control/ToolHandler.h @@ -50,6 +50,11 @@ public: void setColor(int color, bool userSelection); int getColor(); + /** + * @return -1 if fill is disabled, else the fill alpha value + */ + int getFill(); + DrawingType getDrawingType(); void setDrawingType(DrawingType drawingType); @@ -66,12 +71,21 @@ public: void setEraserSize(ToolSize size); void setHilighterSize(ToolSize size); + void setPenFillEnabled(bool fill); + bool getPenFillEnabled(); + void setPenFill(int alpha); + int getPenFill(); + + void setHilighterFillEnabled(bool fill); + bool getHilighterFillEnabled(); + void setHilighterFill(int alpha); + int getHilighterFill(); void selectTool(ToolType type, bool fireToolChanged = true); ToolType getToolType(); void fireToolChanged(); - Tool &getTool(ToolType type); + Tool& getTool(ToolType type); void setEraserType(EraserType eraserType); EraserType getEraserType(); @@ -93,6 +107,9 @@ public: ArrayIterator iterator(); + /** + * Change the selection tools capabilities, depending on the selected elements + */ void setSelectionEditTools(bool setColor, bool setSize); const double* getToolThickness(ToolType type); diff --git a/src/control/tools/InputHandler.cpp b/src/control/tools/InputHandler.cpp index f3c4152e..59bd46c5 100644 --- a/src/control/tools/InputHandler.cpp +++ b/src/control/tools/InputHandler.cpp @@ -57,6 +57,7 @@ void InputHandler::createStroke(Point p) stroke = new Stroke(); stroke->setWidth(h->getThickness()); stroke->setColor(h->getColor()); + stroke->setFill(h->getFill()); if (h->getToolType() == TOOL_PEN) { diff --git a/src/gui/dialog/AboutDialog.cpp b/src/gui/dialog/AboutDialog.cpp index 53472865..69f57a6a 100644 --- a/src/gui/dialog/AboutDialog.cpp +++ b/src/gui/dialog/AboutDialog.cpp @@ -3,7 +3,8 @@ #include #include -AboutDialog::AboutDialog(GladeSearchpath* gladeSearchPath) : GladeGui(gladeSearchPath, "about.glade", "aboutDialog") +AboutDialog::AboutDialog(GladeSearchpath* gladeSearchPath) + : GladeGui(gladeSearchPath, "about.glade", "aboutDialog") { XOJ_INIT_TYPE(AboutDialog); diff --git a/src/gui/dialog/AboutDialog.h b/src/gui/dialog/AboutDialog.h index 3a18f55e..a8a99c3e 100644 --- a/src/gui/dialog/AboutDialog.h +++ b/src/gui/dialog/AboutDialog.h @@ -13,8 +13,6 @@ #include "gui/GladeGui.h" -#include - class AboutDialog : public GladeGui { public: diff --git a/src/gui/dialog/ButtonConfigGui.h b/src/gui/dialog/ButtonConfigGui.h index 63c190c3..ccd92ef5 100644 --- a/src/gui/dialog/ButtonConfigGui.h +++ b/src/gui/dialog/ButtonConfigGui.h @@ -14,8 +14,6 @@ #include "control/Actions.h" #include "gui/GladeGui.h" -#include - #include class Settings; diff --git a/src/gui/dialog/ExportDialog.h b/src/gui/dialog/ExportDialog.h index f4e8b162..c59930aa 100644 --- a/src/gui/dialog/ExportDialog.h +++ b/src/gui/dialog/ExportDialog.h @@ -15,7 +15,6 @@ #include "gui/GladeGui.h" #include -#include #include using boost::filesystem::path; diff --git a/src/gui/dialog/FillTransparencyDialog.cpp b/src/gui/dialog/FillTransparencyDialog.cpp new file mode 100644 index 00000000..00642137 --- /dev/null +++ b/src/gui/dialog/FillTransparencyDialog.cpp @@ -0,0 +1,85 @@ +#include "FillTransparencyDialog.h" + +FillTransparencyDialog::FillTransparencyDialog(GladeSearchpath* gladeSearchPath, int alpha) + : GladeGui(gladeSearchPath, "fillTransparency.glade", "fillTransparencyDialog"), + resultAlpha(-1) +{ + XOJ_INIT_TYPE(FillTransparencyDialog); + + GtkWidget* scaleAlpha = get("scaleAlpha"); + + gtk_range_set_value(GTK_RANGE(scaleAlpha), alpha / 255.0 * 100); + + setPreviewImage(alpha); + + g_signal_connect(scaleAlpha, "change-value", G_CALLBACK( + +[](GtkRange* range, GtkScrollType scroll, gdouble value, FillTransparencyDialog* self) + { + XOJ_CHECK_TYPE_OBJ(self, FillTransparencyDialog); + self->setPreviewImage((int)(value / 100 * 255)); + }), this); +} + +FillTransparencyDialog::~FillTransparencyDialog() +{ + XOJ_RELEASE_TYPE(FillTransparencyDialog); +} + +const int PREVIEW_WIDTH = 70; +const int PREVIEW_HEIGTH = 50; +const int PREVIEW_BORDER = 10; + +void FillTransparencyDialog::setPreviewImage(int alpha) +{ + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, PREVIEW_WIDTH, PREVIEW_HEIGTH); + cairo_t* cr = cairo_create(surface); + + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgb(cr, 255, 255, 255); + cairo_rectangle(cr, 0, 0, PREVIEW_WIDTH, PREVIEW_WIDTH); + cairo_fill(cr); + + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + cairo_set_source_rgba(cr, 0, 0x80 / 255.0, 0, alpha / 255.0); + cairo_rectangle(cr, PREVIEW_BORDER, PREVIEW_BORDER, PREVIEW_WIDTH - PREVIEW_BORDER * 2, PREVIEW_HEIGTH - PREVIEW_BORDER * 2); + cairo_fill(cr); + + cairo_set_line_width(cr, 5); + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgb(cr, 0, 0x80 / 255.0, 0); + cairo_rectangle(cr, PREVIEW_BORDER, PREVIEW_BORDER, PREVIEW_WIDTH - PREVIEW_BORDER * 2, PREVIEW_HEIGTH - PREVIEW_BORDER * 2); + cairo_stroke(cr); + + cairo_destroy(cr); + + GtkWidget* preview = get("imgPreview"); + gtk_image_set_from_surface(GTK_IMAGE(preview), surface); +} + +int FillTransparencyDialog::getResultAlpha() +{ + XOJ_CHECK_TYPE(FillTransparencyDialog); + + return resultAlpha; +} + +void FillTransparencyDialog::show(GtkWindow* parent) +{ + XOJ_CHECK_TYPE(FillTransparencyDialog); + + gtk_window_set_transient_for(GTK_WINDOW(this->window), parent); + int result = gtk_dialog_run(GTK_DIALOG(this->window)); + gtk_widget_hide(this->window); + + // OK Button + if (result == 1) + { + + GtkWidget* scaleAlpha = get("scaleAlpha"); + resultAlpha = gtk_range_get_value(GTK_RANGE(scaleAlpha)); + } + else + { + resultAlpha = -1; + } +} diff --git a/src/gui/dialog/FillTransparencyDialog.h b/src/gui/dialog/FillTransparencyDialog.h new file mode 100644 index 00000000..8f75eb84 --- /dev/null +++ b/src/gui/dialog/FillTransparencyDialog.h @@ -0,0 +1,34 @@ +/* + * Xournal++ + * + * The about dialog + * + * @author Xournal++ Team + * https://github.com/xournalpp/xournalpp + * + * @license GNU GPLv2 or later + */ + +#pragma once + +#include "gui/GladeGui.h" + +class FillTransparencyDialog : public GladeGui +{ +public: + FillTransparencyDialog(GladeSearchpath* gladeSearchPath, int alpha); + virtual ~FillTransparencyDialog(); + +public: + virtual void show(GtkWindow* parent); + + int getResultAlpha(); + +private: + void setPreviewImage(int alpha); + +private: + XOJ_TYPE_ATTRIB; + + int resultAlpha; +}; diff --git a/src/gui/dialog/FormatDialog.h b/src/gui/dialog/FormatDialog.h index b8e7d7eb..f2c978bd 100644 --- a/src/gui/dialog/FormatDialog.h +++ b/src/gui/dialog/FormatDialog.h @@ -14,8 +14,6 @@ #include "control/settings/Settings.h" #include "gui/GladeGui.h" -#include - enum Orientation { ORIENTATION_NOT_DEFINED, ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT diff --git a/src/gui/dialog/GotoDialog.h b/src/gui/dialog/GotoDialog.h index 2c82ac0b..3c6534db 100644 --- a/src/gui/dialog/GotoDialog.h +++ b/src/gui/dialog/GotoDialog.h @@ -12,7 +12,6 @@ #pragma once #include "gui/GladeGui.h" -#include class GotoDialog : public GladeGui { diff --git a/src/gui/dialog/LatexDialog.h b/src/gui/dialog/LatexDialog.h index 5d431606..372d1294 100644 --- a/src/gui/dialog/LatexDialog.h +++ b/src/gui/dialog/LatexDialog.h @@ -17,8 +17,6 @@ #include "model/TexImage.h" -#include - class LatexDialog : public GladeGui { public: diff --git a/src/gui/dialog/PageTemplateDialog.h b/src/gui/dialog/PageTemplateDialog.h index f9890d9b..d744b509 100644 --- a/src/gui/dialog/PageTemplateDialog.h +++ b/src/gui/dialog/PageTemplateDialog.h @@ -16,8 +16,6 @@ #include "control/pagetype/PageTypeMenu.h" #include "control/settings/PageTemplateSettings.h" -#include - class PageTypeHandler; class PageTypeMenu; class PageTypeInfo; diff --git a/src/gui/dialog/SettingsDialog.h b/src/gui/dialog/SettingsDialog.h index f8e35a17..fb7d1fbc 100644 --- a/src/gui/dialog/SettingsDialog.h +++ b/src/gui/dialog/SettingsDialog.h @@ -14,8 +14,6 @@ #include "control/settings/Settings.h" #include "gui/GladeGui.h" -#include - class ButtonConfigGui; class SettingsDialog : public GladeGui diff --git a/src/gui/dialog/ToolbarManageDialog.cpp b/src/gui/dialog/ToolbarManageDialog.cpp index e90ae649..c2e9eded 100644 --- a/src/gui/dialog/ToolbarManageDialog.cpp +++ b/src/gui/dialog/ToolbarManageDialog.cpp @@ -11,8 +11,8 @@ enum COLUMN_STRING, COLUMN_BOLD, COLUMN_POINTER, COLUMN_EDITABLE, N_COLUMNS }; -ToolbarManageDialog::ToolbarManageDialog(GladeSearchpath* gladeSearchPath, ToolbarModel* model) : - GladeGui(gladeSearchPath, "toolbarManageDialog.glade", "DialogManageToolbar") +ToolbarManageDialog::ToolbarManageDialog(GladeSearchpath* gladeSearchPath, ToolbarModel* model) + : GladeGui(gladeSearchPath, "toolbarManageDialog.glade", "DialogManageToolbar") { XOJ_INIT_TYPE(ToolbarManageDialog); diff --git a/src/gui/dialog/ToolbarManageDialog.h b/src/gui/dialog/ToolbarManageDialog.h index 1b7c264b..f7a40c8f 100644 --- a/src/gui/dialog/ToolbarManageDialog.h +++ b/src/gui/dialog/ToolbarManageDialog.h @@ -13,8 +13,6 @@ #include "gui/GladeGui.h" -#include - class ToolbarData; class ToolbarModel; diff --git a/src/gui/toolbarMenubar/ToolMenuHandler.cpp b/src/gui/toolbarMenubar/ToolMenuHandler.cpp index f690768b..7f3aa8c1 100644 --- a/src/gui/toolbarMenubar/ToolMenuHandler.cpp +++ b/src/gui/toolbarMenubar/ToolMenuHandler.cpp @@ -495,10 +495,16 @@ void ToolMenuHandler::initToolItems() registerMenupoint(gui->get("penthicknessThick"), ACTION_TOOL_PEN_SIZE_THICK, GROUP_PEN_SIZE); registerMenupoint(gui->get("penthicknessVeryThick"), ACTION_TOOL_PEN_SIZE_VERY_THICK, GROUP_PEN_SIZE); + registerMenupoint(gui->get("penFill"), ACTION_TOOL_PEN_FILL, GROUP_PEN_FILL); + registerMenupoint(gui->get("penFillTransparency"), ACTION_TOOL_PEN_FILL_TRANSPARENCY); + registerMenupoint(gui->get("highlighterFine"), ACTION_TOOL_HILIGHTER_SIZE_FINE, GROUP_HILIGHTER_SIZE); registerMenupoint(gui->get("highlighterMedium"), ACTION_TOOL_HILIGHTER_SIZE_MEDIUM, GROUP_HILIGHTER_SIZE); registerMenupoint(gui->get("highlighterThick"), ACTION_TOOL_HILIGHTER_SIZE_THICK, GROUP_HILIGHTER_SIZE); + registerMenupoint(gui->get("highlighterFill"), ACTION_TOOL_HILIGHTER_FILL, GROUP_HILIGHTER_FILL); + registerMenupoint(gui->get("highlighterFillTransparency"), ACTION_TOOL_HILIGHTER_FILL_TRANSPARENCY); + registerMenupoint(gui->get("menuToolsTextFont"), ACTION_SELECT_FONT); #ifdef ENABLE_MATHTEX diff --git a/src/util/XournalTypeList.h b/src/util/XournalTypeList.h index 6aa192ed..ef35e7f7 100644 --- a/src/util/XournalTypeList.h +++ b/src/util/XournalTypeList.h @@ -249,4 +249,5 @@ XOJ_DECLARE_TYPE(NewGtkInputDevice, 238); XOJ_DECLARE_TYPE(InputSequence, 239); XOJ_DECLARE_TYPE(ZoomGesture, 240); XOJ_DECLARE_TYPE(GroupUndoAction, 241); +XOJ_DECLARE_TYPE(FillTransparencyDialog, 242); diff --git a/ui/fillTransparency.glade b/ui/fillTransparency.glade new file mode 100644 index 00000000..caffa00e --- /dev/null +++ b/ui/fillTransparency.glade @@ -0,0 +1,139 @@ + + + + + + 1 + 100 + 1 + 10 + + + False + Transparency settings + center + pixmaps/xournalpp.svg + dialog + + + True + False + vertical + 4 + + + True + False + end + + + gtk-cancel + True + True + True + False + True + + + False + False + 2 + + + + + gtk-ok + True + True + True + True + + + False + False + 3 + + + + + False + False + end + 0 + + + + + True + False + vertical + 10 + + + True + False + <b>Fill transparency settings</b> +Select transparency for fill color + True + 0 + + + False + True + 0 + + + + + True + False + 10 + + + True + False + gtk-missing-image + + + False + True + 0 + + + + + True + True + adjustment1 + True + 100 + 0 + + + True + True + 1 + + + + + True + True + 1 + + + + + True + True + 2 + + + + + + btCancel + btOk + + + diff --git a/ui/main.glade b/ui/main.glade index e7e707a4..b014b76b 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -299,7 +299,7 @@ Rec-Stop - + False True @@ -307,7 +307,7 @@ Rotation Snapping - + False True @@ -884,6 +884,28 @@ True + + + True + False + + + + + True + False + Fi_ll + True + + + + + True + False + Fill transparency + True + + @@ -999,6 +1021,28 @@ True + + + True + False + + + + + True + False + Fi_ll + True + + + + + True + False + Fill transparency + True + +