From: dvlierop2 Date: Sun, 22 Feb 2009 19:01:44 +0000 (+0000) Subject: Use on-cavas text instead of a tooltip for the snapindicator (fixes some tooltip... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=70c0e45df7e4d98aefc5266c5b551a62cbb7a3e1;p=inkscape.git Use on-cavas text instead of a tooltip for the snapindicator (fixes some tooltip annoyances and fixes bug #330252) --- diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp index e55c8faac..4d16f9ffb 100644 --- a/src/display/snap-indicator.cpp +++ b/src/display/snap-indicator.cpp @@ -16,16 +16,17 @@ #include "desktop.h" #include "desktop-handles.h" #include "display/sodipodi-ctrl.h" +#include "display/canvas-bpath.h" #include "knot.h" #include "preferences.h" #include -#include namespace Inkscape { namespace Display { SnapIndicator::SnapIndicator(SPDesktop * desktop) : _snaptarget(NULL), + _snaptarget_tooltip(NULL), _snapsource(NULL), _desktop(desktop) { @@ -181,6 +182,8 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const p) } //std::cout << "Snapped " << source_name << " to " << target_name << std::endl; + remove_snapsource(); // Don't set both the source and target indicators, as these will overlap + // Display the snap indicator (i.e. the cross) SPCanvasItem * canvasitem = NULL; if (p.getTarget() == SNAPTARGET_NODE_SMOOTH || p.getTarget() == SNAPTARGET_NODE_CUSP) { @@ -205,23 +208,18 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const p) NULL ); } - const int timeout_val = 1000; // TODO add preference for snap indicator timeout? + const int timeout_val = 1200; // TODO add preference for snap indicator timeout? SP_CTRL(canvasitem)->moveto(p.getPoint()); - remove_snapsource(); // Don't set both the source and target indicators, as these will overlap _snaptarget = _desktop->add_temporary_canvasitem(canvasitem, timeout_val); - // Display the tooltip - GtkSettings *settings = gtk_widget_get_settings (&(_desktop->canvas->widget)); - // If we set the timeout too short, then the tooltip might not show at all (most noticeable when a long snap delay is active) - g_object_set(settings, "gtk-tooltip-timeout", 200, NULL); // tooltip will be shown after x msec. - gchar *tooltip_text = g_strconcat(source_name, _(" to "), target_name, NULL); - gtk_widget_set_tooltip_text(&(_desktop->canvas->widget), tooltip_text); - // has_tooltip will be true by now because gtk_widget_set_has_tooltip() has been called implicitly - update_tooltip(); - // The snap indicator will be removed automatically because it's a temporary canvas item; the tooltip - // however must be removed manually, so we'll create a timer to that end - Glib::signal_timeout().connect(sigc::mem_fun(*this, &SnapIndicator::remove_tooltip), timeout_val); + gchar *tooltip_str = g_strconcat(source_name, _(" to "), target_name, NULL); + + SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(_desktop), _desktop, p.getPoint() + Geom::Point(15, -15), tooltip_str); + g_free(tooltip_str); + + sp_canvastext_set_anchor((SPCanvasText* )canvas_tooltip, -1, 1); + _snaptarget_tooltip = _desktop->add_temporary_canvasitem(canvas_tooltip, timeout_val); } } @@ -233,7 +231,11 @@ SnapIndicator::remove_snaptarget() _snaptarget = NULL; } - remove_tooltip(); + if (_snaptarget_tooltip) { + _desktop->remove_temporary_canvasitem(_snaptarget_tooltip); + _snaptarget_tooltip = NULL; + } + } void @@ -259,7 +261,7 @@ SnapIndicator::set_new_snapsource(std::pair const p) SP_CTRL(canvasitem)->moveto(p.first); _snapsource = _desktop->add_temporary_canvasitem(canvasitem, 1000); - } + } } void @@ -271,42 +273,6 @@ SnapIndicator::remove_snapsource() } } -// Shows or hides the tooltip -void SnapIndicator::update_tooltip() const -{ - // When using gtk_widget_trigger_tooltip_query, the tooltip will for some reason always popup - // in the upper-left corner of the screen (probably at (0,0)). As a workaround we'll create - // a motion event instead, which will also trigger the tooltip - gint x, y; - GdkWindow *window; - - GdkDisplay *display = gdk_display_get_default(); - window = gdk_display_get_window_at_pointer(display, &x, &y); - if (window) { - GdkEvent *event = gdk_event_new(GDK_MOTION_NOTIFY); - event->motion.window = window; - event->motion.x = x; - event->motion.y = y; - event->motion.is_hint = FALSE; - - gdk_window_get_origin(window, &x, &y); - event->motion.x_root = event->motion.x + x; - event->motion.y_root = event->motion.y + y; - - gtk_main_do_event(event); - } -} - -// Can be called either directly or through a timer -bool -SnapIndicator::remove_tooltip() const -{ - gtk_widget_set_has_tooltip (&(_desktop->canvas->widget), false); - gtk_widget_trigger_tooltip_query(&(_desktop->canvas->widget)); - return false; -} - - } //namespace Display } /* namespace Inkscape */ diff --git a/src/display/snap-indicator.h b/src/display/snap-indicator.h index ae0963b4f..4391ca6d6 100644 --- a/src/display/snap-indicator.h +++ b/src/display/snap-indicator.h @@ -34,14 +34,13 @@ public: protected: TemporaryItem *_snaptarget; + TemporaryItem *_snaptarget_tooltip; TemporaryItem *_snapsource; SPDesktop *_desktop; private: SnapIndicator(const SnapIndicator&); SnapIndicator& operator=(const SnapIndicator&); - void update_tooltip() const; - bool remove_tooltip() const; }; } //namespace Display diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 141e10611..38b0ae995 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -938,7 +938,6 @@ static gint sp_canvas_key (GtkWidget *widget, GdkEventKey *event); static gint sp_canvas_crossing (GtkWidget *widget, GdkEventCrossing *event); static gint sp_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event); static gint sp_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event); -static gboolean sp_canvas_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip); static GtkWidgetClass *canvas_parent_class; @@ -1051,8 +1050,6 @@ sp_canvas_init (SPCanvas *canvas) canvas->watchdog_id = 0; canvas->watchdog_event = NULL; canvas->context_snap_delay_active = false; - - g_signal_connect(&(canvas->widget), "query-tooltip", G_CALLBACK (sp_canvas_query_tooltip), NULL); } /** @@ -2165,26 +2162,6 @@ sp_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event) return FALSE; } - -static gboolean sp_canvas_query_tooltip (GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip *tooltip) -{ - // We're not really doing anything special here, so we might just as well remove sp_canvas_query_tooltip - // all together (and stop listening to the query_tooltip signal. We might make a custom tooltip however - // someday, for example to display icons instead of just plain text. In that case we will need this call - // so that's why I'm leaving it here for the time being. - - if (canvas_parent_class->query_tooltip) { - return canvas_parent_class->query_tooltip (widget, x, y, keyboard_mode, tooltip); - } - - return false; -} - - /** * Helper that repaints the areas in the canvas that need it. *