diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-09-24 22:17:24 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-09-24 22:17:24 +0000 |
| commit | bcca22a25ae98f70c36fff6292f0a8fe4e578d89 (patch) | |
| tree | a18d382d32f471b7119b9b7b2782cec04d6da43f /src/ui | |
| parent | Refactored SPUse. (diff) | |
| parent | Fix my email address through codebase (diff) | |
| download | inkscape-bcca22a25ae98f70c36fff6292f0a8fe4e578d89.tar.gz inkscape-bcca22a25ae98f70c36fff6292f0a8fe4e578d89.zip | |
Merged from trunk (r12588).
(bzr r11608.1.129)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/ui/clipboard.cpp | 4 | ||||
| -rw-r--r-- | src/ui/dialog/aboutbox.cpp | 5 | ||||
| -rw-r--r-- | src/ui/dialog/document-properties.cpp | 69 | ||||
| -rw-r--r-- | src/ui/dialog/document-properties.h | 3 | ||||
| -rw-r--r-- | src/ui/dialog/export.cpp | 6 | ||||
| -rw-r--r-- | src/ui/dialog/layer-properties.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/layer-properties.h | 2 | ||||
| -rw-r--r-- | src/ui/dialog/pixelartdialog.cpp | 28 | ||||
| -rw-r--r-- | src/ui/dialog/print.cpp | 18 | ||||
| -rw-r--r-- | src/ui/dialog/spellcheck.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.cpp | 123 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.h | 15 | ||||
| -rw-r--r-- | src/ui/dialog/template-widget.cpp | 71 | ||||
| -rw-r--r-- | src/ui/dialog/template-widget.h | 3 | ||||
| -rw-r--r-- | src/ui/dialog/text-edit.cpp | 2 | ||||
| -rw-r--r-- | src/ui/widget/page-sizer.cpp | 64 | ||||
| -rw-r--r-- | src/ui/widget/page-sizer.h | 8 | ||||
| -rw-r--r-- | src/ui/widget/spinbutton.cpp | 22 | ||||
| -rw-r--r-- | src/ui/widget/spinbutton.h | 15 |
20 files changed, 323 insertions, 142 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 233e01862..24324c874 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -175,6 +175,7 @@ set(ui_SRC dialog/object-properties.h dialog/ocaldialogs.h dialog/panel-dialog.h + dialog/pixelartdialog.h dialog/print-colors-preview-dialog.h dialog/print.h @@ -183,7 +184,7 @@ set(ui_SRC dialog/swatches.h dialog/symbols.h dialog/template-load-tab.h - dialog/template-widget.h + dialog/template-widget.h dialog/text-edit.h dialog/tile.h dialog/tracedialog.h diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 8a7812494..1d91a3b4d 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -1087,8 +1087,8 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/) Geom::Point origin (_clipboardSPDoc->getRoot()->x.computed, _clipboardSPDoc->getRoot()->y.computed); Geom::Rect area = Geom::Rect(origin, origin + _clipboardSPDoc->getDimensions()); - unsigned long int width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); - unsigned long int height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); + unsigned long int width = (unsigned long int) (Inkscape::Util::Quantity::convert(area.width(), "px", "in") * dpi + 0.5); + unsigned long int height = (unsigned long int) (Inkscape::Util::Quantity::convert(area.height(), "in", "px") * dpi + 0.5); // read from namedview Inkscape::XML::Node *nv = sp_repr_lookup_name (_clipboardSPDoc->rroot, "sodipodi:namedview"); 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..37d0ce213 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,23 @@ 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 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"; + } else if (doc_w_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { + doc_w_unit = "px"; + doc_w = sp_desktop_document(dt)->getRoot()->viewBox.width(); + } + double 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"; + } else if (doc_h_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { + doc_h_unit = "px"; + doc_h = sp_desktop_document(dt)->getRoot()->viewBox.height(); + } + _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 +1639,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/layer-properties.cpp b/src/ui/dialog/layer-properties.cpp index 3feed2afe..b9e5d4883 100644 --- a/src/ui/dialog/layer-properties.cpp +++ b/src/ui/dialog/layer-properties.cpp @@ -3,7 +3,7 @@ * Dialog for renaming layers. */ /* Author: - * Bryce W. Harrington <bryce@bryceharrington.com> + * Bryce W. Harrington <bryce@bryceharrington.org> * Andrius R. <knutux@gmail.com> * Abhishek Sharma * diff --git a/src/ui/dialog/layer-properties.h b/src/ui/dialog/layer-properties.h index d38b8edf5..d114c6ba5 100644 --- a/src/ui/dialog/layer-properties.h +++ b/src/ui/dialog/layer-properties.h @@ -2,7 +2,7 @@ * @brief Dialog for renaming layers */ /* Author: - * Bryce W. Harrington <bryce@bryceharrington.com> + * Bryce W. Harrington <bryce@bryceharrington.org> * * Copyright (C) 2004 Bryce Harrington * diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index ef181b357..ff527434e 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -16,13 +16,10 @@ # include <config.h> #endif -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pixelartdialog.h" #include <gtkmm/radiobutton.h> #include <gtkmm/stock.h> +#include <gtkmm/messagedialog.h> #include <gtk/gtk.h> //for GTK_RESPONSE* types #include <glibmm/i18n.h> @@ -132,7 +129,9 @@ private: Gtk::RadioButton voronoiRadioButton; Gtk::RadioButton noOptimizeRadioButton; +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH Gtk::RadioButton optimizeRadioButton; +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH SPDesktop *desktop; DesktopTracker deskTrack; @@ -250,12 +249,14 @@ PixelArtDialogImpl::PixelArtDialogImpl() : outputVBox.pack_start(noOptimizeRadioButton, false, false); +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH optimizeRadioButton.set_label(_("_Smooth curves")); optimizeRadioButton.set_tooltip_text(_("The Kopf-Lischinski algorithm")); optimizeRadioButton.set_use_underline(true); optimizeRadioButton.set_group(outputGroup); outputVBox.pack_start(optimizeRadioButton, false, false); +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH outputFrame.set_label(_("Output")); outputFrame.add(outputVBox); @@ -311,7 +312,11 @@ Tracer::Kopf2011::Options PixelArtDialogImpl::options() options.islandsWeight = islandsWeightSpinner.get_value_as_int(); options.sparsePixelsMultiplier = sparsePixelsMultiplierSpinner.get_value(); options.sparsePixelsRadius = sparsePixelsRadiusSpinner.get_value_as_int(); +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH options.optimize = optimizeRadioButton.get_active(); +#else // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH + options.optimize = false; +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH options.nthreads = Inkscape::Preferences::get() ->getIntLimited("/options/threading/numthreads", @@ -367,6 +372,17 @@ void PixelArtDialogImpl::processLibdepixelize(SPImage *img) Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(img->pixbuf->getPixbufRaw(), true); + if ( pixbuf->get_width() > 256 || pixbuf->get_height() > 256 ) { + char *msg = _("Image looks too big. Process may take a while and is" + " wise to save your document before continue." + "\n\nContinue the procedure (without saving)?"); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_OK_CANCEL, true); + + if ( dialog.run() != Gtk::RESPONSE_OK ) + return; + } + if ( voronoiRadioButton.get_active() ) { out = Tracer::Kopf2011::to_voronoi(pixbuf, options()); } else { @@ -442,7 +458,11 @@ void PixelArtDialogImpl::setDefaults() sparsePixelsMultiplierSpinner.set_value(Tracer::Kopf2011::Options ::SPARSE_PIXELS_MULTIPLIER); +#if LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH optimizeRadioButton.set_active(); +#else // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH + noOptimizeRadioButton.set_active(); +#endif // LIBDEPIXELIZE_INKSCAPE_ENABLE_SMOOTH ignorePreview = false; diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index 4c8c77f96..03ac9dc64 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: @@ -101,7 +101,7 @@ static void draw_page( unlink (tmp_png.c_str()); } else { - g_warning(_("Could not open temporary PNG for bitmap printing")); + g_warning("%s", _("Could not open temporary PNG for bitmap printing")); } } else { @@ -144,11 +144,11 @@ static void draw_page( ret = ctx->finish(); } else { - g_warning(_("Could not set up Document")); + g_warning("%s", _("Could not set up Document")); } } else { - g_warning(_("Failed to set CairoRenderContext")); + g_warning("%s", _("Failed to set CairoRenderContext")); } // Clean up @@ -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/spellcheck.cpp b/src/ui/dialog/spellcheck.cpp index 9cc18c02c..45106755c 100644 --- a/src/ui/dialog/spellcheck.cpp +++ b/src/ui/dialog/spellcheck.cpp @@ -459,7 +459,7 @@ SpellCheck::finished () if (_stops) label = g_strdup_printf(_("<b>Finished</b>, <b>%d</b> words added to dictionary"), _adds); else - label = g_strdup_printf(_("<b>Finished</b>, nothing suspicious found")); + label = g_strdup_printf("%s", _("<b>Finished</b>, nothing suspicious found")); banner_label.set_markup(label); g_free(label); } diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 265ee8026..8e33cf503 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -18,12 +18,16 @@ #include <glibmm/fileutils.h> #include <glibmm/miscutils.h> #include <glibmm/stringutils.h> +#include <iostream> +#include <list> +#include "extension/db.h" +#include "extension/effect.h" +#include "inkscape.h" #include "interface.h" #include "file.h" #include "path-prefix.h" #include "preferences.h" -#include "inkscape.h" #include "xml/repr.h" #include "xml/document.h" #include "xml/node.h" @@ -152,7 +156,7 @@ void TemplateLoadTab::_refreshTemplatesList() case LIST_KEYWORD: { for (std::map<Glib::ustring, TemplateData>::iterator it = _tdata.begin() ; it != _tdata.end() ; ++it) { - if (it->second.keywords.count(_current_keyword) != 0){ + if (it->second.keywords.count(_current_keyword.lowercase()) != 0){ Gtk::TreeModel::iterator iter = _tlist_store->append(); Gtk::TreeModel::Row row = *iter; row[_columns.textValue] = it->first; @@ -163,11 +167,11 @@ void TemplateLoadTab::_refreshTemplatesList() case USER_SPECIFIED : { for (std::map<Glib::ustring, TemplateData>::iterator it = _tdata.begin() ; it != _tdata.end() ; ++it) { - if (it->second.keywords.count(_current_keyword) != 0 || - it->second.display_name.find(_current_keyword) != Glib::ustring::npos || - it->second.author.find(_current_keyword) != Glib::ustring::npos || - it->second.short_description.find(_current_keyword) != Glib::ustring::npos || - it->second.long_description.find(_current_keyword) != Glib::ustring::npos ) + if (it->second.keywords.count(_current_keyword.lowercase()) != 0 || + it->second.display_name.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || + it->second.author.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || + it->second.short_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos || + it->second.long_description.lowercase().find(_current_keyword.lowercase()) != Glib::ustring::npos ) { Gtk::TreeModel::iterator iter = _tlist_store->append(); Gtk::TreeModel::Row row = *iter; @@ -187,10 +191,13 @@ void TemplateLoadTab::_loadTemplates() // system templates dir _getTemplatesFromDir(INKSCAPE_TEMPLATESDIR + _loading_path); + + // procedural templates + _getProceduralTemplates(); } -TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib::ustring &path) +TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::string &path) { TemplateData result; result.path = path; @@ -209,7 +216,6 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib:: Inkscape::XML::Document *rdoc; rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI); Inkscape::XML::Node *myRoot; - Inkscape::XML::Node *dataNode; if (rdoc){ myRoot = rdoc->root(); @@ -221,44 +227,14 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const Glib:: if (myRoot == NULL) // No template info return result; - - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_name")) != NULL) - result.display_name = dgettext("Document template name", dataNode->firstChild()->content()); - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:author")) != NULL) - result.author = dataNode->firstChild()->content(); - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_short")) != NULL) - result.short_description = dgettext("Document template short description", dataNode->firstChild()->content()); - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_long") )!= NULL) - result.long_description = dgettext("Document template long description", dataNode->firstChild()->content()); - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:preview")) != NULL) - result.preview_name = dataNode->firstChild()->content(); - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:date")) != NULL){ - result.creation_date = dataNode->firstChild()->content(); - } - - if ((dataNode = sp_repr_lookup_name(myRoot, "inkscape:_keywords")) != NULL){ - Glib::ustring data = dataNode->firstChild()->content(); - while (!data.empty()){ - std::size_t pos = data.find_first_of(" "); - if (pos == Glib::ustring::npos) - pos = data.size(); - - Glib::ustring keyword = dgettext("Document template keyword", data.substr(0, pos).data()); - result.keywords.insert(keyword); - _keywords.insert(keyword); - - if (pos == data.size()) - break; - data.erase(0, pos+1); - } - } + _getDataFromNode(myRoot, result); } return result; } -void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path) +void TemplateLoadTab::_getTemplatesFromDir(const std::string &path) { if ( !Glib::file_test(path, Glib::FILE_TEST_EXISTS) || !Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) @@ -266,9 +242,9 @@ void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path) Glib::Dir dir(path); - Glib::ustring file = Glib::build_filename(path, dir.read_name()); + std::string file = Glib::build_filename(path, dir.read_name()); while (file != path){ - if (Glib::str_has_suffix(file, ".svg") && !Glib::str_has_prefix(Glib::path_get_basename(file), "default")){ + if (Glib::str_has_suffix(file, ".svg") && !Glib::str_has_prefix(Glib::path_get_basename(file), "default.")){ TemplateData tmp = _processTemplateFile(file); if (tmp.display_name != "") _tdata[tmp.display_name] = tmp; @@ -277,5 +253,66 @@ void TemplateLoadTab::_getTemplatesFromDir(const Glib::ustring &path) } } + +void TemplateLoadTab::_getProceduralTemplates() +{ + std::list<Inkscape::Extension::Effect *> effects; + Inkscape::Extension::db.get_effect_list(effects); + + std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin(); + while (it != effects.end()){ + Inkscape::XML::Node *myRoot; + myRoot = (*it)->get_repr(); + myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo"); + + if (myRoot){ + TemplateData result; + result.display_name = (*it)->get_name(); + result.is_procedural = true; + result.path = ""; + result.tpl_effect = *it; + + _getDataFromNode(myRoot, result); + _tdata[result.display_name] = result; + } + ++it; + } +} + + +void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateData &data) +{ + Inkscape::XML::Node *currentData; + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_name")) != NULL) + data.display_name = dgettext("Document template name", currentData->firstChild()->content()); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:author")) != NULL) + data.author = currentData->firstChild()->content(); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_shortdesc")) != NULL) + data.short_description = dgettext("Document template short description", currentData->firstChild()->content()); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_long") )!= NULL) + data.long_description = dgettext("Document template long description", currentData->firstChild()->content()); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:preview")) != NULL) + data.preview_name = currentData->firstChild()->content(); + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:date")) != NULL) + data.creation_date = currentData->firstChild()->content(); + + if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_keywords")) != NULL){ + Glib::ustring tplKeywords = currentData->firstChild()->content(); + while (!tplKeywords.empty()){ + std::size_t pos = tplKeywords.find_first_of(" "); + if (pos == Glib::ustring::npos) + pos = tplKeywords.size(); + + Glib::ustring keyword = dgettext("Document template keyword", tplKeywords.substr(0, pos).data()); + data.keywords.insert(keyword.lowercase()); + _keywords.insert(keyword.lowercase()); + + if (pos == tplKeywords.size()) + break; + tplKeywords.erase(0, pos+1); + } + } +} + } } diff --git a/src/ui/dialog/template-load-tab.h b/src/ui/dialog/template-load-tab.h index 50f3e0be2..744a2a9fb 100644 --- a/src/ui/dialog/template-load-tab.h +++ b/src/ui/dialog/template-load-tab.h @@ -18,6 +18,10 @@ #include <gtkmm/treeview.h> #include <map> #include <set> +#include <string> + +#include "xml/node.h" +#include "extension/effect.h" namespace Inkscape { @@ -32,7 +36,7 @@ public: struct TemplateData { bool is_procedural; - Glib::ustring path; + std::string path; Glib::ustring display_name; Glib::ustring author; Glib::ustring short_description; @@ -40,6 +44,7 @@ public: Glib::ustring preview_name; Glib::ustring creation_date; std::set<Glib::ustring> keywords; + Inkscape::Extension::Effect *tpl_effect; }; TemplateLoadTab(); @@ -60,7 +65,7 @@ protected: Glib::ustring _current_keyword; Glib::ustring _current_template; - Glib::ustring _loading_path; + std::string _loading_path; std::map<Glib::ustring, TemplateData> _tdata; std::set<Glib::ustring> _keywords; @@ -91,9 +96,11 @@ private: SearchType _current_search_type; - void _getTemplatesFromDir(const Glib::ustring &); + void _getDataFromNode(Inkscape::XML::Node *, TemplateData &); + void _getProceduralTemplates(); + void _getTemplatesFromDir(const std::string &); void _keywordSelected(); - TemplateData _processTemplateFile(const Glib::ustring &); + TemplateData _processTemplateFile(const std::string &); }; } diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp index be7e2b515..7e34e5a58 100644 --- a/src/ui/dialog/template-widget.cpp +++ b/src/ui/dialog/template-widget.cpp @@ -19,7 +19,14 @@ #include <glibmm/miscutils.h> #include "template-load-tab.h" +#include "desktop.h" +#include "desktop-handles.h" +#include "document.h" +#include "document-undo.h" #include "file.h" +#include "extension/implementation/implementation.h" +#include "inkscape.h" + namespace Inkscape { namespace UI { @@ -28,18 +35,16 @@ namespace UI { TemplateWidget::TemplateWidget() : _more_info_button(_("More info")) , _short_description_label(_(" ")) - , _template_author_label(_(" ")) , _template_name_label(_("no template selected")) + , _effect_prefs(NULL) { pack_start(_template_name_label, Gtk::PACK_SHRINK, 10); - pack_start(_template_author_label, Gtk::PACK_SHRINK, 0); pack_start(_preview_box, Gtk::PACK_SHRINK, 0); _preview_box.pack_start(_preview_image, Gtk::PACK_EXPAND_PADDING, 15); _preview_box.pack_start(_preview_render, Gtk::PACK_EXPAND_PADDING, 10); _short_description_label.set_line_wrap(true); - //_short_description_label.set_size_request(200); Gtk::Alignment *align; align = manage(new Gtk::Alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER, 0.0, 0.0)); @@ -55,10 +60,19 @@ TemplateWidget::TemplateWidget() void TemplateWidget::create() { - if (_current_template.path == "") + if (_current_template.display_name == "") return; - if (_current_template.is_procedural) {} + if (_current_template.is_procedural){ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDesktop *desc = sp_file_new_default(); + _current_template.tpl_effect->effect(desc); + DocumentUndo::clearUndo(sp_desktop_document(desc)); + sp_desktop_document(desc)->setModifiedSinceSave(false); + + if (desktop) + desktop->clearWaitingCursor(); + } else { sp_file_new(_current_template.path); } @@ -68,34 +82,41 @@ void TemplateWidget::create() void TemplateWidget::display(TemplateLoadTab::TemplateData data) { _current_template = data; - if (data.is_procedural){} - else{ - _template_name_label.set_text(_current_template.display_name); - _template_author_label.set_text(_current_template.author); - _short_description_label.set_text(_current_template.short_description); + + _template_name_label.set_text(_current_template.display_name); + _short_description_label.set_text(_current_template.short_description); - Glib::ustring imagePath = Glib::build_filename(Glib::path_get_dirname(_current_template.path), _current_template.preview_name); - if (data.preview_name != ""){ - _preview_image.set(imagePath); - _preview_image.show(); - _preview_render.hide(); - } - else{ - _preview_render.showImage(data.path); - _preview_render.show(); - _preview_image.hide(); - } + _preview_render.hide(); + _preview_image.hide(); + + std::string imagePath = Glib::build_filename(Glib::path_get_dirname(_current_template.path), _current_template.preview_name); + if (data.preview_name != ""){ + _preview_image.set(imagePath); + _preview_image.show(); + } + else if (!data.is_procedural){ + Glib::ustring gPath = data.path.c_str(); + _preview_render.showImage(gPath); + _preview_render.show(); + } + + if (_effect_prefs != NULL){ + remove (*_effect_prefs); + _effect_prefs = NULL; + } + if (data.is_procedural){ + _effect_prefs = data.tpl_effect->get_imp()->prefs_effect(data.tpl_effect, SP_ACTIVE_DESKTOP, NULL, NULL); + pack_start(*_effect_prefs); } } void TemplateWidget::_displayTemplateDetails() { - if (_current_template.path == "") - return; + Glib::ustring message = _current_template.display_name + "\n\n"; - Glib::ustring message = _current_template.display_name + "\n\n" + - _("Path: ") + _current_template.path + "\n\n"; + if (_current_template.path != "") + message += _("Path: ") + _current_template.path + "\n\n"; if (_current_template.long_description != "") message += _("Description: ") + _current_template.long_description + "\n\n"; diff --git a/src/ui/dialog/template-widget.h b/src/ui/dialog/template-widget.h index f7e1267ce..bb35d26a0 100644 --- a/src/ui/dialog/template-widget.h +++ b/src/ui/dialog/template-widget.h @@ -17,6 +17,7 @@ #include "template-load-tab.h" + namespace Inkscape { namespace UI { @@ -36,8 +37,8 @@ private: Gtk::Image _preview_image; Dialog::SVGPreview _preview_render; Gtk::Label _short_description_label; - Gtk::Label _template_author_label; Gtk::Label _template_name_label; + Gtk::Widget *_effect_prefs; void _displayTemplateDetails(); }; 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 ); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 8287452d7..2379dc181 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -442,6 +442,7 @@ PageSizer::init () _portrait_connection = _portraitButton.signal_toggled().connect (sigc::mem_fun (*this, &PageSizer::on_portrait)); _changedw_connection = _dimensionWidth.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed)); _changedh_connection = _dimensionHeight.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed)); + _changedu_connection = _dimensionUnits.getUnitMenu()->signal_changed().connect (sigc::mem_fun (*this, &PageSizer::on_units_changed)); _fitPageButton.signal_clicked().connect(sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing)); show_all_children(); @@ -454,11 +455,11 @@ PageSizer::init () * 'changeList' is true, then adjust the paperSizeList to show the closest * standard page size. * - * \param w, h given in px + * \param w, h * \param changeList whether to modify the paper size list */ void -PageSizer::setDim (double w, double h, bool changeList) +PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList) { static bool _called = false; if (_called) { @@ -473,14 +474,16 @@ PageSizer::setDim (double w, double h, bool changeList) _changedw_connection.block(); _changedh_connection.block(); + _unit = w.unit->abbr; + if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) { SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP); - double const old_height = doc->getHeight(); - doc->setWidth (Inkscape::Util::Quantity(w, "px")); - doc->setHeight (Inkscape::Util::Quantity(h, "px")); + Inkscape::Util::Quantity const old_height = doc->getHeight(); + doc->setWidth (w); + doc->setHeight (h); // The origin for the user is in the lower left corner; this point should remain stationary when // changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this - Geom::Translate const vert_offset(Geom::Point(0, (old_height - h))); + Geom::Translate const vert_offset(Geom::Point(0, (old_height.value("px") - h.value("px")))); doc->getRoot()->translateChildItems(vert_offset); DocumentUndo::done(doc, SP_VERB_NONE, _("Set page size")); } @@ -503,9 +506,10 @@ PageSizer::setDim (double w, double h, bool changeList) _paperSizeListSelection->select(row); } - Unit const& unit = _dimensionUnits.getUnit(); - _dimensionWidth.setValue (w / unit.factor); - _dimensionHeight.setValue (h / unit.factor); + _dimensionWidth.setUnit(w.unit->abbr); + _dimensionWidth.setValue (w.quantity); + _dimensionHeight.setUnit(h.unit->abbr); + _dimensionHeight.setValue (h.quantity); _paper_size_list_connection.unblock(); _landscape_connection.unblock(); @@ -547,12 +551,12 @@ PageSizer::updateFitMarginsUI(Inkscape::XML::Node *nv_repr) * paperSizeListStore->children().end() if no such paper exists. */ Gtk::ListStore::iterator -PageSizer::find_paper_size (double w, double h) const +PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const { - double smaller = w; - double larger = h; + double smaller = w.quantity; + double larger = h.quantity; if ( h < w ) { - smaller = h; larger = w; + smaller = h.quantity; larger = w.quantity; } g_return_val_if_fail(smaller <= larger, _paperSizeListStore->children().end()); @@ -562,8 +566,8 @@ PageSizer::find_paper_size (double w, double h) const iter != _paperSizeTable.end() ; ++iter) { PaperSize paper = iter->second; Inkscape::Util::Unit const &i_unit = paper.unit; - double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, "px"); - double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, "px"); + double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, *w.unit); + double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, *w.unit); g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); @@ -643,8 +647,8 @@ PageSizer::on_paper_size_list_changed() return; } PaperSize paper = piter->second; - double w = paper.smaller; - double h = paper.larger; + Inkscape::Util::Quantity w = Inkscape::Util::Quantity(paper.smaller, paper.unit); + Inkscape::Util::Quantity h = Inkscape::Util::Quantity(paper.larger, paper.unit); if (std::find(lscape_papers.begin(), lscape_papers.end(), paper.name.c_str()) != lscape_papers.end()) { // enforce landscape mode if this is desired for the given page format @@ -654,9 +658,6 @@ PageSizer::on_paper_size_list_changed() _landscape = _landscapeButton.get_active(); } - w = Inkscape::Util::Quantity::convert(w, paper.unit, "px"); - h = Inkscape::Util::Quantity::convert(h, paper.unit, "px"); - if (_landscape) setDim (h, w, false); else @@ -673,8 +674,8 @@ PageSizer::on_portrait() { if (!_portraitButton.get_active()) return; - double w = _dimensionWidth.getValue ("px"); - double h = _dimensionHeight.getValue ("px"); + Inkscape::Util::Quantity w = Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionWidth.getUnit()); + Inkscape::Util::Quantity h = Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionHeight.getUnit()); if (h < w) { setDim (h, w); } @@ -689,8 +690,8 @@ PageSizer::on_landscape() { if (!_landscapeButton.get_active()) return; - double w = _dimensionWidth.getValue ("px"); - double h = _dimensionHeight.getValue ("px"); + Inkscape::Util::Quantity w = Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionWidth.getUnit()); + Inkscape::Util::Quantity h = Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionHeight.getUnit()); if (w < h) { setDim (h, w); } @@ -703,11 +704,18 @@ void PageSizer::on_value_changed() { if (_widgetRegistry->isUpdating()) return; - - setDim (_dimensionWidth.getValue("px"), - _dimensionHeight.getValue("px")); + if (_unit != _dimensionUnits.getUnit().abbr) return; + setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), + Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); +} +void +PageSizer::on_units_changed() +{ + if (_widgetRegistry->isUpdating()) return; + _unit = _dimensionUnits.getUnit().abbr; + setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), + Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); } - } // namespace Widget } // namespace UI diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index 34ed7592d..95836a005 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -161,7 +161,7 @@ public: * Set the page size to the given dimensions. If 'changeList' is * true, then reset the paper size list to the closest match */ - void setDim (double w, double h, bool changeList=true); + void setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList=true); /** * Updates the scalar widgets for the fit margins. (Just changes the value @@ -179,7 +179,7 @@ protected: /** * Find the closest standard paper size in the table, to the */ - Gtk::ListStore::iterator find_paper_size (double w, double h) const; + Gtk::ListStore::iterator find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const; void fire_fit_canvas_to_selection_or_drawing(); @@ -252,13 +252,17 @@ protected: //callback void on_value_changed(); + void on_units_changed(); sigc::connection _changedw_connection; sigc::connection _changedh_connection; + sigc::connection _changedu_connection; Registry *_widgetRegistry; //### state - whether we are currently landscape or portrait bool _landscape; + + Glib::ustring _unit; }; diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp index c107979a8..1114ff32b 100644 --- a/src/ui/widget/spinbutton.cpp +++ b/src/ui/widget/spinbutton.cpp @@ -14,6 +14,7 @@ #include "spinbutton.h" #include "unit-menu.h" +#include "unit-tracker.h" #include "util/expression-evaluator.h" #include "event-context.h" @@ -32,16 +33,23 @@ SpinButton::connect_signals() { int SpinButton::on_input(double* newvalue) { try { - Inkscape::Util::GimpEevlQuantity result; - if (_unit_menu) { - Unit unit = _unit_menu->getUnit(); - result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), &unit); + Inkscape::Util::EvaluatorQuantity result; + if (_unit_menu || _unit_tracker) { + Unit unit; + if (_unit_menu) { + unit = _unit_menu->getUnit(); + } else { + unit = _unit_tracker->getActiveUnit(); + } + Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), &unit); + result = eval.evaluate(); // check if output dimension corresponds to input unit if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) { throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.",""); } } else { - result = Inkscape::Util::gimp_eevl_evaluate (get_text().c_str(), NULL); + Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), NULL); + result = eval.evaluate(); } *newvalue = result.value; @@ -57,7 +65,7 @@ int SpinButton::on_input(double* newvalue) bool SpinButton::on_my_focus_in_event(GdkEventFocus* /*event*/) { - on_focus_in_value = get_value(); + _on_focus_in_value = get_value(); return false; // do not consume the event } @@ -84,7 +92,7 @@ bool SpinButton::on_my_key_press_event(GdkEventKey* event) void SpinButton::undo() { - set_value(on_focus_in_value); + set_value(_on_focus_in_value); } diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h index fe5d699e7..812b5f515 100644 --- a/src/ui/widget/spinbutton.h +++ b/src/ui/widget/spinbutton.h @@ -25,6 +25,7 @@ namespace UI { namespace Widget { class UnitMenu; +class UnitTracker; /** * SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMenu), @@ -37,7 +38,9 @@ class SpinButton : public Gtk::SpinButton public: SpinButton(double climb_rate = 0.0, guint digits = 0) : Gtk::SpinButton(climb_rate, digits), - _unit_menu(NULL) + _unit_menu(NULL), + _unit_tracker(NULL), + _on_focus_in_value(0.) { connect_signals(); }; @@ -47,7 +50,9 @@ public: explicit SpinButton(Gtk::Adjustment& adjustment, double climb_rate = 0.0, guint digits = 0) #endif : Gtk::SpinButton(adjustment, climb_rate, digits), - _unit_menu(NULL) + _unit_menu(NULL), + _unit_tracker(NULL), + _on_focus_in_value(0.) { connect_signals(); }; @@ -55,9 +60,13 @@ public: virtual ~SpinButton() {}; void setUnitMenu(UnitMenu* unit_menu) { _unit_menu = unit_menu; }; + + void addUnitTracker(UnitTracker* ut) { _unit_tracker = ut; }; protected: UnitMenu *_unit_menu; /// Linked unit menu for unit conversion in entered expressions. + UnitTracker *_unit_tracker; // Linked unit tracker for unit conversion in entered expressions. + double _on_focus_in_value; void connect_signals(); @@ -90,8 +99,6 @@ protected: */ void undo(); - double on_focus_in_value; - private: // noncopyable SpinButton(const SpinButton&); |
