[bijiben/wip/sadiq/rewrite: 16/16] Add item thumbnail class
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben/wip/sadiq/rewrite: 16/16] Add item thumbnail class
- Date: Wed, 14 Mar 2018 15:41:21 +0000 (UTC)
commit 5810eec7d39d8a1dfc70172f3462822904e4dcb0
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Wed Mar 14 19:48:51 2018 +0530
Add item thumbnail class
src/resources/bijiben.gresource.xml | 1 +
src/resources/ui/bjb-grid-view-item.ui | 2 +-
src/resources/ui/bjb-item-thumbnail.ui | 11 ++
src/views/bjb-item-thumbnail.c | 171 ++++++++++++++++++++++++++++++++
src/views/bjb-item-thumbnail.h | 34 +++++++
5 files changed, 218 insertions(+), 1 deletions(-)
---
diff --git a/src/resources/bijiben.gresource.xml b/src/resources/bijiben.gresource.xml
index cfb5278..d551258 100644
--- a/src/resources/bijiben.gresource.xml
+++ b/src/resources/bijiben.gresource.xml
@@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">ui/bjb-window.ui</file>
<file preprocess="xml-stripblanks">ui/bjb-main-view.ui</file>
<file preprocess="xml-stripblanks">ui/bjb-grid-view-item.ui</file>
+ <file preprocess="xml-stripblanks">ui/bjb-item-thumbnail.ui</file>
<file>css/style.css</file>
</gresource>
</gresources>
diff --git a/src/resources/ui/bjb-grid-view-item.ui b/src/resources/ui/bjb-grid-view-item.ui
index 2c34e43..1bd9b45 100644
--- a/src/resources/ui/bjb-grid-view-item.ui
+++ b/src/resources/ui/bjb-grid-view-item.ui
@@ -19,7 +19,7 @@
<property name="width-request">200</property>
<property name="height-request">200</property>
<child type="overlay">
- <object class="BjbitemThumbnail" id="preview_label"/>
+ <object class="BjbItemThumbnail" id="preview_label"/>
</child>
</object> <!-- ./GtkOverlay -->
</child>
diff --git a/src/resources/ui/bjb-item-thumbnail.ui b/src/resources/ui/bjb-item-thumbnail.ui
new file mode 100644
index 0000000..78ff462
--- /dev/null
+++ b/src/resources/ui/bjb-item-thumbnail.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk 3.12 -->
+ <template class="BjbItemThumbnail" parent="GtkLabel">
+ <property name="visible">1</property>
+ <property name="use-markup">1</property>
+ <property name="wrap">1</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ </template>
+</interface>
diff --git a/src/views/bjb-item-thumbnail.c b/src/views/bjb-item-thumbnail.c
new file mode 100644
index 0000000..07435cd
--- /dev/null
+++ b/src/views/bjb-item-thumbnail.c
@@ -0,0 +1,171 @@
+/* bjb-item-thumbnail.c
+ *
+ * Copyright 2018 Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * This program 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.
+ *
+ * This program 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "bjb-item-thumbnail"
+
+#include "config.h"
+
+#include "bjb-trace.h"
+
+#include "bjb-item-thumbnail.h"
+
+/**
+ * SECTION: bjb-item-thumbnail
+ * @title: BjbItemThumbnail
+ * @short_description: The thumbnail for the item
+ * @include: "bjb-item-thumbnail.h"
+ *
+ * Use this as an overlay child of a #GtkOverlay and set
+ * the size of overlay based on the requirement.
+ */
+
+struct _BjbItemThumbnail
+{
+ GtkLabel parent_instance;
+
+ GdkRGBA *rgba;
+};
+
+G_DEFINE_TYPE (BjbItemThumbnail, bjb_item_thumbnail, GTK_TYPE_LABEL)
+
+enum {
+ PROP_0,
+ PROP_RGBA,
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
+
+static gboolean
+bjb_item_thumbnail_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ BjbItemThumbnail *self = (BjbItemThumbnail *)widget;
+ GtkStyleContext *style_context;
+ gint width, height;
+
+ g_assert (BJB_IS_ITEM_THUMBNAIL (self));
+
+ style_context = gtk_widget_get_style_context (widget);
+
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+
+ cairo_rectangle (cr, 0, 0, width, height);
+ gdk_cairo_set_source_rgba (cr, self->rgba);
+ cairo_fill_preserve (cr);
+
+ return GTK_WIDGET_CLASS (bjb_item_thumbnail_parent_class)->draw (widget, cr);
+}
+
+static void
+bjb_item_thumbnail_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BjbItemThumbnail *self = (BjbItemThumbnail *)object;
+
+ switch (prop_id)
+ {
+ case PROP_RGBA:
+ g_value_set_boxed (value, self->rgba);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+bjb_item_thumbnail_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BjbItemThumbnail *self = (BjbItemThumbnail *)object;
+
+ switch (prop_id)
+ {
+ case PROP_RGBA:
+ gdk_rgba_free (self->rgba);
+ self->rgba = g_value_dup_boxed (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+bjb_item_thumbnail_finalize (GObject *object)
+{
+ BjbItemThumbnail *self = (BjbItemThumbnail *)object;
+
+ BJB_ENTRY;
+
+ gdk_rgba_free (self->rgba);
+
+ G_OBJECT_CLASS (bjb_item_thumbnail_parent_class)->finalize (object);
+
+ BJB_EXIT;
+}
+
+static void
+bjb_item_thumbnail_class_init (BjbItemThumbnailClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->get_property = bjb_item_thumbnail_get_property;
+ object_class->set_property = bjb_item_thumbnail_set_property;
+ object_class->finalize = bjb_item_thumbnail_finalize;
+
+ widget_class->draw = bjb_item_thumbnail_draw;
+
+ properties[PROP_RGBA] =
+ g_param_spec_boxed ("rgba",
+ "Rgba",
+ "The GdkRGBA background color of the item",
+ GDK_TYPE_RGBA,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/bijiben/"
+ "ui/bjb-item-thumbnail.ui");
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+bjb_item_thumbnail_init (BjbItemThumbnail *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+BjbItemThumbnail *
+bjb_item_thumbnail_new (const gchar *markup,
+ GdkRGBA *rgba)
+{
+ return g_object_new (BJB_TYPE_ITEM_THUMBNAIL,
+ "label", markup,
+ "rgba", rgba,
+ NULL);
+}
diff --git a/src/views/bjb-item-thumbnail.h b/src/views/bjb-item-thumbnail.h
new file mode 100644
index 0000000..7883530
--- /dev/null
+++ b/src/views/bjb-item-thumbnail.h
@@ -0,0 +1,34 @@
+/* bjb-item-thumbnail.h
+ *
+ * Copyright 2018 Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * This program 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.
+ *
+ * This program 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BJB_TYPE_ITEM_THUMBNAIL (bjb_item_thumbnail_get_type ())
+
+G_DECLARE_FINAL_TYPE (BjbItemThumbnail, bjb_item_thumbnail, BJB, ITEM_THUMBNAIL, GtkLabel)
+
+BjbItemThumbnail *bjb_item_thumbnail_new (const gchar *markup,
+ GdkRGBA *rgba);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]