summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/select-tool.cpp
diff options
context:
space:
mode:
authorMichael Soegtrop <MSoegtrop@yahoo.de>2017-06-05 13:01:17 +0000
committerMichael Soegtrop <MSoegtrop@yahoo.de>2017-06-05 13:01:17 +0000
commite7248b2fa042f42a5c4dd14cd86ab6a5b4524059 (patch)
tree9097520c54e355ded9bd0b4d6618af4e8dacdd91 /src/ui/tools/select-tool.cpp
parentupdated to latest trunk (diff)
parent[Bug #1695016] Xaml export misses some radialGradients. (diff)
downloadinkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.tar.gz
inkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.zip
updated to latest trunk
(bzr r14876.2.4)
Diffstat (limited to 'src/ui/tools/select-tool.cpp')
-rw-r--r--src/ui/tools/select-tool.cpp319
1 files changed, 123 insertions, 196 deletions
diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp
index 905e38f2b..bae1793ed 100644
--- a/src/ui/tools/select-tool.cpp
+++ b/src/ui/tools/select-tool.cpp
@@ -15,7 +15,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include <cstring>
#include <string>
@@ -40,14 +40,12 @@
#include "desktop.h"
#include "sp-root.h"
-#include "preferences.h"
#include "ui/tools-switch.h"
#include "message-stack.h"
#include "selection-describer.h"
#include "seltrans.h"
#include "box3d.h"
#include "display/sp-canvas.h"
-#include "display/sp-canvas-item.h"
#include "display/drawing-item.h"
using Inkscape::DocumentUndo;
@@ -65,7 +63,7 @@ static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so t
static gint drag_escaped = 0; // if non-zero, drag was canceled by esc
const std::string& SelectTool::getPrefsPath() {
- return SelectTool::prefsPath;
+ return SelectTool::prefsPath;
}
const std::string SelectTool::prefsPath = "/tools/select";
@@ -111,7 +109,6 @@ SelectTool::SelectTool()
//static gint tolerance = 0;
//static bool within_tolerance = false;
static bool is_cycling = false;
-static bool moved_while_cycling = false;
SelectTool::~SelectTool() {
@@ -129,20 +126,12 @@ SelectTool::~SelectTool() {
this->_describer = NULL;
if (CursorSelectDragging) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(CursorSelectDragging);
-#else
- gdk_cursor_unref (CursorSelectDragging);
-#endif
CursorSelectDragging = NULL;
}
if (CursorSelectMouseover) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(CursorSelectMouseover);
-#else
- gdk_cursor_unref (CursorSelectMouseover);
-#endif
CursorSelectMouseover = NULL;
}
}
@@ -153,7 +142,7 @@ void SelectTool::setup() {
this->_describer = new Inkscape::SelectionDescriber(
desktop->selection,
desktop->messageStack(),
- _("Click selection to toggle scale/rotation handles"),
+ _("Click selection to toggle scale/rotation handles (or Shift+s)"),
_("No objects selected. Click, Shift+click, Alt+scroll mouse on top of objects, or drag around objects to select.")
);
@@ -297,7 +286,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) {
} else {
GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
- this->dragging = TRUE;
+ this->dragging = TRUE;
this->moved = FALSE;
gdk_window_set_cursor(window, CursorSelectDragging);
@@ -347,11 +336,11 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) {
break;
}
case GDK_LEAVE_NOTIFY:
- if (!desktop->isWaitingCursor() && !this->dragging) {
+ if (!desktop->isWaitingCursor() && !this->dragging) {
GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
gdk_window_set_cursor(window, this->cursor);
- }
+ }
break;
case GDK_KEY_PRESS:
@@ -379,61 +368,75 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) {
}
if (!ret) {
- ret = ToolBase::item_handler(item, event);
+ ret = ToolBase::item_handler(item, event);
}
return ret;
}
void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed) {
- if (this->cycling_cur_item == this->cycling_items.end()) {
+ if ( this->cycling_items.empty() )
return;
- }
Inkscape::DrawingItem *arenaitem;
- SPItem *item = *cycling_cur_item;
- g_assert(item != NULL);
- // Deactivate current item
- if (std::find(cycling_items_selected_before.begin(), cycling_items_selected_before.end(), item) == cycling_items_selected_before.end() && selection->includes(item)) {
- selection->remove(item);
+ if(cycling_cur_item) {
+ arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(0.3);
}
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(0.3);
-
// Find next item and activate it
- std::vector<SPItem *>::iterator next = this->cycling_cur_item;
+
+
+ std::vector<SPItem *>::iterator next = cycling_items.end();
+
if (scroll_event->direction == GDK_SCROLL_UP) {
- ++next;
- if (next == this->cycling_items.end() && this->cycling_wrap) {
- next = this->cycling_items.begin();
+ if (! cycling_cur_item) {
+ next = cycling_items.begin();
+ } else {
+ next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item );
+ g_assert (next != cycling_items.end());
+ next++;
+ if (next == cycling_items.end())
+ if ( cycling_wrap )
+ next = cycling_items.begin();
+ else
+ next--;
}
- } else {
- if(next == this->cycling_items.begin()) {
- next = this->cycling_items.end();
+ } else {
+ if (! cycling_cur_item) {
+ next = cycling_items.end();
+ next--;
+ } else {
+ next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item );
+ g_assert (next != cycling_items.end());
+ if (next == cycling_items.begin()){
+ if ( cycling_wrap ) {
+ next = cycling_items.end();
+ next--;
+ }
+ } else {
+ next--;
+ }
}
- --next;
}
- if (next!=this->cycling_items.end()) {
- this->cycling_cur_item = next;
- item = *next;
- g_assert(item != NULL);
- }
+ this->cycling_cur_item = *next;
+ g_assert(next != cycling_items.end());
+ g_assert(cycling_cur_item != NULL);
- arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey);
arenaitem->setOpacity(1.0);
if (shift_pressed) {
- selection->add(item);
+ selection->add(cycling_cur_item);
} else {
- selection->set(item);
+ selection->set(cycling_cur_item);
}
}
void SelectTool::sp_select_context_reset_opacities() {
- for (std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l ) {
+ for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l ) {
SPItem *item = *l;
if (item) {
Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey);
@@ -443,10 +446,8 @@ void SelectTool::sp_select_context_reset_opacities() {
}
}
- this->cycling_items.clear();
- this->cycling_items_selected_before.clear();
- this->cycling_cur_item = this->cycling_items.end();
this->cycling_items_cmp.clear();
+ this->cycling_cur_item = NULL;
}
bool SelectTool::root_handler(GdkEvent* event) {
@@ -466,7 +467,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_2BUTTON_PRESS:
if (event->button.button == 1) {
if (!selection->isEmpty()) {
- SPItem *clicked_item = selection->itemList()[0];
+ SPItem *clicked_item = selection->items().front();
if (dynamic_cast<SPGroup *>(clicked_item) && !dynamic_cast<SPBox3D *>(clicked_item)) { // enter group if it's not a 3D box
desktop->setCurrentLayer(clicked_item);
@@ -533,11 +534,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_MOTION_NOTIFY:
{
- if (is_cycling) {
- moved_while_cycling = true;
- }
-
- tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+ tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) {
Geom::Point const motion_pt(event->motion.x, event->motion.y);
@@ -703,7 +700,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (r->is_started() && !within_tolerance) {
// this was a rubberband drag
- std::vector<SPItem*> items;
+ std::vector<SPItem*> items;
if (r->getMode() == RUBBERBAND_MODE_RECT) {
Geom::OptRect const b = r->getRectangle();
@@ -796,107 +793,67 @@ bool SelectTool::root_handler(GdkEvent* event) {
break;
case GDK_SCROLL: {
- GdkEventScroll *scroll_event = (GdkEventScroll*) event;
-
- if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed
- if (moved_while_cycling) {
- moved_while_cycling = false;
- this->sp_select_context_reset_opacities();
- }
-
- is_cycling = true;
-
- bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK;
-
- /* Rebuild list of items underneath the mouse pointer */
- Geom::Point p = desktop->d2w(desktop->point());
- SPItem *item = desktop->getItemAtPoint(p, true, NULL);
-
- // Save pointer to current cycle-item so that we can find it again later, in the freshly built list
- SPItem *tmp_cur_item = this->cycling_cur_item!=this->cycling_items.end() ? (*(this->cycling_cur_item)) : NULL;
- this->cycling_items.clear();
- this->cycling_cur_item = this->cycling_items.end();
- while(item != NULL) {
- this->cycling_items.push_back(item);
- item = desktop->getItemAtPoint(p, true, item);
- }
-
- /* Compare current item list with item list during previous scroll ... */
- bool item_lists_differ = this->cycling_items != this->cycling_items_cmp;
- /* If list of items under mouse pointer hasn't changed ... */
- if (!item_lists_differ) {
- // ... find current item in the freshly built list and continue cycling ...
- // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead
- this->cycling_cur_item = std::find(this->cycling_items.begin(), this->cycling_items.end(), tmp_cur_item);
- g_assert(this->cycling_cur_item != this->cycling_items.end() || this->cycling_items.empty());
- } else {
- // ... otherwise reset opacities for outdated items ...
- Inkscape::DrawingItem *arenaitem;
-
- for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) {
- SPItem *item = *l;
- if (item) {
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(1.0);
- //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, item) && selection->includes(item))
- if (std::find(this->cycling_items_selected_before.begin(),this->cycling_items_selected_before.end(), item)==this->cycling_items_selected_before.end() && selection->includes(item)) {
- selection->remove(item);
- }
- }
- }
+ GdkEventScroll *scroll_event = (GdkEventScroll*) event;
- // ... clear the lists ...
+ if ( ! (scroll_event->state & GDK_MOD1_MASK)) // do nothing specific if alt was not pressed
+ break;
- this->cycling_items_cmp.clear();
- this->cycling_items_selected_before.clear();
- this->cycling_cur_item = this->cycling_items.end();
+ bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK;
+ is_cycling = true;
- // ... and rebuild them with the new items.
- this->cycling_items_cmp = (this->cycling_items);
+ /* Rebuild list of items underneath the mouse pointer */
+ Geom::Point p = desktop->d2w(desktop->point());
+ SPItem *item = desktop->getItemAtPoint(p, true, NULL);
+ this->cycling_items.clear();
- for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) {
- SPItem *item =*l;
- if (item) {
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(0.3);
+ SPItem *tmp = NULL;
+ while(item != NULL) {
+ this->cycling_items.push_back(item);
+ item = desktop->getItemAtPoint(p, true, item);
+ if (selection->includes(item)) tmp = item;
+ }
- if (selection->includes(item)) {
- // already selected items are stored separately, too
- this->cycling_items_selected_before.push_back(item);
- }
- } else {
- g_assert_not_reached();
- }
+ /* Compare current item list with item list during previous scroll ... */
+ bool item_lists_differ = this->cycling_items != this->cycling_items_cmp;
+
+ if(item_lists_differ) {
+ this->sp_select_context_reset_opacities();
+ for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l)
+ selection->remove(*l); // deselects the previous content of the cycling loop
+ this->cycling_items_cmp = (this->cycling_items);
+
+ // set opacities in new stack
+ for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) {
+ SPItem *item =*l;
+ if (item) {
+ Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(0.3);
}
-
- // set the current item to the bottommost one so that the cycling step below re-starts at the top
- this->cycling_cur_item = this->cycling_items.end();
- this->cycling_cur_item--;
}
+ }
+ if(!cycling_cur_item) cycling_cur_item = tmp;
- this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true);
+ this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true);
- // Cycle through the items underneath the mouse pointer, one-by-one
- this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed);
+ // Cycle through the items underneath the mouse pointer, one-by-one
+ this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed);
- ret = TRUE;
+ ret = TRUE;
- GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) ));
- if (w)
- {
- gtk_window_present(w);
- gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
- }
+ GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) ));
+ if (w) {
+ gtk_window_present(w);
+ gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
}
break;
}
case GDK_KEY_PRESS: // keybindings for select context
- {
- {
- guint keyval = get_group0_keyval(&event->key);
-
+ {
+ {
+ guint keyval = get_group0_keyval(&event->key);
+
bool alt = ( MOD__ALT(event)
|| (keyval == GDK_KEY_Alt_L)
|| (keyval == GDK_KEY_Alt_R)
@@ -924,7 +881,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
// if Alt and nonempty selection, show moving cursor ("move selected"):
if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) {
- GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
+ GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
gdk_window_set_cursor(window, CursorSelectDragging);
}
@@ -945,15 +902,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift
+ desktop->getSelection()->moveScreen(mul*-10, 0); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift
+ desktop->getSelection()->moveScreen(mul*-1, 0); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift
+ desktop->getSelection()->move(mul*-10*nudge, 0); // shift
} else {
- sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift
+ desktop->getSelection()->move(mul*-nudge, 0); // no shift
}
}
@@ -968,15 +925,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift
+ desktop->getSelection()->moveScreen(0, mul*10); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift
+ desktop->getSelection()->moveScreen(0, mul*1); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift
+ desktop->getSelection()->move(0, mul*10*nudge); // shift
} else {
- sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift
+ desktop->getSelection()->move(0, mul*nudge); // no shift
}
}
@@ -991,15 +948,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift
+ desktop->getSelection()->moveScreen(mul*10, 0); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift
+ desktop->getSelection()->moveScreen(mul*1, 0); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift
+ desktop->getSelection()->move(mul*10*nudge, 0); // shift
} else {
- sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift
+ desktop->getSelection()->move(mul*nudge, 0); // no shift
}
}
@@ -1014,15 +971,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift
+ desktop->getSelection()->moveScreen(0, mul*-10); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift
+ desktop->getSelection()->moveScreen(0, mul*-1); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift
+ desktop->getSelection()->move(0, mul*-10*nudge); // shift
} else {
- sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift
+ desktop->getSelection()->move(0, mul*-nudge); // no shift
}
}
@@ -1066,11 +1023,11 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_KEY_bracketleft:
if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_rotate_screen(selection, mul*1);
+ selection->rotateScreen(mul*1);
} else if (MOD__CTRL(event)) {
- sp_selection_rotate(selection, 90);
+ selection->rotate(90);
} else if (snaps) {
- sp_selection_rotate(selection, 180.0/snaps);
+ selection->rotate(180.0/snaps);
}
ret = TRUE;
@@ -1079,46 +1036,16 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_KEY_bracketright:
if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_rotate_screen(selection, -1*mul);
+ selection->rotateScreen(-1*mul);
} else if (MOD__CTRL(event)) {
- sp_selection_rotate(selection, -90);
+ selection->rotate(-90);
} else if (snaps) {
- sp_selection_rotate(selection, -180.0/snaps);
+ selection->rotate(-180.0/snaps);
}
ret = TRUE;
break;
-
- case GDK_KEY_less:
- case GDK_KEY_comma:
- if (MOD__ALT(event)) {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale_screen(selection, -2*mul);
- } else if (MOD__CTRL(event)) {
- sp_selection_scale_times(selection, 0.5);
- } else {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale(selection, -offset*mul);
- }
-
- ret = TRUE;
- break;
-
- case GDK_KEY_greater:
- case GDK_KEY_period:
- if (MOD__ALT(event)) {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale_screen(selection, 2*mul);
- } else if (MOD__CTRL(event)) {
- sp_selection_scale_times(selection, 2);
- } else {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale(selection, offset*mul);
- }
-
- ret = TRUE;
- break;
-
+
case GDK_KEY_Return:
if (MOD__CTRL_ONLY(event)) {
if (selection->singleItem()) {
@@ -1157,7 +1084,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
- sp_selection_to_guides(desktop);
+ desktop->selection->toGuides();
ret = true;
}
break;
@@ -1166,7 +1093,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
break;
}
break;
- }
+ }
case GDK_KEY_RELEASE: {
guint keyval = get_group0_keyval(&event->key);
if (key_is_a_modifier (keyval)) {
@@ -1207,7 +1134,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
}
if (!ret) {
- ret = ToolBase::root_handler(event);
+ ret = ToolBase::root_handler(event);
}
return ret;