diff --git a/src/gui/toolbarMenubar/MenuItem.cpp b/src/gui/toolbarMenubar/MenuItem.cpp index 9bd466b8..4e2117be 100644 --- a/src/gui/toolbarMenubar/MenuItem.cpp +++ b/src/gui/toolbarMenubar/MenuItem.cpp @@ -1,11 +1,5 @@ #include "MenuItem.h" -MenuItem::MenuItem(ActionHandler* handler, GtkWidget* widget, ActionType type) - : AbstractItem("", handler, type, widget) -{ - XOJ_INIT_TYPE(MenuItem); -} - MenuItem::MenuItem(ActionHandler* handler, GtkWidget* widget, ActionType type, ActionGroup group) : AbstractItem("", handler, type, widget) { diff --git a/src/gui/toolbarMenubar/MenuItem.h b/src/gui/toolbarMenubar/MenuItem.h index 63d50ad3..a40dbc7c 100644 --- a/src/gui/toolbarMenubar/MenuItem.h +++ b/src/gui/toolbarMenubar/MenuItem.h @@ -19,8 +19,7 @@ class MenuItem : public AbstractItem { public: - MenuItem(ActionHandler* handler, GtkWidget* widget, ActionType type); - MenuItem(ActionHandler* handler, GtkWidget* widget, ActionType type, ActionGroup group); + MenuItem(ActionHandler* handler, GtkWidget* widget, ActionType type, ActionGroup group = GROUP_NOGROUP); virtual ~MenuItem(); private: diff --git a/src/gui/toolbarMenubar/ToolDrawCombocontrol.cpp b/src/gui/toolbarMenubar/ToolDrawCombocontrol.cpp index b2afbd7a..34801308 100644 --- a/src/gui/toolbarMenubar/ToolDrawCombocontrol.cpp +++ b/src/gui/toolbarMenubar/ToolDrawCombocontrol.cpp @@ -6,6 +6,20 @@ #include #include +struct ToolDrawType { + string name; + string icon; + ActionType type; +}; + +ToolDrawType types[ToolDrawCombocontrol_EntryCount] = { + { .name = _("Draw Rectangle"), .icon = "rect-draw.svg", .type = ACTION_TOOL_DRAW_CIRCLE }, + { .name = _("Draw Circle"), .icon = "circle-draw.svg", .type = ACTION_TOOL_DRAW_ARROW }, + { .name = _("Draw Arrow"), .icon = "arrow-draw.svg", .type = ACTION_TOOL_DRAW_RECT }, + { .name = _("Draw Line"), .icon = "ruler.svg", .type = ACTION_RULER }, + { .name = _("Recognize Lines"), .icon = "shape_recognizer.svg", .type = ACTION_SHAPE_RECOGNIZER } +}; + ToolDrawCombocontrol::ToolDrawCombocontrol(ToolMenuHandler* toolMenuHandler, ActionHandler* handler, GladeGui* gui, string id) : ToolButton(handler, gui, id, ACTION_TOOL_DRAW_RECT, GROUP_RULER, false, "rect-draw.png", _("Draw Rectangle")) { @@ -14,49 +28,27 @@ ToolDrawCombocontrol::ToolDrawCombocontrol(ToolMenuHandler* toolMenuHandler, Act this->toolMenuHandler = toolMenuHandler; this->labelWidget = NULL; this->iconWidget = NULL; - - this->iconDrawRect = gui->loadIconPixbuf("rect-draw.svg"); - g_object_ref(this->iconDrawRect); - - this->iconDrawCirc = gui->loadIconPixbuf("circle-draw.svg"); - g_object_ref(this->iconDrawCirc); - - this->iconDrawArr = gui->loadIconPixbuf("arrow-draw.svg"); - g_object_ref(this->iconDrawArr); - - this->iconDrawLine = gui->loadIconPixbuf("ruler.svg"); - g_object_ref(this->iconDrawLine); - - this->iconAutoDrawLine = gui->loadIconPixbuf("shape_recognizer.svg"); - g_object_ref(this->iconAutoDrawLine); - setPopupMenu(gtk_menu_new()); - createMenuItem(_("Draw Rectangle"), "rect-draw.svg", ACTION_TOOL_DRAW_RECT); - createMenuItem(_C("Draw Circle"), "circle-draw.svg", ACTION_TOOL_DRAW_CIRCLE); - createMenuItem(_C("Draw Arrow"), "arrow-draw.svg", ACTION_TOOL_DRAW_ARROW); - createMenuItem(_C("Draw Line"), "ruler.svg", ACTION_RULER); - createMenuItem(_C("Recognize Lines"), "shape_recognizer.svg", ACTION_SHAPE_RECOGNIZER); + for (int i = 0; i < ToolDrawCombocontrol_EntryCount; i++) + { + ToolDrawType& t = types[i]; + createMenuItem(t.name, t.icon, t.type); + + this->icons[i] = gui->loadIconPixbuf(t.icon); + g_object_ref(this->icons[i]); + } } ToolDrawCombocontrol::~ToolDrawCombocontrol() { XOJ_CHECK_TYPE(ToolDrawCombocontrol); - g_object_unref(this->iconDrawRect); - this->iconDrawRect = NULL; - - g_object_unref(this->iconDrawCirc); - this->iconDrawCirc = NULL; - - g_object_unref(this->iconDrawArr); - this->iconDrawArr = NULL; - - g_object_unref(this->iconDrawLine); - this->iconDrawLine = NULL; - - g_object_unref(this->iconAutoDrawLine); - this->iconAutoDrawLine = NULL; + for (int i = 0; i < ToolDrawCombocontrol_EntryCount; i++) + { + g_object_unref(icons[i]); + icons[i] = NULL; + } XOJ_RELEASE_TYPE(ToolDrawCombocontrol); } @@ -85,50 +77,26 @@ void ToolDrawCombocontrol::selected(ActionGroup group, ActionType action) if (!GTK_IS_TOGGLE_TOOL_BUTTON(this->item)) { - g_warning("selected action %i which is not a toggle action! 2", action); + g_warning("ToolDrawCombocontrol: selected action %i which is not a toggle action!", action); return; } string description; - if (action == ACTION_TOOL_DRAW_RECT && this->action != ACTION_TOOL_DRAW_RECT) - { - this->action = ACTION_TOOL_DRAW_RECT; - gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconDrawRect); - - description = _("Draw Rectangle"); - } - else if (action == ACTION_TOOL_DRAW_CIRCLE && this->action != ACTION_TOOL_DRAW_CIRCLE) + for (int i = 0; i < ToolDrawCombocontrol_EntryCount; i++) { - this->action = ACTION_TOOL_DRAW_CIRCLE; - gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconDrawCirc); - - description = _("Draw Circle"); + ToolDrawType& t = types[i]; + + if (action == t.type && this->action != t.type) + { + this->action = t.type; + gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->icons[i]); + description = t.name; + break; + } } - else if (action == ACTION_TOOL_DRAW_ARROW && this->action != ACTION_TOOL_DRAW_ARROW) - { - this->action = ACTION_TOOL_DRAW_ARROW; - gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconDrawArr); - description = _("Draw Arrow"); - } - else if (action == ACTION_RULER && this->action != ACTION_RULER) - { - this->action = ACTION_RULER; - gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconDrawLine); - - description = _("Draw Line"); - } - else if (action == ACTION_SHAPE_RECOGNIZER && this->action != ACTION_SHAPE_RECOGNIZER) - { - this->action = ACTION_SHAPE_RECOGNIZER; - gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconAutoDrawLine); - - description = _("Recognize Lines"); - } 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); @@ -141,9 +109,9 @@ GtkToolItem* ToolDrawCombocontrol::newItem() XOJ_CHECK_TYPE(ToolDrawCombocontrol); labelWidget = gtk_label_new(_C("Draw Rectangle")); - iconWidget = gtk_image_new_from_pixbuf(this->iconDrawRect); + iconWidget = gtk_image_new_from_pixbuf(this->icons[0]); - GtkToolItem* it = gtk_menu_tool_toggle_button_new(iconWidget, "test0"); + GtkToolItem* it = gtk_menu_tool_toggle_button_new(iconWidget, _C("Draw Rectangle")); 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/ToolDrawCombocontrol.h b/src/gui/toolbarMenubar/ToolDrawCombocontrol.h index 87d3b96f..fd45435a 100644 --- a/src/gui/toolbarMenubar/ToolDrawCombocontrol.h +++ b/src/gui/toolbarMenubar/ToolDrawCombocontrol.h @@ -18,6 +18,8 @@ class ToolMenuHandler; +#define ToolDrawCombocontrol_EntryCount 5 + class ToolDrawCombocontrol : public ToolButton { public: @@ -39,9 +41,5 @@ private: GtkWidget* iconWidget; GtkWidget* labelWidget; - GdkPixbuf* iconDrawRect; - GdkPixbuf* iconDrawCirc; - GdkPixbuf* iconDrawArr; - GdkPixbuf* iconDrawLine; - GdkPixbuf* iconAutoDrawLine; + GdkPixbuf* icons[ToolDrawCombocontrol_EntryCount]; }; diff --git a/src/gui/toolbarMenubar/ToolMenuHandler.cpp b/src/gui/toolbarMenubar/ToolMenuHandler.cpp index 22038526..c2b7f603 100644 --- a/src/gui/toolbarMenubar/ToolMenuHandler.cpp +++ b/src/gui/toolbarMenubar/ToolMenuHandler.cpp @@ -241,20 +241,11 @@ void ToolMenuHandler::addToolItem(AbstractToolItem* it) this->toolItems.push_back(it); } -void ToolMenuHandler::registerMenupoint(GtkWidget* widget, ActionType type) -{ - XOJ_CHECK_TYPE(ToolMenuHandler); - - MenuItem* it = new MenuItem(listener, widget, type); - this->menuItems.push_back(it); -} - void ToolMenuHandler::registerMenupoint(GtkWidget* widget, ActionType type, ActionGroup group) { XOJ_CHECK_TYPE(ToolMenuHandler); - MenuItem* it = new MenuItem(listener, widget, type, group); - this->menuItems.push_back(it); + this->menuItems.push_back(new MenuItem(listener, widget, type, group)); } void ToolMenuHandler::initEraserToolItem() diff --git a/src/gui/toolbarMenubar/ToolMenuHandler.h b/src/gui/toolbarMenubar/ToolMenuHandler.h index a36c70bb..ac2a0b15 100644 --- a/src/gui/toolbarMenubar/ToolMenuHandler.h +++ b/src/gui/toolbarMenubar/ToolMenuHandler.h @@ -47,8 +47,7 @@ public: void load(ToolbarData* d, GtkWidget* toolbar, const char* toolbarName, bool horizontal); - void registerMenupoint(GtkWidget* widget, ActionType type); - void registerMenupoint(GtkWidget* widget, ActionType type, ActionGroup group); + void registerMenupoint(GtkWidget* widget, ActionType type, ActionGroup group = GROUP_NOGROUP); void initToolItems();