Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-annotation-properties-dialog.c
Go to the documentation of this file.
1 /* ev-annotation-properties-dialog.c
2  * this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
5  *
6  * Evince is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Evince is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include <config.h>
22 
23 #include <glib/gi18n.h>
24 
26 
27 enum {
30 };
31 
33  GtkDialog base_instance;
34 
37 
38  GtkWidget *grid;
39 
40  GtkWidget *author;
41  GtkWidget *color;
42  GtkWidget *opacity;
43  GtkWidget *popup_state;
44 
45  /* Text Annotations */
46  GtkWidget *icon;
47 
48  /* Text Markup Annotations */
49  GtkWidget *text_markup_type;
50 };
51 
53  GtkDialogClass base_class;
54 };
55 
56 G_DEFINE_TYPE (EvAnnotationPropertiesDialog, ev_annotation_properties_dialog, GTK_TYPE_DIALOG)
57 
58 static void
60 {
62 
63  if (dialog->annot) {
64  g_object_unref (dialog->annot);
65  dialog->annot = NULL;
66  }
67 
68  G_OBJECT_CLASS (ev_annotation_properties_dialog_parent_class)->dispose (object);
69 }
70 
71 static void
73  guint prop_id,
74  const GValue *value,
75  GParamSpec *pspec)
76 {
78 
79  switch (prop_id) {
80  case PROP_ANNOT_TYPE:
81  dialog->annot_type = g_value_get_enum (value);
82  break;
83  default:
84  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
85  }
86 }
87 
88 static void
90 {
92  GtkWidget *grid = dialog->grid;
93  GtkWidget *label;
94 
95  switch (dialog->annot_type) {
97  label = gtk_label_new (_("Icon:"));
98  gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
99  gtk_grid_attach (GTK_GRID (grid), label, 0, 4, 1, 1);
100  gtk_widget_show (label);
101 
102  dialog->icon = gtk_combo_box_text_new ();
103  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Note"));
104  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Comment"));
105  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Key"));
106  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Help"));
107  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("New Paragraph"));
108  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Paragraph"));
109  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Insert"));
110  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Cross"));
111  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Circle"));
112  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->icon), _("Unknown"));
113  gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon), 0);
114  gtk_grid_attach (GTK_GRID (grid), dialog->icon, 1, 4, 1, 1);
115  gtk_widget_set_hexpand (dialog->icon, TRUE);
116  gtk_widget_show (dialog->icon);
117 
118  break;
120  /* TODO */
121  break;
123  label = gtk_label_new (_("Markup type:"));
124  gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
125  gtk_grid_attach (GTK_GRID (grid), label, 0, 5, 1, 1);
126  gtk_widget_show (label);
127 
128  dialog->text_markup_type = gtk_combo_box_text_new ();
129  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type), _("Highlight"));
130  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type), _("Strike out"));
131  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type), _("Underline"));
132  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dialog->text_markup_type), _("Squiggly"));
133  gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->text_markup_type), 0);
134  gtk_grid_attach (GTK_GRID (grid), dialog->text_markup_type, 1, 5, 1, 1);
135  gtk_widget_set_hexpand (dialog->text_markup_type, TRUE);
136  gtk_widget_show (dialog->text_markup_type);
137  break;
138  default:
139  break;
140  }
141 }
142 
143 static void
145 {
146  GtkDialog *dialog = GTK_DIALOG (annot_dialog);
147  GtkWidget *content_area;
148  GtkWidget *label;
149  GtkWidget *grid;
150  const GdkRGBA yellow = { 1., 1., 0., 1. };
151 
152  gtk_window_set_title (GTK_WINDOW (annot_dialog), _("Annotation Properties"));
153  gtk_window_set_destroy_with_parent (GTK_WINDOW (annot_dialog), TRUE);
154  gtk_container_set_border_width (GTK_CONTAINER (annot_dialog), 5);
155  gtk_dialog_add_buttons (dialog,
156  GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
157  GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
158  NULL);
159  gtk_dialog_set_default_response (dialog, GTK_RESPONSE_APPLY);
160 
161  content_area = gtk_dialog_get_content_area (dialog);
162  gtk_box_set_spacing (GTK_BOX (content_area), 12);
163 
164  grid = gtk_grid_new ();
165  annot_dialog->grid = grid;
166  gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
167  gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
168  gtk_box_pack_start (GTK_BOX (content_area), grid, FALSE, FALSE, 0);
169  gtk_widget_show (grid);
170 
171  label = gtk_label_new (_("Author:"));
172  gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
173  gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
174  gtk_widget_show (label);
175 
176  annot_dialog->author = gtk_entry_new ();
177  gtk_entry_set_text (GTK_ENTRY (annot_dialog->author), g_get_real_name ());
178  gtk_grid_attach (GTK_GRID (grid), annot_dialog->author, 1, 0, 1, 1);
179  gtk_widget_set_hexpand (annot_dialog->author, TRUE);
180  gtk_widget_show (annot_dialog->author);
181 
182  label = gtk_label_new (_("Color:"));
183  gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
184  gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
185  gtk_widget_show (label);
186 
187  annot_dialog->color = gtk_color_button_new_with_rgba (&yellow);
188  gtk_grid_attach (GTK_GRID (grid), annot_dialog->color, 1, 1, 1, 1);
189  gtk_widget_set_hexpand (annot_dialog->color, TRUE);
190  gtk_widget_show (annot_dialog->color);
191 
192  label = gtk_label_new (_("Opacity:"));
193  gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
194  gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
195  gtk_widget_show (label);
196 
197  annot_dialog->opacity = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
198  0, 100, 5);
199  gtk_range_set_value (GTK_RANGE (annot_dialog->opacity), 100);
200  gtk_grid_attach (GTK_GRID (grid), annot_dialog->opacity, 1, 2, 1, 1);
201  gtk_widget_set_hexpand (annot_dialog->opacity, TRUE);
202  gtk_widget_show (annot_dialog->opacity);
203 
204  label = gtk_label_new (_("Initial window state:"));
205  gtk_misc_set_alignment (GTK_MISC (label), 0., 0.5);
206  gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
207  gtk_widget_show (label);
208 
209  annot_dialog->popup_state = gtk_combo_box_text_new ();
210  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (annot_dialog->popup_state), _("Open"));
211  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (annot_dialog->popup_state), _("Close"));
212  gtk_combo_box_set_active (GTK_COMBO_BOX (annot_dialog->popup_state), 1);
213  gtk_grid_attach (GTK_GRID (grid), annot_dialog->popup_state, 1, 3, 1, 1);
214  gtk_widget_set_hexpand (annot_dialog->popup_state, TRUE);
215  gtk_widget_show (annot_dialog->popup_state);
216 }
217 
218 static void
220 {
221  GObjectClass *object_class = G_OBJECT_CLASS (klass);
222 
223  object_class->dispose = ev_annotation_properties_dialog_dispose;
224  object_class->constructed = ev_annotation_properties_dialog_constructed;
225  object_class->set_property = ev_annotation_properties_dialog_set_property;
226 
227  g_object_class_install_property (object_class,
229  g_param_spec_enum ("annot-type",
230  "AnnotType",
231  "The type of annotation",
232  EV_TYPE_ANNOTATION_TYPE,
234  G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
235  G_PARAM_STATIC_STRINGS));
236 }
237 
238 GtkWidget *
240 {
241  return GTK_WIDGET (g_object_new (EV_TYPE_ANNOTATION_PROPERTIES_DIALOG,
242  "annot-type", annot_type,
243  NULL));
244 }
245 
246 GtkWidget *
248 {
250  const gchar *label;
251  gdouble opacity;
252  gboolean is_open;
253  GdkRGBA rgba;
254 
256  dialog->annot = g_object_ref (annot);
257 
259  if (label)
260  gtk_entry_set_text (GTK_ENTRY (dialog->author), label);
261 
262  ev_annotation_get_rgba (annot, &rgba);
263  gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog->color), &rgba);
264 
266  gtk_range_set_value (GTK_RANGE (dialog->opacity), opacity * 100);
267 
269  gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->popup_state),
270  is_open ? 0 : 1);
271 
272  if (EV_IS_ANNOTATION_TEXT (annot)) {
273  EvAnnotationText *annot_text = EV_ANNOTATION_TEXT (annot);
274 
275  gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->icon),
276  ev_annotation_text_get_icon (annot_text));
277  } else if (EV_IS_ANNOTATION_TEXT_MARKUP (annot)) {
278  EvAnnotationTextMarkup *annot_markup = EV_ANNOTATION_TEXT_MARKUP (annot);
279 
280  gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->text_markup_type),
282  }
283 
284  return GTK_WIDGET (dialog);
285 }
286 
287 const gchar *
289 {
290  return gtk_entry_get_text (GTK_ENTRY (dialog->author));
291 }
292 
293 void
295  GdkRGBA *rgba)
296 {
297  gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog->color), rgba);
298 }
299 
300 gdouble
302 {
303  return gtk_range_get_value (GTK_RANGE (dialog->opacity)) / 100;
304 }
305 
306 gboolean
308 {
309  return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->popup_state)) == 0;
310 }
311 
314 {
315  return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->icon));
316 }
317 
320 {
321  return gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->text_markup_type));
322 }