Code

add copy-to-clipboard for selected stops
authorbuliabyak <buliabyak@users.sourceforge.net>
Mon, 22 Oct 2007 18:09:54 +0000 (18:09 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Mon, 22 Oct 2007 18:09:54 +0000 (18:09 +0000)
src/gradient-drag.cpp
src/gradient-drag.h

index 67fa0933372e19c2a62191fbc50512cccae731e5..5d74b561eece74786d9942dd6f27c31644890f63 100644 (file)
 #include "desktop-style.h"
 #include "document.h"
 #include "display/sp-ctrlline.h"
-
 #include "xml/repr.h"
 #include "svg/css-ostringstream.h"
-
 #include "svg/svg.h"
 #include "libnr/nr-point-fns.h"
-
 #include "prefs-utils.h"
 #include "sp-item.h"
 #include "style.h"
@@ -41,9 +38,9 @@
 #include "gradient-chemistry.h"
 #include "gradient-drag.h"
 #include "sp-stop.h"
-
 #include "snap.h"
 #include "sp-namedview.h"
+#include "selection-chemistry.h"
 
 
 #define GR_KNOT_COLOR_NORMAL 0xffffff00
@@ -249,6 +246,63 @@ gr_drag_style_set (const SPCSSAttr *css, gpointer data)
     return true;
 }
 
+bool
+GrDrag::copy()
+{
+    if (!selected)
+        return false;
+
+    float cf[4];
+    cf[0] = cf[1] = cf[2] = cf[3] = 0;
+
+    int count = 0;
+
+    for (GList *i = selected; i != NULL; i = i->next) { // for all selected draggers
+        GrDragger *d = (GrDragger *) i->data;
+        for (GSList const* j = d->draggables; j != NULL; j = j->next) { // for all draggables of dragger
+            GrDraggable *draggable = (GrDraggable *) j->data;
+
+            guint32 c = sp_item_gradient_stop_query_style (draggable->item, draggable->point_type, draggable->point_i, draggable->fill_or_stroke);
+            cf[0] += SP_RGBA32_R_F (c);
+            cf[1] += SP_RGBA32_G_F (c);
+            cf[2] += SP_RGBA32_B_F (c);
+            cf[3] += SP_RGBA32_A_F (c);
+
+            count ++;
+        }
+    }
+
+    if (count) {
+        cf[0] /= count;
+        cf[1] /= count;
+        cf[2] /= count;
+        cf[3] /= count;
+    }
+
+    guint32 const c32 = SP_RGBA32_F_COMPOSE(cf[0], cf[1], cf[2], cf[3]);
+    gchar c[64];
+
+    SPCSSAttr *css = sp_repr_css_attr_new ();
+    g_snprintf(c, 64, "#%06x", c32 >> 8);
+    sp_repr_css_set_property (css, "fill", c);
+    Inkscape::CSSOStringStream os;
+    os << cf[3];
+    sp_repr_css_set_property (css, "opacity", os.str().c_str());
+    sp_set_style_clipboard (css);
+
+    g_snprintf(c, 64, "%06x%02x", c32 >> 8, c32 & 0x000000ff);
+    Glib::ustring text;
+    text += c;
+    if (!text.empty())
+    {
+        Glib::RefPtr<Gtk::Clipboard> refClipboard =
+            Gtk::Clipboard::get();
+        refClipboard->set_text(text);
+    }
+
+    return true;
+}
+
 SPStop *
 GrDrag::addStopNearPoint (SPItem *item, NR::Point mouse_p, double tolerance)
 {
index ae541ebbbf8dc68c47c23892f29536bd23047679..2e547b1832e5e006a94d5c1fc021f522217ed926 100644 (file)
@@ -129,6 +129,8 @@ public: // FIXME: make more of this private!
                SPStop *addStopNearPoint (SPItem *item, NR::Point mouse_p, double tolerance);
     
     void deleteSelected (bool just_one = false);
+
+    bool copy ();
     
     bool keep_selection;