preferences-widget.cpp revision 5cf332777b4c27336d64c273ac63bce3ee27a53d
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Inkscape Preferences dialog.
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Authors:
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Marco Scholten
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Bruno Dilly <bruno.dilly@gmail.com>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm *
032f369baeef7d4a3b8769997df5dcd6dd874830jfbarraud * Copyright (C) 2004, 2006, 2007 Authors
032f369baeef7d4a3b8769997df5dcd6dd874830jfbarraud *
f4a94b19c3c5d7d1e7bd926de1eb7e6c077babb2johanengelen * Released under GNU GPL. Read the file 'COPYING' for more information.
f4a94b19c3c5d7d1e7bd926de1eb7e6c077babb2johanengelen */
f4a94b19c3c5d7d1e7bd926de1eb7e6c077babb2johanengelen
f4a94b19c3c5d7d1e7bd926de1eb7e6c077babb2johanengelen#ifdef HAVE_CONFIG_H
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm# include <config.h>
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelen#endif
5c45bb188ab729e501e48732842cb9de6a9813beAlex Valavanis
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen#ifdef WIN32
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud#include <windows.h>
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud#endif
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud
06cd6b0ab2dbe286184e35d1078bab18c966b0d2jfbarraud#include <gtkmm/frame.h>
081a89987d4cb46e707c9dd5648a7a24a01a750djfbarraud#include <gtkmm/alignment.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtkmm/box.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "preferences.h"
8d9f5d586a04809427ce1df284a5720112177991cilix#include "ui/widget/preferences-widget.h"
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix#include "verbs.h"
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak#include "selcue.h"
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen#include "io/sys.h"
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk#include <iostream>
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen#include "desktop.h"
f4db63be4e929f4706410914295deccaceea19cdcilix#include "enums.h"
ab99111a42436818e6902e044c8f3af2b724263bcilix#include "inkscape.h"
76db360f5f052775326e6d406b9e1e9e2966e11acilix#include "desktop-handles.h"
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix#include "message-stack.h"
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix#include "style.h"
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include "selection.h"
044d712d4d03f8354962d54e47cfac2346a69ccccilix#include "selection-chemistry.h"
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix#include "ui/dialog/filedialog.h"
2f5c0701b333a695eedb1680beb1adf95c0723dacilix#include "xml/repr.h"
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelenusing namespace Inkscape::UI::Widget;
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix
ecf048161ae0284d01d34ca5844204775c0d3fdecilixnamespace Inkscape {
3515994554d167522343ce57417648b39370ccabcilixnamespace UI {
afa1e71af5a64b54df797ac1f0bcf32c6613b371johanengelennamespace Widget {
b62895f15526ccefdf1e274c49c02aa043895ee9johanengelen
4fe8248cd521387d0829c423bf4492e2cbdfd7cdJohan EngelenDialogPage::DialogPage()
05e1ec4d6f1ccc3a0db3cc13e8a3b18489714f14Johan Engelen{
081a89987d4cb46e707c9dd5648a7a24a01a750djfbarraud this->set_border_width(12);
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis this->set_col_spacings(12);
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis this->set_row_spacings(6);
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis}
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanisvoid DialogPage::add_line(bool indent, Glib::ustring const &label, Gtk::Widget &widget, Glib::ustring const &suffix, const Glib::ustring &tip, bool expand_widget)
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis{
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis int start_col;
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis int row = this->property_n_rows();
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis Gtk::Widget* w;
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis if (expand_widget)
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis {
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis w = &widget;
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis }
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis else
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis {
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis Gtk::HBox* hb = Gtk::manage(new Gtk::HBox());
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis hb->set_spacing(12);
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis hb->pack_start(widget,false,false);
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis w = (Gtk::Widget*) hb;
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis }
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis if (label != "")
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis {
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis Gtk::Label* label_widget;
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis label_widget = Gtk::manage(new Gtk::Label(label , Gtk::ALIGN_LEFT , Gtk::ALIGN_CENTER, true));
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis label_widget->set_mnemonic_widget(widget);
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis if (indent)
1b3a8414f17dc95fc921d999ea715c99d10dd4aaAlex Valavanis {
1c88ed492df4a0bcb37006a6cc36127897cd847ejfbarraud Gtk::Alignment* alignment = Gtk::manage(new Gtk::Alignment());
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm alignment->set_padding(0, 0, 12, 0);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm alignment->add(*label_widget);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->attach(*alignment , 0, 1, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
72b7b31db250f20b90730d2888e6a554b434a407johanengelen else
06cd6b0ab2dbe286184e35d1078bab18c966b0d2jfbarraud this->attach(*label_widget , 0, 1, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
790674255fb54e588b4b6d73ee9e15050b45d1a4johanengelen start_col = 1;
790674255fb54e588b4b6d73ee9e15050b45d1a4johanengelen }
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen else
2b2321eb83f7bd0173589734d6f40b4fe90961f9helix start_col = 0;
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen
f555c315692d0a6b221636e8a7004fe9eda0b2cbcilix if (start_col == 0 && indent) //indent this widget
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen {
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen Gtk::Alignment* alignment = Gtk::manage(new Gtk::Alignment());
b62895f15526ccefdf1e274c49c02aa043895ee9johanengelen alignment->set_padding(0, 0, 12, 0);
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen alignment->add(*w);
3515994554d167522343ce57417648b39370ccabcilix this->attach(*alignment, start_col, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::AttachOptions(), 0, 0);
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen }
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen else
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen {
ecf048161ae0284d01d34ca5844204775c0d3fdecilix this->attach(*w, start_col, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::AttachOptions(), 0, 0);
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen }
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen if (suffix != "")
afa1e71af5a64b54df797ac1f0bcf32c6613b371johanengelen {
9de5f3bfa8e35ad5e6adcd6eaad4d0d49e7043a3johanengelen Gtk::Label* suffix_widget = Gtk::manage(new Gtk::Label(suffix , Gtk::ALIGN_LEFT , Gtk::ALIGN_CENTER, true));
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix if (expand_widget)
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen this->attach(*suffix_widget, 2, 3, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen else
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen ((Gtk::HBox*)w)->pack_start(*suffix_widget,false,false);
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen }
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen if (tip != "")
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen {
032f369baeef7d4a3b8769997df5dcd6dd874830jfbarraud widget.set_tooltip_text (tip);
3533ac02ef26a49e50514b619886467fd53c28fbjohanengelen }
4d2f452da50c83a3bced2bab8cb9e2b287c6efd1johanengelen
3533ac02ef26a49e50514b619886467fd53c28fbjohanengelen}
4daaa4a6cb870ab0b4f6fbd66943a7535535f1adjohanengelen
1ba2d157b7006f2f1a6043bc29e9c66be6386373johanengelenvoid DialogPage::add_group_header(Glib::ustring name)
0c4410dc5d53461e85445298c1f5d08d2d823c98jfbarraud{
3cb0f0262354a11d123e45ad10b027bebf957e46jfbarraud int row = this->property_n_rows();
822f89451bdca5665d48668154c774a45ec30c85jfbarraud if (name != "")
a2887d4a3493b24349a0f1390ed069ca1d2b1d61JazzyNico {
a2887d4a3493b24349a0f1390ed069ca1d2b1d61JazzyNico Gtk::Label* label_widget = Gtk::manage(new Gtk::Label(Glib::ustring(/*"<span size='large'>*/"<b>") + name +
a2887d4a3493b24349a0f1390ed069ca1d2b1d61JazzyNico Glib::ustring("</b>"/*</span>"*/) , Gtk::ALIGN_LEFT , Gtk::ALIGN_CENTER, true));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm label_widget->set_use_markup(true);
72b7b31db250f20b90730d2888e6a554b434a407johanengelen this->attach(*label_widget , 0, 4, row, row + 1, Gtk::FILL, Gtk::AttachOptions(), 0, 0);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (row != 1)
a45e91fd09273632e9acf849bb72621832156f07cilix this->set_row_spacing(row - 1, 18);
494c671e141564431d7d05f141c885d9a2789db5cilix }
a45e91fd09273632e9acf849bb72621832156f07cilix}
eac94793745a61429b52a4b489e148737d091749cilix
a45e91fd09273632e9acf849bb72621832156f07cilixvoid DialogPage::set_tip(Gtk::Widget& widget, Glib::ustring const &tip)
a45e91fd09273632e9acf849bb72621832156f07cilix{
a45e91fd09273632e9acf849bb72621832156f07cilix widget.set_tooltip_text (tip);
8791d7447034c34fdedc50f261bf5c89c34e59f5cilix}
8791d7447034c34fdedc50f261bf5c89c34e59f5cilix
a45e91fd09273632e9acf849bb72621832156f07cilixvoid PrefCheckButton::init(Glib::ustring const &label, Glib::ustring const &prefs_path,
a45e91fd09273632e9acf849bb72621832156f07cilix bool default_value)
a45e91fd09273632e9acf849bb72621832156f07cilix{
a45e91fd09273632e9acf849bb72621832156f07cilix _prefs_path = prefs_path;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->set_label(label);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->set_active( prefs->getBool(_prefs_path, default_value) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
8c39cbeab9949a0a7d6ae66b768a7352019e42f8johanengelenvoid PrefCheckButton::on_toggled()
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen{
29f9623ba77fc735b89765ae3a13e0c06aabafcecilix if (this->is_visible()) //only take action if the user toggled it
072916d0ef7dccd696b59381f50bcf776abccefbjohanengelen {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen prefs->setBool(_prefs_path, this->get_active());
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud }
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen}
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud
06cd6b0ab2dbe286184e35d1078bab18c966b0d2jfbarraudvoid PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &prefs_path,
06cd6b0ab2dbe286184e35d1078bab18c966b0d2jfbarraud Glib::ustring const &string_value, bool default_value, PrefRadioButton* group_member)
6c3e745a94ef6b25a4ef9f018d350a7535aa45afTed Gould{
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud _prefs_path = prefs_path;
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen _value_type = VAL_STRING;
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud _string_value = string_value;
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud (void)default_value;
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen this->set_label(label);
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud if (group_member)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Gtk::RadioButtonGroup rbg = group_member->get_group();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->set_group(rbg);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Glib::ustring val = prefs->getString(_prefs_path);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen if ( !val.empty() )
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen this->set_active(val == _string_value);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen else
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen this->set_active( false );
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen}
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen
8d9f5d586a04809427ce1df284a5720112177991cilixvoid PrefRadioButton::init(Glib::ustring const &label, Glib::ustring const &prefs_path,
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen int int_value, bool default_value, PrefRadioButton* group_member)
8d9f5d586a04809427ce1df284a5720112177991cilix{
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix _prefs_path = prefs_path;
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen _value_type = VAL_INT;
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix _int_value = int_value;
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak this->set_label(label);
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak if (group_member)
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak {
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen Gtk::RadioButtonGroup rbg = group_member->get_group();
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen this->set_group(rbg);
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen }
f4db63be4e929f4706410914295deccaceea19cdcilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f4db63be4e929f4706410914295deccaceea19cdcilix if (default_value)
f4db63be4e929f4706410914295deccaceea19cdcilix this->set_active( prefs->getInt(_prefs_path, int_value) == _int_value );
ab99111a42436818e6902e044c8f3af2b724263bcilix else
ab99111a42436818e6902e044c8f3af2b724263bcilix this->set_active( prefs->getInt(_prefs_path, int_value + 1) == _int_value );
ab99111a42436818e6902e044c8f3af2b724263bcilix}
76db360f5f052775326e6d406b9e1e9e2966e11acilix
76db360f5f052775326e6d406b9e1e9e2966e11acilixvoid PrefRadioButton::on_toggled()
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix{
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix this->changed_signal.emit(this->get_active());
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
3d0482af18ffb591c1d8ddecf516629e1bcd2ae4cilix
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix if (this->is_visible() && this->get_active() ) //only take action if toggled by user (to active)
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix {
64aee804a6a47424f7994e60558351b8cf2ea4dbcilix if ( _value_type == VAL_STRING )
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix prefs->setString(_prefs_path, _string_value);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix else if ( _value_type == VAL_INT )
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix prefs->setInt(_prefs_path, _int_value);
044d712d4d03f8354962d54e47cfac2346a69ccccilix }
044d712d4d03f8354962d54e47cfac2346a69ccccilix}
044d712d4d03f8354962d54e47cfac2346a69ccccilix
61cfd957cd023c4f432ea0c7307784a56bf978e9cilixvoid PrefSpinButton::init(Glib::ustring const &prefs_path,
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix double lower, double upper, double step_increment, double /*page_increment*/,
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix double default_value, bool is_int, bool is_percent)
2f5c0701b333a695eedb1680beb1adf95c0723dacilix{
2f5c0701b333a695eedb1680beb1adf95c0723dacilix _prefs_path = prefs_path;
2f5c0701b333a695eedb1680beb1adf95c0723dacilix _is_int = is_int;
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen _is_percent = is_percent;
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
add2ffae3c4686b50d888775bbdf083a4726a210johanengelen double value;
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen if (is_int) {
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen if (is_percent) {
0a75b58e47d3de42550c4f7960e253ea3befc09ajohanengelen value = 100 * prefs->getDoubleLimited(prefs_path, default_value, lower/100.0, upper/100.0);
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix } else {
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix value = (double) prefs->getIntLimited(prefs_path, (int) default_value, (int) lower, (int) upper);
4afe3fc6b9c122bc5c02b27aea3845ba41384d2acilix }
ecf048161ae0284d01d34ca5844204775c0d3fdecilix } else {
ecf048161ae0284d01d34ca5844204775c0d3fdecilix value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper);
ecf048161ae0284d01d34ca5844204775c0d3fdecilix }
3515994554d167522343ce57417648b39370ccabcilix
3515994554d167522343ce57417648b39370ccabcilix this->set_range (lower, upper);
3515994554d167522343ce57417648b39370ccabcilix this->set_increments (step_increment, 0);
790674255fb54e588b4b6d73ee9e15050b45d1a4johanengelen this->set_value (value);
790674255fb54e588b4b6d73ee9e15050b45d1a4johanengelen this->set_width_chars(6);
790674255fb54e588b4b6d73ee9e15050b45d1a4johanengelen if (is_int)
081a89987d4cb46e707c9dd5648a7a24a01a750djfbarraud this->set_digits(0);
081a89987d4cb46e707c9dd5648a7a24a01a750djfbarraud else if (step_increment < 0.1)
081a89987d4cb46e707c9dd5648a7a24a01a750djfbarraud this->set_digits(4);
afa1e71af5a64b54df797ac1f0bcf32c6613b371johanengelen else
afa1e71af5a64b54df797ac1f0bcf32c6613b371johanengelen this->set_digits(2);
afa1e71af5a64b54df797ac1f0bcf32c6613b371johanengelen
b62895f15526ccefdf1e274c49c02aa043895ee9johanengelen}
b62895f15526ccefdf1e274c49c02aa043895ee9johanengelen
b62895f15526ccefdf1e274c49c02aa043895ee9johanengelenvoid PrefSpinButton::on_value_changed()
4fe8248cd521387d0829c423bf4492e2cbdfd7cdJohan Engelen{
4fe8248cd521387d0829c423bf4492e2cbdfd7cdJohan Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4fe8248cd521387d0829c423bf4492e2cbdfd7cdJohan Engelen if (this->is_visible()) //only take action if user changed value
05e1ec4d6f1ccc3a0db3cc13e8a3b18489714f14Johan Engelen {
05e1ec4d6f1ccc3a0db3cc13e8a3b18489714f14Johan Engelen if (_is_int) {
05e1ec4d6f1ccc3a0db3cc13e8a3b18489714f14Johan Engelen if (_is_percent) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setDouble(_prefs_path, this->get_value()/100.0);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm } else {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setInt(_prefs_path, (int) this->get_value());
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm } else {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setDouble(_prefs_path, this->get_value());
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid PrefSpinUnit::init(Glib::ustring const &prefs_path,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm double lower, double upper, double step_increment,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm double default_value, UnitType unit_type, Glib::ustring const &default_unit)
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz{
6656f193fdace606d1b162d6dea0223bc295f0a6cilix _prefs_path = prefs_path;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix _is_percent = (unit_type == UNIT_TYPE_DIMENSIONLESS);
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz
6656f193fdace606d1b162d6dea0223bc295f0a6cilix resetUnitType(unit_type);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix setUnit(default_unit);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix setRange (lower, upper); /// @fixme this disregards changes of units
07b7f1aaaf1087716e784a50cf574a059f7018d3Jon A. Cruz setIncrements (step_increment, 0);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix if (step_increment < 0.1) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix setDigits(4);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix } else {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix setDigits(2);
f4ce66b44581cea80a736cf20244c0539a7525daJohan B. C. Engelen }
6656f193fdace606d1b162d6dea0223bc295f0a6cilix
6656f193fdace606d1b162d6dea0223bc295f0a6cilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
6656f193fdace606d1b162d6dea0223bc295f0a6cilix double value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix Glib::ustring unitstr = prefs->getUnit(prefs_path);
09ba3247163582bf2e30e17c4c154aa259ce038acilix if (unitstr.length() == 0) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix unitstr = default_unit;
6656f193fdace606d1b162d6dea0223bc295f0a6cilix // write the assumed unit to preferences:
6656f193fdace606d1b162d6dea0223bc295f0a6cilix prefs->setDoubleUnit(_prefs_path, value, unitstr);
6656f193fdace606d1b162d6dea0223bc295f0a6cilix }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm setValue(value, unitstr);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen signal_value_changed().connect_notify(sigc::mem_fun(*this, &PrefSpinUnit::on_my_value_changed));
71146abe8aba032d73788a625fee5769a581bd3ccilix}
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
fbb4eb8b63e74d9441220a73a8ca858425be4bd4johanengelenvoid PrefSpinUnit::on_my_value_changed()
9ce14357bb94b9dd92ad40bf43ef435a257b355acilix{
c27006137a3ad49e074b97b3297db753e1ac8eefcilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
c27006137a3ad49e074b97b3297db753e1ac8eefcilix if (getWidget()->is_visible()) //only take action if user changed value
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
71146abe8aba032d73788a625fee5769a581bd3ccilix prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr);
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmconst double ZoomCorrRuler::textsize = 7;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmconst double ZoomCorrRuler::textpadding = 5;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmZoomCorrRuler::ZoomCorrRuler(int width, int height) :
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce _unitconv(1.0),
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen _border(5)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
72b7b31db250f20b90730d2888e6a554b434a407johanengelen set_size(width, height);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid ZoomCorrRuler::set_size(int x, int y)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _min_width = x;
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix _height = y;
507f5de177a9e789927e7ac3e80ac05b27720084Johan B. C. Engelen set_size_request(x + _border*2, y + _border*2);
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix}
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix// The following two functions are borrowed from 2geom's toy-framework-2; if they are useful in
77a4a003111bd5cfb771d4849801c898aeb889b0cilix// other locations, we should perhaps make them (or adapted versions of them) publicly available
77a4a003111bd5cfb771d4849801c898aeb889b0cilixstatic void
77a4a003111bd5cfb771d4849801c898aeb889b0cilixdraw_text(cairo_t *cr, Geom::Point loc, const char* txt, bool bottom = false,
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix double fontsize = ZoomCorrRuler::textsize, std::string fontdesc = "Sans") {
a39c187369a59e887255e3f704a3ababf2b10678Johan B. C. Engelen PangoLayout* layout = pango_cairo_create_layout (cr);
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix pango_layout_set_text(layout, txt, -1);
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix
262d0c3f05130d86368d95f110aa8ccab5f83e5ccilix // set font and size
77a4a003111bd5cfb771d4849801c898aeb889b0cilix std::ostringstream sizestr;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix sizestr << fontsize;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix fontdesc = fontdesc + " " + sizestr.str();
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk PangoFontDescription *font_desc = pango_font_description_from_string(fontdesc.c_str());
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen pango_layout_set_font_description(layout, font_desc);
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk pango_font_description_free (font_desc);
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk PangoRectangle logical_extent;
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk pango_layout_get_pixel_extents(layout, NULL, &logical_extent);
77a4a003111bd5cfb771d4849801c898aeb889b0cilix cairo_move_to(cr, loc[Geom::X], loc[Geom::Y] - (bottom ? logical_extent.height : 0));
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix pango_cairo_show_layout(cr, layout);
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix}
494c671e141564431d7d05f141c885d9a2789db5cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilixstatic void
77a4a003111bd5cfb771d4849801c898aeb889b0cilixdraw_number(cairo_t *cr, Geom::Point pos, double num) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix std::ostringstream number;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix number << num;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix draw_text(cr, pos, number.str().c_str(), true);
77a4a003111bd5cfb771d4849801c898aeb889b0cilix}
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix/*
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * \arg dist The distance between consecutive minor marks
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * \arg major_interval Number of marks after which to draw a major mark
77a4a003111bd5cfb771d4849801c898aeb889b0cilix */
77a4a003111bd5cfb771d4849801c898aeb889b0cilixvoid
494c671e141564431d7d05f141c885d9a2789db5cilixZoomCorrRuler::draw_marks(Cairo::RefPtr<Cairo::Context> cr, double dist, int major_interval) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
77a4a003111bd5cfb771d4849801c898aeb889b0cilix const double zoomcorr = prefs->getDouble("/options/zoomcorrection/value", 1.0);
77a4a003111bd5cfb771d4849801c898aeb889b0cilix double mark = 0;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix int i = 0;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix while (mark <= _drawing_width) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix cr->move_to(mark, _height);
494c671e141564431d7d05f141c885d9a2789db5cilix if ((i % major_interval) == 0) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix // major mark
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk cr->line_to(mark, 0);
97a20864afec63a0b7bb757b628ee2ae596cf648cilix Geom::Point textpos(mark + 3, ZoomCorrRuler::textsize + ZoomCorrRuler::textpadding);
97a20864afec63a0b7bb757b628ee2ae596cf648cilix draw_number(cr->cobj(), textpos, dist * i);
97a20864afec63a0b7bb757b628ee2ae596cf648cilix } else {
97a20864afec63a0b7bb757b628ee2ae596cf648cilix // minor mark
97a20864afec63a0b7bb757b628ee2ae596cf648cilix cr->line_to(mark, ZoomCorrRuler::textsize + 2 * ZoomCorrRuler::textpadding);
97a20864afec63a0b7bb757b628ee2ae596cf648cilix }
97a20864afec63a0b7bb757b628ee2ae596cf648cilix mark += dist * zoomcorr / _unitconv;
97a20864afec63a0b7bb757b628ee2ae596cf648cilix ++i;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix }
77a4a003111bd5cfb771d4849801c898aeb889b0cilix}
77a4a003111bd5cfb771d4849801c898aeb889b0cilix
c27006137a3ad49e074b97b3297db753e1ac8eefcilixvoid
77a4a003111bd5cfb771d4849801c898aeb889b0cilixZoomCorrRuler::redraw() {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix Glib::RefPtr<Gdk::Window> window = get_window();
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
c27006137a3ad49e074b97b3297db753e1ac8eefcilix
77a4a003111bd5cfb771d4849801c898aeb889b0cilix int w, h;
77a4a003111bd5cfb771d4849801c898aeb889b0cilix window->get_size(w, h);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _drawing_width = w - _border * 2;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->set_source_rgb(1.0, 1.0, 1.0);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->set_fill_rule(Cairo::FILL_RULE_WINDING);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->rectangle(0, 0, w, _height + _border*2);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->fill();
b802808a0226a87371021393c4f1da776aa6a6adjohanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->set_source_rgb(0.0, 0.0, 0.0);
b802808a0226a87371021393c4f1da776aa6a6adjohanengelen cr->set_line_width(0.5);
dda97aeba7480d08320ebceecae13b8531db1b81johanengelen
a2fbdfc8e80d3d1845bf0d5df989726ae2ffd5bfjohanengelen cr->translate(_border, _border); // so that we have a small white border around the ruler
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->move_to (0, _height);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm cr->line_to (_drawing_width, _height);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Glib::ustring abbr = prefs->getString("/options/zoomcorrection/unit");
46c4893a7458eda6edcd064121bc000634af7a09johanengelen if (abbr == "cm") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 0.1, 10);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "ft") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 1/12.0, 12);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "in") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 0.25, 4);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "m") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 1/10.0, 10);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "mm") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 10, 10);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "pc") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 1, 10);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "pt") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 10, 10);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else if (abbr == "px") {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 10, 10);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen } else {
46c4893a7458eda6edcd064121bc000634af7a09johanengelen draw_marks(cr, 1, 1);
46c4893a7458eda6edcd064121bc000634af7a09johanengelen }
46c4893a7458eda6edcd064121bc000634af7a09johanengelen cr->stroke();
46c4893a7458eda6edcd064121bc000634af7a09johanengelen}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmbool
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmZoomCorrRuler::on_expose_event(GdkEventExpose */*event*/) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->redraw();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return true;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmZoomCorrRulerSlider::on_slider_value_changed()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this->is_visible() || freeze) //only take action if user changed value
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm freeze = true;
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setDouble("/options/zoomcorrection/value", _slider.get_value() / 100.0);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen _sb.set_value(_slider.get_value());
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen _ruler.redraw();
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen freeze = false;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelenvoid
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruzZoomCorrRulerSlider::on_spinbutton_value_changed()
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (this->is_visible() || freeze) //only take action if user changed value
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen freeze = true;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setDouble("/options/zoomcorrection/value", _sb.get_value() / 100.0);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen _slider.set_value(_sb.get_value());
84d6d1f7365e49f2936df9df890ce49d2c000ce2Kris _ruler.redraw();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm freeze = false;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
0fc5ce7045233dae7e15fdc86774370f1b1d73cbjohanengelenZoomCorrRulerSlider::on_unit_changed() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (GPOINTER_TO_INT(_unit.get_data("sensitive")) == 0) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen // when the unit menu is initialized, the unit is set to the default but
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen // it needs to be reset later so we don't perform the change in this case
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen }
2d107ef9730aff3f4d776ae0c2f7d983e289ce02joncruz Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setString("/options/zoomcorrection/unit", _unit.getUnitAbbr());
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm double conv = _unit.getConversion(_unit.getUnitAbbr(), "px");
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _ruler.set_unit_conversion(conv);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (_ruler.is_visible()) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen _ruler.redraw();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmZoomCorrRulerSlider::init(int ruler_width, int ruler_height, double lower, double upper,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm double step_increment, double page_increment, double default_value)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm double value = prefs->getDoubleLimited("/options/zoomcorrection/value", default_value, lower, upper) * 100.0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix freeze = false;
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix _ruler.set_size(ruler_width, ruler_height);
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix _slider.set_size_request(_ruler.width(), -1);
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix _slider.set_range (lower, upper);
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix _slider.set_increments (step_increment, page_increment);
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix _slider.set_value (value);
797bee69297bbdd86c5cff2e0771a71d1e2ac69dcilix _slider.set_digits(2);
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix _slider.signal_value_changed().connect(sigc::mem_fun(*this, &ZoomCorrRulerSlider::on_slider_value_changed));
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix _sb.signal_value_changed().connect(sigc::mem_fun(*this, &ZoomCorrRulerSlider::on_spinbutton_value_changed));
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix _unit.signal_changed().connect(sigc::mem_fun(*this, &ZoomCorrRulerSlider::on_unit_changed));
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix _sb.set_range (lower, upper);
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix _sb.set_increments (step_increment, 0);
25ad3718fb4b96b39930af8e043c8ee1e624fd10cilix _sb.set_value (value);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix _sb.set_digits(2);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix _unit.set_data("sensitive", GINT_TO_POINTER(0));
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix _unit.setUnitType(UNIT_TYPE_LINEAR);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix _unit.set_data("sensitive", GINT_TO_POINTER(1));
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen _unit.setUnit(prefs->getString("/options/zoomcorrection/unit"));
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix Gtk::Table *table = Gtk::manage(new Gtk::Table());
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix Gtk::Alignment *alignment1 = Gtk::manage(new Gtk::Alignment(0.5,1,0,0));
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix Gtk::Alignment *alignment2 = Gtk::manage(new Gtk::Alignment(0.5,1,0,0));
a0f7fce08805ee4c0e78577d34d914e6d6d789d1scislac alignment1->add(_sb);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix alignment2->add(_unit);
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
bb78cf2c3a2ee8ea2c98433128556847f03f5799cilix table->attach(_slider, 0, 1, 0, 1);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix table->attach(*alignment1, 1, 2, 0, 1, static_cast<Gtk::AttachOptions>(0));
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix table->attach(_ruler, 0, 1, 1, 2);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix table->attach(*alignment2, 1, 2, 1, 2, static_cast<Gtk::AttachOptions>(0));
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
3160bbbab034cde9669d9dbe736bd834b9cb0352Abhishek Sharma Public this->pack_start(*table, Gtk::PACK_EXPAND_WIDGET);
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix}
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
732fb09f9c502000068a77667c3356cbbd5d39d5cilixvoid
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilixPrefSlider::on_slider_value_changed()
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix{
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix if (this->is_visible() || freeze) //only take action if user changed value
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix {
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix freeze = true;
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
732fb09f9c502000068a77667c3356cbbd5d39d5cilix prefs->setDouble(_prefs_path, _slider.get_value());
732fb09f9c502000068a77667c3356cbbd5d39d5cilix _sb.set_value(_slider.get_value());
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix freeze = false;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix }
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix}
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilixvoid
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilixPrefSlider::on_spinbutton_value_changed()
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix{
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix if (this->is_visible() || freeze) //only take action if user changed value
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen {
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix freeze = true;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix prefs->setDouble(_prefs_path, _sb.get_value());
2e2b8bd323e3693f9d86f545ce049d3f1b45d1c2cilix _slider.set_value(_sb.get_value());
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen freeze = false;
73d455c08e8062e257dd052d2d690b9300434351cilix }
73d455c08e8062e257dd052d2d690b9300434351cilix}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
5cf332777b4c27336d64c273ac63bce3ee27a53dAlex Valavanisvoid
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmPrefSlider::init(Glib::ustring const &prefs_path,
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen double lower, double upper, double step_increment, double page_increment, double default_value, int digits)
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen{
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen _prefs_path = prefs_path;
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen double value = prefs->getDoubleLimited(prefs_path, default_value, lower, upper);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix freeze = false;
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix
5cf332777b4c27336d64c273ac63bce3ee27a53dAlex Valavanis _slider.set_range (lower, upper);
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix _slider.set_increments (step_increment, page_increment);
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix _slider.set_value (value);
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix _slider.set_digits(digits);
6192db41ab6e422a6193affbd3e68d61e184627bJon A. Cruz _slider.signal_value_changed().connect(sigc::mem_fun(*this, &PrefSlider::on_slider_value_changed));
5cf332777b4c27336d64c273ac63bce3ee27a53dAlex Valavanis
6192db41ab6e422a6193affbd3e68d61e184627bJon A. Cruz _sb.signal_value_changed().connect(sigc::mem_fun(*this, &PrefSlider::on_spinbutton_value_changed));
6192db41ab6e422a6193affbd3e68d61e184627bJon A. Cruz _sb.set_range (lower, upper);
6192db41ab6e422a6193affbd3e68d61e184627bJon A. Cruz _sb.set_increments (step_increment, 0);
96ef6190a69e8101a3c3a8ef8b01cb35042d1f9dcilix _sb.set_value (value);
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen _sb.set_digits(digits);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Gtk::Table *table = Gtk::manage(new Gtk::Table());
84d6d1f7365e49f2936df9df890ce49d2c000ce2Kris Gtk::Alignment *alignment1 = Gtk::manage(new Gtk::Alignment(0.5,1,0,0));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm alignment1->add(_sb);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm table->attach(_slider, 0, 1, 0, 1);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm table->attach(*alignment1, 1, 2, 0, 1, static_cast<Gtk::AttachOptions>(0));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->pack_start(*table, Gtk::PACK_EXPAND_WIDGET);
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruzvoid PrefCombo::init(Glib::ustring const &prefs_path,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Glib::ustring labels[], int values[], int num_items, int default_value)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz _prefs_path = prefs_path;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz int row = 0;
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz int value = prefs->getInt(_prefs_path, default_value);
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz
f68aabe351946119c80978525cd86564dd33e02fJon A. Cruz for (int i = 0 ; i < num_items; ++i)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->append_text(labels[i]);
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen _values.push_back(values[i]);
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen if (value == values[i])
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen row = i;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen }
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen this->set_active(row);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen}
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelenvoid PrefCombo::init(Glib::ustring const &prefs_path,
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Glib::ustring labels[], Glib::ustring values[], int num_items, Glib::ustring default_value)
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen{
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen _prefs_path = prefs_path;
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
84d6d1f7365e49f2936df9df890ce49d2c000ce2Kris int row = 0;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen Glib::ustring value = prefs->getString(_prefs_path);
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if(value.empty())
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen {
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen value = default_value;
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen for (int i = 0 ; i < num_items; ++i)
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen {
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak this->append_text(labels[i]);
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak _ustr_values.push_back(values[i]);
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak if (value == values[i])
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen row = i;
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak }
a0334366488989ef25fb812d7030d298c0917c96johanengelen this->set_active(row);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen}
a0334366488989ef25fb812d7030d298c0917c96johanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelenvoid PrefCombo::on_changed()
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen{
a0334366488989ef25fb812d7030d298c0917c96johanengelen if (this->is_visible()) //only take action if user changed value
a0334366488989ef25fb812d7030d298c0917c96johanengelen {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if(_values.size() > 0)
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen {
f9504c822b72a774b910958446fd1e730235b7cbjoncruz prefs->setInt(_prefs_path, _values[this->get_active_row_number()]);
a0334366488989ef25fb812d7030d298c0917c96johanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen else
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen {
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen prefs->setString(_prefs_path, _ustr_values[this->get_active_row_number()]);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen }
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen}
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelenvoid PrefEntryButtonHBox::init(Glib::ustring const &prefs_path,
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen bool visibility, Glib::ustring const &default_string)
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen{
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen _prefs_path = prefs_path;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen _default_string = default_string;
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedEntry = new Gtk::Entry();
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedButton = new Gtk::Button(_("Reset"));
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedEntry->set_invisible_char('*');
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedEntry->set_visibility(visibility);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedEntry->set_text(prefs->getString(_prefs_path));
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen this->pack_start(*relatedEntry);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen this->pack_start(*relatedButton);
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedButton->signal_clicked().connect(
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen sigc::mem_fun(*this, &PrefEntryButtonHBox::onRelatedButtonClickedCallback));
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen relatedEntry->signal_changed().connect(
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sigc::mem_fun(*this, &PrefEntryButtonHBox::onRelatedEntryChangedCallback));
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen}
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelenvoid PrefEntryButtonHBox::onRelatedEntryChangedCallback()
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen{
a39c187369a59e887255e3f704a3ababf2b10678Johan B. C. Engelen if (this->is_visible()) //only take action if user changed value
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen {
a69e3ca5fcc8acacf862c577620d75f472d58cecjohanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
a69e3ca5fcc8acacf862c577620d75f472d58cecjohanengelen prefs->setString(_prefs_path, relatedEntry->get_text());
a69e3ca5fcc8acacf862c577620d75f472d58cecjohanengelen }
a69e3ca5fcc8acacf862c577620d75f472d58cecjohanengelen}
a69e3ca5fcc8acacf862c577620d75f472d58cecjohanengelen
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelenvoid PrefEntryButtonHBox::onRelatedButtonClickedCallback()
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen{
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen if (this->is_visible()) //only take action if user changed value
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen {
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen Inkscape::Preferences *prefs = Inkscape::Preferences::get();
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen prefs->setString(_prefs_path, _default_string);
84d6d1f7365e49f2936df9df890ce49d2c000ce2Kris relatedEntry->set_text(_default_string);
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen }
bdd7add6c064afee52d2eabeaa18f745430e5a4djohanengelen}
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelenvoid PrefEntryFileButtonHBox::init(Glib::ustring const &prefs_path,
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen bool visibility)
42ba1b712b7b430669fc49aa9facb439181081becilix{
507f5de177a9e789927e7ac3e80ac05b27720084Johan B. C. Engelen _prefs_path = prefs_path;
42ba1b712b7b430669fc49aa9facb439181081becilix Inkscape::Preferences *prefs = Inkscape::Preferences::get();
42ba1b712b7b430669fc49aa9facb439181081becilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen relatedEntry = new Gtk::Entry();
42ba1b712b7b430669fc49aa9facb439181081becilix relatedEntry->set_invisible_char('*');
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen relatedEntry->set_visibility(visibility);
42ba1b712b7b430669fc49aa9facb439181081becilix relatedEntry->set_text(prefs->getString(_prefs_path));
6c3e745a94ef6b25a4ef9f018d350a7535aa45afTed Gould
507f5de177a9e789927e7ac3e80ac05b27720084Johan B. C. Engelen relatedButton = new Gtk::Button();
6c3e745a94ef6b25a4ef9f018d350a7535aa45afTed Gould Gtk::HBox* pixlabel = new Gtk::HBox(false, 3);
42ba1b712b7b430669fc49aa9facb439181081becilix Gtk::Image *im = new Gtk::Image(Gtk::StockID(Gtk::Stock::INDEX),
42ba1b712b7b430669fc49aa9facb439181081becilix Gtk::ICON_SIZE_BUTTON);
42ba1b712b7b430669fc49aa9facb439181081becilix pixlabel->pack_start(*im);
42ba1b712b7b430669fc49aa9facb439181081becilix Gtk::Label *l = new Gtk::Label();
42ba1b712b7b430669fc49aa9facb439181081becilix l->set_markup_with_mnemonic(_("_Browse..."));
42ba1b712b7b430669fc49aa9facb439181081becilix pixlabel->pack_start(*l);
42ba1b712b7b430669fc49aa9facb439181081becilix relatedButton->add(*pixlabel);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->pack_end(*relatedButton, false, false, 4);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm this->pack_start(*relatedEntry, true, true, 0);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm relatedButton->signal_clicked().connect(
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sigc::mem_fun(*this, &PrefEntryFileButtonHBox::onRelatedButtonClickedCallback));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm relatedEntry->signal_changed().connect(
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sigc::mem_fun(*this, &PrefEntryFileButtonHBox::onRelatedEntryChangedCallback));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid PrefEntryFileButtonHBox::onRelatedEntryChangedCallback()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this->is_visible()) //only take action if user changed value
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setString(_prefs_path, relatedEntry->get_text());
}
}
static Inkscape::UI::Dialog::FileOpenDialog * selectPrefsFileInstance = NULL;
void PrefEntryFileButtonHBox::onRelatedButtonClickedCallback()
{
if (this->is_visible()) //only take action if user changed value
{
//# Get the current directory for finding files
static Glib::ustring open_path;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
Glib::ustring attr = prefs->getString(_prefs_path);
if (!attr.empty()) open_path = attr;
//# Test if the open_path directory exists
if (!Inkscape::IO::file_test(open_path.c_str(),
(GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)))
open_path = "";
#ifdef WIN32
//# If no open path, default to our win32 documents folder
if (open_path.empty())
{
// The path to the My Documents folder is read from the
// value "HKEY_CURRENT_USER\Software\Windows\CurrentVersion\Explorer\Shell Folders\Personal"
HKEY key = NULL;
if(RegOpenKeyExA(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
{
WCHAR utf16path[_MAX_PATH];
DWORD value_type;
DWORD data_size = sizeof(utf16path);
if(RegQueryValueExW(key, L"Personal", NULL, &value_type,
(BYTE*)utf16path, &data_size) == ERROR_SUCCESS)
{
g_assert(value_type == REG_SZ);
gchar *utf8path = g_utf16_to_utf8(
(const gunichar2*)utf16path, -1, NULL, NULL, NULL);
if(utf8path)
{
open_path = Glib::ustring(utf8path);
g_free(utf8path);
}
}
}
}
#endif
//# If no open path, default to our home directory
if (open_path.empty())
{
open_path = g_get_home_dir();
open_path.append(G_DIR_SEPARATOR_S);
}
//# Create a dialog
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (!selectPrefsFileInstance) {
selectPrefsFileInstance =
Inkscape::UI::Dialog::FileOpenDialog::create(
*desktop->getToplevel(),
open_path,
Inkscape::UI::Dialog::EXE_TYPES,
_("Select a bitmap editor"));
}
//# Show the dialog
bool const success = selectPrefsFileInstance->show();
if (!success) {
return;
}
//# User selected something. Get name and type
Glib::ustring fileName = selectPrefsFileInstance->getFilename();
if (!fileName.empty())
{
Glib::ustring newFileName = Glib::filename_to_utf8(fileName);
if ( newFileName.size() > 0)
open_path = newFileName;
else
g_warning( "ERROR CONVERTING OPEN FILENAME TO UTF-8" );
prefs->setString(_prefs_path, open_path);
}
relatedEntry->set_text(fileName);
}
}
void PrefFileButton::init(Glib::ustring const &prefs_path)
{
_prefs_path = prefs_path;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
select_filename(Glib::filename_from_utf8(prefs->getString(_prefs_path)));
signal_selection_changed().connect(sigc::mem_fun(*this, &PrefFileButton::onFileChanged));
}
void PrefFileButton::onFileChanged()
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setString(_prefs_path, Glib::filename_to_utf8(get_filename()));
}
void PrefEntry::init(Glib::ustring const &prefs_path, bool visibility)
{
_prefs_path = prefs_path;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
this->set_invisible_char('*');
this->set_visibility(visibility);
this->set_text(prefs->getString(_prefs_path));
}
void PrefEntry::on_changed()
{
if (this->is_visible()) //only take action if user changed value
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setString(_prefs_path, this->get_text());
}
}
void PrefColorPicker::init(Glib::ustring const &label, Glib::ustring const &prefs_path,
guint32 default_rgba)
{
_prefs_path = prefs_path;
_title = label;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
this->setRgba32( prefs->getInt(_prefs_path, (int)default_rgba) );
}
void PrefColorPicker::on_changed (guint32 rgba)
{
if (this->is_visible()) //only take action if the user toggled it
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(_prefs_path, (int) rgba);
}
}
void PrefUnit::init(Glib::ustring const &prefs_path)
{
_prefs_path = prefs_path;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
setUnitType(UNIT_TYPE_LINEAR);
setUnit(prefs->getString(_prefs_path));
}
void PrefUnit::on_changed()
{
if (this->is_visible()) //only take action if user changed value
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setString(_prefs_path, getUnitAbbr());
}
}
} // namespace Widget
} // namespace UI
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :