Code

Added dialog to name new calligraphic
authoro__b <o__b@users.sourceforge.net>
Fri, 21 Mar 2008 10:00:42 +0000 (10:00 +0000)
committero__b <o__b@users.sourceforge.net>
Fri, 21 Mar 2008 10:00:42 +0000 (10:00 +0000)
profiles

src/dialogs/Makefile_insert
src/dialogs/calligraphic-profile-rename.cpp [new file with mode: 0755]
src/dialogs/calligraphic-profile-rename.h [new file with mode: 0755]
src/preferences-skeleton.h
src/widgets/toolbox.cpp

index 05a077ab573906f03941db414f4c508ec17bf9f5..64e46b4704e5a373914b07d8b60156876f0ea10c 100644 (file)
@@ -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 (executable)
index 0000000..ae9a31c
--- /dev/null
@@ -0,0 +1,99 @@
+/**\r
+ *\r
+ * \brief  Dialog for naming calligraphic profiles\r
+ *\r
+ * Author:\r
+ *   Aubanel MONNIER \r
+ *\r
+ * Copyright (C) 2007 Aubanel MONNIER\r
+ *\r
+ * Released under GNU GPL.  Read the file 'COPYING' for more information\r
+ */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+# include <config.h>\r
+#endif\r
+\r
+#include <glibmm/i18n.h>\r
+#include <gtkmm/stock.h>\r
+\r
+#include "desktop.h"\r
+#include "calligraphic-profile-rename.h"\r
+\r
+\r
+namespace Inkscape {\r
+namespace UI {\r
+namespace Dialogs {\r
+CalligraphicProfileDialog::CalligraphicProfileDialog(): _applied(false){\r
+  Gtk::VBox *mainVBox = get_vbox();\r
+  _layout_table.set_spacings(4);\r
+  _layout_table.resize (1, 2);\r
+\r
+  _profile_name_entry.set_activates_default(true);\r
+\r
+  _profile_name_label.set_label(_("Profile name:"));\r
+  _profile_name_label.set_alignment(1.0, 0.5);\r
+  \r
+  _layout_table.attach(_profile_name_label,\r
+                      0, 1, 0, 1, Gtk::FILL, Gtk::FILL);\r
+  _layout_table.attach(_profile_name_entry,\r
+                      1, 2, 0, 1, Gtk::FILL | Gtk::EXPAND, Gtk::FILL);\r
+  mainVBox->pack_start(_layout_table, false, false, 4);\r
+  // Buttons\r
+  _close_button.set_use_stock(true);\r
+  _close_button.set_label(Gtk::Stock::CANCEL.id);\r
+  _close_button.set_flags(Gtk::CAN_DEFAULT);\r
+  \r
+  _apply_button.set_use_underline(true);\r
+  _apply_button.set_label(_("Save"));\r
+  _apply_button.set_flags(Gtk::CAN_DEFAULT);\r
+  \r
+  _close_button.signal_clicked()\r
+    .connect(sigc::mem_fun(*this, &CalligraphicProfileDialog::_close));\r
+  _apply_button.signal_clicked()\r
+    .connect(sigc::mem_fun(*this, &CalligraphicProfileDialog::_apply));\r
+  \r
+  signal_delete_event().connect(\r
+        sigc::bind_return(\r
+            sigc::hide(sigc::mem_fun(*this, &CalligraphicProfileDialog::_close)),\r
+            true\r
+        )\r
+    );\r
+\r
+  add_action_widget(_close_button, Gtk::RESPONSE_CLOSE);\r
+  add_action_widget(_apply_button, Gtk::RESPONSE_APPLY);\r
+\r
+  _apply_button.grab_default();\r
+\r
+  show_all_children();\r
+\r
+}\r
+\r
+void\r
+CalligraphicProfileDialog::_apply()\r
+{\r
+  _profile_name = _profile_name_entry.get_text();\r
+  _applied = true;\r
+  _close();\r
+}\r
+\r
+void\r
+CalligraphicProfileDialog::_close()\r
+{\r
+  this->Gtk::Dialog::hide();\r
+  \r
+}\r
+\r
+void CalligraphicProfileDialog::show(SPDesktop *desktop){\r
+  CalligraphicProfileDialog &dial = instance();\r
+  dial._applied=false;\r
+  dial.set_modal(true);\r
+  desktop->setWindowTransient (dial.gobj());\r
+  dial.property_destroy_with_parent() = true;\r
+  //  dial.Gtk::Dialog::show();\r
+  //dial.present();\r
+  dial.run();\r
+}\r
+\r
+\r
+}}}\r
diff --git a/src/dialogs/calligraphic-profile-rename.h b/src/dialogs/calligraphic-profile-rename.h
new file mode 100755 (executable)
index 0000000..133d94a
--- /dev/null
@@ -0,0 +1,56 @@
+/**\r
+ *\r
+ * \brief  Dialog for naming calligraphic profiles\r
+ *\r
+ * Author:\r
+ *   Aubanel MONNIER \r
+ *\r
+ * Copyright (C) 2007 Aubanel MONNIER\r
+ *\r
+ * Released under GNU GPL.  Read the file 'COPYING' for more information\r
+ */\r
+\r
+#ifndef INKSCAPE_DIALOG_CALLIGRAPHIC_PROFILE_H\r
+#define INKSCAPE_DIALOG_CALLIGRAPHIC_PROFILE_H\r
+\r
+#include <gtkmm/dialog.h>\r
+#include <gtkmm/entry.h>\r
+#include <gtkmm/label.h>\r
+#include <gtkmm/table.h>\r
+\r
+namespace Inkscape {\r
+  namespace UI {\r
+    namespace Dialogs {\r
+      \r
+      class  CalligraphicProfileDialog: public Gtk::Dialog {  \r
+      public:\r
+       CalligraphicProfileDialog();\r
+       virtual ~CalligraphicProfileDialog(){} ;\r
+       static void show(SPDesktop *desktop);\r
+       static bool applied(){return instance()._applied;}\r
+       static Glib::ustring getProfileName() { return instance()._profile_name;}\r
+\r
+       Glib::ustring getName() const { return "CalligraphicProfileDialog"; }\r
+\r
+       \r
+      protected:\r
+       void _close();\r
+       void _apply();\r
+\r
+       Gtk::Label        _profile_name_label;\r
+       Gtk::Entry        _profile_name_entry;\r
+       Gtk::Table        _layout_table;\r
+       Gtk::Button       _close_button;\r
+       Gtk::Button       _apply_button;\r
+       Glib::ustring _profile_name;\r
+       bool _applied;\r
+      private:\r
+       static CalligraphicProfileDialog &instance(){static CalligraphicProfileDialog instance; return instance;}\r
+       CalligraphicProfileDialog(CalligraphicProfileDialog const &); // no copy\r
+       CalligraphicProfileDialog &operator=(CalligraphicProfileDialog  const &); // no assign\r
+      };      \r
+    }\r
+  }\r
+}\r
+\r
+#endif INKSCAPE_DIALOG_CALLIGRAPHIC_PROFILE_H\r
index e00510590d511b5f73be33b870c11d64604fc829..03e3dc487d623f21f208268aa54001d02975fcc9 100644 (file)
@@ -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" 
index c9413862082b4504c3a402ce711003cf848a3639..d9dcd795ed76d2ac3e0250ac35b0cbdfa82b4d38 100644 (file)
 
 #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 );