summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-04-04 09:54:17 +0000
committerJohn Smith <removethis.john.q.public@bigmail.com>2012-04-04 09:54:17 +0000
commit4d44c257559a9cea38f69eb340fad84688aca3e8 (patch)
tree92666bbd1b6a0d3c5ca11b2ed18f32921fe12a23
parentFix build with gtk < 2.24 (diff)
downloadinkscape-4d44c257559a9cea38f69eb340fad84688aca3e8.tar.gz
inkscape-4d44c257559a9cea38f69eb340fad84688aca3e8.zip
Fix for 170378 : Select same objects by fill or stroke : Added stroke style
(bzr r11146)
-rw-r--r--src/menus-skeleton.h5
-rw-r--r--src/selection-chemistry.cpp131
-rw-r--r--src/selection-chemistry.h19
-rw-r--r--src/ui/context-menu.cpp10
-rw-r--r--src/verbs.cpp19
-rw-r--r--src/verbs.h5
6 files changed, 156 insertions, 33 deletions
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h
index d92274a9e..84ecc83ea 100644
--- a/src/menus-skeleton.h
+++ b/src/menus-skeleton.h
@@ -80,8 +80,9 @@ static char const menus_skeleton[] =
" <verb verb-id=\"EditSelectAllInAllLayers\" />\n"
" <submenu name=\"" N_("Selec_t Same") "\">\n"
" <verb verb-id=\"EditSelectSameFillStroke\" />\n"
-" <verb verb-id=\"EditSelectSameFill\" />\n"
-" <verb verb-id=\"EditSelectSameStroke\" />\n"
+" <verb verb-id=\"EditSelectSameFillColor\" />\n"
+" <verb verb-id=\"EditSelectSameStrokeColor\" />\n"
+" <verb verb-id=\"EditSelectSameStrokeStyle\" />\n"
" </submenu>\n"
" <verb verb-id=\"EditInvert\" />\n"
" <verb verb-id=\"EditDeselect\" />\n"
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index ff6c137a6..2fe3b343f 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -153,19 +153,23 @@ void SelectionHelper::selectNone(SPDesktop *dt)
void SelectionHelper::selectSameFillStroke(SPDesktop *dt)
{
- sp_select_same_fill_stroke(dt, true, true);
+ sp_select_same_fill_stroke_style(dt, true, true, true);
}
-void SelectionHelper::selectSameFill(SPDesktop *dt)
+void SelectionHelper::selectSameFillColor(SPDesktop *dt)
{
- sp_select_same_fill_stroke(dt, true, false);
+ sp_select_same_fill_stroke_style(dt, true, false, false);
}
-void SelectionHelper::selectSameStroke(SPDesktop *dt)
+void SelectionHelper::selectSameStrokeColor(SPDesktop *dt)
{
- sp_select_same_fill_stroke(dt, false, true);
+ sp_select_same_fill_stroke_style(dt, false, true, false);
}
+void SelectionHelper::selectSameStrokeStyle(SPDesktop *dt)
+{
+ sp_select_same_stroke_style(dt);
+}
void SelectionHelper::invert(SPDesktop *dt)
{
@@ -1627,20 +1631,20 @@ sp_selection_rotate(Inkscape::Selection *selection, gdouble const angle_degrees)
}
/*
- * Selects all the visible items with the same fill and/or stroke style as the items in the current selection
+ * Selects all the visible items with the same fill and/or stroke color/style as the items in the current selection
*
* Params:
* desktop - set the selection on this desktop
* fill - select objects matching fill
* stroke - select objects matching stroke
*/
-void sp_select_same_fill_stroke(SPDesktop *desktop, gboolean fill, gboolean stroke)
+void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean stroke, gboolean style)
{
if (!desktop) {
return;
}
- if (!fill && !stroke) {
+ if (!fill && !stroke && !style) {
return;
}
@@ -1653,10 +1657,15 @@ void sp_select_same_fill_stroke(SPDesktop *desktop, gboolean fill, gboolean stro
SPItem *sel = SP_ITEM(sel_iter->data);
GSList *matches = all_list;
if (fill) {
- matches = sp_get_same_fill_or_stroke_items(sel, matches, TRUE);
+ matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_FILL_COLOR);
}
if (stroke) {
- matches = sp_get_same_fill_or_stroke_items(sel, matches, FALSE);
+ matches = sp_get_same_fill_or_stroke_color(sel, matches, SP_STROKE_COLOR);
+ }
+ if (style) {
+ matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH);
+ matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES);
+ matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS);
}
all_matches = g_slist_concat (all_matches, matches);
}
@@ -1669,20 +1678,52 @@ void sp_select_same_fill_stroke(SPDesktop *desktop, gboolean fill, gboolean stro
}
+
+/*
+ * Selects all the visible items with the same stroke style as the items in the current selection
+ *
+ * Params:
+ * desktop - set the selection on this desktop
+ */
+void sp_select_same_stroke_style(SPDesktop *desktop)
+{
+ if (!desktop) {
+ return;
+ }
+
+ GSList *all_list = get_all_items(NULL, desktop->currentRoot(), desktop, true, true, NULL);
+ GSList *matches = all_list;
+
+ Inkscape::Selection *selection = sp_desktop_selection (desktop);
+
+ for (GSList const* sel_iter = selection->itemList(); sel_iter; sel_iter = sel_iter->next) {
+ SPItem *sel = SP_ITEM(sel_iter->data);
+ matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_WIDTH);
+ matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_DASHES);
+ matches = sp_get_same_stroke_style(sel, matches, SP_STROKE_STYLE_MARKERS);
+ }
+
+ selection->clear();
+ selection->setList(matches);
+
+ g_slist_free(matches);
+ g_slist_free(all_list);
+}
+
/*
* Find all items in src list that have the same fill or stroke style as sel
* Return the list of matching items
*/
-GSList *sp_get_same_fill_or_stroke_items(SPItem *sel, GSList *src, gboolean fillorstroke)
+GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type)
{
GSList *matches = NULL;
gboolean match = false;
- SPIPaint *sel_paint = (fillorstroke) ? &(sel->style->fill) : &(sel->style->stroke);
+ SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke);
for (GSList *i = src; i != NULL; i = i->next) {
SPItem *iter = SP_ITEM(i->data);
- SPIPaint *iter_paint = (fillorstroke) ? &(iter->style->fill) : &(iter->style->stroke);
+ SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke);
match = false;
if (sel_paint->isColor() && iter_paint->isColor() // color == color comparision doesnt seem to work here.
&& (sel_paint->value.color.toRGBA32(1.0) == iter_paint->value.color.toRGBA32(1.0))) {
@@ -1690,9 +1731,9 @@ GSList *sp_get_same_fill_or_stroke_items(SPItem *sel, GSList *src, gboolean fill
} else if (sel_paint->isPaintserver() && iter_paint->isPaintserver()) {
SPPaintServer *sel_server =
- (fillorstroke) ? sel->style->getFillPaintServer() : sel->style->getStrokePaintServer();
+ (type == SP_FILL_COLOR) ? sel->style->getFillPaintServer() : sel->style->getStrokePaintServer();
SPPaintServer *iter_server =
- (fillorstroke) ? iter->style->getFillPaintServer() : iter->style->getStrokePaintServer();
+ (type == SP_FILL_COLOR) ? iter->style->getFillPaintServer() : iter->style->getStrokePaintServer();
if ((SP_IS_LINEARGRADIENT(sel_server) || SP_IS_RADIALGRADIENT(sel_server) ||
(SP_IS_GRADIENT(sel_server) && SP_GRADIENT(sel_server)->getVector()->isSwatch()))
@@ -1726,6 +1767,66 @@ GSList *sp_get_same_fill_or_stroke_items(SPItem *sel, GSList *src, gboolean fill
return matches;
}
+/*
+ * Find all items in src list that have the same stroke style as sel by type
+ * Return the list of matching items
+ */
+GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type)
+{
+ GSList *matches = NULL;
+ gboolean match = false;
+
+ SPStyle *sel_style = sel->style;
+
+ if (type == SP_FILL_COLOR || type == SP_STROKE_COLOR) {
+ return sp_get_same_fill_or_stroke_color(sel, src, type);
+ }
+
+ for (GSList *i = src; i != NULL; i = i->next) {
+ SPItem *iter = SP_ITEM(i->data);
+ SPStyle *iter_style = iter->style;
+ match = false;
+
+ if (type == SP_STROKE_STYLE_WIDTH) {
+ match = (sel_style->stroke_width.set == iter_style->stroke_width.set);
+ if (sel_style->stroke_width.set && iter_style->stroke_width.set) {
+ match = (sel_style->stroke_width.computed == iter_style->stroke_width.computed);
+ }
+ }
+ else if (type == SP_STROKE_STYLE_DASHES ) {
+ match = (sel_style->stroke_dasharray_set == iter_style->stroke_dasharray_set);
+ if (sel_style->stroke_dasharray_set && iter_style->stroke_dasharray_set) {
+ match = (sel_style->stroke_dash.n_dash == iter_style->stroke_dash.n_dash);
+ if (sel_style->stroke_dash.n_dash == iter_style->stroke_dash.n_dash) {
+ for (int i = 0; i < sel_style->stroke_dash.n_dash; i++) {
+ if (sel_style->stroke_dash.dash[i] != iter_style->stroke_dash.dash[i]) {
+ match = false;
+ break;
+ }
+ }
+ }
+ }
+ }
+ else if (type == SP_STROKE_STYLE_MARKERS) {
+ match = true;
+ int len = sizeof(sel_style->marker)/sizeof(SPIString);
+ for (int i = 0; i < len; i++) {
+ match = (sel_style->marker[i].set == iter_style->marker[i].set);
+ if (sel_style->marker[i].set && iter_style->marker[i].set &&
+ (strcmp(sel_style->marker[i].value, iter_style->marker[i].value))) {
+ match = false;
+ break;
+ }
+ }
+ }
+
+ if (match) {
+ matches = g_slist_prepend(matches, iter);
+ }
+ }
+
+ return matches;
+}
// helper function:
static
diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h
index 74f80b6af..ccb152602 100644
--- a/src/selection-chemistry.h
+++ b/src/selection-chemistry.h
@@ -37,8 +37,9 @@ namespace Inkscape {
static void selectAllInAll(SPDesktop *desktop);
static void selectNone(SPDesktop *desktop);
static void selectSameFillStroke(SPDesktop *dt);
- static void selectSameFill(SPDesktop *dt);
- static void selectSameStroke(SPDesktop *dt);
+ static void selectSameFillColor(SPDesktop *dt);
+ static void selectSameStrokeColor(SPDesktop *dt);
+ static void selectSameStrokeStyle(SPDesktop *dt);
static void invert(SPDesktop *desktop);
static void invertAllInAll(SPDesktop *desktop);
static void reverse(SPDesktop *dt);
@@ -123,8 +124,18 @@ void sp_selection_next_patheffect_param(SPDesktop * dt);
void sp_selection_edit_clip_or_mask(SPDesktop * dt, bool clip);
-void sp_select_same_fill_stroke(SPDesktop *desktop, gboolean fill, gboolean stroke);
-GSList *sp_get_same_fill_or_stroke_items(SPItem *sel, GSList *src, gboolean fillorstroke);
+enum SPSelectStrokeStyleType {
+ SP_FILL_COLOR = 0,
+ SP_STROKE_COLOR = 1,
+ SP_STROKE_STYLE_WIDTH = 2,
+ SP_STROKE_STYLE_DASHES = 3,
+ SP_STROKE_STYLE_MARKERS = 4
+};
+
+void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolean strok, gboolean style);
+void sp_select_same_stroke_style(SPDesktop *desktop);
+GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrokeStyleType type);
+GSList *sp_get_same_stroke_style(SPItem *sel, GSList *src, SPSelectStrokeStyleType type);
void scroll_to_show_item(SPDesktop *desktop, SPItem *item);
diff --git a/src/ui/context-menu.cpp b/src/ui/context-menu.cpp
index 672ac440d..ad47da68b 100644
--- a/src/ui/context-menu.cpp
+++ b/src/ui/context-menu.cpp
@@ -129,8 +129,12 @@ static void sp_item_menu(SPObject *object, SPDesktop *desktop, GtkMenu *m)
gtk_menu_shell_append(GTK_MENU_SHELL(m), w);
/* Select same fill and stroke */
w = gtk_menu_item_new_with_mnemonic(_("_Select Same Fill and Stroke"));
- g_object_set_data(G_OBJECT(w), "desktop", desktop);
- g_signal_connect(G_OBJECT(w), "activate", G_CALLBACK(sp_item_select_same_fill_stroke), item);
+ if (sp_desktop_selection(desktop)->isEmpty()) {
+ gtk_widget_set_sensitive(w, FALSE);
+ } else {
+ g_object_set_data(G_OBJECT(w), "desktop", desktop);
+ g_signal_connect(G_OBJECT(w), "activate", G_CALLBACK(sp_item_select_same_fill_stroke), item);
+ }
gtk_widget_show(w);
gtk_menu_shell_append(GTK_MENU_SHELL(m), w);
/* Create link */
@@ -272,7 +276,7 @@ static void sp_item_select_same_fill_stroke(GtkMenuItem *menuitem, SPItem * /*it
SPDesktop *desktop = static_cast<SPDesktop*>(g_object_get_data(G_OBJECT(menuitem), "desktop"));
g_return_if_fail(desktop != NULL);
- sp_select_same_fill_stroke(desktop, true, true);
+ sp_select_same_fill_stroke_style(desktop, true, true, true);
}
diff --git a/src/verbs.cpp b/src/verbs.cpp
index ab16c6c93..913cec837 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -964,11 +964,14 @@ void EditVerb::perform(SPAction *action, void *data)
case SP_VERB_EDIT_SELECT_SAME_FILL_STROKE:
SelectionHelper::selectSameFillStroke(dt);
break;
- case SP_VERB_EDIT_SELECT_SAME_FILL:
- SelectionHelper::selectSameFill(dt);
+ case SP_VERB_EDIT_SELECT_SAME_FILL_COLOR:
+ SelectionHelper::selectSameFillColor(dt);
break;
- case SP_VERB_EDIT_SELECT_SAME_STROKE:
- SelectionHelper::selectSameStroke(dt);
+ case SP_VERB_EDIT_SELECT_SAME_STROKE_COLOR:
+ SelectionHelper::selectSameStrokeColor(dt);
+ break;
+ case SP_VERB_EDIT_SELECT_SAME_STROKE_STYLE:
+ SelectionHelper::selectSameStrokeStyle(dt);
break;
case SP_VERB_EDIT_INVERT:
SelectionHelper::invert(dt);
@@ -2297,12 +2300,14 @@ Verb *Verb::_base_verbs[] = {
N_("Select all objects or all nodes"), GTK_STOCK_SELECT_ALL),
new EditVerb(SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, "EditSelectAllInAllLayers", N_("Select All in All La_yers"),
N_("Select all objects in all visible and unlocked layers"), INKSCAPE_ICON("edit-select-all-layers")),
- new EditVerb(SP_VERB_EDIT_SELECT_SAME_FILL_STROKE, "EditSelectSameFillStroke", N_("S_ame Fill and Stroke"),
+ new EditVerb(SP_VERB_EDIT_SELECT_SAME_FILL_STROKE, "EditSelectSameFillStroke", N_("Fill _and Stroke"),
N_("Select all objects with the same fill and stroke as the selected objects"), GTK_STOCK_SELECT_ALL),
- new EditVerb(SP_VERB_EDIT_SELECT_SAME_FILL, "EditSelectSameFill", N_("Same _Fill"),
+ new EditVerb(SP_VERB_EDIT_SELECT_SAME_FILL_COLOR, "EditSelectSameFillColor", N_("_Fill Color"),
N_("Select all objects with the same fill as the selected objects"), GTK_STOCK_SELECT_ALL),
- new EditVerb(SP_VERB_EDIT_SELECT_SAME_STROKE, "EditSelectSameStroke", N_("Same _Stroke"),
+ new EditVerb(SP_VERB_EDIT_SELECT_SAME_STROKE_COLOR, "EditSelectSameStrokeColor", N_("_Stroke Color"),
N_("Select all objects with the same stroke as the selected objects"), GTK_STOCK_SELECT_ALL),
+ new EditVerb(SP_VERB_EDIT_SELECT_SAME_STROKE_STYLE, "EditSelectSameStrokeStyle", N_("Stroke St_yle"),
+ N_("Select all objects with the same stroke style (width, dsh, markers) as the selected objects"), GTK_STOCK_SELECT_ALL),
new EditVerb(SP_VERB_EDIT_INVERT, "EditInvert", N_("In_vert Selection"),
N_("Invert selection (unselect what is selected and select everything else)"), INKSCAPE_ICON("edit-select-invert")),
new EditVerb(SP_VERB_EDIT_INVERT_IN_ALL_LAYERS, "EditInvertInAllLayers", N_("Invert in All Layers"),
diff --git a/src/verbs.h b/src/verbs.h
index ec394b9a5..1a9efdb81 100644
--- a/src/verbs.h
+++ b/src/verbs.h
@@ -88,8 +88,9 @@ enum {
SP_VERB_EDIT_SELECT_ALL,
SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS,
SP_VERB_EDIT_SELECT_SAME_FILL_STROKE,
- SP_VERB_EDIT_SELECT_SAME_FILL,
- SP_VERB_EDIT_SELECT_SAME_STROKE,
+ SP_VERB_EDIT_SELECT_SAME_FILL_COLOR,
+ SP_VERB_EDIT_SELECT_SAME_STROKE_COLOR,
+ SP_VERB_EDIT_SELECT_SAME_STROKE_STYLE,
SP_VERB_EDIT_INVERT,
SP_VERB_EDIT_INVERT_IN_ALL_LAYERS,
SP_VERB_EDIT_SELECT_NEXT,