[bijiben] Implement initial custom color palette for Notes color dialog
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] Implement initial custom color palette for Notes color dialog
- Date: Sun, 2 Dec 2012 02:07:39 +0000 (UTC)
commit b035ab66bf4f25b89c5c6de9f69aafcbb1643b17
Author: Pierre-Yves Luyten <py luyten fr>
Date: Sun Dec 2 03:03:07 2012 +0100
Implement initial custom color palette for Notes color dialog
BjbColorButton just overrides gtk color button
to use add_palette
Colors palette is not yet decided
This commit still relies on standard gtk color chooser dialog
See https://bugzilla.gnome.org/show_bug.cgi?id=689143
src/Makefile.am | 2 +
src/bjb-color-button.c | 177 +++++++++++++++++++++++++++++++++++++++++++
src/bjb-color-button.h | 54 +++++++++++++
src/bjb-note-view.c | 3 +-
src/bjb-selection-toolbar.c | 3 +-
5 files changed, 237 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4df9499..8d9cd68 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,8 @@ bijiben_SOURCES = \
bjb-app-menu.h \
bjb-bijiben.c \
bjb-bijiben.h \
+ bjb-color-button.c \
+ bjb-color-button.h \
bjb-controller.c \
bjb-controller.h \
bjb-debug.c \
diff --git a/src/bjb-color-button.c b/src/bjb-color-button.c
new file mode 100644
index 0000000..cfce972
--- /dev/null
+++ b/src/bjb-color-button.c
@@ -0,0 +1,177 @@
+/* bjb-color-button.c
+ * Copyright (C) Pierre-Yves Luyten 2012 <py luyten fr>
+ *
+ * bijiben is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * anjuta is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/* This is mostly gtk-color-button.c
+ * Just overrides the dialog to choose specific palette
+ * But a dedicated dialog might be better */
+
+#include "bjb-color-button.h"
+
+// Bijiben probably wants something like 6 light colors
+#define BJB_NUM_COLORS 4
+
+static gchar *palette_str[BJB_NUM_COLORS] = {
+ "rgb(239, 242, 209)", // eff2d1 from the mockup
+ "rgb(210, 219, 230)", // d2dbe6 from the mockup
+ "rgb(229, 230, 210)", //
+ "rgb(235, 239, 244)", //
+};
+
+struct _BjbColorButtonPrivate
+{
+ GdkRGBA palette [BJB_NUM_COLORS];
+ GtkWidget *dialog;
+ gchar *title;
+ GdkRGBA rgba;
+};
+
+#define BJB_COLOR_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BJB_TYPE_COLOR_BUTTON, BjbColorButtonPrivate))
+
+
+G_DEFINE_TYPE (BjbColorButton, bjb_color_button, GTK_TYPE_COLOR_BUTTON);
+
+static gboolean
+dialog_destroy (GtkWidget *widget,
+ gpointer data)
+{
+ BjbColorButton *button = BJB_COLOR_BUTTON (data);
+
+ button->priv->dialog = NULL;
+
+ return FALSE;
+}
+
+static void
+dialog_response (GtkDialog *dialog,
+ gint response,
+ gpointer data)
+{
+ BjbColorButton *button = BJB_COLOR_BUTTON (data);
+ BjbColorButtonPrivate *priv = button->priv;
+
+ if (response == GTK_RESPONSE_CANCEL)
+ gtk_widget_hide (GTK_WIDGET (dialog));
+
+ else if (response == GTK_RESPONSE_OK)
+ {
+ gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog),
+ &priv->rgba);
+
+ gtk_widget_hide (GTK_WIDGET (dialog));
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), &priv->rgba);
+ g_signal_emit_by_name (button, "color-set");
+ }
+}
+
+static void
+bjb_color_button_clicked (GtkButton *b)
+{
+ BjbColorButton *button = BJB_COLOR_BUTTON (b);
+ BjbColorButtonPrivate *priv = button->priv;
+ GtkWidget *dialog;
+ gint i;
+
+ /* if dialog already exists, make sure it's shown and raised */
+ if (!button->priv->dialog)
+ {
+ /* Create the dialog and connects its buttons */
+ GtkWidget *parent;
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+
+ button->priv->dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
+
+ if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+ {
+ if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
+
+ gtk_window_set_modal (GTK_WINDOW (dialog),
+ gtk_window_get_modal (GTK_WINDOW (parent)));
+ }
+
+ for (i=0 ; i< BJB_NUM_COLORS ; i++)
+ {
+ GdkRGBA color;
+
+ if (gdk_rgba_parse (&color, palette_str[i]))
+ priv->palette [i] = color;
+ }
+
+ gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog),
+ GTK_ORIENTATION_HORIZONTAL,
+ BJB_NUM_COLORS,
+ BJB_NUM_COLORS,
+ priv->palette);
+
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (dialog_response), button);
+ g_signal_connect (dialog, "destroy",
+ G_CALLBACK (dialog_destroy), button);
+ }
+
+ gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->priv->dialog),
+ &button->priv->rgba);
+
+ gtk_window_present (GTK_WINDOW (button->priv->dialog));
+}
+
+
+
+static void
+bjb_color_button_init (BjbColorButton *self)
+{
+ BjbColorButtonPrivate *priv = BJB_COLOR_BUTTON_GET_PRIVATE(self);
+ self->priv = priv;
+
+ priv->title = "Choose a color for note";
+}
+
+static void
+bjb_color_button_constructed (GObject *obj)
+{
+ G_OBJECT_CLASS (bjb_color_button_parent_class)->constructed (obj);
+}
+
+static void
+bjb_color_button_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (bjb_color_button_parent_class)->finalize (object);
+}
+
+static void
+bjb_color_button_class_init (BjbColorButtonClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (BjbColorButtonPrivate));
+
+ object_class->constructed = bjb_color_button_constructed;
+ object_class->finalize = bjb_color_button_finalize;
+
+ /* Override std::gtk_color_button */
+ button_class->clicked = bjb_color_button_clicked;
+}
+
+GtkWidget *
+bjb_color_button_new (void)
+{
+ return g_object_new (BJB_TYPE_COLOR_BUTTON, NULL);
+}
diff --git a/src/bjb-color-button.h b/src/bjb-color-button.h
new file mode 100644
index 0000000..1768cd1
--- /dev/null
+++ b/src/bjb-color-button.h
@@ -0,0 +1,54 @@
+/* bjb-color-button.h
+ * Copyright (C) Pierre-Yves Luyten 2012 <py luyten fr>
+ *
+ * bijiben is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * anjuta is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _BJB_COLOR_BUTTON_H_
+#define _BJB_COLOR_BUTTON_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BJB_TYPE_COLOR_BUTTON (bjb_color_button_get_type ())
+#define BJB_COLOR_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BJB_TYPE_COLOR_BUTTON, BjbColorButton))
+#define BJB_COLOR_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BJB_TYPE_COLOR_BUTTON, BjbColorButtonClass))
+#define BJB_IS_COLOR_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BJB_TYPE_COLOR_BUTTON))
+#define BJB_IS_COLOR_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BJB_TYPE_COLOR_BUTTON))
+#define BJB_COLOR_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BJB_TYPE_COLOR_BUTTON, BjbColorButtonClass))
+
+typedef struct _BjbColorButtonClass BjbColorButtonClass;
+typedef struct _BjbColorButton BjbColorButton;
+typedef struct _BjbColorButtonPrivate BjbColorButtonPrivate;
+
+
+struct _BjbColorButtonClass
+{
+ GtkColorButtonClass parent_class;
+};
+
+struct _BjbColorButton
+{
+ GtkColorButton parent_instance;
+ BjbColorButtonPrivate *priv;
+};
+
+GType bjb_color_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget * bjb_color_button_new (void);
+
+G_END_DECLS
+
+#endif /* _BJB_COLOR_BUTTON_H_ */
diff --git a/src/bjb-note-view.c b/src/bjb-note-view.c
index 6aeaded..82d9a32 100644
--- a/src/bjb-note-view.c
+++ b/src/bjb-note-view.c
@@ -23,6 +23,7 @@
#include "utils/bjb-icons-colors.h"
#include "bjb-bijiben.h"
+#include "bjb-color-button.h"
#include "bjb-editor-toolbar.h"
#include "bjb-rename-note.h"
#include "bjb-share.h"
@@ -405,7 +406,7 @@ bjb_note_main_toolbar_new (BjbNoteView *self,
g_free (default_color);
}
- color_button = gtk_color_button_new ();
+ color_button = bjb_color_button_new ();
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (color_button), &color);
gd_main_toolbar_add_widget (gd, color_button, FALSE);
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index 70aa839..bc18b08 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -26,6 +26,7 @@
#include <gtk/gtk.h>
#include <libgd/gd.h>
+#include "bjb-color-button.h"
#include "bjb-main-view.h"
#include "bjb-selection-toolbar.h"
@@ -172,7 +173,7 @@ bjb_selection_toolbar_init (BjbSelectionToolbar *self)
gtk_container_add (GTK_CONTAINER (priv->left_box), priv->toolbar_tag);
/* Notes color */
- priv->toolbar_color = gtk_color_button_new ();
+ priv->toolbar_color = bjb_color_button_new ();
gtk_container_add (GTK_CONTAINER (priv->left_box), priv->toolbar_color);
priv->separator = gtk_separator_tool_item_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]