[gtranslator/font-size] WIP: Font size change support
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator/font-size] WIP: Font size change support
- Date: Tue, 8 Sep 2020 08:10:42 +0000 (UTC)
commit ed27d54c191653e454e5b06f47813767e6d41bd4
Author: Daniel GarcĂa Moreno <dani danigm net>
Date: Tue Sep 8 10:10:34 2020 +0200
WIP: Font size change support
build-aux/flatpak/org.gnome.Gtranslator.json | 1 +
src/gtr-tab.c | 52 ++++++++++++++++++
src/gtr-tab.ui | 79 ++++++++++++++++++++++++++++
src/gtr-view.c | 33 ++++++++++++
src/gtr-view.h | 4 ++
5 files changed, 169 insertions(+)
---
diff --git a/build-aux/flatpak/org.gnome.Gtranslator.json b/build-aux/flatpak/org.gnome.Gtranslator.json
index a23f7b40..5a699a68 100644
--- a/build-aux/flatpak/org.gnome.Gtranslator.json
+++ b/build-aux/flatpak/org.gnome.Gtranslator.json
@@ -18,6 +18,7 @@
"--filesystem=~/.config/dconf:ro",
"--filesystem=xdg-download",
"--talk-name=ca.desrt.dconf",
+ "--env=GTK_DEBUG=interactive",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf"
],
"cleanup" : [
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 2f864e6b..be680a36 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -119,6 +119,12 @@ typedef struct
GtkRevealer *search_revealer;
GtrSearchBar *search_bar;
GtkSearchEntry *search;
+
+ /* Text zoom */
+ GtkWidget *zoom_in;
+ GtkWidget *zoom_original;
+ GtkWidget *zoom_out;
+
} GtrTabPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GtrTab, gtr_tab, GTK_TYPE_BOX)
@@ -226,6 +232,42 @@ gtr_page_notify_child_revealed (GtrTab *tab,
//----------------------------------------------------------------//
+// TODO: Zoom also *trans_msgstr[MAX_PLURALS];
+static gboolean
+zoom_in (GtkWidget *widget, GtrTab *tab)
+{
+ GtrTabPrivate *priv;
+ GtrView *view;
+
+ priv = gtr_tab_get_instance_private (tab);
+ view = GTR_VIEW (priv->text_msgid);
+ gtr_view_zoom_in (view);
+ return TRUE;
+}
+
+static gboolean
+zoom_original (GtkWidget *widget, GtrTab *tab)
+{
+ GtrTabPrivate *priv;
+ GtrView *view;
+
+ priv = gtr_tab_get_instance_private (tab);
+ view = GTR_VIEW (priv->text_msgid);
+ gtr_view_zoom_original (view);
+ return TRUE;
+}
+
+static gboolean
+zoom_out (GtkWidget *widget, GtrTab *tab)
+{
+ GtrTabPrivate *priv;
+ GtrView *view;
+
+ priv = gtr_tab_get_instance_private (tab);
+ view = GTR_VIEW (priv->text_msgid);
+ gtr_view_zoom_out (view);
+ return TRUE;
+}
static gboolean
show_hide_revealer (GtkWidget *widget, GdkEvent *ev, GtrTab *tab)
@@ -774,6 +816,13 @@ gtr_tab_init (GtrTab * tab)
g_signal_connect (priv->progress_eventbox, "button-press-event",
G_CALLBACK (show_hide_revealer), tab);
+
+ g_signal_connect (priv->zoom_in, "clicked",
+ G_CALLBACK (zoom_in), tab);
+ g_signal_connect (priv->zoom_original, "clicked",
+ G_CALLBACK (zoom_original), tab);
+ g_signal_connect (priv->zoom_out, "clicked",
+ G_CALLBACK (zoom_out), tab);
}
static void
@@ -959,6 +1008,9 @@ gtr_tab_class_init (GtrTabClass * klass)
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, overlay);
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, search_bar);
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, search_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, zoom_in);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, zoom_original);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, zoom_out);
gtk_widget_class_bind_template_callback (widget_class, gtr_page_notify_child_revealed);
gtk_widget_class_bind_template_callback (widget_class, gtr_page_stop_search);
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index 49a144c9..3c222ffb 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -110,6 +110,85 @@
</style>
</object>
</child>
+
+ <child>
+ <object class="GtkButtonBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">start</property>
+ <property name="halign">end</property>
+ <style>
+ <class name="linked"/>
+ <class name="horizontal"/>
+ </style>
+ <child>
+ <object class="GtkButton" id="zoom_in">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">zoom-in-symbolic</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ <property name="non_homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="zoom_original">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">zoom-original-symbolic</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ <property name="non_homogeneous">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="zoom_out">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">zoom-out-symbolic</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ <property name="non_homogeneous">True</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+
</object>
<packing>
<property name="expand">False</property>
diff --git a/src/gtr-view.c b/src/gtr-view.c
index 2c53cfb5..985663e0 100644
--- a/src/gtr-view.c
+++ b/src/gtr-view.c
@@ -91,6 +91,7 @@ typedef struct
gchar *search_text;
GspellChecker *spell;
+ GtkCssProvider *provider;
} GtrViewPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GtrView, gtr_view, GTK_SOURCE_TYPE_VIEW)
@@ -108,6 +109,11 @@ gtr_view_init (GtrView * view)
priv = gtr_view_get_instance_private (view);
+ priv->provider = gtk_css_provider_new ();
+ gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (view)),
+ GTK_STYLE_PROVIDER (priv->provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
priv->spell = NULL;
priv->editor_settings = g_settings_new ("org.gnome.gtranslator.preferences.editor");
priv->ui_settings = g_settings_new ("org.gnome.gtranslator.preferences.ui");
@@ -160,6 +166,7 @@ gtr_view_dispose (GObject * object)
g_clear_object (&priv->editor_settings);
g_clear_object (&priv->ui_settings);
g_clear_object (&priv->spell);
+ g_object_unref (&priv->provider);
G_OBJECT_CLASS (gtr_view_parent_class)->dispose (object);
}
@@ -898,3 +905,29 @@ gtr_view_reload_scheme_color (GtrView * view)
gtk_source_buffer_set_style_scheme (buf, scheme);
}
+
+// TODO: store the font-size in settings
+// TODO: original, use default font-size
+void
+gtr_view_zoom_in (GtrView *view)
+{
+ GtrViewPrivate *priv = gtr_view_get_instance_private (view);
+ const gchar * css = "textview { font-size: 16pt; }";
+ gtk_css_provider_load_from_data (priv->provider, css, -1, NULL);
+}
+
+void
+gtr_view_zoom_original (GtrView *view)
+{
+ GtrViewPrivate *priv = gtr_view_get_instance_private (view);
+ const gchar * css = "textview { }";
+ gtk_css_provider_load_from_data (priv->provider, css, -1, NULL);
+}
+
+void
+gtr_view_zoom_out (GtrView *view)
+{
+ GtrViewPrivate *priv = gtr_view_get_instance_private (view);
+ const gchar * css = "textview { font-size: 8pt; }";
+ gtk_css_provider_load_from_data (priv->provider, css, -1, NULL);
+}
diff --git a/src/gtr-view.h b/src/gtr-view.h
index 87ee0e3d..1d1bdc19 100644
--- a/src/gtr-view.h
+++ b/src/gtr-view.h
@@ -115,6 +115,10 @@ gtr_view_get_type (void)
void gtr_view_set_language (GtrView *view,
const gchar *lang);
+ void gtr_view_zoom_in (GtrView *view);
+ void gtr_view_zoom_original (GtrView *view);
+ void gtr_view_zoom_out (GtrView *view);
+
/* Search macros */
#define GTR_SEARCH_IS_DONT_SET_FLAGS(sflags) ((sflags & GTR_SEARCH_DONT_SET_FLAGS) != 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]