From c719015609b943decb76fbbdf18618227b6654a9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20=C4=8Cernock=C3=BD?= Date: Thu, 18 Feb 2016 10:47:46 +0100 Subject: [PATCH] Add properties dialog --- data/ui/Makefile.am | 3 +- data/ui/label-properties-dialog.ui | 316 +++++++++++++++++++ src/Makefile.am | 2 + src/file.c | 42 ++- src/file.h | 31 +- src/label-properties-dialog.c | 480 +++++++++++++++++++++++++++++ src/label-properties-dialog.h | 55 ++++ src/label.c | 115 +++++++ src/label.h | 1 + 9 files changed, 1023 insertions(+), 22 deletions(-) create mode 100644 data/ui/label-properties-dialog.ui create mode 100644 src/label-properties-dialog.c create mode 100644 src/label-properties-dialog.h diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am index 833eb26b..41137177 100644 --- a/data/ui/Makefile.am +++ b/data/ui/Makefile.am @@ -10,6 +10,7 @@ builder_DATA = \ merge-properties-dialog.ui \ template-designer.ui \ prefs-dialog.ui \ - object-editor.ui + object-editor.ui \ + label-properties-dialog.ui EXTRA_DIST = $(builder_DATA) diff --git a/data/ui/label-properties-dialog.ui b/data/ui/label-properties-dialog.ui new file mode 100644 index 00000000..e407e443 --- /dev/null +++ b/data/ui/label-properties-dialog.ui @@ -0,0 +1,316 @@ + + + + + true + false + horizontal + top + 18 + 18 + + + + true + 6 + 6 + + + true + Label + 0 + + + + + + 0 + 0 + 2 + + + + + true + Vendor: + 1 + + + + 0 + 1 + + + + + true + false + 0 + true + + + 1 + 1 + + + + + true + Part #: + 1 + + + + 0 + 2 + + + + + true + false + 0 + true + + + 1 + 2 + + + + + true + Description: + 1 + + + + 0 + 3 + + + + + true + false + 0 + true + + + 1 + 3 + + + + + true + Dimensions: + 1 + 0 + 6 + + + + 0 + 4 + + + + + true + false + 17,8 × 10 / 2 mm (width × height / round) + 0 + 0 + true + 6 + + + 1 + 4 + + + + + true + Medium size: + 1 + 6 + + + + 0 + 5 + + + + + true + false + 0 + true + 6 + + + 1 + 5 + + + + + true + Layout: + 1 + + + + 0 + 6 + + + + + true + false + 0 + true + + + 1 + 6 + + + + + true + Margins: + 1 + + + + 0 + 7 + + + + + true + false + 0 + true + + + 1 + 7 + + + + + true + Similar products: + 1 + 0 + 6 + + + + 0 + 8 + + + + + true + false + 0 + 0 + true + 6 + + + 1 + 8 + + + + + + true + Options + 0 + 8 + + + + + + 0 + 9 + 2 + + + + + true + Orientation: + 1 + + + + 0 + 10 + + + + + true + false + horizontal + + + _Normal + true + true + true + + + + + _Rotated + true + true + true + orientation_normal_radio + + + + + 1 + 10 + + + + + end + + + + diff --git a/src/Makefile.am b/src/Makefile.am index e63f32d9..49e87a4f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -152,6 +152,8 @@ glabels_3_SOURCES = \ label-image.h \ label-barcode.c \ label-barcode.h \ + label-properties-dialog.c \ + label-properties-dialog.h \ pixbuf-util.c \ pixbuf-util.h \ xml-label.c \ diff --git a/src/file.c b/src/file.c index ffe82b50..6668a12b 100644 --- a/src/file.c +++ b/src/file.c @@ -30,6 +30,7 @@ #include "recent.h" #include "file-util.h" #include "window.h" +#include "label-properties-dialog.h" #include "new-label-dialog.h" #include @@ -57,7 +58,7 @@ static gchar *save_path = NULL; static void new_complete (GtkDialog *dialog, gpointer user_data); -static void properties_complete (GtkDialog *dialog, +static void properties_choose_complete (GtkDialog *dialog, gpointer user_data); static void open_response (GtkDialog *chooser, @@ -153,13 +154,39 @@ new_complete (GtkDialog *dialog, gl_debug (DEBUG_FILE, "END"); } - /*****************************************************************************/ /* "Properties" menu callback. */ /*****************************************************************************/ void gl_file_properties (glLabel *label, glWindow *window) +{ + GtkWidget *dialog; + gint response; + + gl_debug (DEBUG_FILE, "START"); + + g_return_if_fail (label && GL_IS_LABEL (label)); + g_return_if_fail (window && GTK_IS_WINDOW (window)); + + dialog = gl_label_properties_dialog_new (label, GTK_WINDOW (window)); + /*Translators: dialog title*/ + gtk_window_set_title (GTK_WINDOW (dialog), _("Label properties")); + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); + if (response == GL_RESPONSE_SELECT_OTHER) + gl_file_choose_properties (label, window); + + gl_debug (DEBUG_FILE, "END"); +} + +/*****************************************************************************/ +/* Choose properties assistent. */ +/*****************************************************************************/ +void +gl_file_choose_properties (glLabel *label, + glWindow *window) { const lglTemplate *template; gboolean rotate_flag; @@ -172,11 +199,12 @@ gl_file_properties (glLabel *label, g_return_if_fail (window && GTK_IS_WINDOW (window)); dialog = gl_new_label_dialog_new (GTK_WINDOW (window)); - gtk_window_set_title (GTK_WINDOW (dialog), _("Label properties")); + /*Translators: assistent dialog title*/ + gtk_window_set_title (GTK_WINDOW (dialog), _("Choose label properties")); g_object_set_data (G_OBJECT (dialog), "label", label); - g_signal_connect (G_OBJECT(dialog), "complete", G_CALLBACK (properties_complete), dialog); + g_signal_connect (G_OBJECT(dialog), "complete", G_CALLBACK (properties_choose_complete), dialog); template = gl_label_get_template (label); rotate_flag = gl_label_get_rotate_flag (label); @@ -201,11 +229,11 @@ gl_file_properties (glLabel *label, /*---------------------------------------------------------------------------*/ -/* PRIVATE. Properties "ok" button callback. */ +/* PRIVATE. Properties assistant "OK" button callback. */ /*---------------------------------------------------------------------------*/ static void -properties_complete (GtkDialog *dialog, - gpointer user_data) +properties_choose_complete (GtkDialog *dialog, + gpointer user_data) { lglTemplate *template; glLabel *label; diff --git a/src/file.h b/src/file.h index 3ac975e1..1aa2a9dd 100644 --- a/src/file.h +++ b/src/file.h @@ -28,33 +28,36 @@ G_BEGIN_DECLS -void gl_file_new (glWindow *window); +void gl_file_new (glWindow *window); -void gl_file_properties (glLabel *label, - glWindow *window); +void gl_file_properties (glLabel *label, + glWindow *window); +void gl_file_choose_properties (glLabel *label, + glWindow *window); -void gl_file_open (glWindow *window); +void gl_file_open (glWindow *window); -void gl_file_open_recent (const gchar *filename, - glWindow *window); -gboolean gl_file_open_real (const gchar *filename, - glWindow *window); +void gl_file_open_recent (const gchar *filename, + glWindow *window); +gboolean gl_file_open_real (const gchar *filename, + glWindow *window); -gboolean gl_file_save (glLabel *label, - glWindow *window); -gboolean gl_file_save_as (glLabel *label, - glWindow *window); +gboolean gl_file_save (glLabel *label, + glWindow *window); +gboolean gl_file_save_as (glLabel *label, + glWindow *window); -gboolean gl_file_close (glWindow *window); -void gl_file_exit (void); +gboolean gl_file_close (glWindow *window); + +void gl_file_exit (void); G_END_DECLS diff --git a/src/label-properties-dialog.c b/src/label-properties-dialog.c new file mode 100644 index 00000000..595ec5f4 --- /dev/null +++ b/src/label-properties-dialog.c @@ -0,0 +1,480 @@ +/* + * label-properties-dialog.c + * Copyright (C) 2001-2009 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels 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. + * + * gLabels 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 gLabels. If not, see . + */ + +#include + +#include "label-properties-dialog.h" + +#include +#include + +#include "builder-util.h" +#include "prefs.h" +#include "mini-preview.h" +#include "window.h" +#include "debug.h" + + +#define MINI_PREVIEW_MIN_WIDTH 270 +#define MINI_PREVIEW_MIN_HEIGHT 360 + + +/*========================================================*/ +/* Private types. */ +/*========================================================*/ + +typedef struct +{ + glLabel *label; + GtkBox *box; + GtkWidget *preview; + GtkLabel *vendor; + GtkLabel *partnum; + GtkLabel *description; + GtkLabel *dimensions; + GtkLabel *medium; + GtkLabel *layout; + GtkLabel *margins; + GtkLabel *similar_label; + GtkLabel *similar; + GtkLabel *orientation_label; + GtkBox *orientation_box; + GtkRadioButton *normal_orientation; + GtkRadioButton *rotated_orientation; + +} glLabelPropertiesDialogPrivate; + + +struct _glLabelPropertiesDialog +{ + GtkDialog parent; + + glLabelPropertiesDialogPrivate *priv; +}; + + + +/*========================================================*/ +/* Private function prototypes */ +/*========================================================*/ + +static void gl_label_properties_dialog_finalize (GObject *object); + +static void gl_label_properties_dialog_rotation_cb (glLabelPropertiesDialog *dialog); + +static void gl_label_properties_dialog_response_cb (glLabelPropertiesDialog *dialog, + gint response); + +static void gl_label_properties_dialog_construct (glLabelPropertiesDialog *dialog, + glLabel *label); + + +/*========================================================*/ +/* Private globals. */ +/*========================================================*/ + + +/*****************************************************************************/ +/* Boilerplate object stuff. */ +/*****************************************************************************/ + +G_DEFINE_TYPE_WITH_PRIVATE (glLabelPropertiesDialog, gl_label_properties_dialog, GTK_TYPE_DIALOG) + + + +static void +gl_label_properties_dialog_class_init (glLabelPropertiesDialogClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + gl_debug (DEBUG_UI, ""); + + object_class->finalize = gl_label_properties_dialog_finalize; +} + + +static void +gl_label_properties_dialog_rotation_cb (glLabelPropertiesDialog *dialog) +{ + gboolean rotate_flag; + glWindow *window; + glView *view; + + gl_debug (DEBUG_UI, "START"); + + rotate_flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->rotated_orientation)); + gl_mini_preview_set_rotate (GL_MINI_PREVIEW (dialog->priv->preview), rotate_flag); + gl_label_set_rotate_flag (dialog->priv->label, rotate_flag, TRUE); + + window = GL_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (dialog))); + view = GL_VIEW (window->view); + if (view->zoom_to_fit_flag) + gl_view_zoom_to_fit (view); + + gl_debug (DEBUG_UI, "END"); +} + + +static void +gl_label_properties_dialog_response_cb (glLabelPropertiesDialog *dialog, + gint response) +{ + gl_debug (DEBUG_UI, "START"); + + switch (response) + { + case GL_RESPONSE_SELECT_OTHER: + case GTK_RESPONSE_CLOSE: + case GTK_RESPONSE_DELETE_EVENT: + gtk_widget_hide (GTK_WIDGET (dialog)); + break; + default: + g_print ("response = %d", response); + g_assert_not_reached (); + } + + gl_debug (DEBUG_UI, "END"); +} + + +static void +gl_label_properties_dialog_init (glLabelPropertiesDialog *dialog) +{ + gchar *builder_filename; + GtkBuilder *builder; + static gchar *object_ids[] = {"label_properties_box", NULL}; + GError *error = NULL; + GtkWidget *vbox; + + gl_debug (DEBUG_UI, "START"); + + dialog->priv = gl_label_properties_dialog_get_instance_private (dialog); + + vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + + /*Translators: Button label to choose different template*/ + gtk_dialog_add_button (GTK_DIALOG (dialog), _("Choose _other…"), GL_RESPONSE_SELECT_OTHER); + gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Close"), GTK_RESPONSE_CLOSE); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); + + builder = gtk_builder_new (); + builder_filename = g_build_filename (GLABELS_DATA_DIR, "ui", "label-properties-dialog.ui", NULL); + gtk_builder_add_objects_from_file (builder, builder_filename, object_ids, &error); + g_free (builder_filename); + if (error) { + g_critical ("%s\n\ngLabels may not be installed correctly!", error->message); + g_error_free (error); + return; + } + + gl_builder_util_get_widgets (builder, + "label_properties_box", &dialog->priv->box, + "vendor_value", &dialog->priv->vendor, + "partnum_value", &dialog->priv->partnum, + "description_value", &dialog->priv->description, + "dimensions_value", &dialog->priv->dimensions, + "medium_value", &dialog->priv->medium, + "layout_value", &dialog->priv->layout, + "margins_value", &dialog->priv->margins, + "similar_label", &dialog->priv->similar_label, + "similar_value", &dialog->priv->similar, + "orientation_label", &dialog->priv->orientation_label, + "orientation_box", &dialog->priv->orientation_box, + "orientation_normal_radio", &dialog->priv->normal_orientation, + "orientation_rotated_radio", &dialog->priv->rotated_orientation, + NULL); + + gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (dialog->priv->box)); + + dialog->priv->preview = gl_mini_preview_new (MINI_PREVIEW_MIN_HEIGHT, MINI_PREVIEW_MIN_WIDTH); + gtk_box_pack_start (dialog->priv->box, GTK_WIDGET (dialog->priv->preview), FALSE, FALSE, 0); + gtk_widget_show_all (dialog->priv->preview); + + g_object_unref (G_OBJECT (builder)); + + gl_debug (DEBUG_UI, "END"); +} + + +static void +gl_label_properties_dialog_finalize (GObject *object) +{ + glLabelPropertiesDialog* dialog = GL_LABEL_PROPERTIES_DIALOG (object); + + gl_debug (DEBUG_UI, "START"); + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_LABEL_PROPERTIES_DIALOG (dialog)); + g_return_if_fail (dialog->priv != NULL); + + + G_OBJECT_CLASS (gl_label_properties_dialog_parent_class)->finalize (object); + + gl_debug (DEBUG_UI, "END"); +} + + +/* FIXME: Move this function to library */ +static void +lgl_template_get_margins (const lglTemplate *template, + gdouble *hmargin, + gdouble *vmargin) +{ + GList *p, *q; + const lglTemplateFrame *frame; + const lglTemplateLayout *layout; + + /* Set margins to maximum */ + *hmargin = template->page_width; + *vmargin = template->page_height; + + /* and search lowest margin in layouts */ + for (p = template->frames; p; p = p->next) + { + frame = (lglTemplateFrame *)p->data; + for (q = frame->all.layouts; q; q = q->next) + { + layout = (lglTemplateLayout *)q->data; + if (layout->x0 < *hmargin) + *hmargin = layout->x0; + if (layout->y0 < *vmargin) + *vmargin = layout->y0; + } + } +} + +/* FIXME: Move this function to library */ +gchar * +lgl_template_get_margins_string (const lglTemplate *template) +{ + lglUnits units; + gdouble units_per_point; + gdouble hmargin, vmargin; + gchar *hmargin_str, *vmargin_str; + gchar *margins_str; + + units = gl_prefs_model_get_units (gl_prefs); + units_per_point = lgl_units_get_units_per_point (units); + + lgl_template_get_margins (template, &hmargin, &vmargin); + + if (units == LGL_UNITS_INCH) + { + hmargin_str = lgl_str_format_fraction (hmargin*units_per_point); + vmargin_str = lgl_str_format_fraction (vmargin*units_per_point); + } + else + { + hmargin_str = g_strdup_printf ("%.5g", hmargin*units_per_point); + vmargin_str = g_strdup_printf ("%.5g", vmargin*units_per_point); + } + + /*Translators: first param is numeric value of horizontal margine, second*/ + /*is numeric value of vertical margine and third is unit. Example: */ + /*"10 / 12.5 mm (horizontal / vertical)"*/ + margins_str = g_strdup_printf (_("%s / %s %s (horizontal / vertical)"), + hmargin_str, vmargin_str, lgl_units_get_name (units)); + + g_free (hmargin_str); + g_free (vmargin_str); + + return margins_str; +} + +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Create properties widgets. */ +/*--------------------------------------------------------------------------*/ +static void +gl_label_properties_dialog_construct (glLabelPropertiesDialog *dialog, + glLabel *label) +{ + const lglTemplate *template; + gchar *template_name; + lglUnits units; + gdouble units_per_point; + lglVendor *vendor; + gchar *text; + gchar *link; + gchar *escaped_url; + GList *list, *p; + GString *list_text; + gboolean rotate_flag; + gdouble w, h; + + gl_debug (DEBUG_UI, "START"); + + dialog->priv->label = label; + + template = gl_label_get_template (label); + template_name = lgl_template_get_name (template); + units = gl_prefs_model_get_units (gl_prefs); + units_per_point = lgl_units_get_units_per_point (units); + + /* Vendor */ + vendor = lgl_db_lookup_vendor_from_name (template->brand); + if (vendor && vendor->url) + { + escaped_url = g_markup_escape_text (vendor->url, -1); + link = g_strconcat ("", template->brand, "", NULL); + gtk_label_set_markup (dialog->priv->vendor, link); + g_free (escaped_url); + g_free (link); + } + else + { + gtk_label_set_label (dialog->priv->vendor, template->brand); + } + + /* Part number */ + if (template->product_url) + { + escaped_url = g_markup_escape_text (template->product_url, -1); + link = g_strconcat ("", template->part, "", NULL); + gtk_label_set_markup (dialog->priv->partnum, link); + g_free (escaped_url); + g_free (link); + } + else + { + gtk_label_set_label (dialog->priv->partnum, template->part); + } + + /* Description */ + gtk_label_set_label (dialog->priv->description, template->description); + + /* Dimensions */ + text = gl_label_get_dimensions_string (label); + gtk_label_set_label (dialog->priv->dimensions, text); + g_free (text); + + /* Medium */ + text = lgl_db_lookup_paper_name_from_id (template->paper_id); + gtk_label_set_label (dialog->priv->medium, text); + g_free (text); + + /* Layout */ + text = lgl_template_frame_get_layout_description (template->frames->data); + gtk_label_set_label (dialog->priv->layout, text); + g_free (text); + + /* Margins */ + text = lgl_template_get_margins_string (template); + gtk_label_set_label (dialog->priv->margins, text); + g_free (text); + + /* Similar products */ + list = lgl_db_get_similar_template_name_list (template_name); + if (list) + { + list_text = g_string_new (""); + for (p = list; p; p = p->next) + { + g_string_append (list_text, (char *)p->data); + if (p->next) + g_string_append_c (list_text, '\n'); + } + gtk_label_set_text (dialog->priv->similar, list_text->str); + g_string_free (list_text, TRUE); + } + else + { + gtk_widget_hide (GTK_WIDGET (dialog->priv->similar_label)); + gtk_widget_hide (GTK_WIDGET (dialog->priv->similar)); + } + + /* Orientation */ + gl_label_get_size (label, &w, &h); + if (w == h) + { + gtk_widget_hide (GTK_WIDGET (dialog->priv->orientation_label)); + gtk_widget_hide (GTK_WIDGET (dialog->priv->orientation_box)); + gl_mini_preview_set_draw_arrow (GL_MINI_PREVIEW (dialog->priv->preview), FALSE); + } + else + { + rotate_flag = gl_label_get_rotate_flag (label); + if (rotate_flag) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->rotated_orientation), TRUE); + else + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->normal_orientation), TRUE); + gl_mini_preview_set_draw_arrow (GL_MINI_PREVIEW (dialog->priv->preview), TRUE); + gl_mini_preview_set_rotate (GL_MINI_PREVIEW (dialog->priv->preview), rotate_flag); + } + + /* Preview */ + gl_mini_preview_set_template (GL_MINI_PREVIEW (dialog->priv->preview), template); + + g_free (template_name); + g_free (vendor); + + g_signal_connect_swapped (G_OBJECT (dialog->priv->normal_orientation), + "toggled", + G_CALLBACK (gl_label_properties_dialog_rotation_cb), + dialog); + g_signal_connect_swapped (G_OBJECT (dialog->priv->rotated_orientation), + "toggled", + G_CALLBACK (gl_label_properties_dialog_rotation_cb), + dialog); + g_signal_connect (G_OBJECT (dialog), + "response", + G_CALLBACK (gl_label_properties_dialog_response_cb), + NULL); + + gl_debug (DEBUG_UI, "END"); +} + + +/*****************************************************************************/ +/* NEW document properties dialog. */ +/*****************************************************************************/ +GtkWidget* +gl_label_properties_dialog_new (glLabel *label, + GtkWindow *parent) +{ + glLabelPropertiesDialog *dialog; + + g_assert (GL_IS_LABEL (label)); + + gl_debug (DEBUG_UI, "START"); + + dialog = GL_LABEL_PROPERTIES_DIALOG (g_object_new (GL_TYPE_LABEL_PROPERTIES_DIALOG, NULL)); + + if (parent) + gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); + + gl_label_properties_dialog_construct (GL_LABEL_PROPERTIES_DIALOG (dialog), + label); + + gl_debug (DEBUG_UI, "END"); + + return GTK_WIDGET (dialog); +} + + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/src/label-properties-dialog.h b/src/label-properties-dialog.h new file mode 100644 index 00000000..53c98ccf --- /dev/null +++ b/src/label-properties-dialog.h @@ -0,0 +1,55 @@ +/* + * label-properties-dialog.h + * Copyright (C) 2001-2009 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels 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. + * + * gLabels 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 gLabels. If not, see . + */ + +#ifndef __LABEL_PROPERTIES_DIALOG_H__ +#define __LABEL_PROPERTIES_DIALOG_H__ + + +#include + +#include "label.h" + + +G_BEGIN_DECLS + +#define GL_RESPONSE_SELECT_OTHER 1 + +#define GL_TYPE_LABEL_PROPERTIES_DIALOG (gl_label_properties_dialog_get_type ()) + +G_DECLARE_FINAL_TYPE (glLabelPropertiesDialog, gl_label_properties_dialog, GL, LABEL_PROPERTIES_DIALOG, GtkDialog) + +GtkWidget *gl_label_properties_dialog_new (glLabel *label, GtkWindow *parent); + +G_END_DECLS + + +#endif /* __LABEL_PROPERTIES_DIALOG_H__ */ + + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/src/label.c b/src/label.c index 48df06a4..52292a57 100644 --- a/src/label.c +++ b/src/label.c @@ -703,6 +703,121 @@ gl_label_get_size (glLabel *label, } +/****************************************************************************/ +/* get string with info about dimensions */ +/****************************************************************************/ +gchar * +gl_label_get_dimensions_string (glLabel *label) +{ + gchar *dims; + lglTemplate *template; + const lglTemplateFrame *frame; + lglUnits units; + gdouble units_per_point; + gchar *s1 = NULL; + gchar *s2 = NULL; + gchar *s3 = NULL; + + gl_debug (DEBUG_LABEL, "START"); + + g_return_val_if_fail (label && GL_IS_LABEL (label), NULL); + + template = label->priv->template; + if (!template) + return g_strdup(""); + frame = (lglTemplateFrame *)template->frames->data; + units = gl_prefs_model_get_units (gl_prefs); + units_per_point = lgl_units_get_units_per_point (units); + + switch (frame->shape) + { + case LGL_TEMPLATE_FRAME_SHAPE_RECT: + if (units == LGL_UNITS_INCH) + { + s1 = lgl_str_format_fraction (frame->rect.w*units_per_point); + s2 = lgl_str_format_fraction (frame->rect.h*units_per_point); + s3 = lgl_str_format_fraction (frame->rect.r*units_per_point); + } + else + { + s1 = g_strdup_printf ("%.5g", frame->rect.w*units_per_point); + s2 = g_strdup_printf ("%.5g", frame->rect.h*units_per_point); + s3 = g_strdup_printf ("%.5g", frame->rect.r*units_per_point); + } + if (frame->rect.r == 0) + /*Translators: first param is numeric value of width, second is numeric*/ + /*value of height and third is unit. Example:*/ + /*"60 mm × 22.5 mm (width / height)"*/ + dims = g_strdup_printf (_("%s × %s %s (width × height)"), + s1, s2, lgl_units_get_name (units)); + else + /*Translators: first param is numeric value of width, second is numeric*/ + /*value of height, third is numeric value of round and fourth is unit. */ + /*Example:*/ + /*"50 mm × 30 / 1.5 mm (width × height / round)"*/ + dims = g_strdup_printf (_("%s × %s / %s %s (width × height / round)"), + s1, s2, s3, lgl_units_get_name (units)); + break; + + case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: + if (units == LGL_UNITS_INCH) + { + s1 = lgl_str_format_fraction (frame->ellipse.w*units_per_point); + s2 = lgl_str_format_fraction (frame->ellipse.h*units_per_point); + } + else + { + s1 = g_strdup_printf ("%.5g", frame->ellipse.w*units_per_point); + s2 = g_strdup_printf ("%.5g", frame->ellipse.h*units_per_point); + } + /*Translators: first param is numeric value of width, second is numeric*/ + /*value of height and third is unit. Example:*/ + /*"60 mm × 22.5 mm (width / height)"*/ + dims = g_strdup_printf (_("%s × %s %s (width × height)"), + s1, s2, lgl_units_get_name (units)); + break; + + case LGL_TEMPLATE_FRAME_SHAPE_ROUND: + if (units == LGL_UNITS_INCH) + s1 = lgl_str_format_fraction (2*frame->round.r*units_per_point); + else + s1 = g_strdup_printf ("%.5g", 2*frame->round.r*units_per_point); + /*Translators: first param is numeric value of diameter and secons is*/ + /*unit. Example:*/ + /*"120.5 mm (diameter)"*/ + dims = g_strdup_printf (_("%s %s (diameter)"), + s1, lgl_units_get_name (units)); + break; + + case LGL_TEMPLATE_FRAME_SHAPE_CD: + if (units == LGL_UNITS_INCH) + { + s1 = lgl_str_format_fraction (2*frame->cd.r1*units_per_point); + s2 = lgl_str_format_fraction (2*frame->cd.r2*units_per_point); + } + else + { + s1 = g_strdup_printf ("%.5g", 2*frame->cd.r1*units_per_point); + s2 = g_strdup_printf ("%.5g", 2*frame->cd.r2*units_per_point); + } + /*Translators: first param is numeric value of diameter, second is numeric*/ + /*value of whole and third is unit. Example:*/ + /*"120.5 mm / 30 mm (diameter / hole)"*/ + dims = g_strdup_printf (_("%s / %s %s (diameter / hole)"), + s1, s2, lgl_units_get_name (units)); + break; + } + + g_free (s1); + g_free (s2); + g_free (s3); + + gl_debug (DEBUG_LABEL, "END"); + + return dims; +} + + /****************************************************************************/ /* set merge information structure. */ /****************************************************************************/ diff --git a/src/label.h b/src/label.h index f93f6f4e..003e27bd 100644 --- a/src/label.h +++ b/src/label.h @@ -124,6 +124,7 @@ void gl_label_get_size (glLabel *label, gdouble *w, gdouble *h); +gchar *gl_label_get_dimensions_string (glLabel *label); void gl_label_set_merge (glLabel *label, glMerge *merge, -- 2.39.5