[glabels/vala] Put page preview in a property editor widget.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/vala] Put page preview in a property editor widget.
- Date: Fri, 6 Apr 2012 03:29:09 +0000 (UTC)
commit b92d25df8c97c094094935d63c4c7a4b844ce52e
Author: Jim Evins <evins snaught com>
Date: Thu Apr 5 23:28:10 2012 -0400
Put page preview in a property editor widget.
data/ui/Makefile.am | 2 +-
data/ui/page_preview.ui | 72 ----------------
data/ui/property_editor.ui | 52 ++++++++++++
glabels/Makefile.am | 2 +-
glabels/mini_preview.vala | 2 +-
.../{page_preview.vala => property_editor.vala} | 19 +++--
glabels/view.vala | 86 ++++++++++++--------
glabels/window.vala | 21 +++---
8 files changed, 128 insertions(+), 128 deletions(-)
---
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
index 3035a76..d83cc01 100644
--- a/data/ui/Makefile.am
+++ b/data/ui/Makefile.am
@@ -5,7 +5,7 @@ builderdir = $(datadir)/$(GLABELS_BRANCH)/ui/
builder_DATA = \
new_label_dialog.ui \
object_editor.ui \
- page_preview.ui
+ property_editor.ui
EXTRA_DIST = $(builder_DATA)
diff --git a/data/ui/property_editor.ui b/data/ui/property_editor.ui
new file mode 100644
index 0000000..ee3a2e9
--- /dev/null
+++ b/data/ui/property_editor.ui
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkVBox" id="property_editor_vbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">end</property>
+ <property name="border_width">6</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkNotebook" id="property_editor_notebook">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkBox" id="layout_preview_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">3</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ <child type="tab">
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Preview</property>
+ </object>
+ <packing>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <object class="GtkSizeGroup" id="page_sizegroup">
+ <property name="mode">both</property>
+ </object>
+ <object class="GtkSizeGroup" id="width_sizegroup"/>
+</interface>
diff --git a/glabels/Makefile.am b/glabels/Makefile.am
index 262cd7c..e9285ce 100644
--- a/glabels/Makefile.am
+++ b/glabels/Makefile.am
@@ -45,9 +45,9 @@ glabels_4_SOURCES = \
mini_preview.vala \
new_label_dialog.vala \
object_editor.vala \
- page_preview.vala \
prefs.vala \
print.vala \
+ property_editor.vala \
template_history.vala \
ui.vala \
units_util.vala \
diff --git a/glabels/mini_preview.vala b/glabels/mini_preview.vala
index a2ddc30..3fff2f2 100644
--- a/glabels/mini_preview.vala
+++ b/glabels/mini_preview.vala
@@ -253,7 +253,7 @@ namespace glabels
/* Find offset to center preview. */
double offset_x = (w/scale - template.page_width) / 2.0;
- double offset_y = (h/scale - template.page_height) / 2.0;
+ double offset_y = MARGIN;
/* Set transformation. */
cr.scale( scale, scale );
diff --git a/glabels/page_preview.vala b/glabels/property_editor.vala
similarity index 81%
rename from glabels/page_preview.vala
rename to glabels/property_editor.vala
index 1d0e00f..171612f 100644
--- a/glabels/page_preview.vala
+++ b/glabels/property_editor.vala
@@ -25,22 +25,23 @@ using libglabels;
namespace glabels
{
- class PagePreview : Gtk.Box
+ class PropertyEditor : Gtk.Box
{
private Label label;
- private Gtk.Box title_box;
+ private Gtk.Notebook property_editor_notebook;
+
private Gtk.Box layout_preview_box;
private MiniPreview layout_preview;
- public PagePreview()
+ public PropertyEditor()
{
/* Load the user interface. */
Gtk.Builder builder = new Gtk.Builder();
try
{
- string file = GLib.Path.build_filename( Config.DATADIR, Config.GLABELS_BRANCH, "ui", "page_preview.ui" );
+ string file = GLib.Path.build_filename( Config.DATADIR, Config.GLABELS_BRANCH, "ui", "property_editor.ui" );
string[] objects = { "property_editor_vbox",
null };
builder.add_objects_from_file( file, objects );
@@ -53,11 +54,11 @@ namespace glabels
Gtk.VBox property_editor_vbox = builder.get_object( "property_editor_vbox" ) as Gtk.VBox;
pack_start( property_editor_vbox );
- /* Title widgets. */
- title_box = builder.get_object( "title_box" ) as Gtk.Box;
- title_box.set_sensitive( false );
+ /* Notebook. */
+ property_editor_notebook = builder.get_object( "property_editor_notebook" ) as Gtk.Notebook;
+ property_editor_notebook.set_sensitive( false );
- /* Layout widgets. */
+ /* Preview widgets. */
layout_preview_box = builder.get_object( "layout_preview_box" ) as Gtk.Box;
layout_preview = new MiniPreview( 280, 420 );
@@ -70,7 +71,7 @@ namespace glabels
{
this.label = label;
- title_box.set_sensitive( true );
+ property_editor_notebook.set_sensitive( true );
layout_preview.set_label( label );
}
diff --git a/glabels/view.vala b/glabels/view.vala
index 7bc2d53..8135013 100644
--- a/glabels/view.vala
+++ b/glabels/view.vala
@@ -101,8 +101,6 @@ namespace glabels
private double create_y0;
- public Label label { get; private set; }
-
public double zoom { get; private set; }
private bool _markup_visible;
@@ -136,10 +134,38 @@ namespace glabels
}
- public View( Label label )
+ private Label? _label;
+ public Label? label
{
- this.label = label;
+ get
+ {
+ return _label;
+ }
+
+ set
+ {
+ _label = value;
+ if ( _label != null )
+ {
+ label.changed.connect( on_label_changed );
+ label.selection_changed.connect( on_label_changed );
+ label.size_changed.connect( on_label_size_changed );
+
+ canvas.focus_in_event.connect( on_focus_in_event );
+ canvas.focus_out_event.connect( on_focus_out_event );
+ canvas.enter_notify_event.connect( on_enter_notify_event );
+ canvas.leave_notify_event.connect( on_leave_notify_event );
+ canvas.motion_notify_event.connect( on_motion_notify_event );
+ canvas.button_press_event.connect( on_button_press_event );
+ canvas.button_release_event.connect( on_button_release_event );
+ canvas.key_press_event.connect( on_key_press_event );
+ }
+ }
+ }
+
+ public View()
+ {
prefs = new Prefs();
canvas = new Gtk.Layout( null, null );
@@ -170,17 +196,6 @@ namespace glabels
canvas.realize.connect( on_realize );
canvas.size_allocate.connect( on_size_allocate );
canvas.screen_changed.connect( on_screen_changed );
- canvas.focus_in_event.connect( on_focus_in_event );
- canvas.focus_out_event.connect( on_focus_out_event );
- canvas.enter_notify_event.connect( on_enter_notify_event );
- canvas.leave_notify_event.connect( on_leave_notify_event );
- canvas.motion_notify_event.connect( on_motion_notify_event );
- canvas.button_press_event.connect( on_button_press_event );
- canvas.button_release_event.connect( on_button_release_event );
- canvas.key_press_event.connect( on_key_press_event );
- label.changed.connect( on_label_changed );
- label.selection_changed.connect( on_label_changed );
- label.size_changed.connect( on_label_size_changed );
}
@@ -417,33 +432,36 @@ namespace glabels
private void draw_layers( Gdk.Window window,
Cairo.Context cr )
{
- this.scale = zoom * home_scale;
+ if ( label != null )
+ {
+ this.scale = zoom * home_scale;
- double w, h;
- label.get_size( out w, out h );
+ double w, h;
+ label.get_size( out w, out h );
- canvas.set_size( (int)(w*scale + 8), (int)(h*scale + 8) );
+ canvas.set_size( (int)(w*scale + 8), (int)(h*scale + 8) );
- int canvas_w = window.get_width();
- int canvas_h = window.get_height();
+ int canvas_w = window.get_width();
+ int canvas_h = window.get_height();
- this.x0 = (canvas_w/scale - w) / 2;
- this.y0 = (canvas_h/scale - h) / 2;
+ this.x0 = (canvas_w/scale - w) / 2;
+ this.y0 = (canvas_h/scale - h) / 2;
- cr.save();
+ cr.save();
- cr.scale( scale, scale );
- cr.translate( x0, y0 );
+ cr.scale( scale, scale );
+ cr.translate( x0, y0 );
- draw_bg_layer( cr );
- draw_grid_layer( cr );
- draw_markup_layer( cr );
- draw_objects_layer( cr );
- draw_fg_layer( cr );
- draw_highlight_layer( cr );
- draw_select_region_layer( cr );
+ draw_bg_layer( cr );
+ draw_grid_layer( cr );
+ draw_markup_layer( cr );
+ draw_objects_layer( cr );
+ draw_fg_layer( cr );
+ draw_highlight_layer( cr );
+ draw_select_region_layer( cr );
- cr.restore();
+ cr.restore();
+ }
}
diff --git a/glabels/window.vala b/glabels/window.vala
index 2dcb555..d8dc042 100644
--- a/glabels/window.vala
+++ b/glabels/window.vala
@@ -52,7 +52,7 @@ namespace glabels
private Prefs prefs;
private Ui ui;
- private PagePreview page_preview;
+ private PropertyEditor property_editor;
private ObjectEditor object_editor;
@@ -71,14 +71,18 @@ namespace glabels
Gtk.HBox main_hbox = new Gtk.HBox( false, 0 );
vbox1.pack_start( main_hbox, true, true, 0 );
- page_preview = new PagePreview();
- page_preview.set_hexpand( false );
- main_hbox.pack_start( page_preview, false, false, 0 );
+ property_editor = new PropertyEditor();
+ property_editor.set_hexpand( false );
+ main_hbox.pack_start( property_editor, false, false, 0 );
content_hbox = new Gtk.HBox( false, 0 );
content_hbox.set_hexpand( true );
main_hbox.pack_start( content_hbox, true, true, 0 );
+ view = new View();
+ content_hbox.pack_start( view, true, true, 0 );
+ view.show_all();
+
object_editor = new ObjectEditor();
object_editor.set_hexpand( false );
main_hbox.pack_end( object_editor, false, false, 0 );
@@ -151,7 +155,7 @@ namespace glabels
public bool is_empty()
{
- return view == null;
+ return view.label == null;
}
@@ -160,13 +164,10 @@ namespace glabels
label.modified = false;
set_window_title( label );
- page_preview.set_label( label );
+ property_editor.set_label( label );
+ view.label = label;
object_editor.set_label( label );
- view = new View( label );
- content_hbox.pack_start( view, true, true, 0 );
- view.show_all();
-
view.zoom_to_fit();
view.grid_visible = prefs.grid_visible;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]