From 6f435f1a508f598520d7549c75ebb88a40ddee4b Mon Sep 17 00:00:00 2001
From: Ali Lown <ali@lown.me.uk>
Date: Wed, 21 Nov 2012 22:18:02 +0000
Subject: [PATCH] Implement Preview Window using TiledDrawWidget

Rebase of:
- Add a popup preview window
- Make PreviewWindow a more normal tool widget, add TiledDrawWidget
- Bind to correct 'model'
- Add todo:
- Fix preview window for mypaint-git
---
 gui/application.py         |  3 +++
 gui/drawwindow.py          |  2 +-
 gui/menu.xml               |  1 +
 gui/mypaint.xml            | 13 +++++++++++++
 gui/previewwindow.py       | 31 +++++++++++++++++++++++++++++++
 gui/toolbar-subwindows.xml |  1 +
 6 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 gui/previewwindow.py

diff --git a/gui/application.py b/gui/application.py
index e6553c2..d4e936b 100644
--- a/gui/application.py
+++ b/gui/application.py
@@ -293,6 +293,9 @@ class Application: # singleton
                 'colorWindow': dict(
                         sbindex=0, floating=True, hidden=True,
                         x=-100, y=125, w=250, h=300, sbheight=300),
+                'previewWindow': dict(
+                        sbindex=5, floating=True, hidden=True,
+                        x=-600, y=150, w=250, h=250, sbheight=250),
 
                 # Non-tool subwindows. These cannot be docked, and are all
                 # intially hidden.
diff --git a/gui/drawwindow.py b/gui/drawwindow.py
index 4134ef1..18d14c2 100644
--- a/gui/drawwindow.py
+++ b/gui/drawwindow.py
@@ -22,7 +22,7 @@ from gettext import gettext as _
 import gtk, gobject
 from gtk import gdk, keysyms
 
-import colorselectionwindow, historypopup, stategroup, colorpicker, windowing, layout, toolbar
+import colorselectionwindow, historypopup, stategroup, colorpicker, windowing, layout, toolbar, previewwindow
 import dialogs
 from lib import helpers
 import canvasevent
diff --git a/gui/menu.xml b/gui/menu.xml
index e63547d..f17a5c1 100644
--- a/gui/menu.xml
+++ b/gui/menu.xml
@@ -53,6 +53,7 @@
       -->
       <menuitem action='ShowPopupMenu'/>
       <menuitem action='ToggleSubwindows'/>
+      <menuitem action='PreviewWindow'/>
       <separator/>
       <!-- ResetView is on its own because it also recentres the canvas, -->
       <menuitem action='ResetView'/>
diff --git a/gui/mypaint.xml b/gui/mypaint.xml
index 1b4957a..fa7ed5a 100644
--- a/gui/mypaint.xml
+++ b/gui/mypaint.xml
@@ -16,6 +16,8 @@ Perhaps an increasing amount.
            icon-name="mypaint-tool-scratchpad"/>
     <source stock-id="mypaint-tool-layers"
            icon-name="mypaint-tool-layers"/>
+    <source stock-id="mypaint-tool-preview-window"
+           icon-name="mypaint-tool-preview-window"/>
     <!-- View manipulation -->
     <!--
     TODO: make some MyPaint-specific icons for these. Not sure the object-
@@ -1092,6 +1094,17 @@ Perhaps an increasing amount.
         <accelerator key="s" modifiers="GDK_SHIFT_MASK"/>
       </child>
       <child>
+        <object class="GtkToggleAction" id="PreviewWindow">
+          <property name="stock_id">mypaint-tool-preview-window</property>
+          <property name="label" translatable="yes">Preview</property>
+          <property name="tooltip" translatable="yes"
+            >Show preview of the whole drawing area</property>
+          <signal name="activate" handler="toggle_window_cb"/>
+        </object>
+        <accelerator key="p" modifiers="GDK_SHIFT_MASK"/>
+      </child>
+
+      <child>
         <object class="GtkToggleAction" id="ToggleSubwindows">
           <property name="label" translatable="yes">Subwindows</property>
           <property name="tooltip" translatable="yes">Show subwindows</property>
diff --git a/gui/previewwindow.py b/gui/previewwindow.py
new file mode 100644
index 0000000..4732bcd
--- /dev/null
+++ b/gui/previewwindow.py
@@ -0,0 +1,31 @@
+# This file is part of MyPaint.
+# Copyright (C) 2012 by Ali Lown <ali@lown.me.uk>
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+
+from gettext import gettext as _
+import gtk, gobject, pango
+gdk = gtk.gdk
+import dialogs
+import tileddrawwidget
+
+
+class ToolWidget(gtk.VBox):
+    """Tool widget for previewing the whole canvas"""
+
+    stock_id = "mypaint-tool-preview-window"
+    tool_widget_title = _("Preview")
+
+    def __init__(self, app):
+        gtk.VBox.__init__(self)
+        self.set_size_request(250, 250)
+
+        self.tdw = tileddrawwidget.TiledDrawWidget(app, app.doc.model)
+        self.tdw.set_size_request(250, 250)
+        #TODO: perhaps configure this based on used area?
+        self.tdw.scale = 0.03
+        self.tdw.set_sensitive(False)
+        self.add(self.tdw)
diff --git a/gui/toolbar-subwindows.xml b/gui/toolbar-subwindows.xml
index 9571f8b..fe30afc 100644
--- a/gui/toolbar-subwindows.xml
+++ b/gui/toolbar-subwindows.xml
@@ -15,6 +15,7 @@ the Free Software Foundation; either version 2 of the License, or
       <toolitem action="BrushSelectionWindow"/>
       <toolitem action="LayersWindow"/>
       <toolitem action="ScratchWindow"/>
+      <toolitem action="PreviewWindow"/>
     </placeholder>
 
   </toolbar>
-- 
1.8.0

