Code

* don't strech buttons on lpe dialog when resizing the dialog
[inkscape.git] / src / ui / dialog / transformation.cpp
index a87f473e87b66dbf2d78a4394bd197c944b537fa..e6de922405cad9e19e9b0ae863c9139615f438fa 100644 (file)
@@ -15,6 +15,7 @@
 #endif
 
 #include <gtkmm/stock.h>
+#include <gtkmm/dialog.h>
 
 #include "document.h"
 #include "desktop-handles.h"
@@ -70,8 +71,8 @@ void on_selection_modified( Inkscape::Application */*inkscape*/,
  * we use the ScalarUnit class for this.
  *
  */
-Transformation::Transformation(Behavior::BehaviorFactory behavior_factory)
-    : Dialog (behavior_factory, "dialogs.transformation", SP_VERB_DIALOG_TRANSFORM),
+Transformation::Transformation()
+    : UI::Widget::Panel ("", "dialogs.transformation", SP_VERB_DIALOG_TRANSFORM),
       _page_move              (4, 2),
       _page_scale             (4, 2),
       _page_rotate            (4, 2),
@@ -105,12 +106,12 @@ Transformation::Transformation(Behavior::BehaviorFactory behavior_factory)
       _check_replace_matrix    (_("Edit c_urrent matrix"), _("Edit the current transform= matrix; otherwise, post-multiply transform= by this matrix"))
 
 {
-    // Top level vbox
-    Gtk::VBox *vbox = get_vbox();
-    vbox->set_spacing(0);
+    Gtk::Box *contents = _getContents();
+
+    contents->set_spacing(0);
 
     // Notebook for individual transformations
-    vbox->pack_start(_notebook, true, true);
+    contents->pack_start(_notebook, true, true);
 
     _notebook.append_page(_page_move, _("_Move"), true);
     layoutPageMove();
@@ -130,7 +131,7 @@ Transformation::Transformation(Behavior::BehaviorFactory behavior_factory)
     _notebook.signal_switch_page().connect(sigc::mem_fun(*this, &Transformation::onSwitchPage));
 
     // Apply separately
-    vbox->pack_start(_check_apply_separately, true, true);
+    contents->pack_start(_check_apply_separately, true, true);
     _check_apply_separately.set_active(prefs_get_int_attribute_limited ("dialogs.transformation", "applyseparately", 0, 0, 1));
     _check_apply_separately.signal_toggled().connect(sigc::mem_fun(*this, &Transformation::onApplySeparatelyToggled));
 
@@ -145,18 +146,17 @@ Transformation::Transformation(Behavior::BehaviorFactory behavior_factory)
 
     updateSelection(PAGE_MOVE, _getSelection());
 
-    resetButton = add_button(Gtk::Stock::CLEAR, 0);
+    resetButton = addResponseButton(Gtk::Stock::CLEAR, 0);
     if (resetButton) {
-        tooltips.set_tip((*resetButton), _("Reset the values on the current tab to defaults"));
+        _tooltips.set_tip((*resetButton), _("Reset the values on the current tab to defaults"));
         resetButton->set_sensitive(true);
         resetButton->signal_clicked().connect(sigc::mem_fun(*this, &Transformation::onClear));
     }
 
-    applyButton = add_button(Gtk::Stock::APPLY,   Gtk::RESPONSE_APPLY);
+    applyButton = addResponseButton(Gtk::Stock::APPLY, Gtk::RESPONSE_APPLY);
     if (applyButton) {
-        tooltips.set_tip((*applyButton), _("Apply transformation to selection"));
+        _tooltips.set_tip((*applyButton), _("Apply transformation to selection"));
         applyButton->set_sensitive(false);
-        set_default (*applyButton); // activable by Enter in spinbuttons
     }
 
     // Connect to the global selection changed & modified signals
@@ -172,7 +172,6 @@ Transformation::~Transformation()
 }
 
 
-
 /*########################################################################
 # U T I L I T Y
 ########################################################################*/
@@ -439,15 +438,15 @@ Transformation::updateSelection(PageType page, Inkscape::Selection *selection)
         }
     }
 
-    set_response_sensitive(Gtk::RESPONSE_APPLY,
-                           selection && !selection->isEmpty());
+    setResponseSensitive(Gtk::RESPONSE_APPLY,
+                         selection && !selection->isEmpty());
 }
 
 void
 Transformation::onSwitchPage(GtkNotebookPage */*page*/,
                                    guint pagenum)
 {
-    updateSelection((PageType)pagenum, sp_desktop_selection(SP_ACTIVE_DESKTOP));
+    updateSelection((PageType)pagenum, sp_desktop_selection(getDesktop()));
 }
 
 void
@@ -506,7 +505,16 @@ void
 Transformation::updatePageSkew(Inkscape::Selection *selection)
 {
     if (selection && !selection->isEmpty()) {
-        _page_skew.set_sensitive(true);
+        NR::Maybe<NR::Rect> bbox = selection->bounds();
+        if (bbox) {
+            double w = bbox->extent(NR::X);
+            double h = bbox->extent(NR::Y);
+            _scalar_skew_vertical.setHundredPercent(w);
+            _scalar_skew_horizontal.setHundredPercent(h);
+            _page_skew.set_sensitive(true);
+        } else {
+            _page_skew.set_sensitive(false);
+        }
     } else {
         _page_skew.set_sensitive(false);
     }
@@ -579,7 +587,7 @@ Transformation::_apply()
     }
 
     //Let's play with never turning this off
-    //set_response_sensitive(Gtk::RESPONSE_APPLY, false);
+    //setResponseSensitive(Gtk::RESPONSE_APPLY, false);
 }
 
 void
@@ -617,16 +625,16 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
                 NR::Maybe<NR::Rect> bbox(sp_item_bbox_desktop(item));
                 if (bbox) {
                     double new_width = scaleX;
-                    if (new_width < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object
+                    if (fabs(new_width) < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object
                     double new_height = scaleY;
-                    if (new_height < 1e-6) new_height = 1e-6;
+                    if (fabs(new_height) < 1e-6) new_height = 1e-6;
                     scale = NR::scale(new_width / bbox->extent(NR::X), new_height / bbox->extent(NR::Y));
                 }
             } else {
                 double new_width = scaleX;
-                if (new_width < 1e-6) new_width = 1e-6;
+                if (fabs(new_width) < 1e-6) new_width = 1e-6;
                 double new_height = scaleY;
-                if (new_height < 1e-6) new_height = 1e-6;
+                if (fabs(new_height) < 1e-6) new_height = 1e-6;
                 scale = NR::scale(new_width / 100.0, new_height / 100.0);
             }
             sp_item_scale_rel (item, scale);
@@ -639,15 +647,15 @@ Transformation::applyPageScale(Inkscape::Selection *selection)
             // the values are increments!
             if (_units_scale.isAbsolute()) {
                 double new_width = scaleX;
-                if (new_width < 1e-6) new_width = 1e-6;
+                if (fabs(new_width) < 1e-6) new_width = 1e-6;
                 double new_height = scaleY;
-                if (new_height < 1e-6) new_height = 1e-6;
+                if (fabs(new_height) < 1e-6) new_height = 1e-6;
                 scale = NR::scale(new_width / bbox->extent(NR::X), new_height / bbox->extent(NR::Y));
             } else {
                 double new_width = scaleX;
-                if (new_width < 1e-6) new_width = 1e-6;
+                if (fabs(new_width) < 1e-6) new_width = 1e-6;
                 double new_height = scaleY;
-                if (new_height < 1e-6) new_height = 1e-6;
+                if (fabs(new_height) < 1e-6) new_height = 1e-6;
                 scale = NR::scale(new_width / 100.0, new_height / 100.0);
             }
             sp_selection_scale_relative(selection, center, scale);
@@ -775,7 +783,7 @@ Transformation::applyPageTransform(Inkscape::Selection *selection)
 void
 Transformation::onMoveValueChanged()
 {
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 }
 
 void
@@ -805,7 +813,7 @@ Transformation::onMoveRelativeToggled()
         }
     }
 
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 }
 
 void
@@ -816,7 +824,7 @@ Transformation::onScaleXValueChanged()
         return;
     }
 
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 
     if (_check_scale_proportional.get_active()) {
         if (!_units_scale.isAbsolute()) { // percentage, just copy over
@@ -836,7 +844,7 @@ Transformation::onScaleYValueChanged()
         return;
     }
 
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 
     if (_check_scale_proportional.get_active()) {
         if (!_units_scale.isAbsolute()) { // percentage, just copy over
@@ -851,13 +859,13 @@ Transformation::onScaleYValueChanged()
 void
 Transformation::onRotateValueChanged()
 {
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 }
 
 void
 Transformation::onSkewValueChanged()
 {
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 }
 
 void
@@ -876,7 +884,7 @@ Transformation::onTransformValueChanged()
     //          a, b, c, d, e ,f);
     */
 
-    set_response_sensitive(Gtk::RESPONSE_APPLY, true);
+    setResponseSensitive(Gtk::RESPONSE_APPLY, true);
 }
 
 void
@@ -944,8 +952,8 @@ Transformation::onClear()
         break;
     }
     case PAGE_SCALE: {
-        _scalar_scale_horizontal.setValue(100);
-        _scalar_scale_vertical.setValue(100);
+        _scalar_scale_horizontal.setValue(100, "%");
+        _scalar_scale_vertical.setValue(100, "%");
         break;
     }
     case PAGE_SKEW: {