diff options
| author | Jabiertxof <jabier.arraiza@marker.es> | 2019-07-26 15:44:44 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-08-02 21:26:28 +0000 |
| commit | 7b141551251bbff595b566c38b77643a50eee5aa (patch) | |
| tree | 70fac77d6a0c1d262f34a1e6a4eeae47ae6f64bd /src | |
| parent | Working state (diff) | |
| download | inkscape-7b141551251bbff595b566c38b77643a50eee5aa.tar.gz inkscape-7b141551251bbff595b566c38b77643a50eee5aa.zip | |
Add font size units and Adam UX sugestion
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 4 | ||||
| -rw-r--r-- | src/ui/toolbar/text-toolbar.cpp | 69 | ||||
| -rw-r--r-- | src/ui/toolbar/text-toolbar.h | 7 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.cpp | 12 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.h | 1 |
5 files changed, 74 insertions, 19 deletions
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 1584a7662..8599a6b00 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -486,9 +486,9 @@ void InkscapePreferences::initPageTools() int sizeValues[] = {SP_CSS_UNIT_PX, SP_CSS_UNIT_PT, SP_CSS_UNIT_PC, SP_CSS_UNIT_MM, SP_CSS_UNIT_CM, SP_CSS_UNIT_IN, SP_CSS_UNIT_EM/*, SP_CSS_UNIT_EX, SP_CSS_UNIT_PERCENT*/}; _page_text.add_group_header( _("Text units")); - _font_unit_type.init( "/options/font/unitType", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), SP_CSS_UNIT_PT ); + /* _font_unit_type.init( "/options/font/unitType", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), SP_CSS_UNIT_PT ); _page_text.add_line( true, _("Text size unit type:"), _font_unit_type, "", - _("Set the type of unit used in the text toolbar and text dialogs"), false); + _("Set the type of unit used in the text toolbar and text dialogs"), false); */ _font_output_px.init ( _("Always output text size in pixels (px)"), "/options/font/textOutputPx", true); // _page_text.add_line( false, "", _font_output_px, "", _("Always convert the text size units above into pixels (px) before saving to file")); diff --git a/src/ui/toolbar/text-toolbar.cpp b/src/ui/toolbar/text-toolbar.cpp index 9de5ab0d0..8328e6c25 100644 --- a/src/ui/toolbar/text-toolbar.cpp +++ b/src/ui/toolbar/text-toolbar.cpp @@ -70,7 +70,7 @@ using Inkscape::UI::Widget::UnitTracker; //#define DEBUG_TEXT -//######################## +//########################setActiveUnitByAbbr //## Text Toolbox ## //######################## @@ -101,7 +101,7 @@ static void sp_print_font( SPStyle *query ) {TextTool::~TextTool() { << (query->font_family.value ? query->font_family.value : "No value") << " Style: " << query->font_style.computed << " Weight: " << query->font_weight.computed - << " FontSpec: " + << " FontSpec: "_line_height_units_item->changeLabel("lines", 0); << (query->font_specification.value ? query->font_specification.value : "No value") << std::endl; std::cout << " LineHeight: " << query->line_height.computedif (c_selection_changed) @@ -109,7 +109,7 @@ static void sp_print_font( SPStyle *query ) {TextTool::~TextTool() { if (c_selection_modified) c_selection_modified.disconnect(); if (c_subselection_changed) - c_subselection_changed.disconnect(); + c_subselection_changed.disconnect();setActiveUnitByAbbr if (c_selection_modified_select_tool) c_selection_modified_select_tool.disconnect(); << " WordSpacing: " << query->word_spacing.computed @@ -131,7 +131,7 @@ static void sp_print_fontweight( SPStyle *query ) { this->grabbed = nullptr; } - Inkscape::Rubberband::get(this->desktop)->stop(); + Inkscape::Rubberband::get(this->desktop)->stop();_line_height_units_item->changeLabel("lines", 0); } std::cout << " Weight: " << names[ index ] << " (" << query->font_weight.computed << ")" << std::endl; @@ -248,14 +248,19 @@ namespace Toolbar { TextToolbar::TextToolbar(SPDesktop *desktop) : Toolbar(desktop), _freeze(false), - _tracker(new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR)) + _subselection(false), + _fullsubselection(false), + _tracker(new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR)), + _tracker_fs(new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR)) { /* Line height unit tracker */ _tracker->prependUnit(unit_table.getUnit("")); // Ratio _tracker->addUnit(unit_table.getUnit("%")); _tracker->addUnit(unit_table.getUnit("em")); _tracker->addUnit(unit_table.getUnit("ex")); - _tracker->setActiveUnit(unit_table.getUnit("%")); + _tracker->setActiveUnit(unit_table.getUnit("")); + _tracker->changeLabel("lines", 0); + _tracker_fs->setActiveUnit(unit_table.getUnit("mm")); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -353,12 +358,18 @@ TextToolbar::TextToolbar(SPDesktop *desktop) _font_size_item->signal_changed().connect(sigc::mem_fun(*this, &TextToolbar::fontsize_value_changed)); add(*_font_size_item); } + /* Font_ size units */ + { + _font_size_units_item = _tracker_fs->create_tool_item( _("Units"), ("") ); + _font_size_units_item->signal_changed_after().connect(sigc::mem_fun(*this, &TextToolbar::fontsize_unit_changed)); + add(*_font_size_units_item); + } { // Drop down menu std::vector<Glib::ustring> labels = {_("Smaller spacing"), "", "", "", "", C_("Text tool", "Normal"), "", "", "", "", "", _("Larger spacing")}; std::vector<double> values = { 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0}; - auto line_height_val = prefs->getDouble("/tools/text/lineheight", 1.25); + auto line_height_val = 1.25; _line_height_adj = Gtk::Adjustment::create(line_height_val, 0.0, 1000.0, 0.1, 1.0); _line_height_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("text-line-height", "", _line_height_adj, 0.1, 2)); @@ -1565,6 +1576,23 @@ TextToolbar::lineheight_unit_changed(int /* Not Used */) } void +TextToolbar::fontsize_unit_changed(int /* Not Used */) +{ + // quit if run by the _changed callbacks + Unit const *unit = _tracker_fs->getActiveUnit(); + g_return_if_fail(unit != nullptr); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit. + SPILength temp_size; + Inkscape::CSSOStringStream temp_size_stream; + temp_size_stream << 1 << unit->abbr; + temp_size.read(temp_size_stream.str().c_str()); + prefs->setInt("/options/font/unitType", temp_size.unit); + selection_changed(SP_ACTIVE_DESKTOP->selection); +} + +void TextToolbar::wordspacing_value_changed() { // quit if run by the _changed callbacks @@ -1769,7 +1797,7 @@ TextToolbar::selection_modified_select_tool(Inkscape::Selection *selection, guin } void -TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subselection, bool fullsubselection) // don't bother to update font list if subsel changed +TextToolbar::selection_changed(Inkscape::Selection * /*selection*/) // don't bother to update font list if subsel changed { #ifdef DEBUG_TEXT static int count = 0; @@ -1799,7 +1827,7 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele return; } _freeze = true; - if (!subselection) { + if (!this->_subselection) { this->_outer = true;; this->_sub_active_item = nullptr; } @@ -1923,7 +1951,9 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele _font_size_item->set_tooltip(tooltip.c_str()); Inkscape::CSSOStringStream os; + // We dot want to parse values just show + _tracker_fs->setActiveUnitByAbbr(sp_style_get_css_unit_string(unit)); int rounded_size = std::round(size); if (std::abs((size - rounded_size)/size) < 0.0001) { // We use rounded_size to avoid rounding errors when, say, converting stored 'px' values to displayed 'pt' values. @@ -2002,6 +2032,11 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele // We dot want to parse values just show if (!is_relative(SPCSSUnit(line_height_unit))) { gint absunit = prefs->getInt("/tools/text/lineheight/display_unit", 1); + // For backwards comaptibility + if (is_relative(SPCSSUnit(absunit))) { + prefs->setInt("/tools/text/lineheight/display_unit", 1); + absunit = 1; + } height = Quantity::convert(height, "px", sp_style_get_css_unit_string(absunit)); line_height_unit = absunit; } @@ -2020,7 +2055,7 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele if( line_height_unit == SP_CSS_UNIT_NONE ) { // Function 'sp_style_get_css_unit_string' returns 'px' for unit none. // We need to avoid this. - _tracker->setActiveUnitByAbbr(""); + _tracker->setActiveUnitByAbbr("lines"); } else { _tracker->setActiveUnitByAbbr(sp_style_get_css_unit_string(line_height_unit)); } @@ -2087,7 +2122,6 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele << " letter_spacing.value: " << query.letter_spacing.value << " letter_spacing.unit: " << query.letter_spacing.unit << std::endl; std::cout << " GUI: writing_mode.computed: " << query.writing_mode.computed << std::endl; - std::cout << " GUI: full subselection: " << (fullsubselection ? "yes" : "no") << std::endl; } #endif @@ -2144,10 +2178,10 @@ TextToolbar::watch_ec(SPDesktop* desktop, Inkscape::UI::Tools::ToolBase* ec) { if (SP_IS_TEXT_CONTEXT(ec)) { // Watch selection // Ensure FontLister is updated here first.................. VVVVV - c_selection_changed = desktop->getSelection()->connectChangedFirst(sigc::bind(sigc::mem_fun(*this, &TextToolbar::selection_changed), false, false)); + c_selection_changed = desktop->getSelection()->connectChangedFirst(sigc::mem_fun(*this, &TextToolbar::selection_changed)); c_selection_modified = desktop->getSelection()->connectModifiedFirst(sigc::mem_fun(*this, &TextToolbar::selection_modified)); c_subselection_changed = desktop->connectToolSubselectionChanged(sigc::mem_fun(*this, &TextToolbar::subselection_changed)); - selection_changed(desktop->getSelection(), false, false); + selection_changed(desktop->getSelection()); } else if (SP_IS_SELECT_CONTEXT(ec)) { c_selection_modified_select_tool = desktop->getSelection()->connectModifiedFirst(sigc::mem_fun(*this, &TextToolbar::selection_modified_select_tool)); } else { @@ -2201,6 +2235,8 @@ TextToolbar::subselection_changed(gpointer texttool) std::cout << "subselection_changed: start " << std::endl; #endif // quit if run by the _changed callbacks + this->_subselection = true; + this->_fullsubselection = false; Inkscape::UI::Tools::TextTool *const tc = SP_TEXT_CONTEXT(SP_EVENT_CONTEXT(texttool)); if( tc ) { Inkscape::Text::Layout const *layout = te_get_layout(tc->text); @@ -2240,14 +2276,15 @@ TextToolbar::subselection_changed(gpointer texttool) } ++counter; } - selection_changed(nullptr, true, false); + selection_changed(nullptr); } else if (start_selection == start && end_selection == end) { // full subselection this->_sub_active_item = nullptr; this->_outer = true; - selection_changed(nullptr, true, true); + this->_fullsubselection = true; + selection_changed(nullptr); } else { this->_sub_active_item = nullptr; this->_outer = false; @@ -2286,7 +2323,7 @@ TextToolbar::subselection_changed(gpointer texttool) wrap_end = pos; finished = true; } - selection_changed(nullptr, true, false); + selection_changed(nullptr); } } } diff --git a/src/ui/toolbar/text-toolbar.h b/src/ui/toolbar/text-toolbar.h index 31c65cb38..7307c08da 100644 --- a/src/ui/toolbar/text-toolbar.h +++ b/src/ui/toolbar/text-toolbar.h @@ -65,9 +65,11 @@ private: bool _freeze; bool _text_style_from_prefs; UI::Widget::UnitTracker *_tracker; + UI::Widget::UnitTracker *_tracker_fs; UI::Widget::ComboBoxEntryToolItem *_font_family_item; UI::Widget::ComboBoxEntryToolItem *_font_size_item; + UI::Widget::ComboToolItem *_font_size_units_item; UI::Widget::ComboBoxEntryToolItem *_font_style_item; UI::Widget::ComboToolItem *_line_height_units_item; UI::Widget::SpinButtonToolItem *_line_height_item; @@ -96,6 +98,8 @@ private: int _lineheight_unit; int wrap_start; int wrap_end; + bool _subselection; + bool _fullsubselection; double selection_fontsize; sigc::connection c_selection_changed; sigc::connection c_selection_modified; @@ -117,7 +121,8 @@ private: void dx_value_changed(); void dy_value_changed(); void rotation_value_changed(); - void selection_changed(Inkscape::Selection *selection, bool subselection = false, bool fullsubselection = false); + void fontsize_unit_changed(int not_used); + void selection_changed(Inkscape::Selection *selection); void selection_modified(Inkscape::Selection *selection, guint flags); void selection_modified_select_tool(Inkscape::Selection *selection, guint flags); void subselection_changed(gpointer texttool); diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index 0bdd3210a..b0d2e890b 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -85,6 +85,18 @@ Inkscape::Util::Unit const * UnitTracker::getActiveUnit() const return _activeUnit; } +void UnitTracker::changeLabel(Glib::ustring new_label, gint pos) +{ + ComboToolItemColumns columns; + int index = 0; + for (auto& row: _store->children() ) { + if (index == pos) { + row[columns.col_label ] = new_label; + } + index++; + } +} + void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) { if (unit) { diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index 1f16292ff..2af8a057f 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -50,6 +50,7 @@ public: void addAdjustment(GtkAdjustment *adj); void prependUnit(Inkscape::Util::Unit const *u); void setFullVal(GtkAdjustment *adj, gdouble val); + void changeLabel(Glib::ustring new_label, gint pos); ComboToolItem *create_tool_item(Glib::ustring const &label, Glib::ustring const &tooltip); |
