r17119 by fschmid - Fixed Bug 10446: "after resizing a group, the text cursor is shifted"

scribus-commit scribus-commit at lists.scribus.net
Thu Dec 22 22:55:00 UTC 2011


Author: fschmid
Date: Thu Dec 22 22:55:00 2011
New Revision: 17119

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17119
Log:
Fixed Bug 10446: "after resizing a group, the text cursor is shifted"

Modified:
    trunk/Scribus/scribus/canvasmode.cpp
    trunk/Scribus/scribus/canvasmode_edit.cpp
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/ui/hruler.cpp
    trunk/Scribus/scribus/ui/hruler.h

Modified: trunk/Scribus/scribus/canvasmode.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17119&path=/trunk/Scribus/scribus/canvasmode.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode.cpp (original)
+++ trunk/Scribus/scribus/canvasmode.cpp Thu Dec 22 22:55:00 2011
@@ -933,12 +933,8 @@
 	{
 		dx=textframe->width()-dx;
 	}
-
 	p->save();
-	p->translate ( textframe->xPos(), textframe->yPos() );
-	p->rotate ( textframe->rotation() );
-
-
+	p->setTransform(textframe->getTransform(), true);
 	p->setPen ( cPen );
 	p->setRenderHint ( QPainter::Antialiasing, true );
 	// avoid displaying the cursor on the frameborder

Modified: trunk/Scribus/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17119&path=/trunk/Scribus/scribus/canvasmode_edit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edit.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_edit.cpp Thu Dec 22 22:55:00 2011
@@ -86,8 +86,9 @@
 	PageItem* currItem;
 	if (m_doc->appMode == modeEdit && GetItem(&currItem))
 	{
-		QRectF brect = currItem->getBoundingRect();
-//		qDebug() << "update cursor" << brect;
+		QRectF brect = QRectF(0, 0, currItem->width(), currItem->height());
+		QTransform m = currItem->getTransform();
+		brect = m.mapRect(brect);
 		m_canvas->update(QRectF(m_canvas->canvasToLocal(brect.topLeft()), QSizeF(brect.width(),brect.height())*m_canvas->scale()).toRect());
 	}
 }
@@ -128,9 +129,11 @@
 	PageItem* currItem;
 	if (m_doc->appMode == modeEdit && GetItem(&currItem))
 	{
-		QPoint oldP = m_canvas->canvasToLocal(QPointF(mRulerGuide, currItem->yPos()));
+		QTransform mm = currItem->getTransform();
+		QPointF itPos = mm.map(QPointF(0, currItem->yPos()));
+		QPoint oldP = m_canvas->canvasToLocal(QPointF(mRulerGuide, itPos.y()));
 		mRulerGuide = base + xp;
-		QPoint p = m_canvas->canvasToLocal(QPointF(mRulerGuide, currItem->yPos() + currItem->height()));
+		QPoint p = m_canvas->canvasToLocal(QPointF(mRulerGuide, itPos.y() + currItem->height() * mm.m22()));
 		m_canvas->update(QRect(oldP.x()-2, oldP.y(), p.x()+2, p.y()));
 	}
 }
@@ -147,24 +150,15 @@
 		{
 			if (mRulerGuide >= 0)
 			{
+				QTransform mm = currItem->getTransform();
+				QPointF itPos = mm.map(QPointF(0, currItem->yPos()));
 				p->save();
-				p->translate(currItem->xPos(), currItem->yPos());
-				p->rotate(currItem->rotation());
+				p->setTransform(mm, true);
 				p->setPen(QPen(Qt::blue, 1.0 / m_canvas->scale(), Qt::DashLine, Qt::FlatCap, Qt::MiterJoin));
 				p->setClipRect(QRectF(0.0, 0.0, currItem->width(), currItem->height()));
 				p->setBrush(Qt::NoBrush);
 				p->setRenderHint(QPainter::Antialiasing);
-				if (currItem->imageFlippedH())
-				{
-					p->translate(currItem->width(), 0);
-					p->scale(-1, 1);
-				}
-				if (currItem->imageFlippedV())
-				{
-					p->translate(0, currItem->height());
-					p->scale(1, -1);
-				}
-				p->drawLine(mRulerGuide - currItem->xPos(), 0, mRulerGuide - currItem->xPos(), currItem->height());
+				p->drawLine(mRulerGuide - itPos.x(), 0, mRulerGuide - itPos.x(), currItem->height() * mm.m22());
 				p->restore();
 			}
 			drawTextCursor(p, textframe);
@@ -172,22 +166,11 @@
 		else if (currItem->asImageFrame())
 		{
 			p->save();
-			p->translate(currItem->xPos(), currItem->yPos());
-			p->rotate(currItem->rotation());
+			p->setTransform(currItem->getTransform(), true);
 			p->setPen(QPen(Qt::blue, 1.0 / m_canvas->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 			p->setClipRect(QRectF(0.0, 0.0, currItem->width(), currItem->height()));
 			p->setBrush(QColor(0,0,255,10));
 			p->setRenderHint(QPainter::Antialiasing);
-			if (currItem->imageFlippedH())
-			{
-				p->translate(currItem->width(), 0);
-				p->scale(-1, 1);
-			}
-			if (currItem->imageFlippedV())
-			{
-				p->translate(0, currItem->height());
-				p->scale(1, -1);
-			}
 			p->translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
 			p->rotate(currItem->imageRotation());
 			p->drawRect(0, 0, currItem->OrigW*currItem->imageXScale(), currItem->OrigH*currItem->imageYScale());
@@ -216,23 +199,6 @@
 	}
 	if ( m_cursorVisible )
 	{
-		// Debug
-// 		QString dbgString;
-// 		int lif(qMax(textframe->CPos , textframe->lastInFrame()));
-// 		for(int ti(textframe->firstInFrame());ti < lif; ++ti)
-// 		{
-// 			if(ti == textframe->CPos )
-// 			{
-// 				dbgString += "["+QString::number(textframe->CPos)+"]";
-// 			}
-// 			dbgString += textframe->itemText.text(ti);
-// 		}
-// 		dbgString +="]"+QString::number(textframe->lastInFrame())+"[";
-// 		qDebug()<<"==============================================================";
-// 		qDebug()<<textframe->CPos<<textframe->lastInFrame();
-// 		qDebug()<<dbgString;
-// 		qDebug()<<"==============================================================";
-		// end debug
 		commonDrawTextCursor(p, textframe, QPointF());
 	}
 }
@@ -253,7 +219,6 @@
 
 void CanvasMode_Edit::activate(bool fromGesture)
 {
-//	qDebug() << "CanvasMode_Edit::activate" << fromGesture;
 	m_canvas->m_viewMode.m_MouseButtonPressed = false;
 	m_canvas->resetRenderMode();
 	m_doc->DragP = false;
@@ -290,7 +255,6 @@
 
 void CanvasMode_Edit::deactivate(bool forGesture)
 {
-//	qDebug() << "CanvasMode_Edit::deactivate" << forGesture;
 	m_view->redrawMarker->hide();
 	if (!forGesture)
 	{
@@ -304,7 +268,6 @@
 	m->accept();
 	m_canvas->m_viewMode.m_MouseButtonPressed = false;
 	m_canvas->resetRenderMode();
-//	m_view->stopDragTimer();
 	PageItem *currItem = 0;
 	if (GetItem(&currItem) && (m_doc->appMode == modeEdit) && currItem->asTextFrame())
 	{
@@ -389,19 +352,7 @@
 				if (m->modifiers() & Qt::ShiftModifier)
 				{
 					qApp->changeOverrideCursor(QCursor(loadIcon("Rotieren2.png")));
-					QTransform p;
-					p.translate(currItem->xPos(), currItem->yPos());
-					p.rotate(currItem->rotation());
-					if (currItem->imageFlippedH())
-					{
-						p.translate(currItem->width(), 0);
-						p.scale(-1, 1);
-					}
-					if (currItem->imageFlippedV())
-					{
-						p.translate(0, currItem->height());
-						p.scale(1, -1);
-					}
+					QTransform p = currItem->getTransform();
 					p.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
 					QPointF rotP = p.map(QPointF(0.0, 0.0));
 					double itemRotation = xy2Deg(mousePointDoc.x() - rotP.x(), mousePointDoc.y() - rotP.y());

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17119&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp (original)
+++ trunk/Scribus/scribus/scribusview.cpp Thu Dec 22 22:55:00 2011
@@ -1579,6 +1579,8 @@
 
 	PageItem_TextFrame *textFrame;
 	QPointF canvasPoint;
+	QTransform mm = item->getTransform();
+	QPointF textFramePoint = mm.map(QPointF(0, 0));
 	if (item->isTextFrame())
 	{
 		textFrame = item->asTextFrame();
@@ -1603,15 +1605,21 @@
 		// #9592 : layout must be valid here, or screenToPosition() may crash
 		if (textFrame->invalid)
 			textFrame->layout();
+		double sx, sy;
+		getScaleFromMatrix(mm, sx, sy);
+		QTransform ms;
+		ms.scale(sx, sy);
 		if(textFrame->reversed())
 		{ //handle Right to Left writing
-			FPoint point(textFrame->width() - (canvasPoint.x() - textFrame->xPos()), canvasPoint.y() - textFrame->yPos());
+			FPoint point(textFrame->width() * mm.m11() - (canvasPoint.x() - textFramePoint.x()), canvasPoint.y() - textFramePoint.y());
+			point = point.transformPoint(ms, true);
 			textFrame->itemText.setCursorPosition(textFrame->itemText.length() == 0 ? 0 :
 				textFrame->itemText.screenToPosition(point));
 		}
 		else
 		{
-			FPoint point(canvasPoint.x() - textFrame->xPos(), canvasPoint.y() - textFrame->yPos());
+			FPoint point(canvasPoint.x() - textFramePoint.x(), canvasPoint.y() - textFramePoint.y());
+			point = point.transformPoint(ms, true);
 			textFrame->itemText.setCursorPosition(textFrame->itemText.length() == 0 ? 0 :
 				textFrame->itemText.screenToPosition(point));
 		}

Modified: trunk/Scribus/scribus/ui/hruler.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17119&path=/trunk/Scribus/scribus/ui/hruler.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/hruler.cpp (original)
+++ trunk/Scribus/scribus/ui/hruler.cpp Thu Dec 22 22:55:00 2011
@@ -92,6 +92,7 @@
 	textEditMode = false;
 	drawMark = false;
 	RulerCode = rc_none;
+	itemScale = 1.0;
 	setMouseTracking(true);
 	rulerGesture = new RulerGesture(currView, RulerGesture::HORIZONTAL);
 	unitChange();
@@ -881,8 +882,11 @@
 void Hruler::setItem(PageItem * item)
 {
 	currItem = item;
-	ItemPos = item->xPos();
-	ItemEndPos = ItemPos + item->width();
+	QTransform mm = currItem->getTransform();
+	QPointF itPos = mm.map(QPointF(0, currItem->yPos()));
+	itemScale = mm.m11();
+	ItemPos = itPos.x();
+	ItemEndPos = ItemPos + item->width() * itemScale;
 	/*if (currDoc->guidesPrefs().rulerMode)
 	{
 		ItemPos -= currDoc->currentPage()->xOffset();

Modified: trunk/Scribus/scribus/ui/hruler.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17119&path=/trunk/Scribus/scribus/ui/hruler.h
==============================================================================
--- trunk/Scribus/scribus/ui/hruler.h (original)
+++ trunk/Scribus/scribus/ui/hruler.h Thu Dec 22 22:55:00 2011
@@ -66,6 +66,7 @@
 	double ItemPos;
 	double ItemEndPos;
 	double offs;
+	double itemScale;
 public:
 	double ruleSpacing();
 	void setItem(PageItem * item);




More information about the scribus-commit mailing list