diff options
author | Matthias Clasen <mclasen@redhat.com> | 2014-10-02 21:42:08 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2014-10-02 21:42:08 -0400 |
commit | 5b36bd704b79f0674018d01c5e5c461600d420fe (patch) | |
tree | 549c31fff1c748efafae4e63f435b7ccc92d7bf0 /demos/widget-factory | |
parent | 59637c95a6e8e51ee61334ba387062a2ce5ed49c (diff) | |
download | gtk+-5b36bd704b79f0674018d01c5e5c461600d420fe.tar.gz |
widget-factory: Add a scale button
Instead of two volume buttons, make the second one a scale button
and use microphones.
Diffstat (limited to 'demos/widget-factory')
-rw-r--r-- | demos/widget-factory/widget-factory.c | 56 | ||||
-rw-r--r-- | demos/widget-factory/widget-factory.ui | 10 |
2 files changed, 64 insertions, 2 deletions
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 072d3c53a3..3e9003388e 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -19,6 +19,7 @@ */ #include "config.h" +#include <glib/gi18n.h> #include <gtk/gtk.h> static void @@ -234,7 +235,59 @@ on_entry_icon_release (GtkEntry *entry, pulse_it (GTK_WIDGET (entry)); } } +} + +#define EPSILON (1e-10) + +static gboolean +on_scale_button_query_tooltip (GtkWidget *button, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip *tooltip, + gpointer user_data) +{ + GtkScaleButton *scale_button = GTK_SCALE_BUTTON (button); + GtkAdjustment *adjustment; + gdouble val; + gchar *str; + AtkImage *image; + + image = ATK_IMAGE (gtk_widget_get_accessible (button)); + adjustment = gtk_scale_button_get_adjustment (scale_button); + val = gtk_scale_button_get_value (scale_button); + + if (val < (gtk_adjustment_get_lower (adjustment) + EPSILON)) + { + str = g_strdup (_("Muted")); + } + else if (val >= (gtk_adjustment_get_upper (adjustment) - EPSILON)) + { + str = g_strdup (_("Full Volume")); + } + else + { + gint percent; + + percent = (gint) (100. * val / (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_lower (adjustment)) + .5); + + str = g_strdup_printf (C_("volume percentage", "%d %%"), percent); + } + + gtk_tooltip_set_text (tooltip, str); + atk_image_set_image_description (image, str); + g_free (str); + + return TRUE; +} + +static void +on_scale_button_value_changed (GtkScaleButton *button, + gdouble value, + gpointer user_data) +{ + gtk_widget_trigger_tooltip_query (GTK_WIDGET (button)); } static void @@ -819,6 +872,9 @@ activate (GApplication *app) builder = gtk_builder_new_from_resource ("/org/gtk/WidgetFactory/widget-factory.ui"); gtk_builder_add_callback_symbol (builder, "on_entry_icon_release", (GCallback)on_entry_icon_release); + gtk_builder_add_callback_symbol (builder, "on_scale_button_value_changed", (GCallback)on_scale_button_value_changed); + gtk_builder_add_callback_symbol (builder, "on_scale_button_query_tooltip", (GCallback)on_scale_button_query_tooltip); + gtk_builder_connect_signals (builder, NULL); window = (GtkWindow *)gtk_builder_get_object (builder, "window"); diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index 4ab4048fb6..15b342a4b5 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -2069,13 +2069,19 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property> </packing> </child> <child> - <object class="GtkVolumeButton"> + <object class="GtkScaleButton" id="mic-button"> <property name="visible">True</property> + <property name="has-tooltip">True</property> <property name="orientation">horizontal</property> + <property name="icons">microphone-sensitivity-muted-symbolic +microphone-sensitivity-high-symbolic +microphone-sensitivity-low-symbolic +microphone-sensitivity-medium-symbolic</property> <property name="valign">center</property> - <property name="use-symbolic">True</property> <property name="value">.5</property> <property name="halign">center</property> + <signal name="query-tooltip" handler="on_scale_button_query_tooltip" swapped="no"/> + <signal name="value-changed" handler="on_scale_button_value_changed" swapped="no"/> </object> <packing> <property name="left-attach">0</property> |