Code

Initial cut of sliders in toolbars
authorjoncruz <joncruz@users.sourceforge.net>
Mon, 30 Jun 2008 07:40:18 +0000 (07:40 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Mon, 30 Jun 2008 07:40:18 +0000 (07:40 +0000)
src/ege-adjustment-action.cpp
src/ege-adjustment-action.h
src/widgets/toolbox.cpp

index 1983534df49797a5be255f22c04b245096315a11..2380e2e6bf669fbf15bdcc48444d995bba1bd51c 100644 (file)
@@ -46,6 +46,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtktoolitem.h>
 #include <gtk/gtkspinbutton.h>
+#include <gtk/gtkhscale.h>
 #include <gtk/gtkhbox.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkmisc.h>
@@ -80,6 +81,14 @@ static void egeAct_free_all_descriptions( EgeAdjustmentAction* action );
 static GtkActionClass* gParentClass = 0;
 static GQuark gDataName = 0;
 
+enum {
+    APPEARANCE_UNKNOWN = -1,
+    APPEARANCE_NONE = 0,
+    APPEARANCE_FULL,    // label, then all choices represented by separate buttons
+    APPEARANCE_COMPACT, // label, then choices in a drop-down menu
+    APPEARANCE_MINIMAL, // no label, just choices in a drop-down menu
+};
+
 typedef struct _EgeAdjustmentDescr EgeAdjustmentDescr;
 
 struct _EgeAdjustmentDescr
@@ -102,8 +111,10 @@ struct _EgeAdjustmentActionPrivate
     gdouble lastVal;
     gdouble step;
     gdouble page;
+    gint appearanceMode;
     gboolean transferFocus;
     GList* descriptions;
+    gchar* appearance;
 };
 
 #define EGE_ADJUSTMENT_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), EGE_ADJUSTMENT_ACTION_TYPE, EgeAdjustmentActionPrivate ) )
@@ -114,7 +125,8 @@ enum {
     PROP_CLIMB_RATE,
     PROP_DIGITS,
     PROP_SELFID,
-    PROP_TOOL_POST
+    PROP_TOOL_POST,
+    PROP_APPEARANCE
 };
 
 enum {
@@ -216,6 +228,14 @@ static void ege_adjustment_action_class_init( EgeAdjustmentActionClass* klass )
                                                                "Function for final adjustments",
                                                                (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
 
+        g_object_class_install_property( objClass,
+                                         PROP_APPEARANCE,
+                                         g_param_spec_string( "appearance",
+                                                              "Appearance hint",
+                                                              "A hint for how to display",
+                                                              "",
+                                                              (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
+
         g_type_class_add_private( klass, sizeof(EgeAdjustmentActionClass) );
     }
 }
@@ -235,8 +255,10 @@ static void ege_adjustment_action_init( EgeAdjustmentAction* action )
     action->private_data->lastVal = 0.0;
     action->private_data->step = 0.0;
     action->private_data->page = 0.0;
+    action->private_data->appearanceMode = APPEARANCE_NONE;
     action->private_data->transferFocus = FALSE;
     action->private_data->descriptions = 0;
+    action->private_data->appearance = 0;
 }
 
 static void ege_adjustment_action_finalize( GObject* object )
@@ -310,6 +332,10 @@ static void ege_adjustment_action_get_property( GObject* obj, guint propId, GVal
             g_value_set_pointer( value, (void*)action->private_data->toolPost );
             break;
 
+        case PROP_APPEARANCE:
+            g_value_set_string( value, action->private_data->appearance );
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
     }
@@ -376,6 +402,27 @@ void ege_adjustment_action_set_property( GObject* obj, guint propId, const GValu
         }
         break;
 
+        case PROP_APPEARANCE:
+        {
+            gchar* tmp = action->private_data->appearance;
+            gchar* newVal = g_value_dup_string( value );
+            action->private_data->appearance = newVal;
+            g_free( tmp );
+
+            if ( !action->private_data->appearance || (strcmp("", newVal) == 0) ) {
+                action->private_data->appearanceMode = APPEARANCE_NONE;
+            } else if ( strcmp("full", newVal) == 0 ) {
+                action->private_data->appearanceMode = APPEARANCE_FULL;
+            } else if ( strcmp("compact", newVal) == 0 ) {
+                action->private_data->appearanceMode = APPEARANCE_COMPACT;
+            } else if ( strcmp("minimal", newVal) == 0 ) {
+                action->private_data->appearanceMode = APPEARANCE_MINIMAL;
+            } else {
+                action->private_data->appearanceMode = APPEARANCE_UNKNOWN;
+            }
+        }
+        break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec );
     }
@@ -460,6 +507,11 @@ void ege_adjustment_action_set_descriptions( EgeAdjustmentAction* action, gchar
     }
 }
 
+void ege_adjustment_action_set_appearance( EgeAdjustmentAction* action, gchar const* val )
+{
+    g_object_set( G_OBJECT(action), "appearance", val, NULL );
+}
+
 static void process_menu_action( GtkWidget* obj, gpointer data )
 {
     GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(obj);
@@ -538,7 +590,7 @@ static void create_single_menu_item( GCallback toggleCb, int val, GtkWidget* men
         cur = g_list_next( cur );
     }
 
-    str = g_strdup_printf( act->private_data->format, num, 
+    str = g_strdup_printf( act->private_data->format, num,
                            ((marker && marker->descr) ? ": " : ""),
                            ((marker && marker->descr) ? marker->descr : ""));
 
@@ -705,10 +757,17 @@ static GtkWidget* create_tool_item( GtkAction* action )
 
     if ( IS_EGE_ADJUSTMENT_ACTION(action) ) {
         EgeAdjustmentAction* act = EGE_ADJUSTMENT_ACTION( action );
-        GtkWidget* spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits );
+        GtkWidget* spinbutton = 0;
         GtkWidget* hb = gtk_hbox_new( FALSE, 5 );
         GValue value;
 
+        if ( act->private_data->appearanceMode == APPEARANCE_FULL ) {
+            spinbutton = gtk_hscale_new( act->private_data->adj);
+            gtk_widget_set_size_request(spinbutton, 100, -1);
+        } else {
+            spinbutton = gtk_spin_button_new( act->private_data->adj, act->private_data->climbRate, act->private_data->digits );
+        }
+
         item = GTK_WIDGET( gtk_tool_item_new() );
 
         memset( &value, 0, sizeof(value) );
@@ -737,7 +796,11 @@ static GtkWidget* create_tool_item( GtkAction* action )
 
         gtk_box_pack_start( GTK_BOX(hb), filler1, FALSE, FALSE, 0 );
         gtk_box_pack_start( GTK_BOX(hb), lbl, FALSE, FALSE, 0 );
-        gtk_box_pack_start( GTK_BOX(hb), spinbutton, FALSE, FALSE, 0 );
+        if ( act->private_data->appearanceMode == APPEARANCE_FULL ) {
+            gtk_box_pack_start( GTK_BOX(hb), spinbutton, TRUE, TRUE, 0 );
+        }  else {
+            gtk_box_pack_start( GTK_BOX(hb), spinbutton, FALSE, FALSE, 0 );
+        }
 
         gtk_container_add( GTK_CONTAINER(item), hb );
 
@@ -752,7 +815,11 @@ static GtkWidget* create_tool_item( GtkAction* action )
         g_signal_connect( G_OBJECT(spinbutton), "value-changed", G_CALLBACK(value_changed_cb), action );
 
         g_signal_connect_swapped( G_OBJECT(spinbutton), "event", G_CALLBACK(event_cb), action );
-        gtk_entry_set_width_chars( GTK_ENTRY(spinbutton), act->private_data->digits + 3 );
+        if ( act->private_data->appearanceMode == APPEARANCE_FULL ) {
+            /* */
+        } else {
+            gtk_entry_set_width_chars( GTK_ENTRY(spinbutton), act->private_data->digits + 3 );
+        }
 
         gtk_widget_show_all( item );
 
@@ -791,7 +858,11 @@ gboolean focus_in_cb( GtkWidget *widget, GdkEventKey *event, gpointer data )
     (void)event;
     if ( IS_EGE_ADJUSTMENT_ACTION(data) ) {
         EgeAdjustmentAction* action = EGE_ADJUSTMENT_ACTION( data );
-        action->private_data->lastVal = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) );
+        if ( GTK_IS_SPIN_BUTTON(widget) ) {
+            action->private_data->lastVal = gtk_spin_button_get_value( GTK_SPIN_BUTTON(widget) );
+        } else if (GTK_IS_RANGE(widget) ) {
+            action->private_data->lastVal = gtk_range_get_value( GTK_RANGE(widget) );
+        }
         action->private_data->transferFocus = TRUE;
     }
 
index 0fa89687901b78b09992c4aaffc129ae707c77b2..4a8a172e201f78760b66499e98c780f4c36481ed 100644 (file)
@@ -148,6 +148,15 @@ GtkWidget* ege_adjustment_action_get_focuswidget( EgeAdjustmentAction* action );
  */
 void ege_adjustment_action_set_descriptions( EgeAdjustmentAction* action, gchar const** descriptions, gdouble const* values, guint count );
 
+/**
+ * Sets a hint to be used in determining the display form.
+ * This is the XForms style 'appearance' hint: "full", "compact", "minimal".
+ *
+ * @param action The action to set the tooltip column for.
+ * @param val The value of the appearance hint.
+ */
+void ege_adjustment_action_set_appearance( EgeAdjustmentAction* action, gchar const* val );
+
 /** Callback type for post-creation 'fixup' pass on generated widgets */
 typedef void (*EgeWidgetFixup)(GtkWidget *widget);
 
index 6e2c011ea059b404c547474d5c68473fc6c5818a..dd8bed289c96b9118103f499b24b9bb6b3afc35b 100644 (file)
@@ -3357,45 +3357,45 @@ sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tbl)
     }
     // in turn, prevent listener from responding
     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
-    prefs_set_double_attribute("tools.freehand.pencil", 
+    prefs_set_double_attribute("tools.freehand.pencil",
                                "tolerance", adj->value);
     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
-    
+
 }
 
 
 
 static void
-sp_pencil_tb_tolerance_value_changed_external(Inkscape::XML::Node *repr, 
-                                              const gchar *key, 
-                                              const gchar *oldval, 
-                                              const gchar *newval, 
-                                              bool is_interactive, 
+sp_pencil_tb_tolerance_value_changed_external(Inkscape::XML::Node *repr,
+                                              const gchar *key,
+                                              const gchar *oldval,
+                                              const gchar *newval,
+                                              bool is_interactive,
                                               void * data)
 {
     GObject* tbl = G_OBJECT(data);
     if (g_object_get_data( tbl, "freeze" )) {
         return;
-    }    
+    }
 
     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
 
     GtkAdjustment * adj = (GtkAdjustment*)g_object_get_data(tbl,
                                                             "tolerance");
-    
-    double v = prefs_get_double_attribute("tools.freehand.pencil", 
+
+    double v = prefs_get_double_attribute("tools.freehand.pencil",
                                             "tolerance", adj->value);
     gtk_adjustment_set_value(adj, v);
     g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
-    
+
 }
 
-static Inkscape::XML::NodeEventVector pencil_node_events = 
+static Inkscape::XML::NodeEventVector pencil_node_events =
 {
-    NULL, 
-    NULL, 
+    NULL,
+    NULL,
     sp_pencil_tb_tolerance_value_changed_external,
-    NULL, 
+    NULL,
     NULL,
 };
 
@@ -3410,19 +3410,19 @@ static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
     {
 
         eact = create_adjustment_action( "PencilToleranceAction",
-                 _("Number of pixels allowed in interpolating"), 
+                 _("Number of pixels allowed in interpolating"),
                                          _("Tolerance:"), _("Tolerance"),
-                                         "tools.freehand.pencil", "tolerance", 
+                                         "tools.freehand.pencil", "tolerance",
                                          3.0,
-                                         GTK_WIDGET(desktop->canvas), NULL, 
+                                         GTK_WIDGET(desktop->canvas), NULL,
                                          holder, TRUE, "altx-pencil",
-                                         0.5, 100.0, 0.5, 1.0, 
+                                         0.5, 100.0, 0.5, 1.0,
                                          NULL, NULL, 0,
                                          sp_pencil_tb_tolerance_value_changed,
                                          1, 2);
         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
 
-        Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, 
+        Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE,
                                                       "tools.freehand.pencil");
         repr->addListener(&pencil_node_events, G_OBJECT(holder));
         g_object_set_data(G_OBJECT(holder), "repr", repr);
@@ -3438,7 +3438,7 @@ static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
         g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_pencil_tb_defaults), holder );
         gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
     }
-    
+
     g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
 
 }
@@ -3859,13 +3859,13 @@ static void sp_dcc_save_profile( GtkWidget */*widget*/, GObject *dataKludge ){
 
     unsigned int new_index = pref_path_number_of_children("tools.calligraphic.preset") +1;
     gchar *profile_id = g_strdup_printf("dcc%d", new_index);
-    gchar *pref_path = create_pref("tools.calligraphic.preset",profile_id);    
-    
+    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_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);
@@ -3887,11 +3887,11 @@ static void sp_dcc_save_profile( GtkWidget */*widget*/, GObject *dataKludge ){
 
 
 static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject *dataKludge) {
-    
-    gint preset_index = ege_select_one_action_get_active( act ); 
+
+    gint preset_index = ege_select_one_action_get_active( act );
     gchar *profile_name = get_pref_nth_child("tools.calligraphic.preset", preset_index);
-       
-    if ( profile_name) {        
+
+    if ( profile_name) {
         g_object_set_data(dataKludge, "profile_selector",NULL); //temporary hides the selector so no one will updadte it
         for (unsigned i = 0; i < PROFILE_FLOAT_SIZE; ++i) {
             ProfileFloatElement const &pe = f_profile[i];
@@ -3900,7 +3900,7 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject *dataKludge)
             if ( adj ) {
                 gtk_adjustment_set_value(adj, v);
             }
-        } 
+        }
         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);
@@ -3983,6 +3983,7 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
                                                               0.0, 1.0, 0.01, 0.1,
                                                               labels, values, G_N_ELEMENTS(labels),
                                                               sp_ddc_flatness_value_changed, 0.01, 2 );
+        ege_adjustment_action_set_appearance( eact, "full" );
         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
         }
@@ -4017,6 +4018,7 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
                                                               labels, values, G_N_ELEMENTS(labels),
                                                               sp_ddc_tremor_value_changed, 0.01, 2 );
 
+        ege_adjustment_action_set_appearance( eact, "full" );
         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
         }
@@ -4033,6 +4035,7 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
                                                               0.0, 1.0, 0.01, 0.1,
                                                               labels, values, G_N_ELEMENTS(labels),
                                                               sp_ddc_wiggle_value_changed, 0.01, 2 );
+        ege_adjustment_action_set_appearance( eact, "full" );
         gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
         gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
         }
@@ -4096,7 +4099,7 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
 
         /*calligraphic profile */
         {
-            GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );            
+            GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
             gchar *pref_path;
 
 
@@ -4111,9 +4114,9 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main
             while (child_repr) {
                 GtkTreeIter iter;
                 char *preset_name = (char *) child_repr->attribute("name");
-                gtk_list_store_append( model, &iter );                
-                gtk_list_store_set( model, &iter, 0, preset_name, 1, ++ii, -1 );                
-                child_repr = sp_repr_next(child_repr); 
+                gtk_list_store_append( model, &iter );
+                gtk_list_store_set( model, &iter, 0, preset_name, 1, ++ii, -1 );
+                child_repr = sp_repr_next(child_repr);
             }
 
             pref_path = NULL;
@@ -4122,7 +4125,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 */
@@ -4642,7 +4645,7 @@ static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio
         ege_select_one_action_set_active( act, eraserMode );
         g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_erasertb_mode_changed), holder );
     }
-    
+
 }
 
 //########################