Code

enable click-action and general tooltip for style swatches
authorbuliabyak <buliabyak@users.sourceforge.net>
Thu, 15 Feb 2007 21:48:09 +0000 (21:48 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Thu, 15 Feb 2007 21:48:09 +0000 (21:48 +0000)
src/ui/dialog/inkscape-preferences.cpp
src/ui/widget/style-swatch.cpp
src/ui/widget/style-swatch.h
src/widgets/toolbox.cpp

index 079a987f57836eba977675a50e75cb5405568883..34cdee00bf40df11678ff115e14f1bb8bceb1469 100644 (file)
@@ -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);
     }
index ef27ff390f2b8e88e1de201cdefb596cfb2bd659..705083a8f9afa2784671dc53797939722812f76e 100644 (file)
@@ -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()
index 1f7dd2e377e1470030e51f64c71d85b1c89aa62d..5efd561f380fd9092ffb295e9bf5abd0ec02ebf6 100644 (file)
@@ -21,6 +21,7 @@
 #include <glibmm/i18n.h>
 
 #include <desktop.h>
+#include <verbs.h>
 
 #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];
index c2de24d6f42861308801183f663a94b70b56612a..8d2f5c00afa950ffb34be2878c2001dd47008133 100644 (file)
@@ -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);