[gtranslator] Progress widget as horizontal progress bar
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] Progress widget as horizontal progress bar
- Date: Thu, 11 Oct 2018 14:39:58 +0000 (UTC)
commit d9a6d592cccb1f0fa5602a516367d58b7f3b9fc9
Author: Daniel GarcĂa Moreno <danigm wadobo com>
Date: Thu Oct 11 16:38:16 2018 +0200
Progress widget as horizontal progress bar
This new widget shows a small bar at the top with the percentage of
translated, fuzzy and untranslated messages.
When you click on this new bar, a revealer shows the real numbers.
Fix #14
src/gtr-notebook.c | 43 ----------------------
src/gtr-notebook.h | 2 --
src/gtr-notebook.ui | 99 +--------------------------------------------------
src/gtr-progress.c | 37 +++++--------------
src/gtr-tab.c | 65 ++++++++++++++++++++++++++++++++++
src/gtr-tab.h | 2 ++
src/gtr-tab.ui | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++-
src/gtr-window.c | 6 ++--
src/styles.css | 12 +++++++
9 files changed, 192 insertions(+), 174 deletions(-)
---
diff --git a/src/gtr-notebook.c b/src/gtr-notebook.c
index 9f8efd85..c0c88872 100644
--- a/src/gtr-notebook.c
+++ b/src/gtr-notebook.c
@@ -24,7 +24,6 @@
#include "gtr-tab.h"
#include "gtr-tab-label.h"
#include "gtr-debug.h"
-#include "gtr-progress.h"
#include <glib.h>
#include <glib-object.h>
@@ -34,13 +33,7 @@
typedef struct
{
GtkWidget *titlebar;
- GtkWidget *progress_button;
- GtkWidget *progress_percentage;
- GtkWidget *progress_trans;
- GtkWidget *progress_fuzzy;
- GtkWidget *progress_untrans;
GtkWidget *save;
- GtrProgress *progress;
GtkWidget *undo;
GtkWidget *redo;
@@ -116,12 +109,7 @@ update_tabs_visibility (GtrNotebook *nb)
static void
gtr_notebook_init (GtrNotebook * notebook)
{
- GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
gtk_widget_init_template (GTK_WIDGET (notebook));
-
- priv->progress = gtr_progress_new ();
- gtk_widget_show (GTK_WIDGET (priv->progress));
- gtk_container_add (GTK_CONTAINER (priv->progress_button), GTK_WIDGET (priv->progress));
}
static void
@@ -151,11 +139,6 @@ gtr_notebook_class_init (GtrNotebookClass * klass)
"/org/gnome/translator/gtr-notebook.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, titlebar);
- gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_button);
- gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_trans);
- gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_fuzzy);
- gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_untrans);
- gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, progress_percentage);
gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, undo);
gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, redo);
gtk_widget_class_bind_template_child_private (widget_class, GtrNotebook, save);
@@ -270,32 +253,6 @@ gtr_notebook_get_header (GtrNotebook *notebook)
return priv->titlebar;
}
-void
-gtr_notebook_set_progress (GtrNotebook *notebook,
- gint trans,
- gint untrans,
- gint fuzzy)
-{
- GtrNotebookPrivate *priv = gtr_notebook_get_instance_private (notebook);
- gchar *percentage, *trans_text, *fuzzy_text, *untrans_text;
-
- gtr_progress_set (priv->progress, trans, untrans, fuzzy);
-
- percentage = g_strdup_printf (_("Translated: %0.2f%%"), (float)trans * 100 / (float)(trans + untrans +
fuzzy));
- trans_text = g_strdup_printf (_("Translated: %d"), trans);
- untrans_text = g_strdup_printf (_("Untranslated: %d"), untrans);
- fuzzy_text = g_strdup_printf (_("Fuzzy: %d"), fuzzy);
-
- gtk_label_set_text (GTK_LABEL (priv->progress_percentage), percentage);
- gtk_label_set_text (GTK_LABEL (priv->progress_fuzzy), fuzzy_text);
- gtk_label_set_text (GTK_LABEL (priv->progress_untrans), untrans_text);
- gtk_label_set_text (GTK_LABEL (priv->progress_trans), trans_text);
-
- g_free (percentage);
- g_free (trans_text);
- g_free (fuzzy_text);
- g_free (untrans_text);
-}
void
gtr_notebook_enable_save (GtrNotebook *notebook,
diff --git a/src/gtr-notebook.h b/src/gtr-notebook.h
index 164e9ab0..72c74429 100644
--- a/src/gtr-notebook.h
+++ b/src/gtr-notebook.h
@@ -75,8 +75,6 @@ GtrTab *gtr_notebook_get_page (GtrNotebook * notebook);
GtkWidget *gtr_notebook_get_header (GtrNotebook *notebook);
-void gtr_notebook_set_progress (GtrNotebook *notebook, gint trans, gint untrans, gint fuzzy);
-
void gtr_notebook_enable_save (GtrNotebook *notebook, gboolean enable);
void gtr_notebook_update_undo_buttons (GtrNotebook *notebook, GtrView *view);
diff --git a/src/gtr-notebook.ui b/src/gtr-notebook.ui
index ecde1580..5c9473ce 100644
--- a/src/gtr-notebook.ui
+++ b/src/gtr-notebook.ui
@@ -162,84 +162,6 @@
</packing>
</child>
</object>
- <object class="GtkPopover" id="progress_popover">
- <property name="can_focus">False</property>
- <property name="position">bottom</property>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin_left">6</property>
- <property name="margin_right">6</property>
- <property name="margin_top">6</property>
- <property name="margin_bottom">6</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel" id="progress_percentage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label">translated: 0.00%</property>
- <property name="xalign">0</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkSeparator">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="progress_trans">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label">Translated: 0</property>
- <property name="xalign">0</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="progress_fuzzy">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label">untranslated: 0</property>
- <property name="xalign">0</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="progress_untrans">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label">fuzzy: 0</property>
- <property name="xalign">0</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">4</property>
- </packing>
- </child>
- </object>
- </child>
- </object>
<object class="GtkHeaderBar" id="titlebar">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -555,26 +477,6 @@
<property name="position">6</property>
</packing>
</child>
- <child>
- <object class="GtkMenuButton" id="progress_button">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="popover">progress_popover</property>
- <child>
- <placeholder/>
- </child>
- <child internal-child="accessible">
- <object class="AtkObject" id="progress_button-atkobject">
- <property name="AtkObject::accessible-name" translatable="yes">Progress button</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack_type">end</property>
- <property name="position">6</property>
- </packing>
- </child>
<style>
<class name="titlebar"/>
</style>
@@ -582,3 +484,4 @@
</interface>
+
diff --git a/src/gtr-progress.c b/src/gtr-progress.c
index 7510d98d..66415574 100644
--- a/src/gtr-progress.c
+++ b/src/gtr-progress.c
@@ -115,54 +115,35 @@ on_draw (GtkWidget *widget,
{
GtrProgressPrivate *priv = gtr_progress_get_instance_private (GTR_PROGRESS (widget));
- gdouble ratio, ratio_fuzzy;
- guint width;
- guint height;
GdkRGBA background;
GdkRGBA foreground;
GdkRGBA fuzzy_color;
GtkStyleContext *style_context;
- gfloat percentage = 0.0;
+ gfloat translated = 0.0, fuzzy = 0.0;
gint total = priv->trans + priv->untrans + priv->fuzzy;
+ gint width, height;
style_context = gtk_widget_get_style_context (widget);
gtk_style_context_lookup_color (style_context, "theme_selected_bg_color", &foreground);
gtk_style_context_lookup_color (style_context, "warning_color", &fuzzy_color);
- gtk_style_context_get_color (style_context, gtk_widget_get_state_flags (widget), &background);
- background.alpha *= 0.3;
+ gtk_style_context_lookup_color (style_context, "error_color", &background);
- percentage = (float) (priv->trans * 100) / (float) total;
- ratio = percentage / 100.0;
-
- percentage = (float) (priv->fuzzy * 100) / (float) total;
- ratio_fuzzy = percentage / 100.0;
+ translated = (float) (priv->trans) / (float) total;
+ fuzzy = (float) (priv->fuzzy) / (float) total;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
gdk_cairo_set_source_rgba (cr, &background);
- cairo_arc (cr,
- width / 2.0, height / 2.0,
- MIN (width, height) / 2.0,
- 0, 2 * G_PI);
+ cairo_rectangle (cr, 0, 0, width * total, height);
cairo_fill (cr);
- cairo_move_to (cr, width / 2.0, height / 2.0);
gdk_cairo_set_source_rgba (cr, &foreground);
- cairo_arc (cr,
- width / 2.0, height / 2.0,
- MIN (width, height) / 2.0,
- -G_PI / 2.0, ratio * 2 * G_PI - G_PI / 2.0);
+ cairo_rectangle (cr, 0, 0, width * translated, height);
cairo_fill (cr);
- cairo_move_to (cr, width / 2.0, height / 2.0);
gdk_cairo_set_source_rgba (cr, &fuzzy_color);
- cairo_arc (cr,
- width / 2.0, height / 2.0,
- MIN (width, height) / 2.0,
- ratio * 2 * G_PI - G_PI / 2.0,
- (ratio + ratio_fuzzy) * 2 * G_PI - G_PI / 2.0);
-
+ cairo_rectangle (cr, width * translated, 0, width * fuzzy, height);
cairo_fill (cr);
}
@@ -212,7 +193,7 @@ gtr_progress_init (GtrProgress *self)
priv->untrans = 0;
priv->fuzzy = 0;
- gtk_widget_set_size_request (GTK_WIDGET (self), 16, 16);
+ gtk_widget_set_size_request (GTK_WIDGET (self), -1, 8);
g_signal_connect (G_OBJECT (self), "draw",
G_CALLBACK (on_draw), NULL);
}
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 8f1809dd..0eaeef6b 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -45,6 +45,7 @@
#include "gtr-dirs.h"
#include "gtr-debug.h"
#include "gtr-window.h"
+#include "gtr-progress.h"
#include <glib.h>
#include <glib-object.h>
@@ -63,6 +64,16 @@ typedef struct
GSettings *editor_settings;
GSettings *state_settings;
+ GtkWidget *progress_eventbox;
+ GtkWidget *progress_box;
+ GtkWidget *progress_revealer;
+ GtkWidget *progress_percentage;
+ GtkWidget *progress_trans;
+ GtkWidget *progress_fuzzy;
+ GtkWidget *progress_untrans;
+
+ GtrProgress *progress;
+
GtrPo *po;
GtkWidget *dock;
@@ -125,6 +136,19 @@ static guint signals[LAST_SIGNAL];
static gboolean gtr_tab_autosave (GtrTab * tab);
+static gboolean
+show_hide_revealer (GtkWidget *widget, GdkEvent *ev, GtrTab *tab)
+{
+ GtrTabPrivate *priv;
+ GtkRevealer *rev;
+
+ priv = gtr_tab_get_instance_private (tab);
+ rev = GTK_REVEALER (priv->progress_revealer);
+ gtk_revealer_set_reveal_child (rev, !gtk_revealer_get_reveal_child (rev));
+
+ return TRUE;
+}
+
static gboolean
msg_grab_focus (GtrTab *tab)
{
@@ -622,6 +646,13 @@ gtr_tab_init (GtrTab * tab)
GTR_SETTINGS_AUTO_SAVE_INTERVAL);
if (priv->autosave_interval <= 0)
priv->autosave_interval = 1;
+
+ priv->progress = gtr_progress_new ();
+ gtk_widget_show (GTK_WIDGET (priv->progress));
+ gtk_container_add (GTK_CONTAINER (priv->progress_box), GTK_WIDGET (priv->progress));
+
+ g_signal_connect (priv->progress_eventbox, "button-press-event",
+ G_CALLBACK (show_hide_revealer), tab);
}
static void
@@ -796,6 +827,14 @@ gtr_tab_class_init (GtrTabClass * klass)
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, trans_notebook);
gtk_widget_class_bind_template_child_private (widget_class, GtrTab, context);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_eventbox);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_box);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_trans);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_fuzzy);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_untrans);
+ gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_percentage);
+
g_type_ensure (gtr_view_get_type ());
g_type_ensure (gtr_context_panel_get_type ());
g_type_ensure (gtr_message_table_get_type ());
@@ -1733,3 +1772,29 @@ gtr_tab_get_msg (GtrTab *tab)
return msg;
}
+void
+gtr_tab_set_progress (GtrTab *tab,
+ gint trans,
+ gint untrans,
+ gint fuzzy)
+{
+ GtrTabPrivate *priv = gtr_tab_get_instance_private (tab);
+ gchar *percentage, *trans_text, *fuzzy_text, *untrans_text;
+
+ gtr_progress_set (priv->progress, trans, untrans, fuzzy);
+
+ percentage = g_strdup_printf (_("Translated: %0.2f%%"), (float)trans * 100 / (float)(trans + untrans +
fuzzy));
+ trans_text = g_strdup_printf (_("Translated: %d"), trans);
+ untrans_text = g_strdup_printf (_("Untranslated: %d"), untrans);
+ fuzzy_text = g_strdup_printf (_("Fuzzy: %d"), fuzzy);
+
+ gtk_label_set_text (GTK_LABEL (priv->progress_percentage), percentage);
+ gtk_label_set_text (GTK_LABEL (priv->progress_fuzzy), fuzzy_text);
+ gtk_label_set_text (GTK_LABEL (priv->progress_untrans), untrans_text);
+ gtk_label_set_text (GTK_LABEL (priv->progress_trans), trans_text);
+
+ g_free (percentage);
+ g_free (trans_text);
+ g_free (fuzzy_text);
+ g_free (untrans_text);
+}
diff --git a/src/gtr-tab.h b/src/gtr-tab.h
index 33de3bee..519ec05d 100644
--- a/src/gtr-tab.h
+++ b/src/gtr-tab.h
@@ -152,6 +152,8 @@ void gtr_tab_set_info_bar (GtrTab * tab, GtkWidget * infobar);
GtrMsg * gtr_tab_get_msg (GtrTab *tab);
+void gtr_tab_set_progress (GtrTab *tab, gint trans, gint untrans, gint fuzzy);
+
/* Semi-public methods */
gchar *_gtr_tab_get_name (GtrTab * tab);
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index 64dde0e5..c638aff7 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -6,6 +6,103 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
+ <child>
+ <object class="GtkEventBox" id="progress_eventbox">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox" id="progress_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+
+ <object class="GtkRevealer" id="progress_revealer">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">6</property>
+ <property name="margin_right">6</property>
+ <property name="margin_top">6</property>
+ <property name="margin_bottom">6</property>
+ <property name="orientation">Horizontal</property>
+ <property name="homogeneous">True</property>
+ <child>
+ <object class="GtkLabel" id="progress_percentage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">translated: 0.00%</property>
+ <property name="xalign">0.5</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="progress_trans">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">Translated: 0</property>
+ <property name="xalign">0.5</property>
+ <style>
+ <class name="progress_trans"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="progress_fuzzy">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">fuzzy: 0</property>
+ <property name="xalign">0.5</property>
+ <style>
+ <class name="progress_fuzzy"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="progress_untrans">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">untranslated: 0</property>
+ <property name="xalign">0.5</property>
+ <style>
+ <class name="progress_untranslated"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">false</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
<child>
<object class="GtkPaned" id="hbox">
<property name="visible">True</property>
@@ -182,9 +279,10 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
</template>
</interface>
+
diff --git a/src/gtr-window.c b/src/gtr-window.c
index 665f9777..ffe4b219 100644
--- a/src/gtr-window.c
+++ b/src/gtr-window.c
@@ -134,6 +134,7 @@ gtr_window_update_statusbar_message_count (GtrTab * tab,
GtrWindow * window)
{
GtrWindowPrivate *priv = gtr_window_get_instance_private(window);
+ GtrTab *active_tab;
GtrPo *po;
gchar *msg;
const gchar *status;
@@ -156,8 +157,9 @@ gtr_window_update_statusbar_message_count (GtrTab * tab,
untranslated = gtr_po_get_untranslated_count (po);
status = NULL;
- gtr_notebook_set_progress (GTR_NOTEBOOK (priv->notebook),
- translated, untranslated, fuzzy);
+ active_tab = gtr_window_get_active_tab (window);
+ gtr_tab_set_progress (GTR_TAB (active_tab),
+ translated, untranslated, fuzzy);
switch (gtr_msg_get_status (message))
{
diff --git a/src/styles.css b/src/styles.css
index 65112d9b..b3c8f728 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -14,3 +14,15 @@
margin-left: 10px;
color: @warning_color;
}
+
+.progress_trans {
+ color: @theme_selected_bg_color;
+}
+
+.progress_fuzzy {
+ color: @warning_color;
+}
+
+.progress_untranslated {
+ color: @error_color;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]