Commit f00aabaa authored by Thomas Zander's avatar Thomas Zander

- Let KWord do its own WYSIWYG text layout.

- Make KoShape::recalcMatrix no longer virtual, but provide a shapeChanged() hook
- Make KoTextShape be aware of multiple shapes using 1 document, as thats what
  KWord needs
- Fix clipping in KoTextShape for paragraphs other then the first

svn path=/trunk/koffice/; revision=555850
parent 23f96b93
......@@ -83,6 +83,7 @@ void KoShape::scale( double sx, double sy )
m_scaleX = sx;
m_scaleY = sy;
recalcMatrix();
shapeChanged(ScaleChanged);
}
void KoShape::rotate( double angle )
......@@ -93,6 +94,7 @@ void KoShape::rotate( double angle )
while(m_angle >= 360) m_angle -= 360;
while(m_angle <= -360) m_angle += 360;
recalcMatrix();
shapeChanged(RotationChanged);
}
void KoShape::shear( double sx, double sy )
......@@ -102,6 +104,7 @@ void KoShape::shear( double sx, double sy )
m_shearX = sx;
m_shearY = sy;
recalcMatrix();
shapeChanged(ShearChanged);
}
void KoShape::resize( const QSizeF &size )
......@@ -109,6 +112,8 @@ void KoShape::resize( const QSizeF &size )
if(m_size == size)
return;
m_size = size;
recalcMatrix();
shapeChanged(SizeChanged);
}
void KoShape::setPosition( const QPointF &position )
......@@ -117,6 +122,7 @@ void KoShape::setPosition( const QPointF &position )
return;
m_pos = position;
recalcMatrix();
shapeChanged(PositionChanged);
}
bool KoShape::hitTest( const QPointF &position ) const
......@@ -195,6 +201,7 @@ void KoShape::setParent(KoShapeContainer *parent) {
else
m_parent = 0;
recalcMatrix();
shapeChanged(ParentChanged);
}
int KoShape::zIndex() const {
......
......@@ -359,7 +359,7 @@ public:
/**
* Called internally whenever a property is changed that requires the matrix to be recalculated.
*/
virtual void recalcMatrix();
void recalcMatrix();
/**
* returns the outline of the shape in the form of a path.
......@@ -486,6 +486,22 @@ protected:
*/
virtual void copySettings(const KoShape *shape);
enum ChangeType {
PositionChanged,
RotationChanged,
ScaleChanged,
ShearChanged,
SizeChanged,
ParentChanged
};
/**
* A hook that allows inheriting classes to do something after a KoShape property changed
* This is called whenever the shape, position rotation or scale properties were altered.
* @param type an indicator which type was changed.
*/
virtual void shapeChanged(ChangeType type) { Q_UNUSED(type); }
private:
double m_scaleX;
double m_scaleY;
......
......@@ -102,8 +102,8 @@ void KoShapeContainer::paint(QPainter &painter, KoViewConverter &converter) {
}
}
void KoShapeContainer::recalcMatrix() {
KoShape::recalcMatrix();
void KoShapeContainer::shapeChanged(ChangeType type) {
Q_UNUSED(type);
if(m_children == 0)
return;
m_children->containerChanged(this);
......
......@@ -223,7 +223,7 @@ private:
private: // members
QList <Relation *> m_relations;
};
void recalcMatrix();
void shapeChanged(ChangeType type);
private: // members
KoGraphicsContainerModel *m_children;
......
......@@ -44,10 +44,15 @@ void KoTextShape::paint(QPainter &painter, KoViewConverter &converter) {
pc.cursorPosition = -1;
QTextDocument *doc = m_textShapeData->document();
doc->setPageSize(size());
painter.translate(0, -m_textShapeData->documentOffset());
doc->documentLayout()->draw( &painter, pc);
}
QPointF KoTextShape::convertScreenPos(const QPointF &point) {
return m_invMatrix.map(point);
}
void KoTextShape::shapeChanged(ChangeType type) {
if(type == KoShape::SizeChanged)
m_textShapeData->document()->setPageSize(size());
}
......@@ -41,6 +41,8 @@ public:
QPointF convertScreenPos(const QPointF &point);
private:
void shapeChanged(ChangeType type);
KoTextShapeData *m_textShapeData;
};
......
......@@ -22,6 +22,8 @@
KoTextShapeData::KoTextShapeData()
: m_ownsDocument(false)
, m_offset(0.0)
, m_textCursor(0)
{
m_document = new QTextDocument();
}
......
......@@ -39,10 +39,14 @@ public:
void setTextCursor(QTextCursor *textCursor) { m_textCursor = textCursor; }
QTextCursor *textCursor() const { return m_textCursor; }
double documentOffset() const { return m_offset; }
void setDocumentOffset(double offset) { m_offset = offset; }
private:
QTextDocument *m_document;
bool m_ownsDocument;
QTextCursor *m_textCursor;
double m_offset;
};
#endif
......@@ -39,10 +39,11 @@ KoTextTool::~KoTextTool() {
}
void KoTextTool::paint( QPainter &painter, KoViewConverter &converter) {
//kDebug() << "clip? " << painter.hasClipping() << endl;
// clipping
if(painter.clipRegion().intersect( QRegion(m_textShape->boundingRect().toRect()) ).isEmpty())
return;
if(painter.hasClipping()) {
QRect shape = converter.documentToView(m_textShape->boundingRect()).toRect();
if(painter.clipRegion().intersect( QRegion(shape) ).isEmpty())
return;
}
painter.setMatrix( painter.matrix() * m_textShape->transformationMatrix(&converter) );
double zoomX, zoomY;
......@@ -112,7 +113,7 @@ kDebug() << " appending" << endl;
pen.setColor(invert);
}
painter.setPen(pen);
block.layout()->drawCursor(&painter, QPointF(0,0), m_caret.position());
block.layout()->drawCursor(&painter, QPointF(0,0), m_caret.position() - block.position());
}
void KoTextTool::mousePressEvent( KoPointerEvent *event ) {
......@@ -231,13 +232,24 @@ void KoTextTool::deactivate() {
}
void KoTextTool::repaint() {
QTextBlock block = m_caret.block();
if(block.layout()) {
QTextLine tl = block.layout()->lineForTextPosition(m_caret.position());
if(!tl.isValid()) // layouting info was removed already :(
QTextFrame *frame = m_caret.block().document()->frameAt(m_caret.position());
if(frame == 0)
return;
QTextFrame::Iterator iter = frame->begin();
while(! iter.atEnd()) {
QTextBlock block = iter.currentBlock();
if(block.isValid() && block.contains(m_caret.position())) {
QTextLine tl = block.layout()->lineForTextPosition(m_caret.position() - block.position());
QRectF repaintRect;
if(tl.isValid())
repaintRect = tl.rect();
else { // layouting info was removed already :(
repaintRect = block.layout()->boundingRect();
}
repaintRect.moveTopLeft(repaintRect.topLeft() + m_textShape->position());
m_canvas->updateCanvas(repaintRect);
return;
QRectF line = tl.rect();
line.moveTopLeft(line.topLeft() + m_textShape->position());
m_canvas->updateCanvas(line);
}
iter++;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment