gnome-scan r681 - trunk/lib



Author: bersace
Date: Sun Dec 14 16:00:45 2008
New Revision: 681
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=681&view=rev

Log:
Added int option and scale widget for int options.

Added:
   trunk/lib/gnome-scan-scale-widget.vala
Modified:
   trunk/lib/Makefile.am
   trunk/lib/gnome-scan-init.vala
   trunk/lib/gnome-scan-option.vala

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Sun Dec 14 16:00:45 2008
@@ -26,6 +26,7 @@
 	gnome-scan-init.vala			\
 	gnome-scan-option-widget.vala		\
 	gnome-scan-checkbox-widget.vala		\
+	gnome-scan-scale-widget.vala		\
 	gnome-scan-option-box.vala		\
 	gnome-scan-option-page.vala		\
 	gnome-scan-scanner-selector.vala	\

Modified: trunk/lib/gnome-scan-init.vala
==============================================================================
--- trunk/lib/gnome-scan-init.vala	(original)
+++ trunk/lib/gnome-scan-init.vala	Sun Dec 14 16:00:45 2008
@@ -39,6 +39,7 @@
 
 		option_manager = new OptionManager();
 		option_manager.register_rule_by_type(typeof(OptionBool), typeof(CheckboxWidget));
+		option_manager.register_rule_by_type(typeof(OptionInt), typeof(ScaleWidget));
 
 		module_path = string.join(GLib.Path.SEARCHPATH_SEPARATOR_S, MODULE_DIR,
 								  "modules/gsfile", "modules/gsane",

Modified: trunk/lib/gnome-scan-option.vala
==============================================================================
--- trunk/lib/gnome-scan-option.vala	(original)
+++ trunk/lib/gnome-scan-option.vala	Sun Dec 14 16:00:45 2008
@@ -65,4 +65,26 @@
 			this.hint = hint;
 		}
 	}
+
+	public class OptionInt : Option {
+		public int value {set; get;}
+		public int min {set construct; get;}
+		public int step {set construct; get;}
+		public int max {set construct; get;}
+
+		public OptionInt(string name, string title, string desc, string group, string domain, int value, int min, int step, int max, Gnome.Scan.Unit unit, OptionHint hint)
+		{
+			this.name = name;
+			this.title = title;
+			this.desc = desc;
+			this.group = group;
+			this.domain = domain;
+			this.value = value;
+			this.min = min;
+			this.step = step;
+			this.max = max;
+			this.unit = unit;
+			this.hint = hint;
+		}
+	}
 }

Added: trunk/lib/gnome-scan-scale-widget.vala
==============================================================================
--- (empty file)
+++ trunk/lib/gnome-scan-scale-widget.vala	Sun Dec 14 16:00:45 2008
@@ -0,0 +1,70 @@
+/* GNOME Scan - Scan as easy as you print
+ * Copyright  2006-2008  Ãtienne Bersac <bersace gnome org>
+ *
+ * GNOME Scan is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * GNOME Scan 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GNOME Scan. If not, write to:
+ *
+ *	the Free Software Foundation, Inc.
+ *	51 Franklin Street, Fifth Floor
+ *	Boston, MA 02110-1301, USA
+ */
+
+using Gtk;
+
+namespace Gnome.Scan {
+	public class ScaleWidget : OptionWidget {
+		private Adjustment adj;
+		private bool inhibit = false;
+
+		construct {
+			this.expand = false;
+			this.no_label = false;
+
+			var option = this.option as OptionInt;
+			option.notify["value"] += this.on_option_value_changed;
+
+			adj = new Adjustment(option.value, option.min, option.max, option.step, option.step, 0);
+			adj.value_changed += this.on_adj_value_changed;
+
+			var scale = new HScale(adj);
+			scale.draw_value = false;
+			this.pack_start(scale, true, true, 0);
+
+			var spin = new SpinButton(adj, option.step, 0);
+			this.pack_start(spin, false, true, 0);
+		}
+
+		private void on_option_value_changed()
+		{
+			if (inhibit)
+				return;
+
+			var option = this.option as OptionInt;
+
+			inhibit = true;
+			adj.value = (double) option.value;
+			inhibit = false;
+		}
+
+		private void on_adj_value_changed()
+		{
+			if (inhibit)
+				return;
+
+			var option = this.option as OptionInt;
+			inhibit = true;
+			option.value = (int) adj.value;
+			inhibit = false;
+		}
+	}
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]