SVN commit 581816 by zander: Make editing text and updating the caret work for all shapes, not just the first one. M +2 -1 KoTextShape.cpp M +0 -1 KoTextShapeData.cpp M +0 -4 KoTextShapeData.h M +13 -12 KoTextTool.cpp M +1 -0 KoTextTool.h --- trunk/koffice/libs/kotext/KoTextShape.cpp #581815:581816 @@ -50,7 +50,8 @@ } QPointF KoTextShape::convertScreenPos(const QPointF &point) { - return m_invMatrix.map(point); + QPointF p = m_invMatrix.map(point); + return p + QPointF(0.0, m_textShapeData->documentOffset()); } void KoTextShape::shapeChanged(ChangeType type) { --- trunk/koffice/libs/kotext/KoTextShapeData.cpp #581815:581816 @@ -23,7 +23,6 @@ KoTextShapeData::KoTextShapeData() : m_ownsDocument(true) , m_dirty(true) -, m_textCursor(0) , m_offset(0.0) , m_position(-1) , m_endPosition(-1) --- trunk/koffice/libs/kotext/KoTextShapeData.h #581815:581816 @@ -52,9 +52,6 @@ /// return the document QTextDocument *document(); - void setTextCursor(QTextCursor *textCursor) { m_textCursor = textCursor; } - QTextCursor *textCursor() const { return m_textCursor; } - /** * return the amount of points into the document (y) this shape will display. */ @@ -94,7 +91,6 @@ private: QTextDocument *m_document; bool m_ownsDocument, m_dirty; - QTextCursor *m_textCursor; double m_offset; int m_position, m_endPosition; }; --- trunk/koffice/libs/kotext/KoTextTool.cpp #581815:581816 @@ -32,6 +32,7 @@ KoTextTool::KoTextTool(KoCanvasBase *canvas) : KoTool(canvas) , m_textShape(0) +, m_textShapeData(0) { } @@ -39,8 +40,6 @@ } void KoTextTool::paint( QPainter &painter, KoViewConverter &converter) { - // TODO using the member m_textShape is incorrect, use m_canvas to reach the KoSelection object - // instead and iterator over the selected shapes. if(painter.hasClipping()) { QRect shape = converter.documentToView(m_textShape->boundingRect()).toRect(); if(painter.clipRegion().intersect( QRegion(shape) ).isEmpty()) @@ -115,6 +114,7 @@ pen.setColor(invert); } painter.setPen(pen); + painter.translate(0, -m_textShapeData->documentOffset()); block.layout()->drawCursor(&painter, QPointF(0,0), m_caret.position() - block.position()); } @@ -128,9 +128,8 @@ } int KoTextTool::pointToPosition(const QPointF & point) const { - QTextBlock block = m_caret.block(); QPointF p = m_textShape->convertScreenPos(point); - return block.document()->documentLayout()->hitTest(p, Qt::FuzzyHit); + return m_caret.block().document()->documentLayout()->hitTest(p, Qt::FuzzyHit); } void KoTextTool::mouseDoubleClickEvent( KoPointerEvent *event ) { @@ -218,23 +217,24 @@ void KoTextTool::activate (bool temporary) { Q_UNUSED(temporary); - KoShape *shape = m_canvas->shapeManager()->selection()->firstSelectedShape(); - m_textShape = dynamic_cast (shape); - if(m_textShape == 0) { + foreach(KoShape *shape, m_canvas->shapeManager()->selection()->selectedShapes().toList()) { + m_textShape = dynamic_cast (shape); + if(m_textShape) + break; + } + if(m_textShape == 0) { // none found emit sigDone(); return; } - KoTextShapeData *data = static_cast (shape->userData()); - m_caret = QTextCursor(data->document()); - data->setTextCursor(&m_caret); + m_textShapeData = static_cast (m_textShape->userData()); + m_caret = QTextCursor(m_textShapeData->document()); useCursor(Qt::IBeamCursor, true); m_textShape->repaint(); } void KoTextTool::deactivate() { - if(m_textShape) - static_cast (m_textShape->userData())->setTextCursor(0); m_textShape = 0; + m_textShapeData = 0; } void KoTextTool::repaint() { @@ -246,6 +246,7 @@ repaintRect = tl.rect(); else // layouting info was removed already :( repaintRect = block.layout()->boundingRect(); + repaintRect.moveTop(repaintRect.y() - m_textShapeData->documentOffset()); repaintRect.moveTopLeft(repaintRect.topLeft() + m_textShape->position()); m_canvas->updateCanvas(repaintRect); } --- trunk/koffice/libs/kotext/KoTextTool.h #581815:581816 @@ -52,6 +52,7 @@ private: KoTextShape *m_textShape; + KoTextShapeData *m_textShapeData; QTextCursor m_caret; };