summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dc56487)
raw | patch | inline | side by side (parent: dc56487)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Sun, 22 Feb 2009 19:01:44 +0000 (19:01 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Sun, 22 Feb 2009 19:01:44 +0000 (19:01 +0000) |
src/display/snap-indicator.cpp | patch | blob | history | |
src/display/snap-indicator.h | patch | blob | history | |
src/display/sp-canvas.cpp | patch | blob | history |
index e55c8faac2d88dca24e15c3c08da99ca52e3ff0f..4d16f9ffbff33285f8196dc3336404aa62729264 100644 (file)
#include "desktop.h"
#include "desktop-handles.h"
#include "display/sodipodi-ctrl.h"
+#include "display/canvas-bpath.h"
#include "knot.h"
#include "preferences.h"
#include <glibmm/i18n.h>
-#include <gtk/gtk.h>
namespace Inkscape {
namespace Display {
SnapIndicator::SnapIndicator(SPDesktop * desktop)
: _snaptarget(NULL),
+ _snaptarget_tooltip(NULL),
_snapsource(NULL),
_desktop(desktop)
{
}
//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) {
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);
}
}
_snaptarget = NULL;
}
- remove_tooltip();
+ if (_snaptarget_tooltip) {
+ _desktop->remove_temporary_canvasitem(_snaptarget_tooltip);
+ _snaptarget_tooltip = NULL;
+ }
+
}
void
SP_CTRL(canvasitem)->moveto(p.first);
_snapsource = _desktop->add_temporary_canvasitem(canvasitem, 1000);
- }
+ }
}
void
}
}
-// 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 */
index ae0963b4f93ad0ac5d5e6a4c681d686768abeca5..4391ca6d6043a4d05d190ee595ffd6d3b4060bb9 100644 (file)
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
index 141e10611e7310a88c221648f4e9150be75af339..38b0ae995cd972e745961a655786a2a5b156fa27 100644 (file)
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;
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);
}
/**
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.
*