diff --git a/src/event-context.cpp b/src/event-context.cpp
index 9df17114631543479188ed8cb0a2eb1b777156d3..7039c3b130c050ef37d87de12f61e4ae4f4c0991 100644 (file)
--- a/src/event-context.cpp
+++ b/src/event-context.cpp
#include "interface.h"
#include "macros.h"
#include "tools-switch.h"
-#include "prefs-utils.h"
+#include "preferences.h"
#include "message-context.h"
#include "gradient-drag.h"
#include "object-edit.h"
event_context->_selcue = NULL;
event_context->_grdrag = NULL;
event_context->space_panning = false;
+ event_context->shape_editor = NULL;
}
/**
ec->desktop = NULL;
}
- if (ec->prefs_repr) {
- sp_repr_remove_listener_by_data(ec->prefs_repr, ec);
- Inkscape::GC::release(ec->prefs_repr);
- ec->prefs_repr = NULL;
+ if (ec->pref_observer) {
+ delete ec->pref_observer;
}
G_OBJECT_CLASS(parent_class)->dispose(object);
@@ -338,17 +337,19 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
static unsigned int zoom_rb = 0;
SPDesktop *desktop = event_context->desktop;
-
- tolerance = prefs_get_int_attribute_limited(
- "options.dragtolerance","value", 0, 0, 100);
- double const zoom_inc = prefs_get_double_attribute_limited(
- "options.zoomincrement", "value", M_SQRT2, 1.01, 10);
- double const acceleration = prefs_get_double_attribute_limited(
- "options.scrollingacceleration", "value", 0, 0, 6);
- int const key_scroll = prefs_get_int_attribute_limited(
- "options.keyscroll", "value", 10, 0, 1000);
- int const wheel_scroll = prefs_get_int_attribute_limited(
- "options.wheelscroll", "value", 40, 0, 1000);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+ /// @todo REmove redundant /value in preference keys
+ tolerance = prefs->getIntLimited(
+ "/options/dragtolerance/value", 0, 0, 100);
+ double const zoom_inc = prefs->getDoubleLimited(
+ "/options/zoomincrement/value", M_SQRT2, 1.01, 10);
+ double const acceleration = prefs->getDoubleLimited(
+ "/options/scrollingacceleration/value", 0, 0, 6);
+ int const key_scroll = prefs->getIntLimited(
+ "/options/keyscroll/value", 10, 0, 1000);
+ int const wheel_scroll = prefs->getIntLimited(
+ "/options/wheelscroll/value", 40, 0, 1000);
gint ret = FALSE;
@@ -499,7 +500,7 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
ret = TRUE;
} else if (zoom_rb == event->button.button) {
zoom_rb = 0;
- boost::optional<Geom::Rect> const b = Inkscape::Rubberband::get(desktop)->getRectangle();
+ Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle();
Inkscape::Rubberband::get(desktop)->stop();
if (b && !within_tolerance) {
desktop->set_display_area(*b, 10);
@@ -533,6 +534,16 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
ret = TRUE;
}
break;
+ case GDK_Q:
+ case GDK_q:
+ if (desktop->quick_zoomed()) {
+ ret = TRUE;
+ }
+ if (!MOD__SHIFT && !MOD__CTRL && !MOD__ALT) {
+ desktop->zoom_quick(true);
+ ret = TRUE;
+ }
+ break;
case GDK_W:
case GDK_w:
case GDK_F4:
@@ -593,7 +604,7 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
}
break;
case GDK_space:
- if (prefs_get_int_attribute("options.spacepans","value", 0) == 1) {
+ if (prefs->getBool("/options/spacepans/value")) {
event_context->space_panning = true;
event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, _("<b>Space+mouse drag</b> to pan canvas"));
ret= TRUE;
@@ -628,6 +639,13 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
ret= TRUE;
}
break;
+ case GDK_Q:
+ case GDK_q:
+ if (desktop->quick_zoomed()) {
+ desktop->zoom_quick(false);
+ ret = TRUE;
+ }
+ break;
default:
break;
}
@@ -635,7 +653,7 @@ static gint sp_event_context_private_root_handler(SPEventContext *event_context,
case GDK_SCROLL:
{
bool ctrl = (event->scroll.state & GDK_CONTROL_MASK);
- bool wheelzooms = (prefs_get_int_attribute("options.wheelzooms","value", 0) == 1);
+ bool wheelzooms = prefs->getBool("/options/wheelzooms/value");
/* shift + wheel, pan left--right */
if (event->scroll.state & GDK_SHIFT_MASK) {
switch (event->scroll.direction) {
@@ -721,34 +739,30 @@ sp_event_context_private_item_handler(SPEventContext *ec, SPItem *item, GdkEvent
}
/**
- * Gets called when attribute changes value.
+ * @brief An observer that relays pref changes to the derived classes
*/
-static void
-sp_ec_repr_attr_changed(Inkscape::XML::Node */*prefs_repr*/, gchar const *key, gchar const */*oldval*/, gchar const *newval,
- bool /*is_interactive*/, gpointer data)
-{
- SPEventContext *ec;
-
- ec = SP_EVENT_CONTEXT(data);
-
- if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set) {
- ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set(ec, key, newval);
+class ToolPrefObserver : public Inkscape::Preferences::Observer {
+public:
+ ToolPrefObserver(Glib::ustring const &path, SPEventContext *ec) :
+ Inkscape::Preferences::Observer(path),
+ _ec(ec) {}
+ virtual void notify(Inkscape::Preferences::Entry const &val)
+ {
+ if (((SPEventContextClass *) G_OBJECT_GET_CLASS(_ec))->set) {
+ ((SPEventContextClass *) G_OBJECT_GET_CLASS(_ec))->set(_ec,
+ const_cast<Inkscape::Preferences::Entry*>(&val));
+ }
}
-}
-
-Inkscape::XML::NodeEventVector sp_ec_event_vector = {
- NULL, /* Child added */
- NULL, /* Child removed */
- sp_ec_repr_attr_changed,
- NULL, /* Content changed */
- NULL /* Order changed */
+private:
+ SPEventContext * const _ec;
};
/**
* Creates new SPEventContext object and calls its virtual setup() function.
+ * @todo This is bogus. pref_path should be a private property of the inheriting objects.
*/
SPEventContext *
-sp_event_context_new(GType type, SPDesktop *desktop, Inkscape::XML::Node *prefs_repr, unsigned int key)
+sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, unsigned int key)
{
g_return_val_if_fail(g_type_is_a(type, SP_TYPE_EVENT_CONTEXT), NULL);
g_return_val_if_fail(desktop != NULL, NULL);
@@ -758,10 +772,13 @@ sp_event_context_new(GType type, SPDesktop *desktop, Inkscape::XML::Node *prefs_
ec->desktop = desktop;
ec->_message_context = new Inkscape::MessageContext(desktop->messageStack());
ec->key = key;
- ec->prefs_repr = prefs_repr;
- if (ec->prefs_repr) {
- Inkscape::GC::anchor(ec->prefs_repr);
- sp_repr_add_listener(ec->prefs_repr, &sp_ec_event_vector, ec);
+ ec->pref_observer = NULL;
+
+ if (pref_path) {
+ ec->pref_observer = new ToolPrefObserver(pref_path, ec);
+
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ prefs->addObserver(*(ec->pref_observer));
}
if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->setup)
g_return_if_fail(SP_IS_EVENT_CONTEXT(ec));
g_return_if_fail(key != NULL);
- if (ec->prefs_repr) {
- gchar const *val = ec->prefs_repr->attribute(key);
- if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set)
- ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set(ec, key, val);
+ if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ Inkscape::Preferences::Entry val = prefs->getEntry(
+ ec->pref_observer->observed_path + '/' + key );
+ ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set(ec, &val);
}
}
@@ -1041,48 +1059,9 @@ sp_event_context_over_item (SPDesktop *desktop, SPItem *item, Geom::Point const
ShapeEditor *
sp_event_context_get_shape_editor (SPEventContext *ec)
{
- if (SP_IS_NODE_CONTEXT(ec)) {
- return SP_NODE_CONTEXT(ec)->shape_editor;
- } else if (SP_IS_LPETOOL_CONTEXT(ec)) {
- return SP_LPETOOL_CONTEXT(ec)->shape_editor;
- } else {
- g_warning("ShapeEditor only exists in Node and Geometric Tool.");
- return NULL;
- }
-}
-
-/**
- * Called when SPEventContext subclass node attribute changed.
- */
-void
-ec_shape_event_attr_changed(Inkscape::XML::Node */*shape_repr*/, gchar const *name,
- gchar const */*old_value*/, gchar const */*new_value*/,
- bool const /*is_interactive*/, gpointer const data)
-{
- if (!name
- || !strcmp(name, "style")
- || SP_ATTRIBUTE_IS_CSS(sp_attribute_lookup(name))) {
- // no need to regenrate knotholder if only style changed
- return;
- }
-
- SPEventContext *ec = SP_EVENT_CONTEXT(data);
-
- if (ec->shape_knot_holder) {
- delete ec->shape_knot_holder;
- }
- ec->shape_knot_holder = NULL;
-
- SPDesktop *desktop = ec->desktop;
-
- SPItem *item = sp_desktop_selection(desktop)->singleItem();
-
- if (item) {
- ec->shape_knot_holder = sp_item_knot_holder(item, desktop);
- }
+ return ec->shape_editor;
}
-
void
event_context_print_event_info(GdkEvent *event, bool print_return) {
switch (event->type) {