summaryrefslogtreecommitdiffstats
path: root/kolourpaint/views
diff options
context:
space:
mode:
Diffstat (limited to 'kolourpaint/views')
-rw-r--r--kolourpaint/views/Makefile.am14
-rw-r--r--kolourpaint/views/kpthumbnailview.cpp98
-rw-r--r--kolourpaint/views/kpthumbnailview.h90
-rw-r--r--kolourpaint/views/kpunzoomedthumbnailview.cpp212
-rw-r--r--kolourpaint/views/kpunzoomedthumbnailview.h106
-rw-r--r--kolourpaint/views/kpzoomedthumbnailview.cpp140
-rw-r--r--kolourpaint/views/kpzoomedthumbnailview.h95
-rw-r--r--kolourpaint/views/kpzoomedview.cpp103
-rw-r--r--kolourpaint/views/kpzoomedview.h96
9 files changed, 954 insertions, 0 deletions
diff --git a/kolourpaint/views/Makefile.am b/kolourpaint/views/Makefile.am
new file mode 100644
index 00000000..2d771cfc
--- /dev/null
+++ b/kolourpaint/views/Makefile.am
@@ -0,0 +1,14 @@
+INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../cursors -I$(srcdir)/../interfaces \
+ -I$(srcdir)/../pixmapfx \
+ -I$(srcdir)/../tools \
+ -I$(srcdir)/../views \
+ -I$(srcdir)/../widgets $(all_includes)
+
+noinst_LTLIBRARIES = libkolourpaintviews.la
+libkolourpaintviews_la_SOURCES = kpthumbnailview.cpp \
+ kpunzoomedthumbnailview.cpp \
+ kpzoomedthumbnailview.cpp \
+ kpzoomedview.cpp
+
+METASOURCES = AUTO
+
diff --git a/kolourpaint/views/kpthumbnailview.cpp b/kolourpaint/views/kpthumbnailview.cpp
new file mode 100644
index 00000000..32c54376
--- /dev/null
+++ b/kolourpaint/views/kpthumbnailview.cpp
@@ -0,0 +1,98 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#define DEBUG_KP_THUMBNAIL_VIEW 0
+
+
+#include <kpthumbnailview.h>
+
+#include <kdebug.h>
+
+
+kpThumbnailView::kpThumbnailView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name)
+
+ : kpView (document, toolToolBar, viewManager,
+ buddyView,
+ scrollableContainer,
+ parent, name)
+{
+}
+
+kpThumbnailView::~kpThumbnailView ()
+{
+}
+
+
+// protected
+void kpThumbnailView::setMaskToCoverDocument ()
+{
+#if DEBUG_KP_THUMBNAIL_VIEW
+ kdDebug () << "kpThumbnailView::setMaskToCoverDocument()"
+ << " origin=" << origin ()
+ << " zoomedDoc: width=" << zoomedDocWidth ()
+ << " height=" << zoomedDocHeight ()
+ << endl;
+#endif
+
+ setMask (QRegion (QRect (origin ().x (), origin ().y (),
+ zoomedDocWidth (), zoomedDocHeight ())));
+}
+
+
+// protected virtual [base kpView]
+void kpThumbnailView::resizeEvent (QResizeEvent *e)
+{
+#if DEBUG_KP_THUMBNAIL_VIEW
+ kdDebug () << "kpThumbnailView(" << name () << ")::resizeEvent()"
+ << endl;
+#endif
+
+ // For QResizeEvent's, Qt already throws an entire widget repaint into
+ // the event loop. So eat useless update() calls that can only slow
+ // things down.
+ // TODO: this doesn't seem to work.
+ const bool oldIsUpdatesEnabled = isUpdatesEnabled ();
+ setUpdatesEnabled (false);
+
+ {
+ kpView::resizeEvent (e);
+
+ adjustToEnvironment ();
+ }
+
+ setUpdatesEnabled (oldIsUpdatesEnabled);
+}
+
+
+#include <kpthumbnailview.moc>
+
diff --git a/kolourpaint/views/kpthumbnailview.h b/kolourpaint/views/kpthumbnailview.h
new file mode 100644
index 00000000..c3420833
--- /dev/null
+++ b/kolourpaint/views/kpthumbnailview.h
@@ -0,0 +1,90 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef KP_THUMBNAIL_VIEW
+#define KP_THUMBNAIL_VIEW
+
+
+#include <kpview.h>
+
+
+/**
+ * @short Abstract base class for all thumbnail views.
+ *
+ * @author Clarence Dang <dang@kde.org>
+ */
+class kpThumbnailView : public kpView
+{
+Q_OBJECT
+
+public:
+ /**
+ * Constructs a thumbnail view.
+ *
+ * You must call adjustEnvironment() at the end of your constructor.
+ */
+ kpThumbnailView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name);
+
+ /**
+ * Destructs this thumbnail view.
+ */
+ virtual ~kpThumbnailView ();
+
+
+ /**
+ * @returns the caption to display in an enclosing thumbnail window.
+ */
+ virtual QString caption () const = 0;
+
+
+protected:
+ /**
+ * Sets the mask to cover the rectangle with top-left, origin() and
+ * dimensions equal to or slightly less than (in case of rounding
+ * error) the size of the document in view coordinates. This ensures
+ * that all pixels are initialised with either document pixels or the
+ * standard widget background.
+ */
+ void setMaskToCoverDocument ();
+
+
+ /**
+ * Calls adjustToEnvironment() in response to a resize event.
+ *
+ * Extends @ref kpView.
+ */
+ virtual void resizeEvent (QResizeEvent *e);
+};
+
+
+#endif // KP_THUMBNAIL_VIEW
diff --git a/kolourpaint/views/kpunzoomedthumbnailview.cpp b/kolourpaint/views/kpunzoomedthumbnailview.cpp
new file mode 100644
index 00000000..09d5aed1
--- /dev/null
+++ b/kolourpaint/views/kpunzoomedthumbnailview.cpp
@@ -0,0 +1,212 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#define DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW 0
+
+
+#include <kpunzoomedthumbnailview.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <kpdocument.h>
+#include <kpviewmanager.h>
+#include <kpviewscrollablecontainer.h>
+
+
+struct kpUnzoomedThumbnailViewPrivate
+{
+};
+
+
+kpUnzoomedThumbnailView::kpUnzoomedThumbnailView (
+ kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name)
+
+ : kpThumbnailView (document, toolToolBar, viewManager,
+ buddyView,
+ scrollableContainer,
+ parent, name),
+ d (new kpUnzoomedThumbnailViewPrivate ())
+{
+ if (buddyViewScrollableContainer ())
+ {
+ connect (buddyViewScrollableContainer (),
+ SIGNAL (contentsMovingSoon (int, int)),
+ this,
+ SLOT (adjustToEnvironment ()));
+ }
+
+ // Call to virtual function - this is why the class is sealed
+ adjustToEnvironment ();
+}
+
+
+kpUnzoomedThumbnailView::~kpUnzoomedThumbnailView ()
+{
+ delete d;
+}
+
+
+// public virtual [base kpThumbnailView]
+QString kpUnzoomedThumbnailView::caption () const
+{
+ return i18n ("Unzoomed Mode - Thumbnail");
+}
+
+
+// public slot virtual [base kpView]
+void kpUnzoomedThumbnailView::adjustToEnvironment ()
+{
+ if (!buddyView () || !buddyViewScrollableContainer () || !document ())
+ return;
+
+ const int scrollViewContentsX =
+ buddyViewScrollableContainer ()->contentsXSoon ();
+ const int scrollViewContentsY =
+ buddyViewScrollableContainer ()->contentsYSoon ();
+
+#if DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW
+ kdDebug () << "kpUnzoomedThumbnailView(" << name ()
+ << ")::adjustToEnvironment("
+ << scrollViewContentsX
+ << ","
+ << scrollViewContentsY
+ << ") width=" << width ()
+ << " height=" << height ()
+ << endl;
+#endif
+
+
+#if 1
+ int x;
+ if (document ()->width () > width ())
+ {
+ x = (int) buddyView ()->transformViewToDocX (scrollViewContentsX);
+ const int rightMostAllowedX = QMAX (0, document ()->width () - width ());
+ #if DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW
+ kdDebug () << "\tdocX=" << x
+ << " docWidth=" << document ()->width ()
+ << " rightMostAllowedX=" << rightMostAllowedX
+ << endl;
+ #endif
+ if (x > rightMostAllowedX)
+ x = rightMostAllowedX;
+ }
+ // Thumbnail width <= doc width
+ else
+ {
+ // Centre X (rather than flush left to be consistent with
+ // kpZoomedThumbnailView)
+ x = -(width () - document ()->width ()) / 2;
+ }
+
+
+ int y;
+ if (document ()->height () > height ())
+ {
+ y = (int) buddyView ()->transformViewToDocY (scrollViewContentsY);
+ const int bottomMostAllowedY = QMAX (0, document ()->height () - height ());
+ #if DEBUG_KP_UNZOOMED_THUMBNAIL_VIEW
+ kdDebug () << "\tdocY=" << y
+ << " docHeight=" << document ()->height ()
+ << " bottomMostAllowedY=" << bottomMostAllowedY
+ << endl;
+ #endif
+ if (y > bottomMostAllowedY)
+ y = bottomMostAllowedY;
+ }
+ // Thumbnail height <= doc height
+ else
+ {
+ // Centre Y (rather than flush top to be consistent with
+ // kpZoomedThumbnailView)
+ y = -(height () - document ()->height ()) / 2;
+ }
+// Prefer to keep visible area centred in thumbnail instead of flushed left.
+// Gives more editing context to the left and top.
+// But feels awkward for left-to-right users. So disabled for now.
+// Not totally tested.
+#else
+ if (!buddyViewScrollableContainer ())
+ return;
+
+ QRect docRect = buddyView ()->transformViewToDoc (
+ QRect (buddyViewScrollableContainer ()->contentsXSoon (),
+ buddyViewScrollableContainer ()->contentsYSoon (),
+ QMIN (buddyView ()->width (), buddyViewScrollableContainer ()->visibleWidth ()),
+ QMIN (buddyView ()->height (), buddyViewScrollableContainer ()->visibleHeight ())));
+
+ x = docRect.x () - (width () - docRect.width ()) / 2;
+ kdDebug () << "\tnew suggest x=" << x << endl;
+ const int rightMostAllowedX = QMAX (0, document ()->width () - width ());
+ if (x < 0)
+ x = 0;
+ if (x > rightMostAllowedX)
+ x = rightMostAllowedX;
+
+ y = docRect.y () - (height () - docRect.height ()) / 2;
+ kdDebug () << "\tnew suggest y=" << y << endl;
+ const int bottomMostAllowedY = QMAX (0, document ()->height () - height ());
+ if (y < 0)
+ y = 0;
+ if (y > bottomMostAllowedY)
+ y = bottomMostAllowedY;
+#endif
+
+
+ if (viewManager ())
+ {
+ viewManager ()->setFastUpdates ();
+ viewManager ()->setQueueUpdates ();
+ }
+
+ {
+ // OPT: scrollView impl would be much, much faster
+ setOrigin (QPoint (-x, -y));
+ setMaskToCoverDocument ();
+
+ // Above might be a NOP even if e.g. doc size changed so force
+ // update
+ if (viewManager ())
+ viewManager ()->updateView (this);
+ }
+
+ if (viewManager ())
+ {
+ viewManager ()->restoreQueueUpdates ();
+ viewManager ()->restoreFastUpdates ();
+ }
+}
+
+
+#include <kpunzoomedthumbnailview.moc>
diff --git a/kolourpaint/views/kpunzoomedthumbnailview.h b/kolourpaint/views/kpunzoomedthumbnailview.h
new file mode 100644
index 00000000..0f7ccf53
--- /dev/null
+++ b/kolourpaint/views/kpunzoomedthumbnailview.h
@@ -0,0 +1,106 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef KP_UNZOOMED_THUMBNAIL_VIEW_H
+#define KP_UNZOOMED_THUMBNAIL_VIEW_H
+
+
+#include <kpthumbnailview.h>
+
+
+class kpViewScrollableContainer;
+
+
+/**
+ * @short Unzoomed thumbnail view of a document.
+ *
+ * This is an unzoomed thumbnail view of a document. Unlike
+ * @ref kpZoomedThumbnailView, it never changes the zoom level. And unlike
+ * @ref kpZoomedView, it never resizes itself. Instead, it changes its
+ * origin according to the main view's scrollable container so that the
+ * top-left most document pixel displayed in the scrollable container will
+ * be visible.
+ *
+ * Do not call setZoomLevel() nor setOrigin().
+ *
+ * This class is sealed. Do not derive from it.
+ *
+ * @author Clarence Dang <dang@kde.org>
+ */
+/*sealed*/ class kpUnzoomedThumbnailView : public kpThumbnailView
+{
+Q_OBJECT
+
+public:
+ /**
+ * Constructs an unzoomed thumbnail view.
+ */
+ kpUnzoomedThumbnailView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name);
+
+ /**
+ * Destructs an unzoomed thumbnail view.
+ */
+ virtual ~kpUnzoomedThumbnailView ();
+
+
+ /**
+ * Implements @ref kpThumbnailView.
+ */
+ QString caption () const;
+
+
+public slots:
+ /**
+ * Changes its origin according to the main view's scrollable container
+ * so that the top-left most document pixel displayed in the scrollable
+ * container will be visible.
+ *
+ * It tries to maximise the used area of this view. Unused areas will
+ * be set to the widget background thanks to the mask.
+ *
+ * Call this if the size of the document changes.
+ * Already connected to buddyViewScrollableContainer()'s
+ * contentsMovingSoon(int,int) signal.
+ * Already called by @ref kpThumbnailView resizeEvent().
+ *
+ * Implements @ref kpView.
+ */
+ virtual void adjustToEnvironment ();
+
+
+private:
+ struct kpUnzoomedThumbnailViewPrivate *d;
+};
+
+
+#endif // KP_UNZOOMED_THUMBNAIL_VIEW_H
diff --git a/kolourpaint/views/kpzoomedthumbnailview.cpp b/kolourpaint/views/kpzoomedthumbnailview.cpp
new file mode 100644
index 00000000..ecbfd317
--- /dev/null
+++ b/kolourpaint/views/kpzoomedthumbnailview.cpp
@@ -0,0 +1,140 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#define DEBUG_KP_ZOOMED_THUMBNAIL_VIEW 0
+
+
+#include <kpzoomedthumbnailview.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <kpdocument.h>
+#include <kpviewmanager.h>
+
+
+kpZoomedThumbnailView::kpZoomedThumbnailView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name)
+
+ : kpThumbnailView (document, toolToolBar, viewManager,
+ buddyView,
+ scrollableContainer,
+ parent, name)
+{
+ // Call to virtual function - this is why the class is sealed
+ adjustToEnvironment ();
+}
+
+
+kpZoomedThumbnailView::~kpZoomedThumbnailView ()
+{
+}
+
+
+// public virtual [base kpThumbnailView]
+QString kpZoomedThumbnailView::caption () const
+{
+ return i18n ("%1% - Thumbnail").arg (zoomLevelX ());
+}
+
+
+// public slot virtual [base kpView]
+void kpZoomedThumbnailView::adjustToEnvironment ()
+{
+#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW
+ kdDebug () << "kpZoomedThumbnailView(" << name ()
+ << ")::adjustToEnvironment()"
+ << " width=" << width ()
+ << " height=" << height ()
+ << endl;
+#endif
+
+ if (!document ())
+ return;
+
+#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW
+ kdDebug () << "\tdoc: width=" << document ()->width ()
+ << " height=" << document ()->height ()
+ << endl;
+#endif
+
+ if (document ()->width () <= 0 || document ()->height () <= 0)
+ {
+ kdError () << "kpZoomedThumbnailView::adjustToEnvironment() doc:"
+ << " width=" << document ()->width ()
+ << " height=" << document ()->height ()
+ << endl;
+ return;
+ }
+
+
+ int hzoom = QMAX (1, width () * 100 / document ()->width ());
+ int vzoom = QMAX (1, height () * 100 / document ()->height ());
+
+ // keep aspect ratio
+ if (hzoom < vzoom)
+ vzoom = hzoom;
+ else
+ hzoom = vzoom;
+
+#if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1
+ kdDebug () << "\tproposed zoom=" << hzoom << endl;
+#endif
+ if (hzoom > 100 || vzoom > 100)
+ {
+ #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1
+ kdDebug () << "\twon't magnify - setting zoom to 100%" << endl;
+ #endif
+ hzoom = 100, vzoom = 100;
+ }
+
+
+ if (viewManager ())
+ viewManager ()->setQueueUpdates ();
+
+ {
+ setZoomLevel (hzoom, vzoom);
+
+ setOrigin (QPoint ((width () - zoomedDocWidth ()) / 2,
+ (height () - zoomedDocHeight ()) / 2));
+ setMaskToCoverDocument ();
+
+ if (viewManager ())
+ viewManager ()->updateView (this);
+ }
+
+ if (viewManager ())
+ viewManager ()->restoreQueueUpdates ();
+}
+
+
+#include <kpzoomedthumbnailview.moc>
diff --git a/kolourpaint/views/kpzoomedthumbnailview.h b/kolourpaint/views/kpzoomedthumbnailview.h
new file mode 100644
index 00000000..0bcb367c
--- /dev/null
+++ b/kolourpaint/views/kpzoomedthumbnailview.h
@@ -0,0 +1,95 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef KP_ZOOMED_THUMBNAIL_VIEW_H
+#define KP_ZOOMED_THUMBNAIL_VIEW_H
+
+
+#include <kpthumbnailview.h>
+
+
+/**
+ * @short Zoomed thumbnail view of a document.
+ *
+ * This is a zoomed thumbnail view of a document. Unlike @ref kpZoomedView,
+ * it never resizes itself. Instead, it changes its zoom level to
+ * accommodate the display of entire document in the view, while
+ * maintaining aspect.
+ *
+ * Do not call setZoomLevel() nor setOrigin().
+ *
+ * This class is sealed. Do not derive from it.
+ *
+ * @author Clarence Dang <dang@kde.org>
+ */
+/*sealed*/ class kpZoomedThumbnailView : public kpThumbnailView
+{
+Q_OBJECT
+
+public:
+ /**
+ * Constructs a zoomed thumbnail view.
+ */
+ kpZoomedThumbnailView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name);
+
+ /**
+ * Destructs a zoomed thumbnail view.
+ */
+ virtual ~kpZoomedThumbnailView ();
+
+
+ /**
+ * Implements @ref kpThumbnailView.
+ */
+ QString caption () const;
+
+
+public slots:
+ /**
+ * Changes its zoom level to accommodate the display of entire document
+ * in the view. It maintains aspect by changing the origin and mask.
+ *
+ * Call this if the size of the document changes.
+ * Already called by @ref kpThumbnailView resizeEvent().
+ *
+ * Implements @ref kpView.
+ */
+ virtual void adjustToEnvironment ();
+
+
+private:
+ struct kpZoomedThumbnailViewPrivate *d;
+};
+
+
+#endif // KP_ZOOMED_THUMBNAIL_VIEW_H
diff --git a/kolourpaint/views/kpzoomedview.cpp b/kolourpaint/views/kpzoomedview.cpp
new file mode 100644
index 00000000..ef1d6981
--- /dev/null
+++ b/kolourpaint/views/kpzoomedview.cpp
@@ -0,0 +1,103 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#define DEBUG_KP_ZOOMED_VIEW 0
+
+
+#include <kpzoomedview.h>
+
+#include <kdebug.h>
+
+#include <kpdocument.h>
+#include <kpview.h>
+#include <kpviewmanager.h>
+
+
+kpZoomedView::kpZoomedView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name)
+
+ : kpView (document, toolToolBar, viewManager,
+ buddyView,
+ scrollableContainer,
+ parent, name)
+{
+ // Call to virtual function - this is why the class is sealed
+ adjustToEnvironment ();
+}
+
+kpZoomedView::~kpZoomedView ()
+{
+}
+
+
+// public virtual [base kpView]
+void kpZoomedView::setZoomLevel (int hzoom, int vzoom)
+{
+#if DEBUG_KP_ZOOMED_VIEW
+ kdDebug () << "kpZoomedView(" << name () << ")::setZoomLevel("
+ << hzoom << "," << vzoom << ")" << endl;
+#endif
+
+ if (viewManager ())
+ viewManager ()->setQueueUpdates ();
+
+ {
+ kpView::setZoomLevel (hzoom, vzoom);
+
+ adjustToEnvironment ();
+ }
+
+ if (viewManager ())
+ viewManager ()->restoreQueueUpdates ();
+}
+
+
+// public slot virtual [base kpView]
+void kpZoomedView::adjustToEnvironment ()
+{
+#if DEBUG_KP_ZOOMED_VIEW
+ kdDebug () << "kpZoomedView(" << name () << ")::adjustToEnvironment()"
+ << " doc: width=" << document ()->width ()
+ << " height=" << document ()->height ()
+ << endl;
+#endif
+
+ if (document ())
+ {
+ // TODO: use zoomedDocWidth() & zoomedDocHeight()?
+ resize ((int) transformDocToViewX (document ()->width ()),
+ (int) transformDocToViewY (document ()->height ()));
+ }
+}
+
+
+#include <kpzoomedview.moc>
diff --git a/kolourpaint/views/kpzoomedview.h b/kolourpaint/views/kpzoomedview.h
new file mode 100644
index 00000000..c3729282
--- /dev/null
+++ b/kolourpaint/views/kpzoomedview.h
@@ -0,0 +1,96 @@
+
+/*
+ Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#ifndef KP_ZOOMED_VIEW_H
+#define KP_ZOOMED_VIEW_H
+
+
+#include <kpview.h>
+
+
+/**
+ * @short Zoomed view of a document. Suitable as an ordinary editing view.
+ *
+ * This is a zoomed view of a document. It resizes according to the size
+ * of the document and the zoom level. Do not manually call resize() for
+ * this reason.
+ *
+ * It is suitable as an ordinary editing view.
+ *
+ * Do not call setOrigin().
+ *
+ * This class is sealed. Do not derive from it.
+ *
+ * @author Clarence Dang <dang@kde.org>
+ */
+/*sealed*/ class kpZoomedView : public kpView
+{
+Q_OBJECT
+
+public:
+ /**
+ * Constructs a zoomed view.
+ */
+ kpZoomedView (kpDocument *document,
+ kpToolToolBar *toolToolBar,
+ kpViewManager *viewManager,
+ kpView *buddyView,
+ kpViewScrollableContainer *scrollableContainer,
+ QWidget *parent, const char *name);
+
+ /**
+ * Destructs an unzoomed view.
+ */
+ virtual ~kpZoomedView ();
+
+
+ /**
+ * Extends @kpView. Calls adjustToEnvironment().
+ */
+ virtual void setZoomLevel (int hzoom, int vzoom);
+
+
+public slots:
+ /**
+ * Resizes itself so that the entire document in the zoom level fits
+ * almost perfectly.
+ *
+ * Call this if the size of the document changes.
+ * Already called by setZoomLevel().
+ *
+ * Implements @ref kpView.
+ */
+ virtual void adjustToEnvironment ();
+
+
+private:
+ struct kpZoomedViewPrivate *d;
+};
+
+
+#endif // KP_ZOOMED_VIEW_H