From 89657de66511cef584d2354ea31980c3b6685f4b Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 3 Sep 2016 00:52:38 +0300 Subject: Removed some duplicate code. Removed some duplicate code by extracting a function and a loop. (bzr r15100.1.1) --- src/widgets/eraser-toolbar.cpp | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index 7f710a777..49ebb9cfe 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -65,6 +65,14 @@ static void sp_erc_mass_value_changed( GtkAdjustment *adj, GObject* tbl ) update_presets_list(tbl); } +static inline void toggle_actions_visibility_based_on_eraserMode( GObject *const tbl, const bool eraserMode) +{ + const std::array arr = {"split", "mass", "width"}; + for(const gchar * str : arr) { + gtk_action_set_visible( GTK_ACTION( g_object_get_data(tbl, str) ), eraserMode ); + } +} + static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); @@ -73,18 +81,7 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool( "/tools/eraser/mode", eraserMode ); } - GtkAction *split = GTK_ACTION( g_object_get_data(tbl, "split") ); - GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); - GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); - if(eraserMode == TRUE){ - gtk_action_set_visible( split, TRUE ); - gtk_action_set_visible( mass, TRUE ); - gtk_action_set_visible( width, TRUE ); - } else { - gtk_action_set_visible( split, FALSE ); - gtk_action_set_visible( mass, FALSE ); - gtk_action_set_visible( width, FALSE ); - } + toggle_actions_visibility_based_on_eraserMode(tbl, eraserMode); // only take action if run by the attr_changed listener if (!g_object_get_data( tbl, "freeze" )) { // in turn, prevent listener from responding @@ -193,19 +190,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toogle_break_apart), holder) ; gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); } - GtkAction *split = GTK_ACTION( g_object_get_data(holder, "split") ); - GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); - GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); - if(eraserMode == TRUE){ - gtk_action_set_visible( split, TRUE ); - gtk_action_set_visible( mass, TRUE ); - gtk_action_set_visible( width, TRUE ); - } else { - gtk_action_set_visible( split, FALSE ); - gtk_action_set_visible( mass, FALSE ); - gtk_action_set_visible( width, FALSE ); - } - + toggle_actions_visibility_based_on_eraserMode(holder, eraserMode); } /* -- cgit v1.2.3 From 0fda0bb3398bf960f64aa5b9a219a53892d2c600 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 3 Sep 2016 17:33:26 +0300 Subject: Remove == true. (bzr r15100.1.8) --- src/widgets/spray-toolbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index a724637e3..f456bc763 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -211,7 +211,7 @@ static void sp_toggle_pressure_scale( GtkToggleAction* act, gpointer data) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/usepressurescale", active); - if(active == true){ + if(active){ prefs->setDouble("/tools/spray/scale_variation", 0); } GObject *tbl = G_OBJECT(data); @@ -238,7 +238,7 @@ static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gboolean active = gtk_toggle_action_get_active(act); prefs->setBool("/tools/spray/picker", active); - if(active == true){ + if(active){ prefs->setBool("/dialogs/clonetiler/dotrace", false); SPDesktop *dt = SP_ACTIVE_DESKTOP; if (Inkscape::UI::Dialog::CloneTiler *ct = get_clone_tiler_panel(dt)){ -- cgit v1.2.3 From c14ec0bf6954beca505ed58b794632bd1ffe72ca Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 1 Oct 2016 02:00:59 +0300 Subject: Extract a function to prevent assignment + const-ing. (bzr r15100.1.26) --- src/widgets/stroke-style.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 4a658c5dc..f5735190f 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -976,6 +976,16 @@ StrokeStyle::setScaledDash(SPCSSAttr *css, } } +static inline double calcScaleLineWidth(const double width_typed, SPItem *const item, Inkscape::Util::Unit const *const unit) +{ + if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { + return Inkscape::Util::Quantity::convert(width_typed, unit, "px"); + } else { // percentage + const gdouble old_w = item->style->stroke_width.computed; + return old_w * width_typed / 100; + } +} + /** * Sets line properties like width, dashes, markers, etc. on all currently selected items. */ @@ -1007,13 +1017,7 @@ StrokeStyle::scaleLine() for(auto i=items.begin();i!=items.end();++i){ /* Set stroke width */ - double width; - if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { - width = Inkscape::Util::Quantity::convert(width_typed, unit, "px"); - } else { // percentage - gdouble old_w = (*i)->style->stroke_width.computed; - width = old_w * width_typed / 100; - } + const double width = calcScaleLineWidth(width_typed, (*i), unit); { Inkscape::CSSOStringStream os_width; -- cgit v1.2.3 From 13586717311b38bcddfa82602aa39c73e332dc87 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 1 Oct 2016 17:27:14 +0300 Subject: Extract a method instead of assigning a temp bool var. (bzr r15100.1.27) --- src/widgets/stroke-style.cpp | 12 +++++++----- src/widgets/stroke-style.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index f5735190f..47131dec1 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -437,6 +437,12 @@ StrokeStyle::makeRadioButton(Gtk::RadioButtonGroup &grp, return tb; } +bool StrokeStyle::shouldMarkersBeUpdated() +{ + return startMarkerCombo->update() || midMarkerCombo->update() || + endMarkerCombo->update(); +} + /** * Handles when user selects one of the markers from the marker combobox. * Gets the marker uri string and applies it to all selected @@ -444,11 +450,7 @@ StrokeStyle::makeRadioButton(Gtk::RadioButtonGroup &grp, */ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, SPMarkerLoc const /*which*/) { - bool markers_update = spw->startMarkerCombo->update() || - spw->midMarkerCombo->update() || - spw->endMarkerCombo->update(); - - if (spw->update || markers_update) { + if (spw->update || spw->shouldMarkersBeUpdated()) { return; } diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 76582602d..2d7e187a1 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -177,6 +177,7 @@ private: void miterLimitChangedCB(); void lineDashChangedCB(); void unitChangedCB(); + bool shouldMarkersBeUpdated(); static void markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, SPMarkerLoc const which); static void buttonToggledCB(StrokeStyleButton *tb, StrokeStyle *spw); -- cgit v1.2.3 From 086347db66cff034f3e1fdce59a89156c49b5b95 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 2 Oct 2016 15:26:27 +0300 Subject: Extract a function - is_query_style_updateable. (bzr r15100.1.29) --- src/widgets/stroke-style.cpp | 11 +++++------ src/widgets/style-utils.h | 39 +++++++++++++++++++++++++++++++++++++++ src/widgets/text-toolbar.cpp | 3 ++- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/widgets/style-utils.h (limited to 'src/widgets') diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 47131dec1..81a8e8115 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -22,6 +22,7 @@ #include "svg/svg-color.h" #include "ui/widget/unit-menu.h" #include "desktop-widget.h" +#include "widgets/style-utils.h" using Inkscape::DocumentUndo; using Inkscape::Util::unit_table; @@ -912,22 +913,20 @@ StrokeStyle::updateLine() if (result_ml != QUERY_STYLE_NOTHING) (*miterLimitAdj)->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness? - if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT && - result_join != QUERY_STYLE_NOTHING ) { + using Inkscape::is_query_style_updateable; + if (! is_query_style_updateable(result_join)) { setJoinType(query.stroke_linejoin.value); } else { setJoinButtons(NULL); } - if (result_cap != QUERY_STYLE_MULTIPLE_DIFFERENT && - result_cap != QUERY_STYLE_NOTHING ) { + if (! is_query_style_updateable(result_cap)) { setCapType (query.stroke_linecap.value); } else { setCapButtons(NULL); } - if (result_order != QUERY_STYLE_MULTIPLE_DIFFERENT && - result_order != QUERY_STYLE_NOTHING ) { + if (! is_query_style_updateable(result_order)) { setPaintOrder (query.paint_order.value); } else { setPaintOrder (NULL); diff --git a/src/widgets/style-utils.h b/src/widgets/style-utils.h new file mode 100644 index 000000000..5610519fd --- /dev/null +++ b/src/widgets/style-utils.h @@ -0,0 +1,39 @@ +/** + * @file + * Common utility functions for manipulating style. + */ +/* Author: + * Shlomi Fish + * + * Copyright (C) 2016 Shlomi Fish + * + * Released under the Expat licence. + */ + +#ifndef SEEN_DIALOGS_STYLE_UTILS_H +#define SEEN_DIALOGS_STYLE_UTILS_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "desktop-style.h" + +namespace Inkscape { + inline bool is_query_style_updateable(const int style) { + return (style == QUERY_STYLE_MULTIPLE_DIFFERENT || style == QUERY_STYLE_NOTHING); + } +} // namespace Inkscape + +#endif // SEEN_DIALOGS_STYLE_UTILS_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 4b22c8d7e..610d743a0 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -41,6 +41,7 @@ #include "ink-radio-action.h" #include "ink-toggle-action.h" #include "widgets/ink-comboboxentry-action.h" +#include "widgets/style-utils.h" #include "inkscape.h" #include "selection-chemistry.h" #include "sp-flowtext.h" @@ -304,7 +305,7 @@ static void sp_text_script_changed( InkToggleAction* act, GObject *tbl ) bool setSuper = false; bool setSub = false; - if(result_baseline == QUERY_STYLE_NOTHING || result_baseline == QUERY_STYLE_MULTIPLE_DIFFERENT ) { + if (Inkscape::is_query_style_updateable(result_baseline)) { // If not set or mixed, turn on superscript or subscript if( prop == 0 ) { setSuper = true; -- cgit v1.2.3 From 9791f9d502b3a35fb4376b9aa7909690ef392714 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 8 Oct 2016 18:56:14 +0300 Subject: Made the style-utils.h license dual-with-GPLv2+. Probably matters little legally, but it helps to be explicit. (bzr r15100.1.32) --- src/widgets/style-utils.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/style-utils.h b/src/widgets/style-utils.h index 5610519fd..65b635f0c 100644 --- a/src/widgets/style-utils.h +++ b/src/widgets/style-utils.h @@ -7,7 +7,13 @@ * * Copyright (C) 2016 Shlomi Fish * - * Released under the Expat licence. + * Dually-Licensed under: + * + * 1. The Expat license - https://www.gnu.org/licenses/license-list.html#Expat + * + * 2. The GNU General Public License, either version 2, or at your option, + * any later version of it. + * ( https://en.wikipedia.org/wiki/GNU_General_Public_License ) */ #ifndef SEEN_DIALOGS_STYLE_UTILS_H -- cgit v1.2.3