summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAubanel Monnier <aubanel@gmail.com>2008-03-21 10:00:42 +0000
committero__b <o__b@users.sourceforge.net>2008-03-21 10:00:42 +0000
commite3deb7dd034f1bff2e02a5ec60f7ee7ac737087a (patch)
tree8b50eed7f54216ead35a7cfa5fabb3bae5791874 /src
parentReplace char buffer by std::string to prevent buffer overflow when computing ... (diff)
downloadinkscape-e3deb7dd034f1bff2e02a5ec60f7ee7ac737087a.tar.gz
inkscape-e3deb7dd034f1bff2e02a5ec60f7ee7ac737087a.zip
Added dialog to name new calligraphic
profiles (bzr r5142)
Diffstat (limited to 'src')
-rw-r--r--src/dialogs/Makefile_insert5
-rwxr-xr-xsrc/dialogs/calligraphic-profile-rename.cpp99
-rwxr-xr-xsrc/dialogs/calligraphic-profile-rename.h56
-rw-r--r--src/preferences-skeleton.h1
-rw-r--r--src/widgets/toolbox.cpp64
5 files changed, 199 insertions, 26 deletions
diff --git a/src/dialogs/Makefile_insert b/src/dialogs/Makefile_insert
index 05a077ab5..64e46b470 100644
--- a/src/dialogs/Makefile_insert
+++ b/src/dialogs/Makefile_insert
@@ -63,8 +63,9 @@ dialogs_libspdialogs_a_SOURCES = \
dialogs/unclump.cpp \
dialogs/unclump.h \
dialogs/iconpreview.cpp \
- dialogs/iconpreview.h
-
+ dialogs/iconpreview.h \
+ dialogs/calligraphic-profile-rename.cpp \
+ dialogs/calligraphic-profile-rename.cpp
# dialogs/sp-widget.c \
# dialogs/sp-widget.h \
diff --git a/src/dialogs/calligraphic-profile-rename.cpp b/src/dialogs/calligraphic-profile-rename.cpp
new file mode 100755
index 000000000..ae9a31c0e
--- /dev/null
+++ b/src/dialogs/calligraphic-profile-rename.cpp
@@ -0,0 +1,99 @@
+/**
+ *
+ * \brief Dialog for naming calligraphic profiles
+ *
+ * Author:
+ * Aubanel MONNIER
+ *
+ * Copyright (C) 2007 Aubanel MONNIER
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <glibmm/i18n.h>
+#include <gtkmm/stock.h>
+
+#include "desktop.h"
+#include "calligraphic-profile-rename.h"
+
+
+namespace Inkscape {
+namespace UI {
+namespace Dialogs {
+CalligraphicProfileDialog::CalligraphicProfileDialog(): _applied(false){
+ Gtk::VBox *mainVBox = get_vbox();
+ _layout_table.set_spacings(4);
+ _layout_table.resize (1, 2);
+
+ _profile_name_entry.set_activates_default(true);
+
+ _profile_name_label.set_label(_("Profile name:"));
+ _profile_name_label.set_alignment(1.0, 0.5);
+
+ _layout_table.attach(_profile_name_label,
+ 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
+ _layout_table.attach(_profile_name_entry,
+ 1, 2, 0, 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);
+ mainVBox->pack_start(_layout_table, false, false, 4);
+ // Buttons
+ _close_button.set_use_stock(true);
+ _close_button.set_label(Gtk::Stock::CANCEL.id);
+ _close_button.set_flags(Gtk::CAN_DEFAULT);
+
+ _apply_button.set_use_underline(true);
+ _apply_button.set_label(_("Save"));
+ _apply_button.set_flags(Gtk::CAN_DEFAULT);
+
+ _close_button.signal_clicked()
+ .connect(sigc::mem_fun(*this, &CalligraphicProfileDialog::_close));
+ _apply_button.signal_clicked()
+ .connect(sigc::mem_fun(*this, &CalligraphicProfileDialog::_apply));
+
+ signal_delete_event().connect(
+ sigc::bind_return(
+ sigc::hide(sigc::mem_fun(*this, &CalligraphicProfileDialog::_close)),
+ true
+ )
+ );
+
+ add_action_widget(_close_button, Gtk::RESPONSE_CLOSE);
+ add_action_widget(_apply_button, Gtk::RESPONSE_APPLY);
+
+ _apply_button.grab_default();
+
+ show_all_children();
+
+}
+
+void
+CalligraphicProfileDialog::_apply()
+{
+ _profile_name = _profile_name_entry.get_text();
+ _applied = true;
+ _close();
+}
+
+void
+CalligraphicProfileDialog::_close()
+{
+ this->Gtk::Dialog::hide();
+
+}
+
+void CalligraphicProfileDialog::show(SPDesktop *desktop){
+ CalligraphicProfileDialog &dial = instance();
+ dial._applied=false;
+ dial.set_modal(true);
+ desktop->setWindowTransient (dial.gobj());
+ dial.property_destroy_with_parent() = true;
+ // dial.Gtk::Dialog::show();
+ //dial.present();
+ dial.run();
+}
+
+
+}}}
diff --git a/src/dialogs/calligraphic-profile-rename.h b/src/dialogs/calligraphic-profile-rename.h
new file mode 100755
index 000000000..133d94a28
--- /dev/null
+++ b/src/dialogs/calligraphic-profile-rename.h
@@ -0,0 +1,56 @@
+/**
+ *
+ * \brief Dialog for naming calligraphic profiles
+ *
+ * Author:
+ * Aubanel MONNIER
+ *
+ * Copyright (C) 2007 Aubanel MONNIER
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_DIALOG_CALLIGRAPHIC_PROFILE_H
+#define INKSCAPE_DIALOG_CALLIGRAPHIC_PROFILE_H
+
+#include <gtkmm/dialog.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/label.h>
+#include <gtkmm/table.h>
+
+namespace Inkscape {
+ namespace UI {
+ namespace Dialogs {
+
+ class CalligraphicProfileDialog: public Gtk::Dialog {
+ public:
+ CalligraphicProfileDialog();
+ virtual ~CalligraphicProfileDialog(){} ;
+ static void show(SPDesktop *desktop);
+ static bool applied(){return instance()._applied;}
+ static Glib::ustring getProfileName() { return instance()._profile_name;}
+
+ Glib::ustring getName() const { return "CalligraphicProfileDialog"; }
+
+
+ protected:
+ void _close();
+ void _apply();
+
+ Gtk::Label _profile_name_label;
+ Gtk::Entry _profile_name_entry;
+ Gtk::Table _layout_table;
+ Gtk::Button _close_button;
+ Gtk::Button _apply_button;
+ Glib::ustring _profile_name;
+ bool _applied;
+ private:
+ static CalligraphicProfileDialog &instance(){static CalligraphicProfileDialog instance; return instance;}
+ CalligraphicProfileDialog(CalligraphicProfileDialog const &); // no copy
+ CalligraphicProfileDialog &operator=(CalligraphicProfileDialog const &); // no assign
+ };
+ }
+ }
+}
+
+#endif INKSCAPE_DIALOG_CALLIGRAPHIC_PROFILE_H
diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h
index e00510590..03e3dc487 100644
--- a/src/preferences-skeleton.h
+++ b/src/preferences-skeleton.h
@@ -76,6 +76,7 @@ static char const preferences_skeleton[] =
" <group id=\"cp1\" name=\"Marker\" mass=\"0.02\" wiggle=\"0.0\" angle=\"90.0\" width=\"15.0\" thinning=\"0.0\" tremor=\"0.0\" flatness=\"0.0\" cap_rounding=\"1.0\" tracebackground=\"0\" usepressure=\"0\" usetilt=\"0\" />\n"
" <group id=\"cp2\" name=\"Brush\" mass=\"0.02\" wiggle=\"0.25\" angle=\"45.0\" width=\"10.0\" thinning=\"-0.4\" tremor=\"0.0\" flatness=\"0.16\" cap_rounding=\".1\" tracebackground=\"0\" usepressure=\"1\" usetilt=\"1\" />\n"
" <group id=\"cp3\" name=\"Reed pen\" mass=\"0.02\" wiggle=\"0.0\" angle=\"20.0\" width=\"15.0\" thinning=\"0.0\" tremor=\"0.0\" flatness=\"1.0\" cap_rounding=\"0.0\" tracebackground=\"0\" usepressure=\"1\" usetilt=\"1\"/>\n"
+" <group id=\"cp4\" name=\"Mad brush\" usetilt=\"1\" tracebackground=\"0\" usepressure=\"1\" width=\"15\" cap_rounding=\"0.1\" flatness=\"0.16\" tremor=\"0.18\" thinning=\"-0.3\" angle=\"30\" wiggle=\"0.48\" mass=\"0.02\" />\n"
" </group>\n"
" </eventcontext>\n"
" <eventcontext id=\"text\" usecurrent=\"0\" gradientdrag=\"1\"\n"
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index c94138620..d9dcd795e 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -103,6 +103,8 @@
#include "svg/css-ostringstream.h"
+#include "calligraphic-profile-rename.h"
+
using Inkscape::UnitTracker;
typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop);
@@ -3432,67 +3434,78 @@ static void sp_ddc_tilt_state_changed( GtkToggleAction *act, GObject* tbl )
}
-#define PROFILE_FLOAT_SIZE 8
-#define PROFILE_BOOL_SIZE 3
+#define PROFILE_FLOAT_SIZE 7
+#define PROFILE_INT_SIZE 4
struct ProfileFloatElement {
char const *name;
double def;
double min;
double max;
};
-struct ProfileBoolElement {
+struct ProfileIntElement {
char const *name;
- bool def;
+ int def;
+ int min;
+ int max;
};
+
+
static ProfileFloatElement f_profile[PROFILE_FLOAT_SIZE] = {
{"mass",0.02, 0.0, 1.0},
{"wiggle",0.0, 0.0, 1.0},
{"angle",30.0, -90.0, 90.0},
- {"width",15.0, 1.0, 100.0},
{"thinning",0.1, -1.0, 1.0},
{"tremor",0.0, 0.0, 1.0},
{"flatness",0.9, 0.0, 1.0},
{"cap_rounding",0.0, 0.0, 5.0}
};
-static ProfileBoolElement b_profile[PROFILE_BOOL_SIZE] = {
- {"usepressure",true},
- {"tracebackground",false},
- {"usetilt",true},
+static ProfileIntElement i_profile[PROFILE_INT_SIZE] = {
+ {"width",15, 1, 100},
+ {"usepressure",1,0,1},
+ {"tracebackground",0,0,1},
+ {"usetilt",1,0,1},
};
static void sp_dcc_save_profile( GtkWidget */*widget*/, GObject *dataKludge ){
+ SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" );
+ if (! desktop) return;
- unsigned int new_index = pref_path_number_of_children("tools.calligraphic.preset");
+ Inkscape::UI::Dialogs::CalligraphicProfileDialog::show(desktop);
+ if ( ! Inkscape::UI::Dialogs::CalligraphicProfileDialog::applied()) return;
+ Glib::ustring profile_name = Inkscape::UI::Dialogs::CalligraphicProfileDialog::getProfileName();
+
+ unsigned int new_index = pref_path_number_of_children("tools.calligraphic.preset") +1;
gchar *profile_id = g_strdup_printf("dcc%d", new_index);
- gchar *profile_name = g_strdup_printf("Profile %d", new_index);
gchar *pref_path = create_pref("tools.calligraphic.preset",profile_id);
-
+
for (unsigned i = 0; i < PROFILE_FLOAT_SIZE; ++i) {
ProfileFloatElement const &pe = f_profile[i];
double v = prefs_get_double_attribute_limited("tools.calligraphic",pe.name, pe.def, pe.min, pe.max);
prefs_set_double_attribute(pref_path,pe.name,v);
- }
- for (unsigned i = 0; i < PROFILE_BOOL_SIZE; ++i) {
- ProfileBoolElement const &pe = b_profile[i];
- int v = prefs_get_int_attribute_limited("tools.calligraphic",pe.name, pe.def?1:0 ,0,1);
+ }
+ for (unsigned i = 0; i < PROFILE_INT_SIZE; ++i) {
+ ProfileIntElement const &pe = i_profile[i];
+ int v = prefs_get_int_attribute_limited("tools.calligraphic",pe.name, pe.def,pe.min, pe.max);
prefs_set_int_attribute(pref_path,pe.name,v);
- }
- prefs_set_string_attribute(pref_path,"name",profile_name);
+ }
+ prefs_set_string_attribute(pref_path,"name",profile_name.c_str());
EgeSelectOneAction* selector = static_cast<EgeSelectOneAction *>(g_object_get_data(dataKludge, "profile_selector"));
GtkListStore* model = GTK_LIST_STORE(ege_select_one_action_get_model(selector));
GtkTreeIter iter;
gtk_list_store_append( model, &iter );
- gtk_list_store_set( model, &iter, 0, profile_name, 1, new_index, -1 );
+ gtk_list_store_set( model, &iter, 0, profile_name.c_str(), 1, new_index, -1 );
free(profile_id);
- free(profile_name);
free(pref_path);
+
+ ege_select_one_action_set_active(selector, new_index);
}
+
static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject *dataKludge) {
gint preset_index = ege_select_one_action_get_active( act );
@@ -3508,16 +3521,16 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject *dataKludge)
gtk_adjustment_set_value(adj, v);
}
}
- for (unsigned i = 0; i < PROFILE_BOOL_SIZE; ++i) {
- ProfileBoolElement const &pe = b_profile[i];
- int v = prefs_get_int_attribute_limited(profile_name, pe.name, pe.def, 0, 1);
+ for (unsigned i = 0; i < PROFILE_INT_SIZE; ++i) {
+ ProfileIntElement const &pe = i_profile[i];
+ int v = prefs_get_int_attribute_limited(profile_name, pe.name, pe.def, pe.min, pe.max);
GtkToggleAction* toggle = static_cast<GtkToggleAction *>(g_object_get_data(dataKludge, pe.name));
if ( toggle ) {
gtk_toggle_action_set_active(toggle, v);
} else printf("No toggle");
}
free(profile_name);
- g_object_set_data(dataKludge, "profile_selector",act); //restor selector visibility
+ g_object_set_data(dataKludge, "profile_selector",act); //restore selector visibility
}
}
@@ -3729,6 +3742,7 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(sp_ddc_change_profile), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
g_object_set_data( holder, "profile_selector", act1 );
+
}
/*Save or delete calligraphic profile */
@@ -3738,6 +3752,8 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
_("Save current settings as new profile"),
GTK_STOCK_SAVE );
g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_dcc_save_profile), holder );
+
+
gtk_action_group_add_action( mainActions, act );
gtk_action_set_sensitive( act, TRUE );
g_object_set_data( holder, "profile_save_delete", act );