From beb551b18fea86b81dbd0ca426e61bdd6709f0b8 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Thu, 15 Feb 2007 21:48:09 +0000 Subject: [PATCH] enable click-action and general tooltip for style swatches --- src/ui/dialog/inkscape-preferences.cpp | 2 +- src/ui/widget/style-swatch.cpp | 38 ++++++++++++++++++++++---- src/ui/widget/style-swatch.h | 13 ++++++++- src/widgets/toolbox.cpp | 32 ++++++++++++++++------ 4 files changed, 69 insertions(+), 16 deletions(-) diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 079a987f5..34cdee00b 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -288,7 +288,7 @@ void InkscapePreferences::AddNewObjectsStyle(DialogPage& p, const std::string& p StyleSwatch *swatch = 0; if (tool_repr) { SPCSSAttr *css = sp_repr_css_attr_inherited(tool_repr, "style"); - swatch = new StyleSwatch(css); + swatch = new StyleSwatch(css, _("This tool's style of new objects")); hb->add(*swatch); sp_repr_css_attr_unref(css); } diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index ef27ff390..705083a8f 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -26,6 +26,7 @@ #include "xml/node-event-vector.h" #include "widgets/widget-sizes.h" #include "helper/units.h" +#include "helper/action.h" #include "inkscape.h" enum { @@ -87,7 +88,7 @@ namespace Inkscape { namespace UI { namespace Widget { -StyleSwatch::StyleSwatch(SPCSSAttr *css) +StyleSwatch::StyleSwatch(SPCSSAttr *css, gchar const *main_tip) : _tool_path(NULL), _css (NULL), @@ -101,8 +102,8 @@ StyleSwatch::StyleSwatch(SPCSSAttr *css) _tooltips () { - _label[SS_FILL].set_markup(_("F:")); - _label[SS_STROKE].set_markup(_("S:")); + _label[SS_FILL].set_markup(_("Fill:")); + _label[SS_STROKE].set_markup(_("Stroke:")); for (int i = SS_FILL; i <= SS_STROKE; i++) { _label[i].set_alignment(0.0, 0.5); @@ -121,8 +122,8 @@ StyleSwatch::StyleSwatch(SPCSSAttr *css) _stroke_width_place.add(_stroke_width); _stroke.pack_start(_stroke_width_place, Gtk::PACK_SHRINK); - _table.attach(_label[SS_FILL], 0,1, 0,1, Gtk::SHRINK, Gtk::SHRINK); - _table.attach(_label[SS_STROKE], 0,1, 1,2, Gtk::SHRINK, Gtk::SHRINK); + _table.attach(_label[SS_FILL], 0,1, 0,1, Gtk::FILL, Gtk::SHRINK); + _table.attach(_label[SS_STROKE], 0,1, 1,2, Gtk::FILL, Gtk::SHRINK); _table.attach(_place[SS_FILL], 1,2, 0,1); _table.attach(_stroke, 1,2, 1,2); @@ -130,7 +131,8 @@ StyleSwatch::StyleSwatch(SPCSSAttr *css) _opacity_place.add(_opacity_value); _table.attach(_opacity_place, 2,3, 0,2, Gtk::SHRINK, Gtk::SHRINK); - pack_start(_table, true, true, 0); + _swatch.add(_table); + pack_start(_swatch, true, true, 0); set_size_request (STYLE_SWATCH_WIDTH, -1); @@ -143,6 +145,30 @@ StyleSwatch::StyleSwatch(SPCSSAttr *css) } setStyle (css); + + _swatch.signal_button_press_event().connect(sigc::mem_fun(*this, &StyleSwatch::on_click)); + + _tooltips.set_tip(_swatch, main_tip); +} + +void StyleSwatch::setClickVerb(sp_verb_t verb_t) { + _verb_t = verb_t; +} + +void StyleSwatch::setDesktop(SPDesktop *desktop) { + _desktop = desktop; +} + +bool +StyleSwatch::on_click(GdkEventButton *event) +{ + if (this->_desktop && this->_verb_t != SP_VERB_NONE) { + Inkscape::Verb *verb = Inkscape::Verb::get(this->_verb_t); + SPAction *action = verb->get_action((Inkscape::UI::View::View *) this->_desktop); + sp_action_perform (action, NULL); + return true; + } + return false; } StyleSwatch::~StyleSwatch() diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h index 1f7dd2e37..5efd561f3 100644 --- a/src/ui/widget/style-swatch.h +++ b/src/ui/widget/style-swatch.h @@ -21,6 +21,7 @@ #include #include +#include #include "button.h" @@ -41,7 +42,7 @@ namespace Widget { class StyleSwatch : public Gtk::HBox { public: - StyleSwatch (SPCSSAttr *attr); + StyleSwatch (SPCSSAttr *attr, gchar const *main_tip); ~StyleSwatch(); @@ -52,14 +53,24 @@ public: void setWatched (Inkscape::XML::Node *watched, Inkscape::XML::Node *secondary); void setWatchedTool (const char *path, bool synthesize); + void setClickVerb(sp_verb_t verb_t); + void setDesktop(SPDesktop *desktop); + bool on_click(GdkEventButton *event); + char *_tool_path; protected: + SPDesktop *_desktop; + + sp_verb_t _verb_t; + SPCSSAttr *_css; Inkscape::XML::Node *_watched; Inkscape::XML::Node *_watched_tool; + Gtk::EventBox _swatch; + Gtk::Table _table; Gtk::Label _label[2]; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index c2de24d6f..8d2f5c00a 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -1336,7 +1336,9 @@ sp_star_toolbox_new(SPDesktop *desktop) gtk_box_pack_start(GTK_BOX(tbl),hb, FALSE, FALSE, AUX_SPACING); } - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new stars")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_STAR_PREFS); swatch->setWatchedTool ("tools.shapes.star", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); @@ -1668,7 +1670,9 @@ sp_rect_toolbox_new(SPDesktop *desktop) gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS); } - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new rectangles")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_RECT_PREFS); swatch->setWatchedTool ("tools.shapes.rect", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); @@ -1917,7 +1921,9 @@ sp_spiral_toolbox_new(SPDesktop *desktop) gtk_box_pack_start(GTK_BOX(tbl),hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS); } - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new spirals")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_SPIRAL_PREFS); swatch->setWatchedTool ("tools.shapes.spiral", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); @@ -1945,7 +1951,9 @@ sp_pen_toolbox_new(SPDesktop *desktop) gtk_object_set_data(GTK_OBJECT(tbl), "dtw", desktop->canvas); gtk_object_set_data(GTK_OBJECT(tbl), "desktop", desktop); - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new paths created by Pen")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_PEN_PREFS); swatch->setWatchedTool ("tools.freehand.pen", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); @@ -1963,7 +1971,9 @@ sp_pencil_toolbox_new(SPDesktop *desktop) gtk_object_set_data(GTK_OBJECT(tbl), "dtw", desktop->canvas); gtk_object_set_data(GTK_OBJECT(tbl), "desktop", desktop); - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new paths created by Pencil")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_PENCIL_PREFS); swatch->setWatchedTool ("tools.freehand.pencil", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); @@ -2333,7 +2343,9 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) gtk_table_attach( GTK_TABLE(holder), toolBar, 0, 1, 0, 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0 ); - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new calligraphic strokes")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS); swatch->setWatchedTool ("tools.calligraphic", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_table_attach( GTK_TABLE(holder), swatch_, 1, 2, 0, 1, (GtkAttachOptions)(GTK_SHRINK | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), AUX_BETWEEN_BUTTON_GROUPS, 0 ); @@ -2489,7 +2501,9 @@ sp_calligraphy_toolbox_new(SPDesktop *desktop) } - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new calligraphic strokes")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS); swatch->setWatchedTool ("tools.calligraphic", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); @@ -2846,7 +2860,9 @@ sp_arc_toolbox_new(SPDesktop *desktop) ); g_signal_connect(G_OBJECT(tbl), "destroy", G_CALLBACK(delete_connection), connection); - Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL); + Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch(NULL, _("Style of new ellipses")); + swatch->setDesktop (desktop); + swatch->setClickVerb (SP_VERB_CONTEXT_ARC_PREFS); swatch->setWatchedTool ("tools.shapes.arc", true); GtkWidget *swatch_ = GTK_WIDGET(swatch->gobj()); gtk_box_pack_end(GTK_BOX(tbl), swatch_, FALSE, FALSE, 0); -- 2.30.2