mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-15 13:10:08 +00:00
color editor: Add a color picker button
The button is shown if we have a GtkColorPicker implemenation. Currently, there are none, so the button is never shown.
This commit is contained in:
parent
0cc0714312
commit
984274497d
@ -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;
|
||||
@ -337,6 +342,36 @@ scaled_adjustment (GtkAdjustment *a,
|
||||
return as;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -385,6 +420,10 @@ gtk_color_editor_init (GtkColorEditor *editor)
|
||||
gtk_widget_add_controller (editor->priv->a_entry, controller);
|
||||
|
||||
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
|
||||
@ -393,6 +432,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);
|
||||
}
|
||||
@ -495,6 +535,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, dismiss_current_popup);
|
||||
@ -503,6 +544,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_changed);
|
||||
gtk_widget_class_bind_template_callback (widget_class, popup_edit);
|
||||
gtk_widget_class_bind_template_callback (widget_class, pick_color);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -38,6 +38,20 @@
|
||||
<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="icon-name">color-select-symbolic</property>
|
||||
<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="name">editor-color-sample</property>
|
||||
|
Loading…
Reference in New Issue
Block a user