[gimp/tito: 15/15] app: add an opacity button to the search dialog to change window opacity



commit c821dce741f15d2dfef032d1b756abc16f2d3fd0
Author: Jehan <jehan girinstud io>
Date:   Sat Nov 30 20:44:34 2013 +1300

    app: add an opacity button to the search dialog to change window opacity

 app/dialogs/action-search-dialog.c |  112 +++++++++++++++++++++++++++---------
 1 files changed, 84 insertions(+), 28 deletions(-)
---
diff --git a/app/dialogs/action-search-dialog.c b/app/dialogs/action-search-dialog.c
index 4a4a1d9..53f275d 100644
--- a/app/dialogs/action-search-dialog.c
+++ b/app/dialogs/action-search-dialog.c
@@ -22,17 +22,20 @@
 
 #include <glib/gstdio.h>
 
+#include <gegl.h>
 #include <gtk/gtk.h>
 
 #include <gdk/gdkkeysyms.h>
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpwidgets/gimpwidgets.h"
 
 #include "dialogs-types.h"
 
 #include "widgets/gimpuimanager.h"
 #include "widgets/gimpaction.h"
 #include "widgets/gimpaction-history.h"
+#include "widgets/gimpspinscale.h"
 
 #include "config/gimpguiconfig.h"
 #include "core/gimp.h"
@@ -49,6 +52,9 @@ typedef struct
   GtkWidget     *keyword_entry;
   GtkWidget     *results_list;
   GtkWidget     *list_view;
+
+  GtkWidget     *opacity_scale;
+  GtkAdjustment *opacity_adjustment;
 } SearchDialog;
 
 static void         key_released                           (GtkWidget         *widget,
@@ -85,9 +91,14 @@ static void         action_search_finalizer                (SearchDialog      *p
 static gboolean     window_configured                      (GtkWindow         *window,
                                                             GdkEvent          *event,
                                                             SearchDialog      *private);
-static gboolean     window_scrolled                        (GtkWidget         *widget,
+static gboolean     opacity_button_scrolled                (GtkWidget         *widget,
+                                                            GdkEvent          *event,
+                                                            SearchDialog      *private);
+static gboolean     opacity_button_clicked                 (GtkWidget         *widget,
                                                             GdkEvent          *event,
                                                             SearchDialog      *private);
+static void         opacity_scale_changed                  (GtkAdjustment     *adjustment,
+                                                            SearchDialog      *private);
 static void         action_search_setup_results_list       (GtkWidget        **results_list,
                                                             GtkWidget        **list_view);
 static void         search_dialog_free                     (SearchDialog      *private);
@@ -110,6 +121,7 @@ action_search_dialog_create (Gimp *gimp)
   SearchDialog  *private;
   GimpGuiConfig *config;
   GtkWidget     *main_vbox, *main_hbox;
+  GtkWidget     *opacity_button;
 
   gtk_accel_map_change_entry ("<Actions>/dialogs/dialogs-action-search", 'd', 0, FALSE);
 
@@ -142,6 +154,22 @@ action_search_dialog_create (Gimp *gimp)
   gtk_widget_show (private->keyword_entry);
   gtk_box_pack_start (GTK_BOX (main_hbox), private->keyword_entry, TRUE, TRUE, 0);
 
+  opacity_button = gtk_button_new ();
+  gtk_button_set_image (GTK_BUTTON (opacity_button),
+                        gtk_image_new_from_stock (GIMP_STOCK_TRANSPARENCY,
+                                                  GTK_ICON_SIZE_MENU));
+  gtk_widget_set_can_focus (opacity_button, FALSE);
+  gtk_widget_set_events (opacity_button, GDK_BUTTON_PRESS_MASK);
+  gtk_widget_set_tooltip_text (opacity_button, _("Set this dialog opacity."));
+  gtk_box_pack_end (GTK_BOX (main_hbox), opacity_button, FALSE, TRUE, 0);
+  gtk_widget_show (opacity_button);
+
+  private->opacity_adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (100.0, 40.0, 100.0,
+                                                                    1.0, 10.0, 0.0));
+  private->opacity_scale = gimp_spin_scale_new (private->opacity_adjustment, _("Dialog Opacity"), 1);
+  gtk_box_pack_end (GTK_BOX (main_hbox), private->opacity_scale, TRUE, TRUE, 0);
+  gtk_widget_set_can_focus (private->opacity_scale, FALSE);
+
   action_search_setup_results_list (&private->results_list, &private->list_view);
   gtk_box_pack_start (GTK_BOX (main_vbox), private->list_view, TRUE, TRUE, 0);
 
@@ -153,7 +181,9 @@ action_search_dialog_create (Gimp *gimp)
   g_signal_connect (private->keyword_entry, "key-release-event", G_CALLBACK (key_released), private);
   g_signal_connect (private->results_list, "key_press_event", G_CALLBACK (result_selected), private);
   g_signal_connect (action_search_dialog, "event", G_CALLBACK (window_configured), private);
-  g_signal_connect (action_search_dialog, "scroll-event", G_CALLBACK (window_scrolled), private);
+  g_signal_connect (opacity_button, "scroll-event", G_CALLBACK (opacity_button_scrolled), private);
+  g_signal_connect (opacity_button, "clicked", G_CALLBACK (opacity_button_clicked), private);
+  g_signal_connect (private->opacity_adjustment, "value-changed", G_CALLBACK (opacity_scale_changed), 
private);
 
   gtk_widget_show (action_search_dialog);
 
@@ -835,44 +865,70 @@ window_configured (GtkWindow    *window,
 }
 
 static gboolean
-window_scrolled (GtkWidget    *widget,
-                 GdkEvent     *event,
-                 SearchDialog *private)
+opacity_button_scrolled (GtkWidget    *widget,
+                         GdkEvent     *event,
+                         SearchDialog *private)
 {
-  GdkEventScroll *scroll = (GdkEventScroll*) event;
+  GdkEventScroll *scroll      = (GdkEventScroll*) event;
+  GimpGuiConfig  *config      = private->config;
+  gint            new_opacity = config->search_dialog_opacity;
 
-  if (scroll->state & GDK_CONTROL_MASK)
+  switch (scroll->direction)
     {
-      GimpGuiConfig *config      = private->config;
-      gint           new_opacity = config->search_dialog_opacity;
-
-      switch (scroll->direction)
-        {
-        case GDK_SCROLL_UP:
-          new_opacity = MIN (config->search_dialog_opacity + 5, 100);
-          break;
+    case GDK_SCROLL_UP:
+      new_opacity = MIN (config->search_dialog_opacity + 2, 100);
+      break;
 
-        case GDK_SCROLL_DOWN:
-          new_opacity = MAX (config->search_dialog_opacity - 5, 10);
-          break;
+    case GDK_SCROLL_DOWN:
+      new_opacity = MAX (config->search_dialog_opacity - 2, 40);
+      break;
 
-        default:
-          break;
-        }
-
-      if (new_opacity != config->search_dialog_opacity)
-        {
-          config->search_dialog_opacity = new_opacity;
-          gtk_window_set_opacity (GTK_WINDOW (private->dialog),
-                                  (gdouble) new_opacity / 100.0);
-        }
+    default:
+      break;
+    }
 
+  if (new_opacity != config->search_dialog_opacity)
+    {
+      gtk_adjustment_set_value (private->opacity_adjustment,
+                                (gdouble) new_opacity);
       return TRUE;
     }
 
   return FALSE;
 }
 
+static gboolean
+opacity_button_clicked (GtkWidget    *widget,
+                        GdkEvent     *event,
+                        SearchDialog *private)
+{
+  if (gtk_widget_get_visible (private->opacity_scale))
+    {
+      gtk_widget_hide (private->opacity_scale);
+    }
+  else
+    {
+      gtk_widget_show (private->opacity_scale);
+    }
+
+  return TRUE;
+}
+
+static void
+opacity_scale_changed (GtkAdjustment *adjustment,
+                       SearchDialog  *private)
+{
+  GimpGuiConfig *config  = private->config;
+  gdouble        opacity = gtk_adjustment_get_value (adjustment);
+
+  if (opacity != config->search_dialog_opacity)
+    {
+      config->search_dialog_opacity = opacity;
+      gtk_window_set_opacity (GTK_WINDOW (private->dialog),
+                              (gdouble) opacity / 100.0);
+    }
+}
+
 static void
 action_search_setup_results_list (GtkWidget **results_list,
                                   GtkWidget **list_view)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]