summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-09-20 17:09:19 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-09-20 17:09:19 +0000
commitcf74f053a081f6f4b460da9cd72afaab23d54d13 (patch)
tree427aa22ba3dcad9b55edb90522b5ab0208074e06 /src/ui/dialog
parentUsing inkscape compact settings to save the icons.svg file (diff)
parentMerge from trunk. (diff)
downloadinkscape-cf74f053a081f6f4b460da9cd72afaab23d54d13.tar.gz
inkscape-cf74f053a081f6f4b460da9cd72afaab23d54d13.zip
Merge Google Summer of Code unit improvement.
(bzr r12554)
Diffstat (limited to 'src/ui/dialog')
-rw-r--r--src/ui/dialog/aboutbox.cpp5
-rw-r--r--src/ui/dialog/document-properties.cpp63
-rw-r--r--src/ui/dialog/document-properties.h3
-rw-r--r--src/ui/dialog/export.cpp6
-rw-r--r--src/ui/dialog/print.cpp12
-rw-r--r--src/ui/dialog/text-edit.cpp2
6 files changed, 76 insertions, 15 deletions
diff --git a/src/ui/dialog/aboutbox.cpp b/src/ui/dialog/aboutbox.cpp
index 6f1137e46..121773b6d 100644
--- a/src/ui/dialog/aboutbox.cpp
+++ b/src/ui/dialog/aboutbox.cpp
@@ -34,6 +34,7 @@
#include "svg-view-widget.h"
#include "sp-text.h"
#include "text-editing.h"
+#include "util/units.h"
#include "inkscape-version.h"
@@ -175,8 +176,8 @@ Gtk::Widget *build_splash_widget() {
GtkWidget *v=sp_svg_view_widget_new(doc);
- double width=doc->getWidth();
- double height=doc->getHeight();
+ double width=doc->getWidth().value("px");
+ double height=doc->getHeight().value("px");
doc->doUnref();
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp
index 511e63d02..ec04f6d98 100644
--- a/src/ui/dialog/document-properties.cpp
+++ b/src/ui/dialog/document-properties.cpp
@@ -31,9 +31,12 @@
#include "inkscape.h"
#include "io/sys.h"
#include "preferences.h"
+#include "shape-editor.h"
#include "sp-namedview.h"
#include "sp-root.h"
#include "sp-script.h"
+#include "svg/stringstream.h"
+#include "tools-switch.h"
#include "ui/widget/color-picker.h"
#include "ui/widget/scalar-unit.h"
#include "ui/dialog/filedialog.h"
@@ -53,6 +56,8 @@
#include <gtkmm/stock.h>
#include <gtkmm/table.h>
+#include <2geom/transforms.h>
+
using std::pair;
namespace Inkscape {
@@ -168,6 +173,9 @@ DocumentProperties::DocumentProperties()
signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
+
+ _rum_deflt._changed_connection.block();
+ _rum_deflt.getUnitMenu()->signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::onDocUnitChange));
}
void DocumentProperties::init()
@@ -1432,9 +1440,17 @@ void DocumentProperties::update()
if (nv->doc_units)
_rum_deflt.setUnit (nv->doc_units->abbr);
- double const doc_w_px = sp_desktop_document(dt)->getWidth();
- double const doc_h_px = sp_desktop_document(dt)->getHeight();
- _page_sizer.setDim (doc_w_px, doc_h_px);
+ double const doc_w = sp_desktop_document(dt)->getRoot()->width.value;
+ Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit).abbr;
+ if (doc_w_unit == "") {
+ doc_w_unit = "px";
+ }
+ double const doc_h = sp_desktop_document(dt)->getRoot()->height.value;
+ Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit).abbr;
+ if (doc_h_unit == "") {
+ doc_h_unit = "px";
+ }
+ _page_sizer.setDim(Inkscape::Util::Quantity(doc_w, doc_w_unit), Inkscape::Util::Quantity(doc_h, doc_h_unit));
_page_sizer.updateFitMarginsUI(nv->getRepr());
//-----------------------------------------------------------guide page
@@ -1617,6 +1633,47 @@ void DocumentProperties::onRemoveGrid()
}
}
+/** Callback for document unit change. */
+void DocumentProperties::onDocUnitChange()
+{
+ SPDocument *doc = SP_ACTIVE_DOCUMENT;
+ Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr();
+ Inkscape::Util::Unit old_doc_unit = unit_table.getUnit("px");
+ if(repr->attribute("inkscape:document-units")) {
+ old_doc_unit = unit_table.getUnit(repr->attribute("inkscape:document-units"));
+ }
+ Inkscape::Util::Unit doc_unit = _rum_deflt.getUnit();
+
+ // Don't execute when change is being undone
+ if (!DocumentUndo::getUndoSensitive(doc)) {
+ return;
+ }
+
+ // Set document unit
+ Inkscape::SVGOStringStream os;
+ os << doc_unit.abbr;
+ repr->setAttribute("inkscape:document-units", os.str().c_str());
+
+ // Set viewBox
+ Inkscape::Util::Quantity width = doc->getWidth();
+ Inkscape::Util::Quantity height = doc->getHeight();
+ doc->setViewBox(Geom::Rect::from_xywh(0, 0, width.value(doc_unit), height.value(doc_unit)));
+
+ // TODO: Fix bug in nodes tool instead of switching away from it
+ if (tools_active(getDesktop()) == TOOLS_NODES) {
+ tools_switch(getDesktop(), TOOLS_SELECT);
+ }
+
+ // Scale and translate objects
+ gdouble scale = Inkscape::Util::Quantity::convert(1, old_doc_unit, doc_unit);
+ ShapeEditor::blockSetItem(true);
+ doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, doc->getHeight().value("px")));
+ ShapeEditor::blockSetItem(false);
+
+ doc->setModifiedSinceSave();
+
+ DocumentUndo::done(doc, SP_VERB_NONE, _("Changed document unit"));
+}
} // namespace Dialog
} // namespace UI
diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h
index 56fed30c4..e3ca91731 100644
--- a/src/ui/dialog/document-properties.h
+++ b/src/ui/dialog/document-properties.h
@@ -216,6 +216,9 @@ private:
// callback methods for buttons on grids page.
void onNewGrid();
void onRemoveGrid();
+
+ // callback for document unit change
+ void onDocUnitChange();
};
} // namespace Dialog
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index 0b20c08a2..577793496 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -762,7 +762,7 @@ void Export::onAreaToggled ()
}
case SELECTION_PAGE:
bbox = Geom::Rect(Geom::Point(0.0, 0.0),
- Geom::Point(doc->getWidth(), doc->getHeight()));
+ Geom::Point(doc->getWidth().value("px"), doc->getHeight().value("px")));
// std::cout << "Using selection: PAGE" << std::endl;
key = SELECTION_PAGE;
@@ -1475,8 +1475,8 @@ void Export::detectSize() {
doc = sp_desktop_document (SP_ACTIVE_DESKTOP);
Geom::Point x(0.0, 0.0);
- Geom::Point y(doc->getWidth(),
- doc->getHeight());
+ Geom::Point y(doc->getWidth().value("px"),
+ doc->getHeight().value("px"));
Geom::Rect bbox(x, y);
if (bbox_equal(bbox,current_bbox)) {
diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp
index 4c8c77f96..e6dae278b 100644
--- a/src/ui/dialog/print.cpp
+++ b/src/ui/dialog/print.cpp
@@ -49,8 +49,8 @@ static void draw_page(
if (junk->_tab->as_bitmap()) {
// Render as exported PNG
- gdouble width = (junk->_doc)->getWidth();
- gdouble height = (junk->_doc)->getHeight();
+ gdouble width = (junk->_doc)->getWidth().value("px");
+ gdouble height = (junk->_doc)->getHeight().value("px");
gdouble dpi = junk->_tab->bitmap_dpi();
std::string tmp_png;
std::string tmp_base = "inkscape-print-png-XXXXXX";
@@ -72,8 +72,8 @@ static void draw_page(
sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0,
width, height,
- (unsigned long)(width * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")),
- (unsigned long)(height * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")),
+ (unsigned long)(Inkscape::Util::Quantity::convert(width, "px", "in") * dpi),
+ (unsigned long)(Inkscape::Util::Quantity::convert(height, "px", "in") * dpi),
dpi, dpi, bgcolor, NULL, NULL, true, NULL);
// This doesn't seem to work:
@@ -195,8 +195,8 @@ Print::Print(SPDocument *doc, SPItem *base) :
// set up paper size to match the document size
gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS);
GtkPageSetup *page_setup = gtk_page_setup_new();
- gdouble doc_width = _doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt");
- gdouble doc_height = _doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt");
+ gdouble doc_width = _doc->getWidth().value("pt");
+ gdouble doc_height = _doc->getHeight().value("pt");
GtkPaperSize *paper_size;
if (doc_width > doc_height) {
gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE);
diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp
index 4a25f723b..9124681a0 100644
--- a/src/ui/dialog/text-edit.cpp
+++ b/src/ui/dialog/text-edit.cpp
@@ -401,7 +401,7 @@ void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase)
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT);
- double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * Inkscape::Util::Quantity::convert(1, "px", "pt");
+ double pt_size = Inkscape::Util::Quantity::convert(sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit), "px", "pt");
// Pango font size is in 1024ths of a point
// C++11: Glib::ustring size = std::to_string( pt_size * PANGO_SCALE );