[gimp/soc-2011-gimpunitentry] GimpUnitEntryTable: function for adding a GimpChainButton and changes in add_label()
- From: Enrico Schröder <eschroeder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2011-gimpunitentry] GimpUnitEntryTable: function for adding a GimpChainButton and changes in add_label()
- Date: Fri, 10 Jun 2011 19:19:56 +0000 (UTC)
commit 9417172065b82326b6bb3c8c6fa4ec7d4f658013
Author: Enrico SchroÌ?der <enni schroeder gmail com>
Date: Fri Jun 10 21:19:26 2011 +0200
GimpUnitEntryTable: function for adding a GimpChainButton and changes in add_label()
Adds a function for adding a GimpChainButton (currently without functionality because we don't have constraints yet).
Changes the add_label function so that it takes the ids of the entries it will show the value of instead of showing the values of all entries.
app/dialogs/layer-options-dialog.c | 4 +-
libgimpwidgets/gimpunitentrytable.c | 152 +++++++++++++++++++++++------------
libgimpwidgets/gimpunitentrytable.h | 20 ++---
libgimpwidgets/test-unitentrygui.c | 4 +-
4 files changed, 112 insertions(+), 68 deletions(-)
---
diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c
index d82afe1..5a0628c 100644
--- a/app/dialogs/layer-options-dialog.c
+++ b/app/dialogs/layer-options-dialog.c
@@ -202,8 +202,8 @@ layer_options_dialog_new (GimpImage *image,
options->size_se = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
entry1 = gimp_unit_entry_table_add_entry (options->size_se, "width", _("Width:"));
entry2 = gimp_unit_entry_table_add_entry (options->size_se, "height", _("Height:"));
- gimp_unit_entry_table_add_label (options->size_se, GIMP_UNIT_PIXEL);
-
+ gimp_unit_entry_table_add_label (options->size_se, GIMP_UNIT_PIXEL, "width", "height");
+
gimp_unit_entry_set_unit (GIMP_UNIT_ENTRY (entry1), GIMP_UNIT_PIXEL);
gimp_unit_entry_set_resolution (GIMP_UNIT_ENTRY (entry1), xres);
gimp_unit_entry_set_resolution (GIMP_UNIT_ENTRY (entry2), yres);
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
index 178fe48..004504f 100644
--- a/libgimpwidgets/gimpunitentrytable.c
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -21,11 +21,12 @@
#include "config.h"
-#include "gimpunitentrytable.h"
-
-#include <gtk/gtklabel.h>
+#include <gtk/gtk.h>
#include <glib/gprintf.h>
+#include "gimpunitentrytable.h"
+#include "gimpwidgets.h"
+
/* debug macro */
//#define UNITENTRY_DEBUG
#ifdef UNITENTRY_DEBUG
@@ -34,9 +35,6 @@
#define DEBUG(x) /* nothing */
#endif
-#define DEFAULT_TABLE_SIZE_X 3
-#define DEFAULT_TABLE_SIZE_Y 3
-
G_DEFINE_TYPE (GimpUnitEntryTable, gimp_unit_entry_table, G_TYPE_OBJECT);
/**
@@ -48,9 +46,9 @@ static void
gimp_unit_entry_table_init (GimpUnitEntryTable *table)
{
/* initialize our fields */
- table->table = gtk_table_new (DEFAULT_TABLE_SIZE_X, DEFAULT_TABLE_SIZE_Y, FALSE);
+ table->table = gtk_table_new (1, 1, FALSE);
table->entries = NULL;
- table->previewLabel = NULL;
+ table->bottom = 0;
}
static void
@@ -78,20 +76,36 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
GimpUnitEntry *entry = GIMP_UNIT_ENTRY (gimp_unit_entry_new (id)) , *entry2;
gint count = g_list_length (table->entries);
GtkWidget *label;
- int i;
-
+ gint i;
+ /* position of the entry */
+ gint leftAttach = 1,
+ rightAttach = 2,
+ topAttach = table->bottom,
+ bottomAttach = table->bottom+1;
+
+ /* remember position in table so that we later can place other widgets around it */
+ g_object_set_data (G_OBJECT (entry), "leftAttach", GINT_TO_POINTER (leftAttach));
+ g_object_set_data (G_OBJECT (entry), "rightAttach", GINT_TO_POINTER (rightAttach));
+ g_object_set_data (G_OBJECT (entry), "topAttach", GINT_TO_POINTER (topAttach));
+ g_object_set_data (G_OBJECT (entry), "bottomAttach", GINT_TO_POINTER (bottomAttach));
+
/* add entry to table at position (1, count) */
gtk_table_attach_defaults (GTK_TABLE (table->table),
GTK_WIDGET (entry),
- 1, 2, count, count + 1);
+ leftAttach,
+ rightAttach,
+ topAttach,
+ bottomAttach);
- /* if label is given, create label and attach to the left of entry */
+ table->bottom++;
+
+ /* if label string is given, create label and attach to the left of entry */
if (labelStr != NULL)
{
label = gtk_label_new (labelStr);
gtk_table_attach (GTK_TABLE (table->table),
label,
- 0, 1, count, count + 1,
+ leftAttach-1 , leftAttach, topAttach, bottomAttach,
GTK_SHRINK, GTK_EXPAND | GTK_FILL,
10, 0);
}
@@ -111,44 +125,84 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
return GTK_WIDGET (entry);
}
-/* add preview label showing the current value in given unit */
-/** TODO: The whole label thing is subject to change.
- * Just a quick'n dirty solution for now
- **/
+/* add preview label showing value of the two given entries in given unit */
void
-gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit)
+gimp_unit_entry_table_add_label (GimpUnitEntryTable *table,
+ GimpUnit unit,
+ const char* id1,
+ const char* id2)
{
GtkWidget *label = gtk_label_new("preview");
- gint count = g_list_length (table->entries);
- gint i;
- GimpUnitEntry *entry;
+ GimpUnitEntry *entry1 = gimp_unit_entry_table_get_entry (table, id1);
+ GimpUnitEntry *entry2 = gimp_unit_entry_table_get_entry (table, id2);
+ gint leftAttach, rightAttach, topAttach, bottomAttach;
/* save unit */
- table->previewUnit = unit;
+ g_object_set_data (G_OBJECT (label), "unit", GINT_TO_POINTER (unit));
+ /* save the two entries */
+ g_object_set_data (G_OBJECT (label), "entry1", (gpointer) entry1);
+ g_object_set_data (G_OBJECT (label), "entry2", (gpointer) entry2);
+
+ /* get the position of the entries and set label accordingly */
+ leftAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "leftAttach"));
+ rightAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "rightAttach"));
+ topAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "bottomAttach"));
+ bottomAttach = topAttach + 1;
/* add label below unit entries */
gtk_table_attach (GTK_TABLE (table->table),
label,
- 1, 2,
- count, count+1,
+ leftAttach, rightAttach,
+ topAttach, bottomAttach,
GTK_SHRINK, GTK_EXPAND | GTK_FILL,
10, 0);
- table->previewLabel = GTK_LABEL (label);
- gtk_widget_show (GTK_WIDGET (table->previewLabel));
+ table->bottom++;
+
+ gtk_widget_show (GTK_WIDGET (label));
/* connect label updater to changed signal */
- for (i = 0; i < count; i++)
- {
- entry = gimp_unit_entry_table_get_nth_entry (table, i);
- g_signal_connect (G_OBJECT (gimp_unit_entry_get_adjustment (entry)), "value-changed",
- G_CALLBACK (label_updater), (gpointer) table);
- }
+ g_signal_connect (G_OBJECT (gimp_unit_entry_get_adjustment (entry1)), "value-changed",
+ G_CALLBACK (label_updater), (gpointer) label);
- label_updater (NULL, (gpointer) table);
+ g_signal_connect (G_OBJECT (gimp_unit_entry_get_adjustment (entry2)), "value-changed",
+ G_CALLBACK (label_updater), (gpointer) label);
+
+ label_updater (NULL, (gpointer) label);
+}
+
+/* add chain button connecting the two given UnitEntries */
+GtkWidget*
+gimp_unit_entry_table_add_chain_button (GimpUnitEntryTable *table,
+ const char* id1,
+ const char* id2)
+{
+ GtkWidget *chainButton = gimp_chain_button_new(GIMP_CHAIN_RIGHT);
+ GimpUnitEntry *entry1 = gimp_unit_entry_table_get_entry (table, id1);
+ GimpUnitEntry *entry2 = gimp_unit_entry_table_get_entry (table, id2);
+
+ /* retrieve position of entries */
+ gint rightAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "rightAttach"));
+ gint topAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "topAttach"));
+ gint bottomAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "bottomAttach"));
+
+ /* add chainbutton to right of entries, spanning from the first to the second */
+ gtk_table_attach (GTK_TABLE (table->table),
+ GTK_WIDGET (chainButton),
+ rightAttach,
+ rightAttach + 1,
+ topAttach,
+ bottomAttach,
+ GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
+
+ gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainButton), TRUE);
+
+ gtk_widget_show (chainButton);
+
+ return chainButton;
}
-/* get UnitEntry by label */
+/* get UnitEntry by identifier */
GimpUnitEntry*
gimp_unit_entry_table_get_entry (GimpUnitEntryTable *table,
const gchar *id)
@@ -181,29 +235,25 @@ gimp_unit_entry_table_get_nth_entry (GimpUnitEntryTable *table,
}
/* updates the text of the preview label */
-/** TODO: The whole label thing is subject to change.
- * Just a quick'n dirty solution for now
- **/
static
void label_updater (GtkAdjustment *adj, gpointer userData)
{
gchar str[40];
- GimpUnitEntryTable *table = GIMP_UNIT_ENTRY_TABLE (userData);
- GimpUnitAdjustment *adjustment;
- gint count = g_list_length (table->entries);
- gint i = 0;
+ GtkLabel *label = GTK_LABEL (userData);
+ GimpUnitEntry *entry1 = GIMP_UNIT_ENTRY (g_object_get_data (G_OBJECT (label), "entry1"));
+ GimpUnitEntry *entry2 = GIMP_UNIT_ENTRY (g_object_get_data (G_OBJECT (label), "entry2"));
+ GimpUnitAdjustment *adjustment;
+ GimpUnit unit;
- if (table->previewLabel == NULL || count <= 0)
- return;
+ /* retrieve preview unit */
+ unit = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "unit"));
- adjustment = gimp_unit_entry_get_adjustment (gimp_unit_entry_table_get_nth_entry (table, 0));
- g_sprintf (str, "%s", gimp_unit_adjustment_to_string_in_unit (adjustment, table->previewUnit));
+ /* retrieve values of the two entries */
+ adjustment = gimp_unit_entry_get_adjustment (entry1);
+ g_sprintf (str, "%s", gimp_unit_adjustment_to_string_in_unit (adjustment, unit));
- for (i = 1; i < count; i++)
- {
- adjustment = gimp_unit_entry_get_adjustment (gimp_unit_entry_table_get_nth_entry (table, i));
- g_sprintf (str, "%s x %s ", str, gimp_unit_adjustment_to_string_in_unit (adjustment, table->previewUnit));
- }
+ adjustment = gimp_unit_entry_get_adjustment (entry2);
+ g_sprintf (str, "%s x %s ", str, gimp_unit_adjustment_to_string_in_unit (adjustment, unit));
- gtk_label_set_text (table->previewLabel, str);
+ gtk_label_set_text (label, str);
}
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
index 8b8b3dd..2f7f0f9 100644
--- a/libgimpwidgets/gimpunitentrytable.h
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -24,8 +24,6 @@
#include <stdarg.h>
-#include <gtk/gtktable.h>
-#include <gtk/gtklabel.h>
#include <glib.h>
#include "gimpunitentry.h"
@@ -45,14 +43,6 @@ G_BEGIN_DECLS
typedef struct _GimpUnitEntryTable GimpUnitEntryTable;
typedef struct _GimpUnitEntryTableClass GimpUnitEntryTableClass;
-/* enum for standard 'set-ups' */
-typedef enum
-{
- GIMP_UNIT_ENTRY_TABLE_EMPTY, /* empty table */
- GIMP_UNIT_ENTRY_TABLE_DEFAULT, /* just two entries */
- GIMP_UNIT_ENTRY_TABLE_DEFAULT_WITH_PREVIEW /* ... with label showing value */
-} GimpUnitEntryTableSetup;
-
struct _GimpUnitEntryTable
{
GObject parent_instance;
@@ -60,8 +50,8 @@ struct _GimpUnitEntryTable
/* private */
GtkWidget *table;
GList *entries; /* list of entries */
- GtkLabel *previewLabel; /* (optional) preview label automatically showing value */
- GimpUnit previewUnit; /* unit in which the preview is shown */
+
+ gint bottom; /* bottom row of our table */
};
struct _GimpUnitEntryTableClass
@@ -78,8 +68,10 @@ GObject *gimp_unit_entry_table_new (void);
/* add UnitEntry */
GtkWidget* gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table, const gchar* id, const gchar *label);
//void gimp_unit_entry_table_add_entries ()
-/* add preview label showing the current value in given unit */
-void gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit);
+/* add preview label showing the current value of two entries in given unit */
+void gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit, const char* id1, const char* id2);
+/* add chain button connecting the two given UnitEntries */
+GtkWidget* gimp_unit_entry_table_add_chain_button (GimpUnitEntryTable *table, const char* id1, const char*id2);
/* get UnitEntry by id */
GimpUnitEntry* gimp_unit_entry_table_get_entry (GimpUnitEntryTable *table, const gchar* id);
/* get UnitEntry by index */
diff --git a/libgimpwidgets/test-unitentrygui.c b/libgimpwidgets/test-unitentrygui.c
index a4d7c7a..bdf76ab 100644
--- a/libgimpwidgets/test-unitentrygui.c
+++ b/libgimpwidgets/test-unitentrygui.c
@@ -43,7 +43,9 @@ create_interface(void)
entryTable = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
gimp_unit_entry_table_add_entry (entryTable, "width", "Width");
gimp_unit_entry_table_add_entry (entryTable, "height", "Height");
- gimp_unit_entry_table_add_label (entryTable, GIMP_UNIT_PIXEL);
+ gimp_unit_entry_table_add_label (entryTable, GIMP_UNIT_PIXEL, "width", "height");
+
+ gimp_unit_entry_table_add_chain_button (entryTable, "width", "height");
/* set some default values */
a = gimp_unit_entry_table_get_entry (entryTable, "width");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]