diff --git a/src/control/Control.cpp b/src/control/Control.cpp index d577d13b..30582cb1 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -351,6 +351,7 @@ void Control::initWindow(MainWindow* win) hilighterSizeChanged(); updateDeletePageButton(); toolFillChanged(); + toolLineStyleChanged(); this->clipboardHandler = new ClipboardHandler(this, win->getXournal()->getWidget()); @@ -1832,8 +1833,25 @@ void Control::toolLineStyleChanged() { XOJ_CHECK_TYPE(Control); - // TODO Implement LineStyle - //fireActionSelected(GROUP_FILL, toolHandler->getFill() != -1 ? ACTION_TOOL_FILL : ACTION_NONE); + const LineStyle& lineStyle = toolHandler->getTool(TOOL_PEN).getLineStyle(); + string style = StrokeStyle::formatStyle(lineStyle); + + if (style == "dash") + { + fireActionSelected(GROUP_LINE_STYLE, ACTION_TOOL_LINE_STYLE_DASH); + } + else if (style == "dashdot") + { + fireActionSelected(GROUP_LINE_STYLE, ACTION_TOOL_LINE_STYLE_DASH_DOT); + } + else if (style == "dot") + { + fireActionSelected(GROUP_LINE_STYLE, ACTION_TOOL_LINE_STYLE_DOT); + } + else + { + fireActionSelected(GROUP_LINE_STYLE, ACTION_TOOL_LINE_STYLE_PLAIN); + } } /** diff --git a/src/control/ToolHandler.cpp b/src/control/ToolHandler.cpp index 48fa152a..9609541f 100644 --- a/src/control/ToolHandler.cpp +++ b/src/control/ToolHandler.cpp @@ -64,8 +64,7 @@ void ToolHandler::initTools() thickness[TOOL_SIZE_VERY_THICK] = 19.84; 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 | - TOOL_CAP_DASH_LINE, + TOOL_CAP_CIRCLE | TOOL_CAP_ARROW | TOOL_CAP_RECOGNIZER | TOOL_CAP_FILL, thickness); tools[TOOL_HILIGHTER - TOOL_PEN] = t; @@ -374,7 +373,7 @@ void ToolHandler::setLineStyle(const LineStyle& style) { XOJ_CHECK_TYPE(ToolHandler); - this->current->lineStyle = style; + this->tools[TOOL_PEN - TOOL_PEN]->lineStyle = style; this->listener->toolLineStyleChanged(); } @@ -512,7 +511,10 @@ void ToolHandler::saveSettings() { st.setInt("fill", t->getFill()); st.setInt("fillAlpha", t->getFillAlpha()); + } + if (t->type == TOOL_PEN) + { st.setString("style", StrokeStyle::formatStyle(t->getLineStyle())); } diff --git a/src/gui/toolbarMenubar/ToolButton.cpp b/src/gui/toolbarMenubar/ToolButton.cpp index 99ead6ea..4e812eb8 100644 --- a/src/gui/toolbarMenubar/ToolButton.cpp +++ b/src/gui/toolbarMenubar/ToolButton.cpp @@ -40,6 +40,47 @@ ToolButton::~ToolButton() XOJ_RELEASE_TYPE(ToolButton); } +/** + * Register a popup menu entry, create a popup menu, if none is there + * + * @param name The name of the item + * @return The created menu item + */ +GtkWidget* ToolButton::registerPopupMenuEntry(string name, string iconName) +{ + XOJ_CHECK_TYPE(ToolButton); + + if (this->popupMenu == NULL) + { + setPopupMenu(gtk_menu_new()); + } + + GtkWidget* menuItem = NULL; + if (iconName == "") + { + menuItem = gtk_check_menu_item_new_with_label(name.c_str()); + } + else + { + menuItem = gtk_check_menu_item_new(); + + GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); + gtk_container_add(GTK_CONTAINER(box), gui->loadIcon(iconName)); + + GtkWidget* label = gtk_label_new(name.c_str()); + gtk_label_set_xalign(GTK_LABEL(label), 0.0); + gtk_box_pack_end(GTK_BOX(box), label, true, true, 0); + + gtk_container_add(GTK_CONTAINER(menuItem), box); + } + + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(menuItem), true); + gtk_widget_show_all(menuItem); + gtk_container_add(GTK_CONTAINER(this->popupMenu), menuItem); + + return menuItem; +} + void ToolButton::updateDescription(string description) { XOJ_CHECK_TYPE(ToolButton); diff --git a/src/gui/toolbarMenubar/ToolButton.h b/src/gui/toolbarMenubar/ToolButton.h index dfc8711f..0422671c 100644 --- a/src/gui/toolbarMenubar/ToolButton.h +++ b/src/gui/toolbarMenubar/ToolButton.h @@ -27,6 +27,15 @@ public: virtual ~ToolButton(); public: + /** + * Register a popup menu entry, create a popup menu, if none is there + * + * @param name The name of the item + * @param iconName To load an icon + * @return The created menu item + */ + GtkWidget* registerPopupMenuEntry(string name, string iconName = ""); + void updateDescription(string description); virtual string getToolDisplayName(); diff --git a/src/gui/toolbarMenubar/ToolLineStyleCombocontrol.cpp b/src/gui/toolbarMenubar/ToolLineStyleCombocontrol.cpp deleted file mode 100644 index 5fd49365..00000000 --- a/src/gui/toolbarMenubar/ToolLineStyleCombocontrol.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "ToolLineStyleCombocontrol.h" - -#include "ToolMenuHandler.h" -#include "gui/widgets/gtkmenutooltogglebutton.h" - -#include -#include - -class ToolLineStyleType { -public: - ToolLineStyleType(string name, string icon, ActionType type) - : name(name), icon(icon), type(type), pixbuf(NULL) - { - } - ~ToolLineStyleType() - { - g_object_unref(pixbuf); - pixbuf = NULL; - } - -public: - string name; - string icon; - ActionType type; - GdkPixbuf* pixbuf; -}; - -ToolLineStyleCombocontrol::ToolLineStyleCombocontrol(ToolMenuHandler* toolMenuHandler, ActionHandler* handler, GladeGui* gui, string id) - : ToolButton(handler, gui, id, ACTION_TOOL_LINE_STYLE_PLAIN, GROUP_LINE_STYLE, false, "line-style-plain.svg", _("Line Style")) -{ - XOJ_INIT_TYPE(ToolLineStyleCombocontrol); - - this->toolMenuHandler = toolMenuHandler; - this->labelWidget = NULL; - this->iconWidget = NULL; - setPopupMenu(gtk_menu_new()); - - drawTypes.push_back(new ToolLineStyleType(_("Plain line"), "line-style-plain.svg", ACTION_TOOL_LINE_STYLE_PLAIN)); - drawTypes.push_back(new ToolLineStyleType(_("Dashed line"), "line-style-dash.svg", ACTION_TOOL_LINE_STYLE_DASH)); - drawTypes.push_back(new ToolLineStyleType(_("Dash-doted line"), "line-style-dash-dot.svg", ACTION_TOOL_LINE_STYLE_DASH_DOT)); - drawTypes.push_back(new ToolLineStyleType(_("Dotted line"), "line-style-dot.svg", ACTION_TOOL_LINE_STYLE_DOT)); - - for (ToolLineStyleType* t : drawTypes) - { - createMenuItem(t->name, t->icon, t->type); - t->pixbuf = gui->loadIconPixbuf(t->icon); - g_object_ref(t->pixbuf); - } -} - -ToolLineStyleCombocontrol::~ToolLineStyleCombocontrol() -{ - XOJ_CHECK_TYPE(ToolLineStyleCombocontrol); - - for (ToolLineStyleType* t : drawTypes) - { - delete t; - } - this->drawTypes.clear(); - this->toolMenuHandler = NULL; - - XOJ_RELEASE_TYPE(ToolLineStyleCombocontrol); -} - -void ToolLineStyleCombocontrol::createMenuItem(string name, string icon, ActionType type) -{ - GtkWidget* menuItem = gtk_menu_item_new (); - GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); - gtk_container_add(GTK_CONTAINER(box), gui->loadIcon(icon)); - gtk_container_add(GTK_CONTAINER(box), gtk_label_new(name.c_str())); - gtk_container_add(GTK_CONTAINER(menuItem), box); - - gtk_container_add(GTK_CONTAINER(popupMenu), menuItem); - toolMenuHandler->registerMenupoint(menuItem, type, GROUP_RULER); - gtk_widget_show_all(menuItem); -} - -void ToolLineStyleCombocontrol::selected(ActionGroup group, ActionType action) -{ - XOJ_CHECK_TYPE(ToolLineStyleCombocontrol); - - if (!this->item) - { - return; - } - - if (!GTK_IS_TOGGLE_TOOL_BUTTON(this->item)) - { - g_warning("ToolLineStyleCombocontrol: selected action %i which is not a toggle action!", action); - return; - } - - string description; - - for (ToolLineStyleType* t : drawTypes) - { - if (action == t->type && this->action != t->type) - { - this->action = t->type; - gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), t->pixbuf); - description = t->name; - break; - } - } - - gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(item), description.c_str()); - if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(this->item)) != (this->action == action)) - { - this->toolToggleButtonActive = (this->action == action); - gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(this->item), this->toolToggleButtonActive); - } -} - -GtkToolItem* ToolLineStyleCombocontrol::newItem() -{ - XOJ_CHECK_TYPE(ToolLineStyleCombocontrol); - labelWidget = gtk_label_new(_("Line Style")); - iconWidget = gtk_image_new_from_pixbuf(drawTypes[0]->pixbuf); - - GtkToolItem* it = gtk_menu_tool_toggle_button_new(iconWidget, _("Line Style")); - gtk_tool_button_set_label_widget(GTK_TOOL_BUTTON(it), labelWidget); - gtk_menu_tool_toggle_button_set_menu(GTK_MENU_TOOL_TOGGLE_BUTTON(it), popupMenu); - return it; -} diff --git a/src/gui/toolbarMenubar/ToolLineStyleCombocontrol.h b/src/gui/toolbarMenubar/ToolLineStyleCombocontrol.h deleted file mode 100644 index d2a51838..00000000 --- a/src/gui/toolbarMenubar/ToolLineStyleCombocontrol.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Xournal++ - * - * Part of the customizable toolbars - * - * @author Xournal++ Team - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - */ - -#pragma once - -#include "ToolButton.h" -#include "gui/GladeGui.h" - -#include - -class ToolMenuHandler; -class ToolLineStyleType; - -class ToolLineStyleCombocontrol : public ToolButton -{ -public: - ToolLineStyleCombocontrol(ToolMenuHandler* toolMenuHandler, ActionHandler* handler, GladeGui* gui, string id); - virtual ~ToolLineStyleCombocontrol(); - -public: - virtual void selected(ActionGroup group, ActionType action); - -protected: - virtual GtkToolItem* newItem(); - void createMenuItem(string name, string icon, ActionType type); - -private: - XOJ_TYPE_ATTRIB; - - ToolMenuHandler* toolMenuHandler; - - GtkWidget* iconWidget; - GtkWidget* labelWidget; - - vector drawTypes; -}; diff --git a/src/gui/toolbarMenubar/ToolMenuHandler.cpp b/src/gui/toolbarMenubar/ToolMenuHandler.cpp index e239c492..f20aee59 100644 --- a/src/gui/toolbarMenubar/ToolMenuHandler.cpp +++ b/src/gui/toolbarMenubar/ToolMenuHandler.cpp @@ -4,7 +4,6 @@ #include "MenuItem.h" #include "ToolButton.h" #include "ToolDrawCombocontrol.h" -#include "ToolLineStyleCombocontrol.h" #include "ToolSelectCombocontrol.h" #include "ToolPageLayer.h" #include "ToolPageSpinner.h" @@ -280,36 +279,51 @@ void ToolMenuHandler::registerMenupoint(GtkWidget* widget, ActionType type, Acti this->menuItems.push_back(new MenuItem(listener, widget, type, group)); } +void ToolMenuHandler::initPenToolItem() +{ + XOJ_CHECK_TYPE(ToolMenuHandler); + + ToolButton* tbPen = new ToolButton(listener, gui, "PEN", ACTION_TOOL_PEN, GROUP_TOOL, true, "tool_pencil.svg", + _("Pen"), gui->get("menuToolsPen")); + + registerMenupoint(tbPen->registerPopupMenuEntry(_("standard"), "line-style-plain.svg"), + ACTION_TOOL_LINE_STYLE_PLAIN, GROUP_LINE_STYLE); + registerMenupoint(gui->get("penStandard"), + ACTION_TOOL_LINE_STYLE_PLAIN, GROUP_LINE_STYLE); + + registerMenupoint(tbPen->registerPopupMenuEntry(_("dashed"), "line-style-dash.svg"), + ACTION_TOOL_LINE_STYLE_DASH, GROUP_LINE_STYLE); + registerMenupoint(gui->get("penStyleDashed"), + ACTION_TOOL_LINE_STYLE_DASH, GROUP_LINE_STYLE); + + registerMenupoint(tbPen->registerPopupMenuEntry(_("dash-/ doted"), "line-style-dash-dot.svg"), + ACTION_TOOL_LINE_STYLE_DASH_DOT, GROUP_LINE_STYLE); + registerMenupoint(gui->get("penStyleDashDotted"), + ACTION_TOOL_LINE_STYLE_DASH_DOT, GROUP_LINE_STYLE); + + registerMenupoint(tbPen->registerPopupMenuEntry(_("dotted"), "line-style-dot.svg"), + ACTION_TOOL_LINE_STYLE_DOT, GROUP_LINE_STYLE); + registerMenupoint(gui->get("penStyleDotted"), + ACTION_TOOL_LINE_STYLE_DOT, GROUP_LINE_STYLE); + + addToolItem(tbPen); +} + void ToolMenuHandler::initEraserToolItem() { XOJ_CHECK_TYPE(ToolMenuHandler); ToolButton* tbEraser = new ToolButton(listener, gui, "ERASER", ACTION_TOOL_ERASER, GROUP_TOOL, true, "tool_eraser.svg", _("Eraser"), gui->get("menuToolsEraser")); - GtkWidget* eraserPopup = gtk_menu_new(); - GtkWidget* eraserPopupStandard = gtk_check_menu_item_new_with_label(_("standard")); - gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(eraserPopupStandard), true); - gtk_widget_show(eraserPopupStandard); - gtk_container_add(GTK_CONTAINER(eraserPopup), eraserPopupStandard); + registerMenupoint(tbEraser->registerPopupMenuEntry(_("standard")), ACTION_TOOL_ERASER_STANDARD, GROUP_ERASER_MODE); registerMenupoint(gui->get("eraserStandard"), ACTION_TOOL_ERASER_STANDARD, GROUP_ERASER_MODE); - registerMenupoint(eraserPopupStandard, ACTION_TOOL_ERASER_STANDARD, GROUP_ERASER_MODE); - GtkWidget* eraserPopupWhiteout = gtk_check_menu_item_new_with_label(_("whiteout")); - gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(eraserPopupWhiteout), true); - gtk_widget_show(eraserPopupWhiteout); - gtk_container_add(GTK_CONTAINER(eraserPopup), eraserPopupWhiteout); + registerMenupoint(tbEraser->registerPopupMenuEntry(_("whiteout")), ACTION_TOOL_ERASER_WHITEOUT, GROUP_ERASER_MODE); registerMenupoint(gui->get("eraserWhiteout"), ACTION_TOOL_ERASER_WHITEOUT, GROUP_ERASER_MODE); - registerMenupoint(eraserPopupWhiteout, ACTION_TOOL_ERASER_WHITEOUT, GROUP_ERASER_MODE); - GtkWidget* eraserPopupDeleteStroke = gtk_check_menu_item_new_with_label(_("delete stroke")); - gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(eraserPopupDeleteStroke), true); - gtk_widget_show(eraserPopupDeleteStroke); - gtk_container_add(GTK_CONTAINER(eraserPopup), eraserPopupDeleteStroke); + registerMenupoint(tbEraser->registerPopupMenuEntry(_("delete stroke")), ACTION_TOOL_ERASER_DELETE_STROKE, GROUP_ERASER_MODE); registerMenupoint(gui->get("eraserDeleteStrokes"), ACTION_TOOL_ERASER_DELETE_STROKE, GROUP_ERASER_MODE); - registerMenupoint(eraserPopupDeleteStroke, ACTION_TOOL_ERASER_DELETE_STROKE, GROUP_ERASER_MODE); - - tbEraser->setPopupMenu(eraserPopup); addToolItem(tbEraser); } @@ -385,9 +399,7 @@ void ToolMenuHandler::initToolItems() addToolItem(new ColorToolItem(listener, toolHandler, this->parent, 0xff0000, true)); - addToolItem(new ToolButton(listener, gui, "PEN", ACTION_TOOL_PEN, GROUP_TOOL, true, "tool_pencil.svg", _("Pen"), - gui->get("menuToolsPen"))); - + initPenToolItem(); initEraserToolItem(); addToolItem(new ToolButton(listener, gui, "DELETE_CURRENT_PAGE", ACTION_DELETE_PAGE, "delPage.svg", _("Delete current page"))); @@ -396,8 +408,6 @@ void ToolMenuHandler::initToolItems() addToolItem(new ToolDrawCombocontrol(this, listener, gui, "DRAW")); - addToolItem(new ToolLineStyleCombocontrol(this, listener, gui, "LINE_STYLE")); - ToolButton* tbInsertNewPage = new ToolButton(listener, gui, "INSERT_NEW_PAGE", ACTION_NEW_PAGE_AFTER, "addPage.svg", _("Insert page")); addToolItem(tbInsertNewPage); diff --git a/src/gui/toolbarMenubar/ToolMenuHandler.h b/src/gui/toolbarMenubar/ToolMenuHandler.h index 888d8a60..f0f40ca5 100644 --- a/src/gui/toolbarMenubar/ToolMenuHandler.h +++ b/src/gui/toolbarMenubar/ToolMenuHandler.h @@ -74,6 +74,7 @@ public: private: void addToolItem(AbstractToolItem* it); + void initPenToolItem(); void initEraserToolItem(); private: diff --git a/src/model/StrokeStyle.cpp b/src/model/StrokeStyle.cpp index 75f721c7..a1ea89c9 100644 --- a/src/model/StrokeStyle.cpp +++ b/src/model/StrokeStyle.cpp @@ -68,7 +68,7 @@ LineStyle StrokeStyle::parseStyle(const char* style) } #define FORMAT_STYLE(name, def) \ - if (count == (sizeof(def) / sizeof(def[0])) && memcmp(dashes, def, count) == 0) \ + if (count == (sizeof(def) / sizeof(def[0])) && memcmp(dashes, def, count * sizeof(def[0])) == 0) \ { \ return name; \ } diff --git a/src/util/XournalTypeList.h b/src/util/XournalTypeList.h index bdbd6a08..ae165f21 100644 --- a/src/util/XournalTypeList.h +++ b/src/util/XournalTypeList.h @@ -263,8 +263,7 @@ XOJ_DECLARE_TYPE(FillUndoActionEntry, 253); XOJ_DECLARE_TYPE(MoveLayerUndoAction, 254); XOJ_DECLARE_TYPE(EmergencySaveRestore, 255); XOJ_DECLARE_TYPE(LineStyle, 256); -XOJ_DECLARE_TYPE(ToolLineStyleCombocontrol, 257); -XOJ_DECLARE_TYPE(UndoRedoController, 258); +XOJ_DECLARE_TYPE(UndoRedoController, 257); diff --git a/ui/main.glade b/ui/main.glade index 5e852bfe..607b44d2 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -87,8 +87,8 @@ False True True - + @@ -112,8 +112,8 @@ False Export as... True - + @@ -398,8 +398,8 @@ False True True - + @@ -409,8 +409,8 @@ False True True - + @@ -911,6 +911,48 @@ True + + + True + False + + + + + True + False + standard + True + True + + + + + True + False + dashed + True + True + + + + + True + False + dash-/ doted + True + True + + + + + True + False + dotted + True + True + + True