diff options
| author | Andrew Higginson <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
|---|---|---|
| committer | Andrew <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
| commit | 80960b623a99aae1402ab651b2974ef544ed3b03 (patch) | |
| tree | ba49d42c2789e9e11f805e2d5263e10f9fedeef8 /src/ui/widget | |
| parent | try to fix bug (diff) | |
| parent | GDL: Cherry-pick upstream patch 73852 (2011-03-23) - Add missing return value. (diff) | |
| download | inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.tar.gz inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.zip | |
merged with trunk so I can build again...
(bzr r10092.1.36)
Diffstat (limited to 'src/ui/widget')
77 files changed, 1294 insertions, 840 deletions
diff --git a/src/ui/widget/CMakeLists.txt b/src/ui/widget/CMakeLists.txt deleted file mode 100644 index ffc94c299..000000000 --- a/src/ui/widget/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -SET(ui_widget_SRC -button.cpp -color-picker.cpp -color-preview.cpp -combo-text.cpp -dock.cpp -dock-item.cpp -entity-entry.cpp -entry.cpp -filter-effect-chooser.cpp -handlebox.cpp -icon-widget.cpp -imageicon.cpp -imagetoggler.cpp -labelled.cpp -licensor.cpp -notebook-page.cpp -object-composite-settings.cpp -page-sizer.cpp -panel.cpp -point.cpp -preferences-widget.cpp -random.cpp -registered-widget.cpp -registry.cpp -rendering-options.cpp -rotateable.cpp -ruler.cpp -scalar.cpp -scalar-unit.cpp -selected-style.cpp -spin-slider.cpp -style-subject.cpp -style-swatch.cpp -svg-canvas.cpp -tolerance-slider.cpp -toolbox.cpp -unit-menu.cpp -zoom-status.cpp -) diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index b6069631b..bd23b6782 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -66,6 +66,8 @@ ink_common_sources += \ ui/widget/scalar.h \ ui/widget/selected-style.h \ ui/widget/selected-style.cpp \ + ui/widget/spinbutton.h \ + ui/widget/spinbutton.cpp \ ui/widget/spin-slider.h \ ui/widget/spin-slider.cpp \ ui/widget/style-subject.h \ diff --git a/src/ui/widget/attr-widget.h b/src/ui/widget/attr-widget.h index 7b9c35ab7..94906c8e8 100644 --- a/src/ui/widget/attr-widget.h +++ b/src/ui/widget/attr-widget.h @@ -1,6 +1,4 @@ -/** - * \brief Very basic interface for classes that control attributes - * +/* * Authors: * Nicholas Bishop <nicholasbishop@gmail.com> * Rodrigo Kumpera <kumpera@gmail.com> @@ -32,6 +30,9 @@ enum DefaultValueType T_CHARPTR }; +/** + * Very basic interface for classes that control attributes. + */ class DefaultValueHolder { DefaultValueType type; diff --git a/src/ui/widget/button.cpp b/src/ui/widget/button.cpp index 19c69ba44..ae1dbbe98 100644 --- a/src/ui/widget/button.cpp +++ b/src/ui/widget/button.cpp @@ -1,6 +1,4 @@ -/** - * \brief Button and CheckButton widgets - * +/* * Author: * buliabyak@gmail.com * diff --git a/src/ui/widget/button.h b/src/ui/widget/button.h index 7e942b324..1ed88a2da 100644 --- a/src/ui/widget/button.h +++ b/src/ui/widget/button.h @@ -1,6 +1,4 @@ -/** - * \brief Button and CheckButton widgets - * +/* * Author: * buliabyak@gmail.com * @@ -20,6 +18,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Button widget. + */ class Button : public Gtk::Button { public: @@ -29,6 +30,9 @@ protected: Gtk::Tooltips _tooltips; }; +/** + * CheckButton widget. + */ class CheckButton : public Gtk::CheckButton { public: diff --git a/src/ui/widget/color-picker.cpp b/src/ui/widget/color-picker.cpp index 650ed10f6..f32e25885 100644 --- a/src/ui/widget/color-picker.cpp +++ b/src/ui/widget/color-picker.cpp @@ -1,6 +1,4 @@ -/** \file - * \brief Color picker button & window - * +/* * Authors: * Lauris Kaplinski <lauris@kaplinski.com> * bulia byak <buliabyak@users.sf.net> diff --git a/src/ui/widget/color-preview.cpp b/src/ui/widget/color-preview.cpp index add596444..22ca1ebe0 100644 --- a/src/ui/widget/color-preview.cpp +++ b/src/ui/widget/color-preview.cpp @@ -1,6 +1,4 @@ -/** \file - * Implemenmtation of a simple color preview widget - * +/* * Author: * Lauris Kaplinski <lauris@kaplinski.com> * Ralf Stephan <ralf@ark.in-berlin.de> @@ -11,8 +9,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "display/nr-plain-stuff-gdk.h" -#include "color-preview.h" +#include "ui/widget/color-preview.h" +#include "display/cairo-utils.h" #define SPCP_DEFAULT_WIDTH 32 #define SPCP_DEFAULT_HEIGHT 12 @@ -76,6 +74,9 @@ ColorPreview::paint (GdkRectangle *area) if (!gdk_rectangle_intersect (area, &warea, &wpaint)) return; + GtkWidget *widget = GTK_WIDGET(this->gobj()); + cairo_t *ct = gdk_cairo_create(widget->window); + /* Transparent area */ w2 = warea.width / 2; @@ -86,11 +87,15 @@ ColorPreview::paint (GdkRectangle *area) carea.height = warea.height; if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - nr_gdk_draw_rgba32_solid (get_window()->gobj(), - get_style()->get_black_gc()->gobj(), - cpaint.x, cpaint.y, - cpaint.width, cpaint.height, - _rgba); + cairo_pattern_t *checkers = ink_cairo_pattern_create_checkerboard(); + + cairo_rectangle(ct, carea.x, carea.y, carea.width, carea.height); + cairo_set_source(ct, checkers); + cairo_fill_preserve(ct); + ink_cairo_set_source_rgba32(ct, _rgba); + cairo_fill(ct); + + cairo_pattern_destroy(checkers); } /* Solid area */ @@ -101,12 +106,12 @@ ColorPreview::paint (GdkRectangle *area) carea.height = warea.height; if (gdk_rectangle_intersect (area, &carea, &cpaint)) { - nr_gdk_draw_rgba32_solid (get_window()->gobj(), - get_style()->get_black_gc()->gobj(), - cpaint.x, cpaint.y, - cpaint.width, cpaint.height, - _rgba | 0xff); + cairo_rectangle(ct, carea.x, carea.y, carea.width, carea.height); + ink_cairo_set_source_rgba32(ct, _rgba | 0xff); + cairo_fill(ct); } + + cairo_destroy(ct); } }}} diff --git a/src/ui/widget/color-preview.h b/src/ui/widget/color-preview.h index 424c58665..aa4c7e11d 100644 --- a/src/ui/widget/color-preview.h +++ b/src/ui/widget/color-preview.h @@ -1,9 +1,6 @@ -#ifndef __COLOR_PREVIEW_H__ -#define __COLOR_PREVIEW_H__ - -/** \file - * A simple color preview widget, mainly used within a picker button. - * +#ifndef SEEN_COLOR_PREVIEW_H +#define SEEN_COLOR_PREVIEW_H +/* * Authors: * Lauris Kaplinski <lauris@kaplinski.com> * Ralf Stephan <ralf@ark.in-berlin.de> @@ -17,9 +14,12 @@ #include <gtkmm/eventbox.h> namespace Inkscape { - namespace UI { - namespace Widget { +namespace UI { +namespace Widget { +/** + * A simple color preview widget, mainly used within a picker button. + */ class ColorPreview : public Gtk::Widget { public: ColorPreview (guint32 rgba); @@ -34,9 +34,11 @@ protected: guint32 _rgba; }; -}}} +} // namespace Widget +} // namespace UI +} // namespace Inkscape -#endif +#endif // SEEN_COLOR_PREVIEW_H /* Local Variables: diff --git a/src/ui/widget/combo-enums.h b/src/ui/widget/combo-enums.h index d9044daa6..9dfb920a5 100644 --- a/src/ui/widget/combo-enums.h +++ b/src/ui/widget/combo-enums.h @@ -1,6 +1,4 @@ -/** - * \brief Simplified management of enumerations in the UI as combobox. - * +/* * Authors: * Nicholas Bishop <nicholasbishop@gmail.com> * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> @@ -23,6 +21,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Simplified management of enumerations in the UI as combobox. + */ template<typename E> class ComboBoxEnum : public Gtk::ComboBox, public AttrWidget { private: @@ -176,6 +177,9 @@ private: }; +/** + * Simplified management of enumerations in the UI as combobox. + */ template<typename E> class LabelledComboBoxEnum : public Labelled { public: diff --git a/src/ui/widget/combo-text.cpp b/src/ui/widget/combo-text.cpp index 7706f7c29..43428adb8 100644 --- a/src/ui/widget/combo-text.cpp +++ b/src/ui/widget/combo-text.cpp @@ -23,7 +23,7 @@ #endif #include "combo-text.h" -#include <gtk/gtkcombobox.h> +#include <gtk/gtk.h> ComboText::ComboText() : Gtk::ComboBox() diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp index 72a20c385..14b219110 100644 --- a/src/ui/widget/dock-item.cpp +++ b/src/ui/widget/dock-item.cpp @@ -1,6 +1,4 @@ -/** - * \brief A custom Inkscape wrapper around gdl_dock_item - * +/* * Author: * Gustav Broberg <broberg@kth.se> * @@ -262,7 +260,7 @@ DockItem::present() void DockItem::grab_focus() { - if (GTK_WIDGET_REALIZED (_gdl_dock_item)) { + if (gtk_widget_get_realized (_gdl_dock_item)) { // make sure the window we're in is present Gtk::Widget *toplevel = getWidget().get_toplevel(); diff --git a/src/ui/widget/dock-item.h b/src/ui/widget/dock-item.h index 79d69d862..48cd71846 100644 --- a/src/ui/widget/dock-item.h +++ b/src/ui/widget/dock-item.h @@ -1,6 +1,4 @@ -/** - * \brief A custom wrapper around gdl-dock-item - * +/* * Author: * Gustav Broberg <broberg@kth.se> * @@ -19,7 +17,7 @@ #include <gtkmm/paned.h> #include <gtkmm/window.h> -#include "libgdl/libgdl.h" +#include "libgdl/gdl.h" namespace Inkscape { namespace UI { @@ -27,6 +25,9 @@ namespace Widget { class Dock; +/** + * A custom wrapper around gdl-dock-item. + */ class DockItem { public: diff --git a/src/ui/widget/dock.cpp b/src/ui/widget/dock.cpp index 02e1f2b41..627b01e27 100644 --- a/src/ui/widget/dock.cpp +++ b/src/ui/widget/dock.cpp @@ -1,5 +1,6 @@ -/** @file - * @brief A desktop dock pane to dock dialogs. +/** + * @file + * A desktop dock pane to dock dialogs. */ /* Author: * Gustav Broberg <broberg@kth.se> diff --git a/src/ui/widget/dock.h b/src/ui/widget/dock.h index 5836cf83f..bd5685348 100644 --- a/src/ui/widget/dock.h +++ b/src/ui/widget/dock.h @@ -20,7 +20,7 @@ #include "ui/widget/dock-item.h" -#include "libgdl/libgdl.h" +#include "libgdl/gdl.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/entity-entry.cpp b/src/ui/widget/entity-entry.cpp index e191a9360..aaf67a7a2 100644 --- a/src/ui/widget/entity-entry.cpp +++ b/src/ui/widget/entity-entry.cpp @@ -1,5 +1,4 @@ -/** \file - * +/* * Authors: * bulia byak <buliabyak@users.sf.net> * Bryce W. Harrington <bryce@bryceharrington.org> @@ -25,6 +24,7 @@ #include "sp-object.h" #include "rdf.h" #include "ui/widget/registry.h" +#include "sp-root.h" #include "entity-entry.h" @@ -87,8 +87,8 @@ void EntityLineEntry::update(SPDocument *doc) { const char *text = rdf_get_work_entity (doc, _entity); // If RDF title is not set, get the document's <title> and set the RDF: - if ( !text && !strcmp(_entity->name, "title") && doc->root ) { - text = doc->root->title(); + if ( !text && !strcmp(_entity->name, "title") && doc->getRoot() ) { + text = doc->getRoot()->title(); rdf_set_work_entity(doc, _entity, text); } static_cast<Gtk::Entry*>(_packable)->set_text (text ? text : ""); @@ -133,8 +133,8 @@ void EntityMultiLineEntry::update(SPDocument *doc) { const char *text = rdf_get_work_entity (doc, _entity); // If RDF title is not set, get the document's <title> and set the RDF: - if ( !text && !strcmp(_entity->name, "title") && doc->root ) { - text = doc->root->title(); + if ( !text && !strcmp(_entity->name, "title") && doc->getRoot() ) { + text = doc->getRoot()->title(); rdf_set_work_entity(doc, _entity, text); } Gtk::ScrolledWindow *s = static_cast<Gtk::ScrolledWindow*>(_packable); diff --git a/src/ui/widget/entity-entry.h b/src/ui/widget/entity-entry.h index 5bdee9a90..c96f3351d 100644 --- a/src/ui/widget/entity-entry.h +++ b/src/ui/widget/entity-entry.h @@ -1,6 +1,4 @@ -/** \file - * \brief - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * diff --git a/src/ui/widget/entry.cpp b/src/ui/widget/entry.cpp index 7b19ac861..7ac8532fb 100644 --- a/src/ui/widget/entry.cpp +++ b/src/ui/widget/entry.cpp @@ -1,7 +1,4 @@ -/** \file - * - * \brief Helperclass for Gtk::Entry widgets - * +/* * Authors: * Johan Engelen <goejendaagh@zonnet.nl> * diff --git a/src/ui/widget/entry.h b/src/ui/widget/entry.h index bb6c1321a..3338f0888 100644 --- a/src/ui/widget/entry.h +++ b/src/ui/widget/entry.h @@ -1,7 +1,4 @@ -/** \file - * - * \brief Helperclass for Gtk::Entry widgets - * +/* * Authors: * Johan Engelen <goejendaagh@zonnet.nl> * @@ -23,6 +20,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Helperclass for Gtk::Entry widgets. + */ class Entry : public Labelled { public: diff --git a/src/ui/widget/filter-effect-chooser.cpp b/src/ui/widget/filter-effect-chooser.cpp index aba3a18e8..52ce0b5bc 100644 --- a/src/ui/widget/filter-effect-chooser.cpp +++ b/src/ui/widget/filter-effect-chooser.cpp @@ -22,10 +22,10 @@ namespace UI { namespace Widget { SimpleFilterModifier::SimpleFilterModifier(int flags) - : _lb_blend(_("_Blend mode:")), + : _lb_blend(_("Blend mode:")), _lb_blur(_("_Blur:"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, true), _blend(BlendModeConverter, SP_ATTR_INVALID, false), - _blur(0, 0, 100, 1, 0.01, 1) + _blur(0, 0, 100, 1, 0.01, 2) { _flags = flags; diff --git a/src/ui/widget/handlebox.cpp b/src/ui/widget/handlebox.cpp index b82b715bb..0ac84ef3a 100644 --- a/src/ui/widget/handlebox.cpp +++ b/src/ui/widget/handlebox.cpp @@ -1,10 +1,4 @@ -/** - * \brief HandleBox Widget - Adds a detachment handle to another widget. - * - * This work really doesn't amount to much more than a convenience constructor - * for Gtk::HandleBox. Maybe this could be contributed back to Gtkmm, as - * Gtkmm provides several convenience constructors for other widgets as well. - * +/* * Author: * Derek P. Moore <derekm@hackunix.org> * diff --git a/src/ui/widget/handlebox.h b/src/ui/widget/handlebox.h index 41a993e9d..db384552b 100644 --- a/src/ui/widget/handlebox.h +++ b/src/ui/widget/handlebox.h @@ -1,9 +1,4 @@ -/** - * \brief HandleBox Widget - Adds a detachment handle to another widget. - * - * This work really doesn't amount to much more than a convenience constructor - * for Gtk::HandleBox. Maybe this could be contributed back to Gtkmm, as - * Gtkmm provides several convenience constructors for other widgets as well. +/* * * Author: * Derek P. Moore <derekm@hackunix.org> @@ -22,6 +17,13 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Adds a detachment handle to another widget. + * + * This work really doesn't amount to much more than a convenience constructor + * for Gtk::HandleBox. Maybe this could be contributed back to Gtkmm, as + * Gtkmm provides several convenience constructors for other widgets as well. + */ class HandleBox : public Gtk::HandleBox { public: diff --git a/src/ui/widget/icon-widget.cpp b/src/ui/widget/icon-widget.cpp index 64415f421..d04f89b15 100644 --- a/src/ui/widget/icon-widget.cpp +++ b/src/ui/widget/icon-widget.cpp @@ -1,6 +1,4 @@ -/** - * \brief Icon Widget - * +/* * Author: * Bryce Harrington <bryce@bryceharrington.org> * @@ -14,28 +12,23 @@ # include <config.h> #endif -#include <glib/gmem.h> +#include <glib.h> #include "icon-widget.h" namespace Inkscape { namespace UI { namespace Widget { -/** - * General purpose icon widget, supporting SVG, etc. icon loading - * - * \param ... - * - * An icon widget is a ... - */ - -IconWidget::IconWidget() +IconWidget::IconWidget() : + _pb(0), + _size(0), + _do_bitmap_icons(false) { - _pb = NULL; - _size = 0; } -IconWidget::IconWidget(int unsigned size, int unsigned scale, gchar const *name) +IconWidget::IconWidget(int unsigned size, int unsigned scale, gchar const *name) : + _pb(0), + _do_bitmap_icons(false) { _size = std::max((int unsigned)128, std::min(size, (int unsigned)1)); @@ -45,7 +38,7 @@ IconWidget::IconWidget(int unsigned size, int unsigned scale, gchar const *name) if (pixels == NULL) { g_warning("Couldn't find matching icon for %s - has this application been installed?", name); - _pb = NULL; + //_pb = NULL; } else { /* TODO _pb = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB, @@ -55,7 +48,9 @@ IconWidget::IconWidget(int unsigned size, int unsigned scale, gchar const *name) } } -IconWidget::IconWidget(int unsigned size, guchar const */*px*/) +IconWidget::IconWidget(int unsigned size, guchar const */*px*/) : + _pb(0), + _do_bitmap_icons(false) { _size = std::max((int unsigned)128, std::min(size, (int unsigned)1)); diff --git a/src/ui/widget/icon-widget.h b/src/ui/widget/icon-widget.h index 3ca461b33..329702f2e 100644 --- a/src/ui/widget/icon-widget.h +++ b/src/ui/widget/icon-widget.h @@ -1,6 +1,4 @@ -/** - * \brief Icon Widget - General image widget (including SVG icons) - * +/* * Author: * Bryce Harrington <bryce@bryceharrington.org> * @@ -19,6 +17,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Icon Widget - General image widget (including SVG icons). + */ class IconWidget : public Gtk::Widget { public: diff --git a/src/ui/widget/labelled.cpp b/src/ui/widget/labelled.cpp index c55b57616..0a13d6347 100644 --- a/src/ui/widget/labelled.cpp +++ b/src/ui/widget/labelled.cpp @@ -1,7 +1,4 @@ -/** - * \brief Labelled Widget - Adds a label with optional icon or suffix to - * another widget. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Derek P. Moore <derekm@hackunix.org> @@ -24,18 +21,6 @@ namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a Labelled Widget. - * - * \param label Label. - * \param widget Widget to label; should be allocated with new, as it will - * be passed to Gtk::manage(). - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the text - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to true). - */ Labelled::Labelled(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Widget *widget, Glib::ustring const &suffix, @@ -60,9 +45,6 @@ Labelled::Labelled(Glib::ustring const &label, Glib::ustring const &tooltip, } -/** - * Allow the setting of the width of the labelled widget - */ void Labelled::setWidgetSizeRequest(int width, int height) { if (_widget) diff --git a/src/ui/widget/labelled.h b/src/ui/widget/labelled.h index a8b00ebb6..8c2ec8939 100644 --- a/src/ui/widget/labelled.h +++ b/src/ui/widget/labelled.h @@ -1,7 +1,4 @@ -/** - * \brief Labelled Widget - Adds a label with optional icon or suffix to - * another widget. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Derek P. Moore <derekm@hackunix.org> @@ -23,9 +20,25 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Adds a label with optional icon or suffix to another widget. + */ class Labelled : public Gtk::HBox { public: + + /** + * Construct a Labelled Widget. + * + * @param label Label. + * @param widget Widget to label; should be allocated with new, as it will + * be passed to Gtk::manage(). + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the text + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ Labelled(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Widget *widget, Glib::ustring const &suffix = "", diff --git a/src/ui/widget/layer-selector.cpp b/src/ui/widget/layer-selector.cpp index 7111e17be..de482fb74 100644 --- a/src/ui/widget/layer-selector.cpp +++ b/src/ui/widget/layer-selector.cpp @@ -95,7 +95,7 @@ LayerSelector::LayerSelector(SPDesktop *desktop) AlternateIcons *label; label = Gtk::manage(new AlternateIcons(Inkscape::ICON_SIZE_DECORATION, - INKSCAPE_ICON_OBJECT_VISIBLE, INKSCAPE_ICON_OBJECT_HIDDEN)); + INKSCAPE_ICON("object-visible"), INKSCAPE_ICON("object-hidden"))); _visibility_toggle.add(*label); _visibility_toggle.signal_toggled().connect( sigc::compose( @@ -116,7 +116,7 @@ LayerSelector::LayerSelector(SPDesktop *desktop) pack_start(_visibility_toggle, Gtk::PACK_EXPAND_PADDING); label = Gtk::manage(new AlternateIcons(Inkscape::ICON_SIZE_DECORATION, - INKSCAPE_ICON_OBJECT_UNLOCKED, INKSCAPE_ICON_OBJECT_LOCKED)); + INKSCAPE_ICON("object-unlocked"), INKSCAPE_ICON("object-locked"))); _lock_toggle.add(*label); _lock_toggle.signal_toggled().connect( sigc::compose( @@ -236,6 +236,8 @@ void LayerSelector::_selectLayer(SPObject *layer) { using Inkscape::Util::reverse_list; _selection_changed_connection.block(); + _visibility_toggled_connection.block(); + _lock_toggled_connection.block(); while (!_layer_model->children().empty()) { Gtk::ListStore::iterator first_row(_layer_model->children().begin()); @@ -285,6 +287,8 @@ void LayerSelector::_selectLayer(SPObject *layer) { _lock_toggle.set_active(( SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false )); } + _lock_toggled_connection.unblock(); + _visibility_toggled_connection.unblock(); _selection_changed_connection.unblock(); } diff --git a/src/ui/widget/licensor.cpp b/src/ui/widget/licensor.cpp index c9550bb27..7caf732a4 100644 --- a/src/ui/widget/licensor.cpp +++ b/src/ui/widget/licensor.cpp @@ -1,5 +1,4 @@ -/** \file - * +/* * Authors: * bulia byak <buliabyak@users.sf.net> * Bryce W. Harrington <bryce@bryceharrington.org> @@ -58,8 +57,7 @@ LicenseItem::LicenseItem (struct rdf_license_t const* license, EntityEntry* enti } /// \pre it is assumed that the license URI entry is a Gtk::Entry -void -LicenseItem::on_toggled() +void LicenseItem::on_toggled() { if (_wr.isUpdating()) return; @@ -84,8 +82,7 @@ Licensor::~Licensor() if (_eentry) delete _eentry; } -void -Licensor::init (Gtk::Tooltips& tt, Registry& wr) +void Licensor::init (Gtk::Tooltips& tt, Registry& wr) { /* add license-specific metadata entry areas */ rdf_work_entity_t* entity = rdf_find_entity ( "license_uri" ); @@ -119,8 +116,7 @@ Licensor::init (Gtk::Tooltips& tt, Registry& wr) show_all_children(); } -void -Licensor::update (SPDocument *doc) +void Licensor::update (SPDocument *doc) { /* identify the license info */ struct rdf_license_t * license = rdf_get_license (doc); diff --git a/src/ui/widget/licensor.h b/src/ui/widget/licensor.h index 9f41a6d0d..3c503b5ba 100644 --- a/src/ui/widget/licensor.h +++ b/src/ui/widget/licensor.h @@ -1,7 +1,4 @@ -/** \file - * \brief Widget for specifying a document's license; part of document - * preferences dialog. - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -10,8 +7,8 @@ * Released under GNU GPL. Read the file 'COPYING' for more information. */ -#ifndef INKSCAPE_UI_WIDGET_LICENSOR__H -#define INKSCAPE_UI_WIDGET_LICENSOR__H +#ifndef INKSCAPE_UI_WIDGET_LICENSOR_H +#define INKSCAPE_UI_WIDGET_LICENSOR_H #include <gtkmm/box.h> @@ -29,6 +26,10 @@ class EntityEntry; class Registry; +/** + * Widget for specifying a document's license; part of document + * preferences dialog. + */ class Licensor : public Gtk::VBox { public: Licensor(); @@ -45,7 +46,7 @@ protected: } // namespace UI } // namespace Inkscape -#endif // INKSCAPE_UI_WIDGET_LICENSOR__H +#endif // INKSCAPE_UI_WIDGET_LICENSOR_H /* Local Variables: diff --git a/src/ui/widget/notebook-page.cpp b/src/ui/widget/notebook-page.cpp index 47035ce2f..92bcb6937 100644 --- a/src/ui/widget/notebook-page.cpp +++ b/src/ui/widget/notebook-page.cpp @@ -1,5 +1,5 @@ -/** - * \brief Notebook page widget +/* + * Notebook page widget. * * Author: * Bryce Harrington <bryce@bryceharrington.org> @@ -19,12 +19,6 @@ namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a NotebookPage - * - * \param label Label. - */ - NotebookPage::NotebookPage(int n_rows, int n_columns, bool expand, bool fill, guint padding) :_table(n_rows, n_columns) { diff --git a/src/ui/widget/notebook-page.h b/src/ui/widget/notebook-page.h index 38c13005e..a541f3ba0 100644 --- a/src/ui/widget/notebook-page.h +++ b/src/ui/widget/notebook-page.h @@ -1,6 +1,4 @@ -/** - * \brief Notebook Page Widget - A tabbed notebook page for dialogs. - * +/* * Author: * Bryce Harrington <bryce@bryceharrington.org> * @@ -20,10 +18,18 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A tabbed notebook page for dialogs. + */ class NotebookPage : public Gtk::VBox { public: + NotebookPage(); + + /** + * Construct a NotebookPage. + */ NotebookPage(int n_rows, int n_columns, bool expand=false, bool fill=false, guint padding=0); Gtk::Table& table() { return _table; } diff --git a/src/ui/widget/object-composite-settings.h b/src/ui/widget/object-composite-settings.h index 76538d6a7..8ef31a889 100644 --- a/src/ui/widget/object-composite-settings.h +++ b/src/ui/widget/object-composite-settings.h @@ -17,7 +17,7 @@ #include <gtkmm/alignment.h> #include <gtkmm/adjustment.h> #include <gtkmm/label.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" #include <gtkmm/scale.h> #include <glibmm/ustring.h> @@ -47,7 +47,7 @@ private: Gtk::Label _opacity_label; Gtk::Adjustment _opacity_adjustment; Gtk::HScale _opacity_hscale; - Gtk::SpinButton _opacity_spin_button; + Inkscape::UI::Widget::SpinButton _opacity_spin_button; StyleSubject *_subject; diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index f306b9eea..0b18f1039 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -1,7 +1,9 @@ -/** \file +/** + * @file * * Paper-size widget and helper functions - * + */ +/* * Authors: * bulia byak <buliabyak@users.sf.net> * Lauris Kaplinski <lauris@kaplinski.com> @@ -24,6 +26,7 @@ #include <string> #include <string.h> #include <vector> +#include <2geom/transforms.h> #include "desktop-handles.h" #include "document.h" @@ -235,9 +238,17 @@ PageSizer::PageSizer(Registry & _wr) _marginLeft( _("L_eft:"), _("Left margin"), "fit-margin-left", _wr), _marginRight( _("Ri_ght:"), _("Right margin"), "fit-margin-right", _wr), _marginBottom( _("Botto_m:"), _("Bottom margin"), "fit-margin-bottom", _wr), - + _lockMarginUpdate(false), _widgetRegistry(&_wr) { + // set precision of scalar entry boxes + _dimensionWidth.setDigits(5); + _dimensionHeight.setDigits(5); + _marginTop.setDigits(5); + _marginLeft.setDigits(5); + _marginRight.setDigits(5); + _marginBottom.setDigits(5); + //# Set up the Paper Size combo box _paperSizeListStore = Gtk::ListStore::create(_paperSizeListColumns); _paperSizeList.set_model(_paperSizeListStore); @@ -422,7 +433,7 @@ PageSizer::setDim (double w, double h, bool changeList) // 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))); - SP_GROUP(SP_ROOT(doc->root))->translateChildItems(vert_offset); + doc->getRoot()->translateChildItems(vert_offset); DocumentUndo::done(doc, SP_VERB_NONE, _("Set page size")); } @@ -464,18 +475,20 @@ PageSizer::setDim (double w, double h, bool changeList) void PageSizer::updateFitMarginsUI(Inkscape::XML::Node *nv_repr) { - double value = 0.0; - if (sp_repr_get_double(nv_repr, "fit-margin-top", &value)) { - _marginTop.setValue(value); - } - if (sp_repr_get_double(nv_repr, "fit-margin-left", &value)) { - _marginLeft.setValue(value); - } - if (sp_repr_get_double(nv_repr, "fit-margin-right", &value)) { - _marginRight.setValue(value); - } - if (sp_repr_get_double(nv_repr, "fit-margin-bottom", &value)) { - _marginBottom.setValue(value); + if (!_lockMarginUpdate) { + double value = 0.0; + if (sp_repr_get_double(nv_repr, "fit-margin-top", &value)) { + _marginTop.setValue(value); + } + if (sp_repr_get_double(nv_repr, "fit-margin-left", &value)) { + _marginLeft.setValue(value); + } + if (sp_repr_get_double(nv_repr, "fit-margin-right", &value)) { + _marginRight.setValue(value); + } + if (sp_repr_get_double(nv_repr, "fit-margin-bottom", &value)) { + _marginBottom.setValue(value); + } } } @@ -498,7 +511,7 @@ PageSizer::find_paper_size (double w, double h) const std::map<Glib::ustring, PaperSize>::const_iterator iter; for (iter = _paperSizeTable.begin() ; - iter != _paperSizeTable.end() ; iter++) { + iter != _paperSizeTable.end() ; ++iter) { PaperSize paper = iter->second; SPUnit const &i_unit = sp_unit_get_by_id(paper.unit); double smallX = sp_units_get_pixels(paper.smaller, i_unit); @@ -512,7 +525,7 @@ PageSizer::find_paper_size (double w, double h) const // We need to search paperSizeListStore explicitly for the // specified paper size because it is sorted in a different // way than paperSizeTable (which is sorted alphabetically) - for (p = _paperSizeListStore->children().begin(); p != _paperSizeListStore->children().end(); p++) { + for (p = _paperSizeListStore->children().begin(); p != _paperSizeListStore->children().end(); ++p) { if ((*p)[_paperSizeListColumns.nameColumn] == paper.name) { return p; } @@ -537,14 +550,18 @@ PageSizer::fire_fit_canvas_to_selection_or_drawing() SPDocument *doc; SPNamedView *nv; Inkscape::XML::Node *nv_repr; + if ((doc = sp_desktop_document(SP_ACTIVE_DESKTOP)) && (nv = sp_document_namedview(doc, 0)) && (nv_repr = nv->getRepr())) { + _lockMarginUpdate = true; sp_repr_set_svg_double(nv_repr, "fit-margin-top", _marginTop.getValue()); sp_repr_set_svg_double(nv_repr, "fit-margin-left", _marginLeft.getValue()); sp_repr_set_svg_double(nv_repr, "fit-margin-right", _marginRight.getValue()); sp_repr_set_svg_double(nv_repr, "fit-margin-bottom", _marginBottom.getValue()); + _lockMarginUpdate = false; } + Verb *verb = Verb::get( SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING ); if (verb) { SPAction *action = verb->get_action(dt); diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index 2072aeccd..7f165266c 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -1,6 +1,4 @@ -/** \file - * \brief Widget for specifying page size; part of Document Preferences dialog. - * +/* * Author: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -9,8 +7,8 @@ * Released under GNU GPL. Read the file 'COPYING' for more information. */ -#ifndef INKSCAPE_UI_WIDGET_PAGE_SIZER__H -#define INKSCAPE_UI_WIDGET_PAGE_SIZER__H +#ifndef INKSCAPE_UI_WIDGET_PAGE_SIZER_H +#define INKSCAPE_UI_WIDGET_PAGE_SIZER_H #include <gtkmm.h> #include <stddef.h> @@ -219,6 +217,7 @@ protected: RegisteredScalar _marginBottom; Gtk::Alignment _fitPageButtonAlign; Gtk::Button _fitPageButton; + bool _lockMarginUpdate; //callback void on_value_changed(); @@ -237,7 +236,7 @@ protected: } // namespace Inkscape -#endif /* INKSCAPE_UI_WIDGET_PAGE_SIZER__H */ +#endif // INKSCAPE_UI_WIDGET_PAGE_SIZER_H /* Local Variables: diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index b3c8ce376..8c8603640 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -1,6 +1,4 @@ -/** - * \brief Panel widget - * +/* * Authors: * Bryce Harrington <bryce@bryceharrington.org> * Jon A. Cruz <jon@joncruz.org> @@ -22,7 +20,7 @@ #include <gtkmm/dialog.h> // for Gtk::RESPONSE_* #include <gtkmm/stock.h> -#include <gtk/gtkiconfactory.h> +#include <gtk/gtk.h> #include "panel.h" #include "icon-size.h" @@ -54,10 +52,6 @@ void Panel::prep() { eek_preview_set_size_mappings( G_N_ELEMENTS(sizes), sizes ); } -/** - * Construct a Panel - */ - Panel::Panel(Glib::ustring const &label, gchar const *prefs_path, int verb_num, Glib::ustring const &apply_label, bool menu_desired) : diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h index fe3e226b4..d51d942dd 100644 --- a/src/ui/widget/panel.h +++ b/src/ui/widget/panel.h @@ -1,6 +1,4 @@ -/** - * \brief Generic Panel widget - A generic dockable container. - * +/* * Authors: * Bryce Harrington <bryce@bryceharrington.org> * Jon A. Cruz <jon@joncruz.org> @@ -35,16 +33,23 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A generic dockable container. + */ class Panel : public Gtk::VBox { public: static void prep(); - virtual ~Panel(); + /** + * Construct a Panel. + */ Panel(Glib::ustring const &label = "", gchar const *prefs_path = 0, int verb_num = 0, Glib::ustring const &apply_label = "", bool menu_desired = false); + virtual ~Panel(); + gchar const *getPrefsPath() const; void setLabel(Glib::ustring const &label); Glib::ustring const &getLabel() const; diff --git a/src/ui/widget/point.cpp b/src/ui/widget/point.cpp index ca7f7a501..385b60122 100644 --- a/src/ui/widget/point.cpp +++ b/src/ui/widget/point.cpp @@ -1,7 +1,4 @@ -/** - * \brief Point Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary coordinate values. - * +/* * Authors: * Johan Engelen <j.b.c.engelen@utwente.nl> * Carl Hetherington <inkscape@carlh.net> @@ -28,16 +25,6 @@ namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a Point Widget. - * - * \param label Label. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, @@ -51,17 +38,6 @@ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, static_cast<Gtk::VBox*>(_widget)->show_all_children(); } -/** - * Construct a Point Widget. - * - * \param label Label. - * \param digits Number of decimal digits to display. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &suffix, @@ -76,18 +52,6 @@ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, static_cast<Gtk::VBox*>(_widget)->show_all_children(); } -/** - * Construct a Point Widget. - * - * \param label Label. - * \param adjust Adjustment to use for the SpinButton. - * \param digits Number of decimal digits to display (defaults to 0). - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to true). - */ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Adjustment &adjust, unsigned digits, @@ -103,131 +67,105 @@ Point::Point(Glib::ustring const &label, Glib::ustring const &tooltip, static_cast<Gtk::VBox*>(_widget)->show_all_children(); } -/** Fetches the precision of the spin buton */ -unsigned -Point::getDigits() const +unsigned Point::getDigits() const { return xwidget.getDigits(); } -/** Gets the current step ingrement used by the spin button */ -double -Point::getStep() const +double Point::getStep() const { return xwidget.getStep(); } -/** Gets the current page increment used by the spin button */ -double -Point::getPage() const +double Point::getPage() const { return xwidget.getPage(); } -/** Gets the minimum range value allowed for the spin button */ -double -Point::getRangeMin() const +double Point::getRangeMin() const { return xwidget.getRangeMin(); } -/** Gets the maximum range value allowed for the spin button */ -double -Point::getRangeMax() const +double Point::getRangeMax() const { return xwidget.getRangeMax(); } -/** Get the value in the spin_button . */ -double -Point::getXValue() const +double Point::getXValue() const { return xwidget.getValue(); } -double -Point::getYValue() const + +double Point::getYValue() const { return ywidget.getValue(); } -Geom::Point -Point::getValue() const + +Geom::Point Point::getValue() const { return Geom::Point( getXValue() , getYValue() ); } -/** Get the value spin_button represented as an integer. */ -int -Point::getXValueAsInt() const +int Point::getXValueAsInt() const { return xwidget.getValueAsInt(); } -int -Point::getYValueAsInt() const + +int Point::getYValueAsInt() const { return ywidget.getValueAsInt(); } -/** Sets the precision to be displayed by the spin button */ -void -Point::setDigits(unsigned digits) +void Point::setDigits(unsigned digits) { xwidget.setDigits(digits); ywidget.setDigits(digits); } -/** Sets the step and page increments for the spin button */ -void -Point::setIncrements(double step, double page) +void Point::setIncrements(double step, double page) { xwidget.setIncrements(step, page); ywidget.setIncrements(step, page); } -/** Sets the minimum and maximum range allowed for the spin button */ -void -Point::setRange(double min, double max) +void Point::setRange(double min, double max) { xwidget.setRange(min, max); ywidget.setRange(min, max); } -/** Sets the value of the spin button */ -void -Point::setValue(Geom::Point const & p) +void Point::setValue(Geom::Point const & p) { xwidget.setValue(p[0]); ywidget.setValue(p[1]); } -/** Manually forces an update of the spin button */ -void -Point::update() { +void Point::update() +{ xwidget.update(); ywidget.update(); } -/** Check 'setProgrammatically' of both scalar widgets. False if value is changed by user by clicking the widget. */ -bool -Point::setProgrammatically() { +bool Point::setProgrammatically() +{ return (xwidget.setProgrammatically || ywidget.setProgrammatically); } -void -Point::clearProgrammatically() { +void Point::clearProgrammatically() +{ xwidget.setProgrammatically = false; ywidget.setProgrammatically = false; } -/** Signal raised when the spin button's value changes */ -Glib::SignalProxy0<void> -Point::signal_x_value_changed() +Glib::SignalProxy0<void> Point::signal_x_value_changed() { return xwidget.signal_value_changed(); } -Glib::SignalProxy0<void> -Point::signal_y_value_changed() + +Glib::SignalProxy0<void> Point::signal_y_value_changed() { return ywidget.signal_value_changed(); } diff --git a/src/ui/widget/point.h b/src/ui/widget/point.h index 68d2f4c9d..ced43c47a 100644 --- a/src/ui/widget/point.h +++ b/src/ui/widget/point.h @@ -1,7 +1,4 @@ -/** - * \brief Point Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary coordinate values. - * +/* * Authors: * Johan Engelen <j.b.c.engelen@utwente.nl> * Carl Hetherington <inkscape@carlh.net> @@ -13,7 +10,6 @@ * * Released under GNU GPL. Read the file 'COPYING' for more information. */ - #ifndef INKSCAPE_UI_WIDGET_POINT_H #define INKSCAPE_UI_WIDGET_POINT_H @@ -27,20 +23,61 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A labelled text box, with spin buttons and optional icon or suffix, for + * entering arbitrary coordinate values. + */ class Point : public Labelled { public: + + + /** + * Construct a Point Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Point( Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + + /** + * Construct a Point Widget. + * + * @param label Label. + * @param digits Number of decimal digits to display. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Point( Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + + /** + * Construct a Point Widget. + * + * @param label Label. + * @param adjust Adjustment to use for the SpinButton. + * @param digits Number of decimal digits to display (defaults to 0). + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ Point( Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Adjustment &adjust, @@ -49,35 +86,93 @@ public: Glib::ustring const &icon = "", bool mnemonic = true); + /** + * Fetches the precision of the spin buton. + */ unsigned getDigits() const; + + /** + * Gets the current step ingrement used by the spin button. + */ double getStep() const; + + /** + * Gets the current page increment used by the spin button. + */ double getPage() const; + + /** + * Gets the minimum range value allowed for the spin button. + */ double getRangeMin() const; + + /** + * Gets the maximum range value allowed for the spin button. + */ double getRangeMax() const; + bool getSnapToTicks() const; + + /** + * Get the value in the spin_button. + */ double getXValue() const; + double getYValue() const; + Geom::Point getValue() const; + + /** + * Get the value spin_button represented as an integer. + */ int getXValueAsInt() const; + int getYValueAsInt() const; + /** + * Sets the precision to be displayed by the spin button. + */ void setDigits(unsigned digits); + + /** + * Sets the step and page increments for the spin button. + */ void setIncrements(double step, double page); + + /** + * Sets the minimum and maximum range allowed for the spin button. + */ void setRange(double min, double max); + + /** + * Sets the value of the spin button. + */ void setValue(Geom::Point const & p); + /** + * Manually forces an update of the spin button. + */ void update(); + /** + * Signal raised when the spin button's value changes. + */ Glib::SignalProxy0<void> signal_x_value_changed(); + Glib::SignalProxy0<void> signal_y_value_changed(); - bool setProgrammatically(); // true if the value was set by setValue, not changed by the user; - // if a callback checks it, it must reset it back to false + /** + * Check 'setProgrammatically' of both scalar widgets. False if value is changed by user by clicking the widget. + * true if the value was set by setValue, not changed by the user; + * if a callback checks it, it must reset it back to false. + */ + bool setProgrammatically(); + void clearProgrammatically(); protected: - Scalar xwidget, ywidget; - + Scalar xwidget; + Scalar ywidget; }; } // namespace Widget diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index afcaa338e..001d2277d 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -1,5 +1,5 @@ -/** - * \brief Inkscape Preferences dialog +/* + * Inkscape Preferences dialog. * * Authors: * Marco Scholten @@ -227,7 +227,6 @@ void PrefSpinButton::init(Glib::ustring const &prefs_path, this->set_range (lower, upper); this->set_increments (step_increment, 0); - this->set_numeric(); this->set_value (value); this->set_width_chars(6); if (is_int) @@ -256,6 +255,45 @@ void PrefSpinButton::on_value_changed() } } +void PrefSpinUnit::init(Glib::ustring const &prefs_path, + double lower, double upper, double step_increment, + double default_value, UnitType unit_type, Glib::ustring const &default_unit) +{ + _prefs_path = prefs_path; + _is_percent = (unit_type == UNIT_TYPE_DIMENSIONLESS); + + resetUnitType(unit_type); + setUnit(default_unit); + setRange (lower, upper); /// @fixme this disregards changes of units + setIncrements (step_increment, 0); + if (step_increment < 0.1) { + setDigits(4); + } else { + setDigits(2); + } + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper); + Glib::ustring unitstr = prefs->getUnit(prefs_path); + if (unitstr.length() == 0) { + unitstr = default_unit; + // write the assumed unit to preferences: + prefs->setDoubleUnit(_prefs_path, value, unitstr); + } + setValue(value, unitstr); + + signal_value_changed().connect_notify(sigc::mem_fun(*this, &PrefSpinUnit::on_my_value_changed)); +} + +void PrefSpinUnit::on_my_value_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (getWidget()->is_visible()) //only take action if user changed value + { + prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr); + } +} + const double ZoomCorrRuler::textsize = 7; const double ZoomCorrRuler::textpadding = 5; @@ -545,10 +583,6 @@ void PrefCombo::init(Glib::ustring const &prefs_path, this->set_active(row); } -/** - initialize a combo box - second form uses strings as key values -*/ void PrefCombo::init(Glib::ustring const &prefs_path, Glib::ustring labels[], Glib::ustring values[], int num_items, Glib::ustring default_value) { diff --git a/src/ui/widget/preferences-widget.h b/src/ui/widget/preferences-widget.h index 6c7f9ce4a..ea5c377a3 100644 --- a/src/ui/widget/preferences-widget.h +++ b/src/ui/widget/preferences-widget.h @@ -1,6 +1,8 @@ /** - * \brief Inkscape Preferences dialog - * + * @file + * Widgets for Inkscape Preferences dialog. + */ +/* * Authors: * Marco Scholten * Bruno Dilly <bruno.dilly@gmail.com> @@ -17,7 +19,7 @@ #include <vector> #include <gtkmm/table.h> #include <gtkmm/comboboxtext.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" #include <gtkmm/tooltips.h> #include <gtkmm/treeview.h> #include <gtkmm/radiobutton.h> @@ -32,6 +34,8 @@ #include "ui/widget/color-picker.h" #include "ui/widget/unit-menu.h" +#include "ui/widget/spinbutton.h" +#include "ui/widget/scalar-unit.h" namespace Inkscape { namespace UI { @@ -68,7 +72,7 @@ protected: void on_toggled(); }; -class PrefSpinButton : public Gtk::SpinButton +class PrefSpinButton : public SpinButton { public: void init(Glib::ustring const &prefs_path, @@ -81,6 +85,21 @@ protected: void on_value_changed(); }; +class PrefSpinUnit : public ScalarUnit +{ +public: + PrefSpinUnit() : ScalarUnit("", "") {}; + + void init(Glib::ustring const &prefs_path, + double lower, double upper, double step_increment, + double default_value, + UnitType unit_type, Glib::ustring const &default_unit); +protected: + Glib::ustring _prefs_path; + bool _is_percent; + void on_my_value_changed(); +}; + class ZoomCorrRuler : public Gtk::DrawingArea { public: ZoomCorrRuler(int width = 100, int height = 20); @@ -116,7 +135,7 @@ private: void on_spinbutton_value_changed(); void on_unit_changed(); - Gtk::SpinButton _sb; + Inkscape::UI::Widget::SpinButton _sb; UnitMenu _unit; Gtk::HScale _slider; ZoomCorrRuler _ruler; @@ -134,7 +153,7 @@ private: void on_spinbutton_value_changed(); Glib::ustring _prefs_path; - Gtk::SpinButton _sb; + Inkscape::UI::Widget::SpinButton _sb; Gtk::HScale _slider; bool freeze; // used to block recursive updates of slider and spinbutton }; @@ -145,6 +164,11 @@ class PrefCombo : public Gtk::ComboBoxText public: void init(Glib::ustring const &prefs_path, Glib::ustring labels[], int values[], int num_items, int default_value); + + /** + * Initialize a combo box. + * second form uses strings as key values. + */ void init(Glib::ustring const &prefs_path, Glib::ustring labels[], Glib::ustring values[], int num_items, Glib::ustring default_value); protected: diff --git a/src/ui/widget/random.cpp b/src/ui/widget/random.cpp index 02201be12..03cea7d5a 100644 --- a/src/ui/widget/random.cpp +++ b/src/ui/widget/random.cpp @@ -1,10 +1,4 @@ -/** - * \brief Scalar Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary number values. It adds an extra - * number called "startseed", that is not UI edittable, but should be put in SVG. - * This does NOT generate a random number, but provides merely the saving of - * the startseed value. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Derek P. Moore <derekm@hackunix.org> @@ -25,20 +19,12 @@ #include <glibmm/i18n.h> +#include <gtkmm/button.h> + namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a Random scalar Widget. - * - * \param label Label. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, @@ -49,17 +35,6 @@ Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip, addReseedButton(); } -/** - * Construct a Random Scalar Widget. - * - * \param label Label. - * \param digits Number of decimal digits to display. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &suffix, @@ -71,18 +46,6 @@ Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip, addReseedButton(); } -/** - * Construct a Random Scalar Widget. - * - * \param label Label. - * \param adjust Adjustment to use for the SpinButton. - * \param digits Number of decimal digits to display (defaults to 0). - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to true). - */ Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Adjustment &adjust, unsigned digits, @@ -95,23 +58,17 @@ Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip, addReseedButton(); } -/** Gets the startseed */ -long -Random::getStartSeed() const +long Random::getStartSeed() const { return startseed; } -/** Sets the startseed number */ -void -Random::setStartSeed(long newseed) +void Random::setStartSeed(long newseed) { startseed = newseed; } -/** Add reseed button to the widget */ -void -Random::addReseedButton() +void Random::addReseedButton() { Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "randomize", Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); diff --git a/src/ui/widget/random.h b/src/ui/widget/random.h index 71cc8d1e5..cb8c223dc 100644 --- a/src/ui/widget/random.h +++ b/src/ui/widget/random.h @@ -1,7 +1,4 @@ -/** - * \brief Random Scalar Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary number values and generating a random number from it. - * +/* * Authors: * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> * @@ -19,20 +16,63 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A labelled text box, with spin buttons and optional + * icon or suffix, for entering arbitrary number values. It adds an extra + * number called "startseed", that is not UI edittable, but should be put in SVG. + * This does NOT generate a random number, but provides merely the saving of + * the startseed value. + */ class Random : public Scalar { public: + + /** + * Construct a Random scalar Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Random(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + + /** + * Construct a Random Scalar Widget. + * + * @param label Label. + * @param digits Number of decimal digits to display. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Random(Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + + /** + * Construct a Random Scalar Widget. + * + * @param label Label. + * @param adjust Adjustment to use for the SpinButton. + * @param digits Number of decimal digits to display (defaults to 0). + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ Random(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Adjustment &adjust, @@ -41,7 +81,14 @@ public: Glib::ustring const &icon = "", bool mnemonic = true); + /** + * Gets the startseed. + */ long getStartSeed() const; + + /** + * Sets the startseed number. + */ void setStartSeed(long newseed); sigc::signal <void> signal_reseeded; @@ -50,7 +97,12 @@ protected: long startseed; private: + + /** + * Add reseed button to the widget. + */ void addReseedButton(); + void onReseedButtonClick(); }; diff --git a/src/ui/widget/registered-enums.h b/src/ui/widget/registered-enums.h index 056a09fed..9e1682c7d 100644 --- a/src/ui/widget/registered-enums.h +++ b/src/ui/widget/registered-enums.h @@ -1,6 +1,4 @@ -/** - * \brief Simplified management of enumerations in the UI as combobox. - * +/* * Authors: * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> * @@ -19,6 +17,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Simplified management of enumerations in the UI as combobox. + */ template<typename E> class RegisteredEnum : public RegisteredWidget< LabelledComboBoxEnum<E> > { public: diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index c2580013a..f923a7c9c 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -1,6 +1,4 @@ -/** \file - * - * +/* * Authors: * Johan Engelen <j.b.c.engelen@utwente.nl> * bulia byak <buliabyak@users.sf.net> @@ -72,7 +70,7 @@ RegisteredCheckButton::setActive (bool b) setProgrammatically = true; set_active (b); //The slave button is greyed out if the master button is unchecked - for (std::list<Gtk::Widget*>::const_iterator i = _slavewidgets.begin(); i != _slavewidgets.end(); i++) { + for (std::list<Gtk::Widget*>::const_iterator i = _slavewidgets.begin(); i != _slavewidgets.end(); ++i) { (*i)->set_sensitive(b); } setProgrammatically = false; @@ -92,7 +90,7 @@ RegisteredCheckButton::on_toggled() write_to_xml(get_active() ? "true" : "false"); //The slave button is greyed out if the master button is unchecked - for (std::list<Gtk::Widget*>::const_iterator i = _slavewidgets.begin(); i != _slavewidgets.end(); i++) { + for (std::list<Gtk::Widget*>::const_iterator i = _slavewidgets.begin(); i != _slavewidgets.end(); ++i) { (*i)->set_sensitive(get_active()); } @@ -632,13 +630,7 @@ RegisteredVector::setValue(Geom::Point const & p, Geom::Point const & origin) _origin = origin; } -/** - * Changes the widgets text to polar coordinates. The SVG output will still be a normal carthesian vector. - * Careful: when calling getValue(), the return value's X-coord will be the angle, Y-value will be the distance/length. - * After changing the coords type (polar/non-polar), the value has to be reset (setValue). - */ -void -RegisteredVector::setPolarCoords(bool polar_coords) +void RegisteredVector::setPolarCoords(bool polar_coords) { _polar_coords = polar_coords; if (polar_coords) { diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 560c63dd4..df2377464 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -1,6 +1,4 @@ -/** \file - * \brief - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * Johan Engelen <j.b.c.engelen@utwente.nl> @@ -62,9 +60,6 @@ public: bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;} - // provide automatic 'upcast' for ease of use. (do it 'dynamic_cast' instead of 'static' because who knows what W is) - operator const Gtk::Widget () { return dynamic_cast<Gtk::Widget*>(this); } - protected: RegisteredWidget() : W() { construct(); } template< typename A > @@ -350,6 +345,12 @@ public: // redefine setValue, because transform must be applied void setValue(Geom::Point const & p); void setValue(Geom::Point const & p, Geom::Point const & origin); + + /** + * Changes the widgets text to polar coordinates. The SVG output will still be a normal carthesian vector. + * Careful: when calling getValue(), the return value's X-coord will be the angle, Y-value will be the distance/length. + * After changing the coords type (polar/non-polar), the value has to be reset (setValue). + */ void setPolarCoords(bool polar_coords = true); protected: diff --git a/src/ui/widget/registry.cpp b/src/ui/widget/registry.cpp index aa92e6ecb..725e52791 100644 --- a/src/ui/widget/registry.cpp +++ b/src/ui/widget/registry.cpp @@ -1,6 +1,4 @@ -/** \file - * - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * diff --git a/src/ui/widget/registry.h b/src/ui/widget/registry.h index 4d7ad3068..ed1281d79 100644 --- a/src/ui/widget/registry.h +++ b/src/ui/widget/registry.h @@ -1,6 +1,4 @@ -/** \file - * \brief - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -8,7 +6,6 @@ * * Released under GNU GPL. Read the file 'COPYING' for more information. */ - #ifndef INKSCAPE_UI_WIDGET_REGISTRY__H #define INKSCAPE_UI_WIDGET_REGISTRY__H diff --git a/src/ui/widget/rendering-options.cpp b/src/ui/widget/rendering-options.cpp index 48e257af7..bbc0a0039 100644 --- a/src/ui/widget/rendering-options.cpp +++ b/src/ui/widget/rendering-options.cpp @@ -1,6 +1,4 @@ -/** - * \brief Rendering options widget - * +/* * Author: * Kees Cook <kees@outflux.net> * @@ -23,17 +21,11 @@ namespace Inkscape { namespace UI { namespace Widget { -void -RenderingOptions::_toggled() +void RenderingOptions::_toggled() { _frame_bitmap.set_sensitive(as_bitmap()); } -/** - * Construct a Rendering Options widget - * - */ - RenderingOptions::RenderingOptions () : Gtk::VBox (), _frame_backends ( Glib::ustring(_("Backend")) ), diff --git a/src/ui/widget/rendering-options.h b/src/ui/widget/rendering-options.h index 8e047e682..241683fe6 100644 --- a/src/ui/widget/rendering-options.h +++ b/src/ui/widget/rendering-options.h @@ -1,6 +1,4 @@ -/** - * \brief Rendering Options Widget - A container for selecting rendering options - * +/* * Author: * Kees Cook <kees@outflux.net> * @@ -20,9 +18,16 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A container for selecting rendering options. + */ class RenderingOptions : public Gtk::VBox { public: + + /** + * Construct a Rendering Options widget. + */ RenderingOptions(); bool as_bitmap(); // should we render as a bitmap? diff --git a/src/ui/widget/rotateable.cpp b/src/ui/widget/rotateable.cpp index 396280aee..c31e6f529 100644 --- a/src/ui/widget/rotateable.cpp +++ b/src/ui/widget/rotateable.cpp @@ -1,6 +1,4 @@ -/** - * \brief widget adjustable by dragging it to rotate away from a zero-change axis - * +/* * Authors: * buliabyak@gmail.com * @@ -9,13 +7,12 @@ * Released under GNU GPL. Read the file 'COPYING' for more information. */ -#include "event-context.h" -#include "rotateable.h" -#include "libnr/nr-point.h" -#include "libnr/nr-point-fns.h" #include <gtkmm/box.h> #include <gtkmm/eventbox.h> #include <glibmm/i18n.h> +#include <2geom/point.h> +#include "event-context.h" +#include "rotateable.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/rotateable.h b/src/ui/widget/rotateable.h index 79a6daa5b..15e0bf71c 100644 --- a/src/ui/widget/rotateable.h +++ b/src/ui/widget/rotateable.h @@ -1,6 +1,4 @@ -/** - * \brief widget adjustable by dragging it to rotate away from a zero-change axis - * +/* * Authors: * buliabyak@gmail.com * @@ -20,6 +18,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * Widget adjustable by dragging it to rotate away from a zero-change axis. + */ class Rotateable: public Gtk::EventBox { public: diff --git a/src/ui/widget/ruler.cpp b/src/ui/widget/ruler.cpp index a220a54ad..c6ac3a381 100644 --- a/src/ui/widget/ruler.cpp +++ b/src/ui/widget/ruler.cpp @@ -108,7 +108,7 @@ Ruler::on_button_press_event(GdkEventButton *evb) _dragging = true; sp_repr_set_boolean(repr, "showguides", TRUE); sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE); - _guide = sp_guideline_new(_dt->guides, event_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); + _guide = sp_guideline_new(_dt->guides, NULL, event_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); sp_guideline_set_color(SP_GUIDELINE(_guide), _dt->namedview->guidehicolor); (void) get_window()->pointer_grab(false, Gdk::BUTTON_RELEASE_MASK | diff --git a/src/ui/widget/ruler.h b/src/ui/widget/ruler.h index c315418d8..1a455a325 100644 --- a/src/ui/widget/ruler.h +++ b/src/ui/widget/ruler.h @@ -1,9 +1,7 @@ -#ifndef __UI_WIDGET_RULER_H__ -#define __UI_WIDGET_RULER_H__ +#ifndef SEEN_UI_WIDGET_RULER_H +#define SEEN_UI_WIDGET_RULER_H -/** \file - * Gtkmm facade/wrapper around sp_rulers. - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -13,10 +11,10 @@ */ #include <gtkmm/eventbox.h> -#include "libnr/nr-point.h" +#include <2geom/point.h> struct SPCanvasItem; -struct SPDesktop; +class SPDesktop; namespace Glib { class ustring; } @@ -24,9 +22,12 @@ namespace Gtk { class Ruler; } namespace Inkscape { - namespace UI { - namespace Widget { +namespace UI { +namespace Widget { +/** + * Gtkmm facade/wrapper around sp_rulers. + */ class Ruler : public Gtk::EventBox { public: @@ -52,7 +53,9 @@ private: Geom::Point get_event_dt(); }; -/// Horizontal ruler +/** + * Horizontal ruler gtkmm wrapper. + */ class HRuler : public Ruler { public: @@ -60,7 +63,9 @@ public: ~HRuler(); }; -/// Vertical ruler +/** + * Vertical ruler gtkmm wrapper. + */ class VRuler : public Ruler { public: @@ -73,7 +78,7 @@ public: } // namespace Inkscape -#endif +#endif // SEEN_UI_WIDGET_RULER_H /* diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index 6209d40e0..99ff70846 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -1,17 +1,4 @@ -/** - * \brief Scalar Unit Widget - A labelled text box, with spin buttons and - * optional icon or suffix, for entering the values of various unit - * types. - * - * A ScalarUnit is a control for entering, viewing, or manipulating - * numbers with units. This differs from ordinary numbers like 2 or - * 3.14 because the number portion of a scalar *only* has meaning - * when considered with its unit type. For instance, 12 m and 12 in - * have very different actual values, but 1 m and 100 cm have the same - * value. The ScalarUnit allows us to abstract the presentation of - * the scalar to the user from the internal representations used by - * the program. - * +/* * Authors: * Bryce Harrington <bryce@bryceharrington.org> * Derek P. Moore <derekm@hackunix.org> @@ -27,24 +14,12 @@ #endif #include "scalar-unit.h" +#include "spinbutton.h" namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a ScalarUnit - * - * \param label Label. - * \param unit_type Unit type (defaults to UNIT_TYPE_LINEAR). - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param unit_menu UnitMenu drop down; if not specified, one will be created - * and displayed after the widget (defaults to NULL). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to true). - */ ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, UnitType unit_type, Glib::ustring const &suffix, @@ -65,14 +40,33 @@ ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, } _unit_menu->signal_changed() .connect_notify(sigc::mem_fun(*this, &ScalarUnit::on_unit_changed)); + + static_cast<SpinButton*>(_widget)->setUnitMenu(_unit_menu); + + lastUnits = _unit_menu->getUnitAbbr(); } -/** - * Initializes the scalar based on the settings in _unit_menu. - * Requires that _unit_menu has already been initialized. - */ -void -ScalarUnit::initScalar(double min_value, double max_value) +ScalarUnit::ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, + ScalarUnit &take_unitmenu, + Glib::ustring const &suffix, + Glib::ustring const &icon, + bool mnemonic) + : Scalar(label, tooltip, suffix, icon, mnemonic), + _unit_menu(take_unitmenu._unit_menu), + _hundred_percent(0), + _absolute_is_increment(false), + _percentage_is_increment(false) +{ + _unit_menu->signal_changed() + .connect_notify(sigc::mem_fun(*this, &ScalarUnit::on_unit_changed)); + + static_cast<SpinButton*>(_widget)->setUnitMenu(_unit_menu); + + lastUnits = _unit_menu->getUnitAbbr(); +} + + +void ScalarUnit::initScalar(double min_value, double max_value) { g_assert(_unit_menu != NULL); Scalar::setDigits(_unit_menu->getDefaultDigits()); @@ -81,9 +75,8 @@ ScalarUnit::initScalar(double min_value, double max_value) Scalar::setRange(min_value, max_value); } -/** Sets the unit for the ScalarUnit widget */ -bool -ScalarUnit::setUnit(Glib::ustring const &unit) { +bool ScalarUnit::setUnit(Glib::ustring const &unit) +{ g_assert(_unit_menu != NULL); // First set the unit if (!_unit_menu->setUnit(unit)) { @@ -93,37 +86,58 @@ ScalarUnit::setUnit(Glib::ustring const &unit) { return true; } -/** Gets the object for the currently selected unit */ -Unit -ScalarUnit::getUnit() const { +void ScalarUnit::setUnitType(UnitType unit_type) +{ + g_assert(_unit_menu != NULL); + _unit_menu->setUnitType(unit_type); + lastUnits = _unit_menu->getUnitAbbr(); +} + +void ScalarUnit::resetUnitType(UnitType unit_type) +{ + g_assert(_unit_menu != NULL); + _unit_menu->resetUnitType(unit_type); + lastUnits = _unit_menu->getUnitAbbr(); +} + +Unit ScalarUnit::getUnit() const +{ g_assert(_unit_menu != NULL); return _unit_menu->getUnit(); } -/** Gets the UnitType ID for the unit */ -UnitType -ScalarUnit::getUnitType() const { +UnitType ScalarUnit::getUnitType() const +{ g_assert(_unit_menu); return _unit_menu->getUnitType(); } -/** Sets the number and unit system */ -void -ScalarUnit::setValue(double number, Glib::ustring const &units) { +void ScalarUnit::setValue(double number, Glib::ustring const &units) +{ g_assert(_unit_menu != NULL); _unit_menu->setUnit(units); Scalar::setValue(number); } -/** Sets the number only */ -void -ScalarUnit::setValue(double number) { +void ScalarUnit::setValueKeepUnit(double number, Glib::ustring const &units) +{ + g_assert(_unit_menu != NULL); + if (units == "") { + // set the value in the default units + Scalar::setValue(number); + } else { + double conversion = _unit_menu->getConversion(units); + Scalar::setValue(number / conversion); + } +} + +void ScalarUnit::setValue(double number) +{ Scalar::setValue(number); } -/** Returns the value in the given unit system */ -double -ScalarUnit::getValue(Glib::ustring const &unit_name) const { +double ScalarUnit::getValue(Glib::ustring const &unit_name) const +{ g_assert(_unit_menu != NULL); if (unit_name == "") { // Return the value in the default units @@ -134,27 +148,29 @@ ScalarUnit::getValue(Glib::ustring const &unit_name) const { } } -void -ScalarUnit::setHundredPercent(double number) +void ScalarUnit::grabFocusAndSelectEntry() +{ + _widget->grab_focus(); + static_cast<SpinButton*>(_widget)->select_region(0, 20); +} + + +void ScalarUnit::setHundredPercent(double number) { _hundred_percent = number; } -void -ScalarUnit::setAbsoluteIsIncrement(bool value) +void ScalarUnit::setAbsoluteIsIncrement(bool value) { _absolute_is_increment = value; } -void -ScalarUnit::setPercentageIsIncrement(bool value) +void ScalarUnit::setPercentageIsIncrement(bool value) { _percentage_is_increment = value; } -/** Convert value from % to absolute, using _hundred_percent and *_is_increment flags */ -double -ScalarUnit::PercentageToAbsolute(double value) +double ScalarUnit::PercentageToAbsolute(double value) { // convert from percent to absolute double convertedVal = 0; @@ -168,9 +184,7 @@ ScalarUnit::PercentageToAbsolute(double value) return convertedVal; } -/** Convert value from absolute to %, using _hundred_percent and *_is_increment flags */ -double -ScalarUnit::AbsoluteToPercentage(double value) +double ScalarUnit::AbsoluteToPercentage(double value) { double convertedVal = 0; // convert from absolute to percent @@ -191,27 +205,21 @@ ScalarUnit::AbsoluteToPercentage(double value) return convertedVal; } -/** Assuming the current unit is absolute, get the corresponding % value */ -double -ScalarUnit::getAsPercentage() +double ScalarUnit::getAsPercentage() { double convertedVal = AbsoluteToPercentage(Scalar::getValue()); return convertedVal; } -/** Assuming the current unit is absolute, set the value corresponding to a given % */ -void -ScalarUnit::setFromPercentage(double value) +void ScalarUnit::setFromPercentage(double value) { double absolute = PercentageToAbsolute(value); Scalar::setValue(absolute); } -/** Signal handler for updating the value and suffix label when unit is changed */ -void -ScalarUnit::on_unit_changed() +void ScalarUnit::on_unit_changed() { g_assert(_unit_menu != NULL); diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h index d8b2edbd5..4f22f438c 100644 --- a/src/ui/widget/scalar-unit.h +++ b/src/ui/widget/scalar-unit.h @@ -1,8 +1,4 @@ -/** - * \brief Scalar Unit Widget - A labelled text box, with spin buttons and - * optional icon or suffix, for entering the values of various unit - * types. - * +/* * Authors: * Bryce Harrington <bryce@bryceharrington.org> * Derek P. Moore <derekm@hackunix.org> @@ -23,9 +19,35 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A labelled text box, with spin buttons and optional icon or suffix, for + * entering the values of various unit types. + * + * A ScalarUnit is a control for entering, viewing, or manipulating + * numbers with units. This differs from ordinary numbers like 2 or + * 3.14 because the number portion of a scalar *only* has meaning + * when considered with its unit type. For instance, 12 m and 12 in + * have very different actual values, but 1 m and 100 cm have the same + * value. The ScalarUnit allows us to abstract the presentation of + * the scalar to the user from the internal representations used by + * the program. + */ class ScalarUnit : public Scalar { public: + /** + * Construct a ScalarUnit. + * + * @param label Label. + * @param unit_type Unit type (defaults to UNIT_TYPE_LINEAR). + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param unit_menu UnitMenu drop down; if not specified, one will be created + * and displayed after the widget (defaults to NULL). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, UnitType unit_type = UNIT_TYPE_LINEAR, Glib::ustring const &suffix = "", @@ -33,26 +55,109 @@ public: UnitMenu *unit_menu = NULL, bool mnemonic = true); + /** + * Construct a ScalarUnit. + * + * @param label Label. + * @param tooltip Tooltip text. + * @param take_unitmenu Use the unitmenu from this parameter. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ + ScalarUnit(Glib::ustring const &label, Glib::ustring const &tooltip, + ScalarUnit &take_unitmenu, + Glib::ustring const &suffix = "", + Glib::ustring const &icon = "", + bool mnemonic = true); + + /** + * Initializes the scalar based on the settings in _unit_menu. + * Requires that _unit_menu has already been initialized. + */ void initScalar(double min_value, double max_value); + /** + * Gets the object for the currently selected unit. + */ Unit getUnit() const; + + /** + * Gets the UnitType ID for the unit. + */ UnitType getUnitType() const; + + /** + * Returns the value in the given unit system. + */ double getValue(Glib::ustring const &units) const; + /** + * Sets the unit for the ScalarUnit widget. + */ bool setUnit(Glib::ustring const &units); + + /** + * Adds the unit type to the ScalarUnit widget. + */ + void setUnitType(UnitType unit_type); + + /** + * Resets the unit type for the ScalarUnit widget. + */ + void resetUnitType(UnitType unit_type); + + /** + * Sets the number and unit system. + */ void setValue(double number, Glib::ustring const &units); + + /** + * Convert and sets the number only and keeps the current unit. + */ + void setValueKeepUnit(double number, Glib::ustring const &units); + + /** + * Sets the number only. + */ void setValue(double number); + /** + * Grab focus, and select the text that is in the entry field. + */ + void grabFocusAndSelectEntry(); + void setHundredPercent(double number); + void setAbsoluteIsIncrement(bool value); + void setPercentageIsIncrement(bool value); + /** + * Convert value from % to absolute, using _hundred_percent and *_is_increment flags. + */ double PercentageToAbsolute(double value); + + /** + * Convert value from absolute to %, using _hundred_percent and *_is_increment flags. + */ double AbsoluteToPercentage(double value); + /** + * Assuming the current unit is absolute, get the corresponding % value. + */ double getAsPercentage(); + + /** + * Assuming the current unit is absolute, set the value corresponding to a given %. + */ void setFromPercentage(double value); + /** + * Signal handler for updating the value and suffix label when unit is changed. + */ void on_unit_changed(); protected: diff --git a/src/ui/widget/scalar.cpp b/src/ui/widget/scalar.cpp index 26a1f6541..cc051599c 100644 --- a/src/ui/widget/scalar.cpp +++ b/src/ui/widget/scalar.cpp @@ -1,13 +1,11 @@ -/** - * \brief Scalar Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary number values. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Derek P. Moore <derekm@hackunix.org> * Bryce Harrington <bryce@bryceharrington.org> + * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl> * - * Copyright (C) 2004 Carl Hetherington + * Copyright (C) 2004-2011 authors * * Released under GNU GPL. Read the file 'COPYING' for more information. */ @@ -18,191 +16,135 @@ #include "scalar.h" +#include "spinbutton.h" +#include <gtkmm/scale.h> namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a Scalar Widget. - * - * \param label Label. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::SpinButton(), suffix, icon, mnemonic), + : Labelled(label, tooltip, new SpinButton(), suffix, icon, mnemonic), setProgrammatically(false) { - static_cast<Gtk::SpinButton*>(_widget)->set_numeric(); } -/** - * Construct a Scalar Widget. - * - * \param label Label. - * \param digits Number of decimal digits to display. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::SpinButton(0.0, digits), suffix, icon, mnemonic), + : Labelled(label, tooltip, new SpinButton(0.0, digits), suffix, icon, mnemonic), setProgrammatically(false) { - static_cast<Gtk::SpinButton*>(_widget)->set_numeric(); } -/** - * Construct a Scalar Widget. - * - * \param label Label. - * \param adjust Adjustment to use for the SpinButton. - * \param digits Number of decimal digits to display (defaults to 0). - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to true). - */ Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Adjustment &adjust, unsigned digits, Glib::ustring const &suffix, Glib::ustring const &icon, bool mnemonic) - : Labelled(label, tooltip, new Gtk::SpinButton(adjust, 0.0, digits), suffix, icon, mnemonic), + : Labelled(label, tooltip, new SpinButton(adjust, 0.0, digits), suffix, icon, mnemonic), setProgrammatically(false) { - static_cast<Gtk::SpinButton*>(_widget)->set_numeric(); } -/** Fetches the precision of the spin buton */ -unsigned -Scalar::getDigits() const +unsigned Scalar::getDigits() const { g_assert(_widget != NULL); - return static_cast<Gtk::SpinButton*>(_widget)->get_digits(); + return static_cast<SpinButton*>(_widget)->get_digits(); } -/** Gets the current step ingrement used by the spin button */ -double -Scalar::getStep() const +double Scalar::getStep() const { g_assert(_widget != NULL); double step, page; - static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page); + static_cast<SpinButton*>(_widget)->get_increments(step, page); return step; } -/** Gets the current page increment used by the spin button */ -double -Scalar::getPage() const +double Scalar::getPage() const { g_assert(_widget != NULL); double step, page; - static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page); + static_cast<SpinButton*>(_widget)->get_increments(step, page); return page; } -/** Gets the minimum range value allowed for the spin button */ -double -Scalar::getRangeMin() const +double Scalar::getRangeMin() const { g_assert(_widget != NULL); double min, max; - static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max); + static_cast<SpinButton*>(_widget)->get_range(min, max); return min; } -/** Gets the maximum range value allowed for the spin button */ -double -Scalar::getRangeMax() const +double Scalar::getRangeMax() const { g_assert(_widget != NULL); double min, max; - static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max); + static_cast<SpinButton*>(_widget)->get_range(min, max); return max; } -/** Get the value in the spin_button . */ -double -Scalar::getValue() const +double Scalar::getValue() const { g_assert(_widget != NULL); - return static_cast<Gtk::SpinButton*>(_widget)->get_value(); + return static_cast<SpinButton*>(_widget)->get_value(); } -/** Get the value spin_button represented as an integer. */ -int -Scalar::getValueAsInt() const +int Scalar::getValueAsInt() const { g_assert(_widget != NULL); - return static_cast<Gtk::SpinButton*>(_widget)->get_value_as_int(); + return static_cast<SpinButton*>(_widget)->get_value_as_int(); } -/** Sets the precision to be displayed by the spin button */ -void -Scalar::setDigits(unsigned digits) +void Scalar::setDigits(unsigned digits) { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->set_digits(digits); + static_cast<SpinButton*>(_widget)->set_digits(digits); } -/** Sets the step and page increments for the spin button - * @todo Remove the second parameter - deprecated - */ -void -Scalar::setIncrements(double step, double /*page*/) +void Scalar::setIncrements(double step, double /*page*/) { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->set_increments(step, 0); + static_cast<SpinButton*>(_widget)->set_increments(step, 0); } -/** Sets the minimum and maximum range allowed for the spin button */ -void -Scalar::setRange(double min, double max) +void Scalar::setRange(double min, double max) { g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->set_range(min, max); + static_cast<SpinButton*>(_widget)->set_range(min, max); } -/** Sets the value of the spin button */ -void -Scalar::setValue(double value) +void Scalar::setValue(double value) { g_assert(_widget != NULL); setProgrammatically = true; // callback is supposed to reset back, if it cares - static_cast<Gtk::SpinButton*>(_widget)->set_value(value); + static_cast<SpinButton*>(_widget)->set_value(value); } -/** Manually forces an update of the spin button */ -void -Scalar::update() { +void Scalar::update() +{ g_assert(_widget != NULL); - static_cast<Gtk::SpinButton*>(_widget)->update(); + static_cast<SpinButton*>(_widget)->update(); } +void Scalar::addSlider() +{ + Gtk::HScale *scale = new Gtk::HScale( * static_cast<SpinButton*>(_widget)->get_adjustment() ); + scale->set_draw_value(false); + add (*manage (scale)); +} - -/** Signal raised when the spin button's value changes */ -Glib::SignalProxy0<void> -Scalar::signal_value_changed() +Glib::SignalProxy0<void> Scalar::signal_value_changed() { - return static_cast<Gtk::SpinButton*>(_widget)->signal_value_changed(); + return static_cast<SpinButton*>(_widget)->signal_value_changed(); } diff --git a/src/ui/widget/scalar.h b/src/ui/widget/scalar.h index 6de128edb..19ccb7ae0 100644 --- a/src/ui/widget/scalar.h +++ b/src/ui/widget/scalar.h @@ -1,7 +1,4 @@ -/** - * \brief Scalar Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary number values. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Derek P. Moore <derekm@hackunix.org> @@ -15,29 +12,65 @@ #ifndef INKSCAPE_UI_WIDGET_SCALAR_H #define INKSCAPE_UI_WIDGET_SCALAR_H -#include <gtkmm/adjustment.h> -#include <gtkmm/spinbutton.h> - #include "labelled.h" namespace Inkscape { namespace UI { namespace Widget { +/** + * A labelled text box, with spin buttons and optional + * icon or suffix, for entering arbitrary number values. + */ class Scalar : public Labelled { public: + /** + * Construct a Scalar Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + + /** + * Construct a Scalar Widget. + * + * @param label Label. + * @param digits Number of decimal digits to display. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, unsigned digits, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + + /** + * Construct a Scalar Widget. + * + * @param label Label. + * @param adjust Adjustment to use for the SpinButton. + * @param digits Number of decimal digits to display (defaults to 0). + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to true). + */ Scalar(Glib::ustring const &label, Glib::ustring const &tooltip, Gtk::Adjustment &adjust, @@ -46,26 +79,84 @@ public: Glib::ustring const &icon = "", bool mnemonic = true); + /** + * Fetches the precision of the spin buton. + */ unsigned getDigits() const; + + /** + * Gets the current step ingrement used by the spin button. + */ double getStep() const; + + /** + * Gets the current page increment used by the spin button. + */ double getPage() const; + + /** + * Gets the minimum range value allowed for the spin button. + */ double getRangeMin() const; + + /** + * Gets the maximum range value allowed for the spin button. + */ double getRangeMax() const; + bool getSnapToTicks() const; + + /** + * Get the value in the spin_button. + */ double getValue() const; + + /** + * Get the value spin_button represented as an integer. + */ int getValueAsInt() const; + /** + * Sets the precision to be displayed by the spin button. + */ void setDigits(unsigned digits); + + /** + * Sets the step and page increments for the spin button. + * @todo Remove the second parameter - deprecated + */ void setIncrements(double step, double page); + + /** + * Sets the minimum and maximum range allowed for the spin button. + */ void setRange(double min, double max); + + /** + * Sets the value of the spin button. + */ void setValue(double value); + /** + * Manually forces an update of the spin button. + */ void update(); + /** + * Adds a slider (HScale) to the left of the spinbox. + */ + void addSlider(); + + /** + * Signal raised when the spin button's value changes. + */ Glib::SignalProxy0<void> signal_value_changed(); - bool setProgrammatically; // true if the value was set by setValue, not changed by the user; - // if a callback checks it, it must reset it back to false + /** + * true if the value was set by setValue, not changed by the user; + * if a callback checks it, it must reset it back to false. + */ + bool setProgrammatically; }; } // namespace Widget diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 50476dc65..b6722f4cf 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -1,6 +1,4 @@ -/** - * \brief Selected style indicator (fill, stroke, opacity) - * +/* * Author: * buliabyak@gmail.com * Abhishek Sharma @@ -14,7 +12,7 @@ # include <config.h> #endif -#include <gtk/gtkdnd.h> +#include <gtk/gtk.h> #include "selected-style.h" @@ -412,7 +410,7 @@ void SelectedStyle::setDesktop(SPDesktop *desktop) { _desktop = desktop; - gtk_object_set_data (GTK_OBJECT(_opacity_sb.gobj()), "dtw", _desktop->canvas); + g_object_set_data (G_OBJECT(_opacity_sb.gobj()), "dtw", _desktop->canvas); Inkscape::Selection *selection = sp_desktop_selection (desktop); @@ -1092,7 +1090,7 @@ void SelectedStyle::opacity_1(void) {_opacity_sb.set_value(100);} void SelectedStyle::on_opacity_menu (Gtk::Menu *menu) { Glib::ListHandle<Gtk::Widget *> children = menu->get_children(); - for (Glib::ListHandle<Gtk::Widget *>::iterator iter = children.begin(); iter != children.end(); iter++) { + for (Glib::ListHandle<Gtk::Widget *>::iterator iter = children.begin(); iter != children.end(); ++iter) { menu->remove(*(*iter)); } diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index e74d5b1ae..916cbe6d1 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -1,6 +1,4 @@ -/** - * \brief Selected style indicator (fill, stroke, opacity) - * +/* * Authors: * buliabyak@gmail.com * scislac@users.sf.net @@ -21,7 +19,7 @@ #include <gtkmm/menu.h> #include <gtkmm/menuitem.h> #include <gtkmm/adjustment.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" #include <stddef.h> #include <sigc++/sigc++.h> @@ -103,6 +101,9 @@ private: bool cr_set; }; +/** + * Selected style indicator (fill, stroke, opacity). + */ class SelectedStyle : public Gtk::HBox { public: @@ -138,7 +139,7 @@ protected: Gtk::EventBox _opacity_place; Gtk::Adjustment _opacity_adjustment; - Gtk::SpinButton _opacity_sb; + Inkscape::UI::Widget::SpinButton _opacity_sb; Gtk::Label _na[2]; Glib::ustring __na[2]; diff --git a/src/ui/widget/spin-slider.cpp b/src/ui/widget/spin-slider.cpp index faafc63b4..d159ecc15 100644 --- a/src/ui/widget/spin-slider.cpp +++ b/src/ui/widget/spin-slider.cpp @@ -1,6 +1,4 @@ -/** - * \brief Groups an HScale and a SpinButton together using the same Adjustment - * +/* * Author: * Nicholas Bishop <nicholasbishop@gmail.com> * Felipe C. da S. Sanches <juca@members.fsf.org> @@ -20,7 +18,7 @@ namespace UI { namespace Widget { SpinSlider::SpinSlider(double value, double lower, double upper, double step_inc, - double climb_rate, int digits, const SPAttributeEnum a, char* tip_text) + double climb_rate, int digits, const SPAttributeEnum a, const char* tip_text) : AttrWidget(a, value), _adjustment(value, lower, upper, step_inc), _scale(_adjustment), _spin(_adjustment, climb_rate, digits) { @@ -90,11 +88,11 @@ Gtk::HScale& SpinSlider::get_scale() return _scale; } -const Gtk::SpinButton& SpinSlider::get_spin_button() const +const Inkscape::UI::Widget::SpinButton& SpinSlider::get_spin_button() const { return _spin; } -Gtk::SpinButton& SpinSlider::get_spin_button() +Inkscape::UI::Widget::SpinButton& SpinSlider::get_spin_button() { return _spin; } diff --git a/src/ui/widget/spin-slider.h b/src/ui/widget/spin-slider.h index a4d0aa9d6..d2f41603a 100644 --- a/src/ui/widget/spin-slider.h +++ b/src/ui/widget/spin-slider.h @@ -1,6 +1,4 @@ -/** - * \brief Groups an HScale and a SpinButton together using the same Adjustment - * +/* * Author: * Nicholas Bishop <nicholasbishop@gmail.com> * @@ -15,18 +13,21 @@ #include <gtkmm/adjustment.h> #include <gtkmm/box.h> #include <gtkmm/scale.h> -#include <gtkmm/spinbutton.h> +#include "spinbutton.h" #include "attr-widget.h" namespace Inkscape { namespace UI { namespace Widget { +/** + * Groups an HScale and a SpinButton together using the same Adjustment. + */ class SpinSlider : public Gtk::HBox, public AttrWidget { public: SpinSlider(double value, double lower, double upper, double step_inc, - double climb_rate, int digits, const SPAttributeEnum a = SP_ATTR_INVALID, char* tip_text = NULL); + double climb_rate, int digits, const SPAttributeEnum a = SP_ATTR_INVALID, const char* tip_text = NULL); virtual Glib::ustring get_as_attribute() const; virtual void set_from_attribute(SPObject*); @@ -42,8 +43,8 @@ public: const Gtk::HScale& get_scale() const; Gtk::HScale& get_scale(); - const Gtk::SpinButton& get_spin_button() const; - Gtk::SpinButton& get_spin_button(); + const Inkscape::UI::Widget::SpinButton& get_spin_button() const; + Inkscape::UI::Widget::SpinButton& get_spin_button(); void set_update_policy(const Gtk::UpdateType); @@ -52,10 +53,14 @@ public: private: Gtk::Adjustment _adjustment; Gtk::HScale _scale; - Gtk::SpinButton _spin; + Inkscape::UI::Widget::SpinButton _spin; }; -// Contains two SpinSliders for controlling number-opt-number attributes +/** + * Contains two SpinSliders for controlling number-opt-number attributes. + * + * @see SpinSlider + */ class DualSpinSlider : public Gtk::HBox, public AttrWidget { public: diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp new file mode 100644 index 000000000..60b7856f6 --- /dev/null +++ b/src/ui/widget/spinbutton.cpp @@ -0,0 +1,104 @@ +/* + * Author: + * Johan B. C. Engelen + * + * Copyright (C) 2011 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "spinbutton.h" + +#include "unit-menu.h" +#include "util/expression-evaluator.h" +#include "event-context.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + + +void +SpinButton::connect_signals() { + signal_input().connect(sigc::mem_fun(*this, &SpinButton::on_input)); + signal_focus_in_event().connect(sigc::mem_fun(*this, &SpinButton::on_my_focus_in_event)); + signal_key_press_event().connect(sigc::mem_fun(*this, &SpinButton::on_my_key_press_event)); +}; + +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); + // 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); + } + + *newvalue = result.value; + } + catch(Inkscape::Util::EvaluatorException &e) { + g_message ("%s", e.what()); + + return false; + } + + return true; +} + +bool SpinButton::on_my_focus_in_event(GdkEventFocus* /*event*/) +{ + on_focus_in_value = get_value(); + return false; // do not consume the event +} + +bool SpinButton::on_my_key_press_event(GdkEventKey* event) +{ + switch (get_group0_keyval (event)) { + case GDK_Escape: + undo(); + return true; // I consumed the event + break; + case GDK_z: + case GDK_Z: + if (event->state & GDK_CONTROL_MASK) { + undo(); + return true; // I consumed the event + } + break; + default: + break; + } + + return false; // do not consume the event +} + +void SpinButton::undo() +{ + set_value(on_focus_in_value); +} + + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/spinbutton.h b/src/ui/widget/spinbutton.h new file mode 100644 index 000000000..b7764d979 --- /dev/null +++ b/src/ui/widget/spinbutton.h @@ -0,0 +1,104 @@ +/* + * Author: + * Johan B. C. Engelen + * + * Copyright (C) 2011 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_WIDGET_SPINBUTTON_H +#define INKSCAPE_UI_WIDGET_SPINBUTTON_H + +#include <gtkmm/spinbutton.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +class UnitMenu; + +/** + * SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMenu), + * and allows entry of both '.' and ',' for the decimal, even when in numeric mode. + * + * Calling "set_numeric()" effectively disables the expression parsing. If no unit menu is linked, all unitlike characters are ignored. + */ +class SpinButton : public Gtk::SpinButton +{ +public: + SpinButton(double climb_rate = 0.0, guint digits = 0) + : Gtk::SpinButton(climb_rate, digits), + _unit_menu(NULL) + { + connect_signals(); + }; + explicit SpinButton(Gtk::Adjustment& adjustment, double climb_rate = 0.0, guint digits = 0) + : Gtk::SpinButton(adjustment, climb_rate, digits), + _unit_menu(NULL) + { + connect_signals(); + }; + + virtual ~SpinButton() {}; + + void setUnitMenu(UnitMenu* unit_menu) { _unit_menu = unit_menu; }; + +protected: + UnitMenu *_unit_menu; /// Linked unit menu for unit conversion in entered expressions. + + void connect_signals(); + + /** + * This callback function should try to convert the entered text to a number and write it to newvalue. + * It calls a method to evaluate the (potential) mathematical expression. + * + * @retval false No conversion done, continue with default handler. + * @retval true Conversion successful, don't call default handler. + */ + int on_input(double* newvalue); + + /** + * When focus is obtained, save the value to enable undo later. + * @retval false continue with default handler. + * @retval true don't call default handler. + */ + bool on_my_focus_in_event(GdkEventFocus* event); + + /** + * Handle specific keypress events, like Ctrl+Z. + * + * @retval false continue with default handler. + * @retval true don't call default handler. + */ + bool on_my_key_press_event(GdkEventKey* event); + + /** + * Undo the editing, by resetting the value upon when the spinbutton got focus. + */ + void undo(); + + double on_focus_in_value; + +private: + // noncopyable + SpinButton(const SpinButton&); + SpinButton& operator=(const SpinButton&); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_SPINBUTTON_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index f4780896b..d9bf7e2aa 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -1,6 +1,4 @@ -/** - * \brief Abstraction for different style widget operands - * +/* * Copyright (C) 2007 MenTaLguY <mental@rydia.net> * Abhishek Sharma * @@ -147,7 +145,7 @@ StyleSubject::iterator StyleSubject::CurrentLayer::begin() { Geom::OptRect StyleSubject::CurrentLayer::getBounds(SPItem::BBoxType type) { SPObject *layer = _getLayer(); if (layer && SP_IS_ITEM(layer)) { - return SP_ITEM(layer)->getBboxDesktop(type); + return SP_ITEM(layer)->desktopBounds(type); } else { return Geom::OptRect(); } diff --git a/src/ui/widget/style-subject.h b/src/ui/widget/style-subject.h index 6d5c96350..47da91732 100644 --- a/src/ui/widget/style-subject.h +++ b/src/ui/widget/style-subject.h @@ -1,17 +1,17 @@ /** - * \brief Abstraction for different style widget operands - * + * @file + * Abstraction for different style widget operands. + */ +/* * Copyright (C) 2007 MenTaLguY <mental@rydia.net> * * Released under GNU GPL. Read the file 'COPYING' for more information. */ - #ifndef SEEN_INKSCAPE_UI_WIDGET_STYLE_SUBJECT_H #define SEEN_INKSCAPE_UI_WIDGET_STYLE_SUBJECT_H #include "util/glib-list-iterators.h" #include <boost/optional.hpp> -#include "libnr/nr-rect.h" #include <2geom/rect.h> #include "sp-item.h" #include <stddef.h> @@ -45,7 +45,7 @@ public: virtual iterator begin() = 0; virtual iterator end() { return iterator(NULL); } - virtual Geom::OptRect getBounds(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) = 0; + virtual Geom::OptRect getBounds(SPItem::BBoxType type) = 0; virtual int queryStyle(SPStyle *query, int property) = 0; virtual void setCSS(SPCSSAttr *css) = 0; @@ -68,7 +68,7 @@ public: ~Selection(); virtual iterator begin(); - virtual Geom::OptRect getBounds(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX); + virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); @@ -89,7 +89,7 @@ public: ~CurrentLayer(); virtual iterator begin(); - virtual Geom::OptRect getBounds(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX); + virtual Geom::OptRect getBounds(SPItem::BBoxType type); virtual int queryStyle(SPStyle *query, int property); virtual void setCSS(SPCSSAttr *css); @@ -111,7 +111,7 @@ private: } } -#endif +#endif // SEEN_INKSCAPE_UI_WIDGET_STYLE_SUBJECT_H /* Local Variables: diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 47f6292e3..41366f749 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -1,5 +1,6 @@ -/** @file - * @brief Static style swatch (fill, stroke, opacity) +/** + * @file + * Static style swatch (fill, stroke, opacity). */ /* Authors: * buliabyak@gmail.com @@ -43,7 +44,7 @@ namespace UI { namespace Widget { /** - * @brief Watches whether the tool uses the current style + * Watches whether the tool uses the current style. */ class StyleSwatch::ToolObserver : public Inkscape::Preferences::Observer { public: @@ -57,7 +58,7 @@ private: }; /** - * @brief Watches for changes in the observed style pref + * Watches for changes in the observed style pref. */ class StyleSwatch::StyleObserver : public Inkscape::Preferences::Observer { public: diff --git a/src/ui/widget/svg-canvas.cpp b/src/ui/widget/svg-canvas.cpp index 7d37ec355..d3d9f70f2 100644 --- a/src/ui/widget/svg-canvas.cpp +++ b/src/ui/widget/svg-canvas.cpp @@ -1,6 +1,4 @@ -/** \file - * Gtkmm facade/wrapper around SPCanvas. - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -22,7 +20,7 @@ namespace Widget { SVGCanvas::SVGCanvas() { - void *canvas = gtk_type_new (sp_canvas_get_type ()); + void *canvas = g_object_new (sp_canvas_get_type (), NULL); _spcanvas = static_cast<SPCanvas*>(canvas); _widget = Glib::wrap (static_cast<GtkWidget*> (canvas)); _dt = 0; diff --git a/src/ui/widget/svg-canvas.h b/src/ui/widget/svg-canvas.h index cb8dc4013..c513bcf26 100644 --- a/src/ui/widget/svg-canvas.h +++ b/src/ui/widget/svg-canvas.h @@ -1,9 +1,7 @@ -#ifndef __UI_WIDGET_SVGCANVAS_H__ -#define __UI_WIDGET_SVGCANVAS_H__ +#ifndef SEEN_UI_WIDGET_SVGCANVAS_H +#define SEEN_UI_WIDGET_SVGCANVAS_H -/** \file - * Gtkmm facade/wrapper around SPCanvas. - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -16,9 +14,12 @@ struct SPCanvas; struct SPDesktop; namespace Gtk { class Widget; } namespace Inkscape { - namespace UI { - namespace Widget { +namespace UI { +namespace Widget { +/** + * Gtkmm facade/wrapper around SPCanvas. + */ class SVGCanvas { public: @@ -41,7 +42,7 @@ protected: } // namespace Inkscape -#endif +#endif // SEEN_UI_WIDGET_SVGCANVAS_H /* diff --git a/src/ui/widget/text.cpp b/src/ui/widget/text.cpp index 581491f0e..b79bea067 100644 --- a/src/ui/widget/text.cpp +++ b/src/ui/widget/text.cpp @@ -1,7 +1,4 @@ -/** - * \brief Text Widget - A labelled text box, with spin buttons and optional - * icon or suffix, for entering arbitrary number values. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Maximilian Albert <maximilian.albert@gmail.com> @@ -22,16 +19,6 @@ namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a Text Widget. - * - * \param label Label. - * \param suffix Suffix, placed after the widget (defaults to ""). - * \param icon Icon filename, placed before the label (defaults to ""). - * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label - * indicates the next character should be used for the - * mnemonic accelerator key (defaults to false). - */ Text::Text(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix, Glib::ustring const &icon, @@ -41,26 +28,20 @@ Text::Text(Glib::ustring const &label, Glib::ustring const &tooltip, { } -/** Get the text in the entry */ -const char * -Text::getText() const +const char *Text::getText() const { g_assert(_widget != NULL); return static_cast<Gtk::Entry*>(_widget)->get_text().c_str(); } -/** Sets the text of the text entry */ -void -Text::setText(const char* text) +void Text::setText(const char* text) { g_assert(_widget != NULL); setProgrammatically = true; // callback is supposed to reset back, if it cares static_cast<Gtk::Entry*>(_widget)->set_text(text); // FIXME: set correctly } -/** Signal raised when the spin button's value changes */ -Glib::SignalProxy0<void> -Text::signal_activate() +Glib::SignalProxy0<void> Text::signal_activate() { return static_cast<Gtk::Entry*>(_widget)->signal_activate(); } diff --git a/src/ui/widget/text.h b/src/ui/widget/text.h index 0dcfc5cc6..0f6efd01f 100644 --- a/src/ui/widget/text.h +++ b/src/ui/widget/text.h @@ -1,7 +1,4 @@ -/** - * \brief Text Widget - A labelled text box, with optional icon or - * suffix, for entering arbitrary number values. - * +/* * Authors: * Carl Hetherington <inkscape@carlh.net> * Maximilian Albert <maximilian.albert@gmail.com> @@ -23,21 +20,44 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A labelled text box, with optional icon or suffix, for entering arbitrary number values. + */ class Text : public Labelled { public: + + /** + * Construct a Text Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ Text(Glib::ustring const &label, Glib::ustring const &tooltip, Glib::ustring const &suffix = "", Glib::ustring const &icon = "", bool mnemonic = true); + /** + * Get the text in the entry. + */ const char* getText() const; + /** + * Sets the text of the text entry. + */ void setText(const char* text); void update(); + /** + * Signal raised when the spin button's value changes. + */ Glib::SignalProxy0<void> signal_activate(); bool setProgrammatically; // true if the value was set by setValue, not changed by the user; diff --git a/src/ui/widget/tolerance-slider.cpp b/src/ui/widget/tolerance-slider.cpp index 51e0a262f..aa749fb39 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -1,7 +1,4 @@ -/** \file - * - Implementation of tolerance slider widget. - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * Abhishek Sharma @@ -43,9 +40,10 @@ namespace Widget { //==================================================== -ToleranceSlider::ToleranceSlider() +ToleranceSlider::ToleranceSlider(const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& label3, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& tip3, const Glib::ustring& key, Registry& wr) : _vbox(0) { + init(label1, label2, label3, tip1, tip2, tip3, key, wr); } ToleranceSlider::~ToleranceSlider() @@ -54,8 +52,7 @@ ToleranceSlider::~ToleranceSlider() _scale_changed_connection.disconnect(); } -void -ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& label3, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& tip3, const Glib::ustring& key, Registry& wr) +void ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& label3, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& tip3, const Glib::ustring& key, Registry& wr) { // hbox = label + slider // @@ -112,8 +109,7 @@ ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, _vbox->show_all_children(); } -void -ToleranceSlider::setValue (double val) +void ToleranceSlider::setValue (double val) { Gtk::Adjustment *adj = _hscale->get_adjustment(); @@ -138,21 +134,18 @@ ToleranceSlider::setValue (double val) _hbox->show_all(); } -void -ToleranceSlider::setLimits (double theMin, double theMax) +void ToleranceSlider::setLimits (double theMin, double theMax) { _hscale->set_range (theMin, theMax); _hscale->get_adjustment()->set_step_increment (1); } -void -ToleranceSlider::on_scale_changed() +void ToleranceSlider::on_scale_changed() { update (_hscale->get_value()); } -void -ToleranceSlider::on_toggled() +void ToleranceSlider::on_toggled() { if (!_button2->get_active()) { @@ -171,8 +164,7 @@ ToleranceSlider::on_toggled() } } -void -ToleranceSlider::update (double val) +void ToleranceSlider::update (double val) { if (_wr->isUpdating()) return; diff --git a/src/ui/widget/tolerance-slider.h b/src/ui/widget/tolerance-slider.h index 22c04d361..6865ec769 100644 --- a/src/ui/widget/tolerance-slider.h +++ b/src/ui/widget/tolerance-slider.h @@ -1,8 +1,3 @@ -/** \file - * \brief - * - * This widget is part of the Document properties dialog. - */ /* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> @@ -27,11 +22,13 @@ namespace Widget { class Registry; +/** + * Implementation of tolerance slider widget. + * This widget is part of the Document properties dialog. + */ class ToleranceSlider { public: - ToleranceSlider(); - ~ToleranceSlider(); - void init (const Glib::ustring& label1, + ToleranceSlider(const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& label3, const Glib::ustring& tip1, @@ -39,9 +36,19 @@ public: const Glib::ustring& tip3, const Glib::ustring& key, Registry& wr); + ~ToleranceSlider(); void setValue (double); void setLimits (double, double); Gtk::VBox* _vbox; +private: + void init (const Glib::ustring& label1, + const Glib::ustring& label2, + const Glib::ustring& label3, + const Glib::ustring& tip1, + const Glib::ustring& tip2, + const Glib::ustring& tip3, + const Glib::ustring& key, + Registry& wr); protected: void on_scale_changed(); diff --git a/src/ui/widget/toolbox.cpp b/src/ui/widget/toolbox.cpp index e90a58b6e..99891fc44 100644 --- a/src/ui/widget/toolbox.cpp +++ b/src/ui/widget/toolbox.cpp @@ -1,6 +1,4 @@ -/** - * \brief Toolbox Widget - A detachable toolbar for buttons and other widgets. - * +/* * Author: * Derek P. Moore <derekm@hackunix.org> * @@ -14,7 +12,7 @@ #endif #include <gtkmm/radioaction.h> -#include <gtk/gtkmain.h> +#include <gtk/gtk.h> #include "ui/widget/toolbox.h" #include "path-prefix.h" diff --git a/src/ui/widget/toolbox.h b/src/ui/widget/toolbox.h index 9c4e18909..f721bef8a 100644 --- a/src/ui/widget/toolbox.h +++ b/src/ui/widget/toolbox.h @@ -1,6 +1,4 @@ -/** - * \brief Toolbox Widget - A detachable toolbar for buttons and other widgets. - * +/* * Author: * Derek P. Moore <derekm@hackunix.org> * @@ -22,6 +20,9 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A detachable toolbar for buttons and other widgets. + */ class Toolbox : public HandleBox { public: diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp index b4271762c..085783481 100644 --- a/src/ui/widget/unit-menu.cpp +++ b/src/ui/widget/unit-menu.cpp @@ -1,6 +1,4 @@ -/** - * \brief Unit Menu Widget - A drop down menu for choosing unit types. - * +/* * Author: * Bryce Harrington <bryce@bryceharrington.org> * @@ -21,10 +19,6 @@ namespace Inkscape { namespace UI { namespace Widget { -/** - * Construct a UnitMenu - * - */ UnitMenu::UnitMenu() : _type(UNIT_TYPE_NONE) { set_active(0); @@ -33,14 +27,9 @@ UnitMenu::UnitMenu() : _type(UNIT_TYPE_NONE) UnitMenu::~UnitMenu() { } -/** Adds the unit type to the widget. This extracts the corresponding - units from the unit map matching the given type, and appends them - to the dropdown widget. It causes the primary unit for the given - unit_type to be selected. */ -bool -UnitMenu::setUnitType(UnitType unit_type) +bool UnitMenu::setUnitType(UnitType unit_type) { - /* Expand the unit widget with unit entries from the unit table */ + // Expand the unit widget with unit entries from the unit table UnitTable::UnitMap m = _unit_table.units(unit_type); UnitTable::UnitMap::iterator iter = m.begin(); while(iter != m.end()) { @@ -54,10 +43,21 @@ UnitMenu::setUnitType(UnitType unit_type) return true; } -/** Returns the Unit object corresponding to the current selection - in the dropdown widget */ -Unit -UnitMenu::getUnit() const { +bool UnitMenu::resetUnitType(UnitType unit_type) +{ + clear_text(); + + return setUnitType(unit_type); +} + +void UnitMenu::addUnit(Unit const& u) +{ + _unit_table.addUnit(u, false); + append_text(u.abbr); +} + +Unit UnitMenu::getUnit() const +{ if (get_active_text() == "") { g_assert(_type != UNIT_TYPE_NONE); return _unit_table.getUnit(_unit_table.primary(_type)); @@ -65,11 +65,8 @@ UnitMenu::getUnit() const { return _unit_table.getUnit(get_active_text()); } -/** Sets the dropdown widget to the given unit abbreviation. - Returns true if the unit was selectable, false if not - (i.e., if the unit was not present in the widget) */ -bool -UnitMenu::setUnit(Glib::ustring const & unit) { +bool UnitMenu::setUnit(Glib::ustring const & unit) +{ // TODO: Determine if 'unit' is available in the dropdown. // If not, return false @@ -77,63 +74,41 @@ UnitMenu::setUnit(Glib::ustring const & unit) { return true; } -/** Returns the abbreviated unit name of the selected unit */ -Glib::ustring -UnitMenu::getUnitAbbr() const { +Glib::ustring UnitMenu::getUnitAbbr() const +{ if (get_active_text() == "") { return ""; } return getUnit().abbr; } -/** Returns the UnitType of the selected unit */ -UnitType -UnitMenu::getUnitType() const { +UnitType UnitMenu::getUnitType() const +{ return getUnit().type; } -/** Returns the unit factor for the selected unit */ -double -UnitMenu::getUnitFactor() const +double UnitMenu::getUnitFactor() const { return getUnit().factor; } -/** Returns the recommended number of digits for displaying - * numbers of this unit type. - */ -int -UnitMenu::getDefaultDigits() const +int UnitMenu::getDefaultDigits() const { return getUnit().defaultDigits(); } -/** Returns the recommended step size in spin buttons - * displaying units of this type - */ -double -UnitMenu::getDefaultStep() const +double UnitMenu::getDefaultStep() const { int factor_digits = -1*int(log10(getUnit().factor)); return pow(10.0, factor_digits); } -/** Returns the recommended page size (when hitting pgup/pgdn) - * in spin buttons displaying units of this type - */ -double -UnitMenu::getDefaultPage() const +double UnitMenu::getDefaultPage() const { return 10 * getDefaultStep(); } -/** - * Returns the conversion factor required to convert values - * of the currently selected unit into units of type - * new_unit_abbr. - */ -double -UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const +double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const { double old_factor = getUnit().factor; if (old_unit_abbr != "no_unit") @@ -150,18 +125,13 @@ UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const return old_factor / new_unit.factor; } -/** Returns true if the selected unit is not dimensionless - * (false for %, true for px, pt, cm, etc) - */ -bool -UnitMenu::isAbsolute() const { +bool UnitMenu::isAbsolute() const +{ return getUnitType() != UNIT_TYPE_DIMENSIONLESS; } -/** Returns true if the selected unit is radial (deg or rad) - */ -bool -UnitMenu::isRadial() const { +bool UnitMenu::isRadial() const +{ return getUnitType() == UNIT_TYPE_RADIAL; } diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h index 60a9702b4..61e93bd65 100644 --- a/src/ui/widget/unit-menu.h +++ b/src/ui/widget/unit-menu.h @@ -1,6 +1,4 @@ -/** - * \brief Unit Menu Widget - A drop down menu for choosing unit types. - * +/* * Author: * Bryce Harrington <bryce@bryceharrington.org> * @@ -21,28 +19,104 @@ namespace Inkscape { namespace UI { namespace Widget { +/** + * A drop down menu for choosing unit types. + */ class UnitMenu : public ComboText { public: + + /** + * Construct a UnitMenu + */ UnitMenu(); + virtual ~UnitMenu(); + /** + * Adds the unit type to the widget. This extracts the corresponding + * units from the unit map matching the given type, and appends them + * to the dropdown widget. It causes the primary unit for the given + * unit_type to be selected. + */ bool setUnitType(UnitType unit_type); + /** + * Removes all unit entries, then adds the unit type to the widget. + * This extracts the corresponding + * units from the unit map matching the given type, and appends them + * to the dropdown widget. It causes the primary unit for the given + * unit_type to be selected. + */ + bool resetUnitType(UnitType unit_type); + + /** + * Adds a unit, possibly user-defined, to the menu. + */ + void addUnit(Unit const& u); + + /** + * Sets the dropdown widget to the given unit abbreviation. + * Returns true if the unit was selectable, false if not + * (i.e., if the unit was not present in the widget). + */ bool setUnit(Glib::ustring const &unit); + /** + * Returns the Unit object corresponding to the current selection + * in the dropdown widget. + */ Unit getUnit() const; + + /** + * Returns the abbreviated unit name of the selected unit. + */ Glib::ustring getUnitAbbr() const; + + /** + * Returns the UnitType of the selected unit. + */ UnitType getUnitType() const; + + /** + * Returns the unit factor for the selected unit. + */ double getUnitFactor() const; + /** + * Returns the recommended number of digits for displaying + * numbers of this unit type. + */ int getDefaultDigits() const; + + /** + * Returns the recommended step size in spin buttons + * displaying units of this type. + */ double getDefaultStep() const; + + /** + * Returns the recommended page size (when hitting pgup/pgdn) + * in spin buttons displaying units of this type. + */ double getDefaultPage() const; + /** + * Returns the conversion factor required to convert values + * of the currently selected unit into units of type + * new_unit_abbr. + */ double getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr = "no_unit") const; + /** + * Returns true if the selected unit is not dimensionless + * (false for %, true for px, pt, cm, etc). + */ bool isAbsolute() const; + + /** + * Returns true if the selected unit is radial (deg or rad). + */ bool isRadial() const; UnitTable &getUnitTable() {return _unit_table;} diff --git a/src/ui/widget/zoom-status.cpp b/src/ui/widget/zoom-status.cpp index 9322aa803..fa8191671 100644 --- a/src/ui/widget/zoom-status.cpp +++ b/src/ui/widget/zoom-status.cpp @@ -1,7 +1,4 @@ -/** \file - * Gtkmm facade/wrapper around zoom_status code that formerly lived - * in desktop-widget.cpp - * +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * Lauris Kaplinski <lauris@kaplinski.com> @@ -20,7 +17,6 @@ #include "desktop.h" #include "desktop-handles.h" #include "widgets/spw-utilities.h" -#include "libnr/nr-convert2geom.h" namespace Inkscape { namespace UI { diff --git a/src/ui/widget/zoom-status.h b/src/ui/widget/zoom-status.h index 58d595329..b9373589f 100644 --- a/src/ui/widget/zoom-status.h +++ b/src/ui/widget/zoom-status.h @@ -1,9 +1,6 @@ -#ifndef __UI_WIDGET_ZOOMSTATUS_H__ -#define __UI_WIDGET_ZOOMSTATUS_H__ - -/** \file - * Enhanced spinbutton. - * +#ifndef SEEN_UI_WIDGET_ZOOMSTATUS_H +#define SEEN_UI_WIDGET_ZOOMSTATUS_H +/* * Authors: * Ralf Stephan <ralf@ark.in-berlin.de> * @@ -13,7 +10,7 @@ */ #include <gtkmm/adjustment.h> -#include <gtkmm/spinbutton.h> +#include "ui/widget/spinbutton.h" struct SPDesktop; @@ -22,7 +19,10 @@ namespace Inkscape { namespace UI { namespace Widget { -class ZoomStatus : public Gtk::SpinButton +/** + * Enhanced spinbutton. + */ +class ZoomStatus : public Inkscape::UI::Widget::SpinButton { public: ZoomStatus(); @@ -46,7 +46,7 @@ protected: } // namespace Inkscape -#endif +#endif // SEEN_UI_WIDGET_ZOOMSTATUS_H /* |
