Code

Ctrl+click in pen/pencil tool: Created dots are now selected; Alt is used for randomn...
[inkscape.git] / src / ui / dialog / align-and-distribute.cpp
index 7c5908e5853ff654df4232544547bc48e417de4b..4846158a712fa7faea9706d9e20214060971ab9d 100644 (file)
@@ -116,7 +116,7 @@ private :
 
     virtual void on_button_click() {
         //Retreive selected objects
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -300,7 +300,7 @@ public :
 private :
     virtual void on_button_click() {
         //Retreive selected objects
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -426,8 +426,8 @@ private :
     virtual void on_button_click()
     {
 
-        if (!SP_ACTIVE_DESKTOP) return;
-       SPEventContext *event_context = sp_desktop_event_context(SP_ACTIVE_DESKTOP);
+        if (!_dialog.getDesktop()) return;
+       SPEventContext *event_context = sp_desktop_event_context(_dialog.getDesktop());
        if (!SP_IS_NODE_CONTEXT (event_context)) return ;
 
         if (_distribute)
@@ -486,7 +486,7 @@ public:
 private :
     virtual void on_button_click()
     {
-        if (!SP_ACTIVE_DESKTOP) return;
+        if (!_dialog.getDesktop()) return;
 
         // see comment in ActionAlign above
         int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
@@ -495,13 +495,13 @@ private :
         // xGap and yGap are the minimum space required between bounding rectangles.
         double const xGap = removeOverlapXGap.get_value();
         double const yGap = removeOverlapYGap.get_value();
-        removeoverlap(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(),
+        removeoverlap(sp_desktop_selection(_dialog.getDesktop())->itemList(),
                       xGap, yGap);
 
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                          _("Remove overlaps"));
     }
 };
@@ -520,18 +520,18 @@ public:
 private :
     virtual void on_button_click()
     {
-        if (!SP_ACTIVE_DESKTOP) return;
+        if (!_dialog.getDesktop()) return;
 
         // see comment in ActionAlign above
         int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
         prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
 
-        graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
+        graphlayout(sp_desktop_selection(_dialog.getDesktop())->itemList());
 
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                          _("Arrange connector network"));
     }
 };
@@ -550,18 +550,18 @@ public :
 private :
     virtual void on_button_click()
     {
-        if (!SP_ACTIVE_DESKTOP) return;
+        if (!_dialog.getDesktop()) return;
 
         // see comment in ActionAlign above
         int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
         prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
 
-        unclump ((GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
+        unclump ((GSList *) sp_desktop_selection(_dialog.getDesktop())->itemList());
 
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done (sp_desktop_document (_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                           _("Unclump"));
     }
 };
@@ -580,7 +580,7 @@ public :
 private :
     virtual void on_button_click()
     {
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -602,9 +602,8 @@ private :
         // This bbox is cached between calls to randomize, so that there's no growth nor shrink
         // nor drift on sequential randomizations. Discard cache on global (or better active
         // desktop's) selection_change signal.
-        if (!_dialog.randomize_bbox_set) {
+        if (!_dialog.randomize_bbox) {
             _dialog.randomize_bbox = *sel_bbox;
-            _dialog.randomize_bbox_set = true;
         }
 
         // see comment in ActionAlign above
@@ -619,10 +618,10 @@ private :
             NR::Maybe<NR::Rect> item_box = sp_item_bbox_desktop (*it);
             if (item_box) {
                 // find new center, staying within bbox 
-                double x = _dialog.randomize_bbox.min()[NR::X] + item_box->extent(NR::X)/2 +
-                    g_random_double_range (0, _dialog.randomize_bbox.extent(NR::X) - item_box->extent(NR::X));
-                double y = _dialog.randomize_bbox.min()[NR::Y] + item_box->extent(NR::Y)/2 +
-                    g_random_double_range (0, _dialog.randomize_bbox.extent(NR::Y) - item_box->extent(NR::Y));
+                double x = _dialog.randomize_bbox->min()[NR::X] + item_box->extent(NR::X)/2 +
+                    g_random_double_range (0, _dialog.randomize_bbox->extent(NR::X) - item_box->extent(NR::X));
+                double y = _dialog.randomize_bbox->min()[NR::Y] + item_box->extent(NR::Y)/2 +
+                    g_random_double_range (0, _dialog.randomize_bbox->extent(NR::Y) - item_box->extent(NR::Y));
                 // displacement is the new center minus old:
                 NR::Point t = NR::Point (x, y) - 0.5*(item_box->max() + item_box->min());
                 sp_item_move_rel(*it, NR::translate(t));
@@ -632,7 +631,7 @@ private :
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                           _("Randomize positions"));
     }
 };
@@ -674,7 +673,7 @@ private :
     bool _distribute;
     virtual void on_button_click()
     {
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -729,7 +728,7 @@ private :
             }
 
             if (changed) {
-                sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+                sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                                   _("Distribute text baselines"));
             }
 
@@ -749,7 +748,7 @@ private :
             }
 
             if (changed) {
-                sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+                sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                                   _("Align text baselines"));
             }
         }
@@ -767,7 +766,7 @@ void on_tool_changed(Inkscape::Application *inkscape, SPEventContext *context, A
 
 void on_selection_changed(Inkscape::Application *inkscape, Inkscape::Selection *selection, AlignAndDistribute *daad)
 {
-    daad->randomize_bbox_set = false;
+    daad->randomize_bbox = NR::Nothing();
 }
 
 /////////////////////////////////////////////////////////
@@ -776,8 +775,8 @@ void on_selection_changed(Inkscape::Application *inkscape, Inkscape::Selection *
 
 
 AlignAndDistribute::AlignAndDistribute() 
-    : Dialog ("dialogs.align", SP_VERB_DIALOG_ALIGN_DISTRIBUTE),
-      randomize_bbox (NR::Point (0, 0), NR::Point (0, 0)),
+    : UI::Widget::Panel ("", "dialogs.align", SP_VERB_DIALOG_ALIGN_DISTRIBUTE),
+      randomize_bbox(NR::Nothing()),
       _alignFrame(_("Align")),
       _distributeFrame(_("Distribute")),
       _removeOverlapFrame(_("Remove overlaps")),
@@ -909,7 +908,7 @@ AlignAndDistribute::AlignAndDistribute()
     _combo.append_text(_("Drawing"));
     _combo.append_text(_("Selection"));
 
-    _combo.set_active(6);
+    _combo.set_active(prefs_get_int_attribute("dialogs.align", "align-to", 6));
     _combo.signal_changed().connect(sigc::mem_fun(*this, &AlignAndDistribute::on_ref_change));
 
     _anchorBox.pack_start(_anchorLabel);
@@ -924,25 +923,23 @@ AlignAndDistribute::AlignAndDistribute()
     _graphLayoutFrame.add(_graphLayoutTable);
     _nodesFrame.add(_nodesTable);
 
-    // Top level vbox
-    Gtk::VBox *vbox = get_vbox();
-    vbox->set_spacing(4);
+    Gtk::Box *contents = _getContents();
+    contents->set_spacing(4);
 
     // Notebook for individual transformations
 
-    vbox->pack_start(_alignFrame, true, true);
-    vbox->pack_start(_distributeFrame, true, true);
-    vbox->pack_start(_removeOverlapFrame, true, true);
-    vbox->pack_start(_graphLayoutFrame, true, true);
-    vbox->pack_start(_nodesFrame, true, true);
+    contents->pack_start(_alignFrame, true, true);
+    contents->pack_start(_distributeFrame, true, true);
+    contents->pack_start(_removeOverlapFrame, true, true);
+    contents->pack_start(_graphLayoutFrame, true, true);
+    contents->pack_start(_nodesFrame, true, true);
 
     //Connect to the global tool change signal
     g_signal_connect (G_OBJECT (INKSCAPE), "set_eventcontext", G_CALLBACK (on_tool_changed), this);
 
     // Connect to the global selection change, to invalidate cached randomize_bbox
     g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this);
-    randomize_bbox = NR::Rect (NR::Point (0, 0), NR::Point (0, 0));
-    randomize_bbox_set = false;
+    randomize_bbox = NR::Nothing();
 
     show_all_children();
 
@@ -960,7 +957,10 @@ AlignAndDistribute::~AlignAndDistribute()
 }
 
 void AlignAndDistribute::on_ref_change(){
-//Make blink the master
+
+    prefs_set_int_attribute("dialogs.align", "align-to", _combo.get_active_row_number());
+
+    //Make blink the master
 }