From 2e44ac00ce01273776c52bf66673020cd7729d96 Mon Sep 17 00:00:00 2001 From: o__b Date: Fri, 21 Mar 2008 10:00:42 +0000 Subject: [PATCH] Added dialog to name new calligraphic profiles --- src/dialogs/Makefile_insert | 5 +- src/dialogs/calligraphic-profile-rename.cpp | 99 +++++++++++++++++++++ src/dialogs/calligraphic-profile-rename.h | 56 ++++++++++++ src/preferences-skeleton.h | 1 + src/widgets/toolbox.cpp | 64 ++++++++----- 5 files changed, 199 insertions(+), 26 deletions(-) create mode 100755 src/dialogs/calligraphic-profile-rename.cpp create mode 100755 src/dialogs/calligraphic-profile-rename.h 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 +#endif + +#include +#include + +#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 +#include +#include +#include + +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[] = " \n" " \n" " \n" +" \n" " \n" " \n" " (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(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 ); -- 2.30.2