[calligra/krita-testing-kazakov] krita/ui/canvas: Limit Pseudo Infinite canvas feature not to create too huge images

Dmitry Kazakov dimula73 at gmail.com
Fri Jun 6 06:43:10 UTC 2014


Git commit 9e6307cee61ded62efd684146789d7dba93e40f2 by Dmitry Kazakov.
Committed on 06/06/2014 at 06:41.
Pushed by dkazakov into branch 'krita-testing-kazakov'.

Limit Pseudo Infinite canvas feature not to create too huge images

The changes:

1) The expansion is now limited by 100%. This is actually quite
   easy way to double the dimension of the image: zoom out, move
   to one side, press the button and one dimension of the image
   is doubled!

2) If you press only on one side panel, then the image will be expanded
   into exactly *one* direction. This allows you to expand an image in
   a single dimension only.

3) If you press in the corner of the canvas (that is on two panels at
   once), the image will be expanded in two corresponding dimensions.

CCMAIL:kimageshop at kde.org
BUG:335830

M  +41   -7    krita/ui/canvas/kis_infinity_manager.cpp
M  +11   -1    krita/ui/canvas/kis_infinity_manager.h

http://commits.kde.org/calligra/9e6307cee61ded62efd684146789d7dba93e40f2

diff --git a/krita/ui/canvas/kis_infinity_manager.cpp b/krita/ui/canvas/kis_infinity_manager.cpp
index ba6a981..16fd530 100644
--- a/krita/ui/canvas/kis_infinity_manager.cpp
+++ b/krita/ui/canvas/kis_infinity_manager.cpp
@@ -37,12 +37,13 @@
 KisInfinityManager::KisInfinityManager(KisView2 *view, KisCanvas2 *canvas)
     : KisCanvasDecoration(INFINITY_DECORATION_ID, view),
       m_filterInstalled(false),
-      m_cursorSwitched(false)
+      m_cursorSwitched(false),
+      m_sideRects(NSides)
 {
     connect(canvas, SIGNAL(documentOffsetUpdateFinished()), SLOT(imagePositionChanged()));
 }
 
-inline void KisInfinityManager::addDecoration(const QRect &areaRect, const QPointF &handlePoint, qreal angle)
+inline void KisInfinityManager::addDecoration(const QRect &areaRect, const QPointF &handlePoint, qreal angle, Side side)
 {
     QTransform t;
     t.rotate(angle);
@@ -50,6 +51,7 @@ inline void KisInfinityManager::addDecoration(const QRect &areaRect, const QPoin
     m_handleTransform << t;
 
     m_decorationPath.addRect(areaRect);
+    m_sideRects[side] = areaRect;
 }
 
 void KisInfinityManager::imagePositionChanged()
@@ -76,33 +78,36 @@ void KisInfinityManager::imagePositionChanged()
 
     m_handleTransform.clear();
 
+    m_sideRects.clear();
+    m_sideRects.resize(NSides);
+
     bool visible = false;
 
     if (imageRect.x() <= -xThreshold) {
         QRect areaRect(widgetRect.adjusted(xCut, 0, 0, 0));
         QPointF pt = areaRect.center() + QPointF(-0.1 * stripeWidth, 0);
-        addDecoration(areaRect, pt, 0);
+        addDecoration(areaRect, pt, 0, Right);
         visible = true;
     }
 
     if (imageRect.y() <= -yThreshold) {
         QRect areaRect(widgetRect.adjusted(0, yCut, 0, 0));
         QPointF pt = areaRect.center() + QPointF(0, -0.1 * stripeWidth);
-        addDecoration(areaRect, pt, 90);
+        addDecoration(areaRect, pt, 90, Bottom);
         visible = true;
     }
 
     if (imageRect.right() > widgetRect.width() + xThreshold) {
         QRect areaRect(widgetRect.adjusted(0, 0, -xCut, 0));
         QPointF pt = areaRect.center() + QPointF(0.1 * stripeWidth, 0);
-        addDecoration(areaRect, pt, 180);
+        addDecoration(areaRect, pt, 180, Left);
         visible = true;
     }
 
     if (imageRect.bottom() > widgetRect.height() + yThreshold) {
         QRect areaRect(widgetRect.adjusted(0, 0, 0, -yCut));
         QPointF pt = areaRect.center() + QPointF(0, 0.1 * stripeWidth);
-        addDecoration(areaRect, pt, 270);
+        addDecoration(areaRect, pt, 270, Top);
         visible = true;
     }
 
@@ -148,6 +153,16 @@ void KisInfinityManager::drawDecoration(QPainter& gc, const QRectF& updateArea,
     gc.restore();
 }
 
+inline int expandLeft(int x0, int x1, int maxExpand)
+{
+    return qMax(x0 - maxExpand, qMin(x0, x1));
+}
+
+inline int expandRight(int x0, int x1, int maxExpand)
+{
+    return qMin(x0 + maxExpand, qMax(x0, x1));
+}
+
 bool KisInfinityManager::eventFilter(QObject *obj, QEvent *event)
 {
     bool retval = false;
@@ -186,10 +201,29 @@ bool KisInfinityManager::eventFilter(QObject *obj, QEvent *event)
         retval = mouseEvent->button() == Qt::LeftButton && m_cursorSwitched;
 
         if (retval) {
+            QPoint pos = mouseEvent->pos();
+
             const KisCoordinatesConverter *converter = view()->canvasBase()->coordinatesConverter();
             QRect widgetRect = converter->widgetToImage(view()->canvas()->rect()).toAlignedRect();
             KisImageWSP image = view()->document()->image();
-            QRect cropRect = widgetRect | image->bounds();
+            QRect cropRect = image->bounds();
+
+            const int hLimit = cropRect.width();
+            const int vLimit = cropRect.height();
+
+            if (m_sideRects[Right].contains(pos)) {
+                cropRect.setRight(expandRight(cropRect.right(), widgetRect.right(), hLimit));
+            }
+            if (m_sideRects[Bottom].contains(pos)) {
+                cropRect.setBottom(expandRight(cropRect.bottom(), widgetRect.bottom(), vLimit));
+            }
+            if (m_sideRects[Left].contains(pos)) {
+                cropRect.setLeft(expandLeft(cropRect.left(), widgetRect.left(), hLimit));
+            }
+            if (m_sideRects[Top].contains(pos)) {
+                cropRect.setTop(expandLeft(cropRect.top(), widgetRect.top(), vLimit));
+            }
+
             image->resizeImage(cropRect);
         }
         break;
diff --git a/krita/ui/canvas/kis_infinity_manager.h b/krita/ui/canvas/kis_infinity_manager.h
index 591ce0f..1be69e0 100644
--- a/krita/ui/canvas/kis_infinity_manager.h
+++ b/krita/ui/canvas/kis_infinity_manager.h
@@ -41,7 +41,15 @@ public slots:
     void imagePositionChanged();
 
 private:
-    inline void addDecoration(const QRect &areaRect, const QPointF &handlePoint, qreal angle);
+    enum Side {
+        Right = 0,
+        Bottom,
+        Left,
+        Top,
+
+        NSides
+    };
+    inline void addDecoration(const QRect &areaRect, const QPointF &handlePoint, qreal angle, Side side);
 
 private:
     QPainterPath m_decorationPath;
@@ -50,6 +58,8 @@ private:
     bool m_cursorSwitched;
     QCursor m_oldCursor;
     QVector<QTransform> m_handleTransform;
+
+    QVector<QRect> m_sideRects;
 };
 
 #endif /* __KIS_INFINITY_MANAGER_H */


More information about the kimageshop mailing list