Commit 6b3272e4 authored by Matthias Clasen's avatar Matthias Clasen

color editor: Add a color picker button

The button is shown if we have a GtkColorPicker implementation.
Currently, there are none, so the button is never shown.
parent 543fb6d7
......@@ -24,7 +24,9 @@
#include "gtkcolorscaleprivate.h"
#include "gtkcolorswatchprivate.h"
#include "gtkcolorutils.h"
#include "gtkcolorpickerprivate.h"
#include "gtkgrid.h"
#include "gtkbutton.h"
#include "gtkintl.h"
#include "gtkorientable.h"
#include "gtkentry.h"
......@@ -61,6 +63,9 @@ struct _GtkColorEditorPrivate
GtkAdjustment *v_adj;
GtkAdjustment *a_adj;
GtkWidget *picker_button;
GtkColorPicker *picker;
gint popup_position;
guint text_changed : 1;
......@@ -353,6 +358,36 @@ popup_draw (GtkWidget *popup,
return FALSE;
}
static void
color_picked (GObject *source,
GAsyncResult *res,
gpointer data)
{
GtkColorPicker *picker = GTK_COLOR_PICKER (source);
GtkColorEditor *editor = data;
GError *error = NULL;
GdkRGBA *color;
color = gtk_color_picker_pick_finish (picker, res, &error);
if (color == NULL)
{
g_warning ("Picking color failed: %s", error->message);
g_error_free (error);
}
else
{
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (editor), color);
gdk_rgba_free (color);
}
}
static void
pick_color (GtkButton *button,
GtkColorEditor *editor)
{
gtk_color_picker_pick (editor->priv->picker, color_picked, editor);
}
static void
gtk_color_editor_init (GtkColorEditor *editor)
{
......@@ -394,6 +429,10 @@ gtk_color_editor_init (GtkColorEditor *editor)
gtk_overlay_add_overlay (GTK_OVERLAY (editor->priv->overlay), editor->priv->a_popup);
gtk_style_context_remove_class (gtk_widget_get_style_context (editor->priv->swatch), "activatable");
editor->priv->picker = gtk_color_picker_new ();
if (editor->priv->picker == NULL)
gtk_widget_hide (editor->priv->picker_button);
}
static void
......@@ -402,6 +441,7 @@ gtk_color_editor_dispose (GObject *object)
GtkColorEditor *editor = GTK_COLOR_EDITOR (object);
dismiss_current_popup (editor);
g_clear_object (&editor->priv->picker);
G_OBJECT_CLASS (gtk_color_editor_parent_class)->dispose (object);
}
......@@ -504,6 +544,7 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, s_adj);
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, v_adj);
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, a_adj);
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, picker_button);
gtk_widget_class_bind_template_callback (widget_class, hsv_changed);
gtk_widget_class_bind_template_callback (widget_class, popup_draw);
......@@ -514,6 +555,7 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
gtk_widget_class_bind_template_callback (widget_class, entry_apply);
gtk_widget_class_bind_template_callback (widget_class, entry_focus_out);
gtk_widget_class_bind_template_callback (widget_class, popup_edit);
gtk_widget_class_bind_template_callback (widget_class, pick_color);
}
static void
......
......@@ -40,6 +40,27 @@
<property name="margin-end">30</property>
<property name="row-spacing">12</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkButton" id="picker_button">
<property name="visible">1</property>
<property name="no-show-all">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="icon-name">color-select-symbolic</property>
</object>
</child>
<property name="tooltip-text" translatable="yes">Pick a color from the screen</property>
<signal name="clicked" handler="pick_color"/>
<style>
<class name="circular"/>
</style>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkColorSwatch" id="swatch">
<property name="visible">True</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment