[simple-scan] add buttons to change orientation of even/odd pages - usecase for RADF scanners
- From: Bartosz <bkosiorek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [simple-scan] add buttons to change orientation of even/odd pages - usecase for RADF scanners
- Date: Thu, 22 Sep 2022 07:56:02 +0000 (UTC)
commit 85032a55b9cd7e95b802b113c762f49a3bc60b11
Author: Bernhard Schuster <bernhard+gitlab gnome ahoi io>
Date: Thu Sep 22 07:55:50 2022 +0000
add buttons to change orientation of even/odd pages - usecase for RADF scanners
src/app-window.vala | 34 ++++++++++++++++++++++++++++++----
src/book.vala | 20 ++++++++++++++++++++
src/page-icon.vala | 21 +++++++++++++++++++--
3 files changed, 69 insertions(+), 6 deletions(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index cea6837d..fe54315b 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -1343,6 +1343,27 @@ public class AppWindow : Hdy.ApplicationWindow
b.visible = true;
g.attach (b, 1, 2, 1, 1);
+ /* Label on button for keeping the ordering, but flip every second upside down */
+ b = make_reorder_button (_("Flip odd pages upside-down"), "R1U2R3U4R5U6-R1R2R3R4R5R6");
+ b.clicked.connect (() =>
+ {
+ book.flip_every_second(false);
+ dialog.destroy ();
+ });
+ b.visible = true;
+ g.attach (b, 0, 3, 1, 1);
+
+
+ /* Label on button for keeping the ordering, but flip every second upside down */
+ b = make_reorder_button (_("Flip even pages upside-down"), "U1R2U3R4U5R6-R1R2R3R4R5R6");
+ b.clicked.connect (() =>
+ {
+ book.flip_every_second(true);
+ dialog.destroy ();
+ });
+ b.visible = true;
+ g.attach (b, 1, 3, 1, 1);
+
dialog.present ();
}
@@ -1401,10 +1422,15 @@ public class AppWindow : Hdy.ApplicationWindow
page_box.visible = true;
box.add (page_box);
}
-
- var icon = new PageIcon (side, items[i] - '1');
- icon.visible = true;
- page_box.add (icon);
+ if (side == 'U') {
+ var icon = new PageIcon (side, items[i] - '1', 180);
+ icon.visible = true;
+ page_box.add (icon);
+ } else {
+ var icon = new PageIcon (side, items[i] - '1', 0);
+ icon.visible = true;
+ page_box.add (icon);
+ }
}
return box;
diff --git a/src/book.vala b/src/book.vala
index d2aa54da..b0ffc3fb 100644
--- a/src/book.vala
+++ b/src/book.vala
@@ -99,6 +99,26 @@ public class Book : Object
changed ();
}
+ public void flip_every_second (bool flip_first)
+ {
+ var new_pages = new List<Page> ();
+ for (var i = 0; i < n_pages; i++)
+ {
+ var page = pages.nth_data (i);
+ if (i % 2 == (int)flip_first) {
+ new_pages.append (page);
+ } else {
+ page.rotate_left();
+ page.rotate_left();
+ new_pages.append (page);
+ }
+ }
+ pages = (owned) new_pages;
+
+ reordered ();
+ changed ();
+ }
+
public void combine_sides_reverse ()
{
var new_pages = new List<Page> ();
diff --git a/src/page-icon.vala b/src/page-icon.vala
index f1a25ead..3e3fa93a 100644
--- a/src/page-icon.vala
+++ b/src/page-icon.vala
@@ -14,12 +14,14 @@ public class PageIcon : Gtk.DrawingArea
{
private char side;
private int position;
+ private int angle;
private const int MINIMUM_WIDTH = 20;
- public PageIcon (char side, int position)
+ public PageIcon (char side, int position, int angle)
{
this.side = side;
this.position = position;
+ this.angle = angle;
}
public override void get_preferred_width (out int minimum_width, out int natural_width)
@@ -73,6 +75,14 @@ public class PageIcon : Gtk.DrawingArea
/* Orange 3 */
rgba.parse ("#ff7800");
break;
+ case 'U':
+ /* green 4 */
+ rgba.parse ("#5cc02e");
+ break;
+ case 'R':
+ /* blue 4 */
+ rgba.parse ("#0deee7");
+ break;
default:
/* Yellow 3 to Red 2 */
Gdk.RGBA start = {}, end = {};
@@ -109,8 +119,15 @@ public class PageIcon : Gtk.DrawingArea
var text = @"$(position + 1)";
Cairo.TextExtents extents;
+
+ var rad = Math.PI / 180.0 * angle;
c.text_extents (text, out extents);
- c.translate ((w - extents.width) * 0.5 - 0.5, (h + extents.height) * 0.5 - 0.5);
+ c.translate ((w - extents.width) * 0.5 - 0.5, extents.height + (h - extents.height) * 0.5 - 0.5);
+ c.rotate(rad);
+ // only correct for 0 and 180 degree
+ var tx = (1.0 - Math.sin(rad)) * extents.width / 2;
+ var ty = (1.0 - Math.sin(rad)) * extents.height / 2;
+ c.translate(-tx, +ty);
c.show_text (text);
return true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]