Hi,

this patch fixes a minor glitch WRT to text overlay boxes: When the text box rectangle is *not* opened towards the lower right (i.e. started at the bottom left corner), the text will not be visible as it is rendered outside of the rectangle. This is caused by a negative width or height of the rectangle.

The attached patch ensures non-negative sizes and establishes a same minimum size during resize.

Regards,
Michael
From 2d554d3b747930e1859fdc96ac6982728e48892c Mon Sep 17 00:00:00 2001
From: Michael Klein <[email protected]>
Date: Sat, 28 Apr 2012 21:34:07 +0200
Subject: [PATCH 2/2] avoid negative height and width for text overlay boxes

---
 src/CMouseAddText.cpp    |    2 +-
 src/CMouseAddTextBox.cpp |    2 +-
 src/COverlayText.cpp     |    3 ++-
 src/COverlayTextBox.cpp  |    3 ++-
 src/IMouse.cpp           |   13 +++++++++++--
 src/IMouse.h             |    2 +-
 6 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/CMouseAddText.cpp b/src/CMouseAddText.cpp
index f5787c0..5ca6ce1 100644
--- a/src/CMouseAddText.cpp
+++ b/src/CMouseAddText.cpp
@@ -78,7 +78,7 @@ void CMouseAddText::mouseReleaseEvent(QMouseEvent * e)
     {
         if(selArea)
         {
-            resizeRect(e->pos());
+            resizeRect(e->pos(), true);
             selArea     = false;
             COverlayDB::self().addText("",rect);
             canvas->setMouseMode(CCanvas::eMouseMoveArea);
diff --git a/src/CMouseAddTextBox.cpp b/src/CMouseAddTextBox.cpp
index ad93fb3..8b88c7c 100644
--- a/src/CMouseAddTextBox.cpp
+++ b/src/CMouseAddTextBox.cpp
@@ -102,7 +102,7 @@ void CMouseAddTextBox::mouseReleaseEvent(QMouseEvent * e)
     {
         if(selArea)
         {
-            resizeRect(e->pos());
+            resizeRect(e->pos(), true);
             selArea     = false;
             selAnchor   = true;
             anchor      = e->pos();
diff --git a/src/COverlayText.cpp b/src/COverlayText.cpp
index 5e87cd6..b1d3d83 100644
--- a/src/COverlayText.cpp
+++ b/src/COverlayText.cpp
@@ -137,7 +137,8 @@ void COverlayText::mouseMoveEvent(QMouseEvent * e)
     }
     else if(doSize)
     {
-        rect.setBottomRight(pos);
+        rect.setBottom(std::max(rect.top()+0+18*2, pos.y()));
+        rect.setRight(std::max(rect.left()+0+18*3, pos.x()));
         rectMove = QRect(rect.topLeft()     + QPoint(2,2)  , QSize(16, 16));
         rectEdit = QRect(rect.topLeft()     + QPoint(20,2) , QSize(16, 16));
         rectDel  = QRect(rect.topRight()    - QPoint(18,-2), QSize(16, 16));
diff --git a/src/COverlayTextBox.cpp b/src/COverlayTextBox.cpp
index dc544aa..44c44b4 100644
--- a/src/COverlayTextBox.cpp
+++ b/src/COverlayTextBox.cpp
@@ -234,7 +234,8 @@ void COverlayTextBox::mouseMoveEvent(QMouseEvent * e)
     }
     else if(doSize)
     {
-        rect.setBottomRight(pos);
+        rect.setBottom(std::max(rect.top()+0+18*2, pos.y()));
+        rect.setRight(std::max(rect.left()+0+18*3, pos.x()));
         rectMove = QRect(rect.topLeft()     + QPoint(2,2)  , QSize(16, 16));
         rectEdit = QRect(rect.topLeft()     + QPoint(20,2) , QSize(16, 16));
         rectDel  = QRect(rect.topRight()    - QPoint(18,-2), QSize(16, 16));
diff --git a/src/IMouse.cpp b/src/IMouse.cpp
index 1730b48..ae9a183 100644
--- a/src/IMouse.cpp
+++ b/src/IMouse.cpp
@@ -79,9 +79,18 @@ void IMouse::startRect(const QPoint& p)
 }
 
 
-void IMouse::resizeRect(const QPoint& p)
+void IMouse::resizeRect(const QPoint& p, bool normalize)
 {
-    rect.setBottomRight(p);
+    if (normalize)
+    {
+        QPoint p0(rect.topLeft());
+        rect.setCoords(std::min(p.x(), p0.x()), std::min(p.y(), p0.y()),
+                       std::max(p.x(), p0.x()), std::max(p.y(), p0.y()));
+    }
+    else
+    {
+        rect.setBottomRight(p);
+    }
     canvas->update();
 }
 
diff --git a/src/IMouse.h b/src/IMouse.h
index 949012c..cbd6f93 100644
--- a/src/IMouse.h
+++ b/src/IMouse.h
@@ -103,7 +103,7 @@ class IMouse : public QObject
         /// for internal use to start a semi-transparent capture rectangle
         void startRect(const QPoint& p);
         /// for internal use to set the bottom right of the capture rectangle
-        void resizeRect(const QPoint& p);
+        void resizeRect(const QPoint& p, bool normalize = false);
         /// actually draw the current capture rectangle
         void drawRect(QPainter& p);
         /// draw selected waypoint
-- 
1.7.9.6

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Qlandkartegt-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qlandkartegt-users

Reply via email to