Commit 7bb73199 authored by Thomas Zander's avatar Thomas Zander

Add zIndex to connection and paint it in the proper z-order

svn path=/trunk/koffice/; revision=638051
parent 8c544f49
......@@ -345,8 +345,8 @@ QMatrix KoShape::transformationMatrix(const KoViewConverter *converter) const {
}
bool KoShape::compareShapeZIndex(KoShape *g1, KoShape *g2) {
return g1->zIndex() < g2->zIndex();
bool KoShape::compareShapeZIndex(KoShape *s1, KoShape *s2) {
return s1->zIndex() < s2->zIndex();
}
void KoShape::setParent(KoShapeContainer *parent) {
......
......@@ -405,10 +405,10 @@ public:
/**
* This is a method used to sort a list using the STL sorting methods.
* @param g1 the first shape
* @param g2 the second shape
* @param s1 the first shape
* @param s2 the second shape
*/
static bool compareShapeZIndex(KoShape *g1, KoShape *g2);
static bool compareShapeZIndex(KoShape *s1, KoShape *s2);
/**
* Called internally whenever a property is changed that requires the matrix to be recalculated.
......
......@@ -33,11 +33,14 @@ public:
gluePointIndex2(gp2)
{
Q_ASSERT(shape1->connectors().count() > gp1);
Q_ASSERT(shape2 && shape2->connectors().count() > gp2);
Q_ASSERT(shape2 == 0 || shape2->connectors().count() > gp2);
point1 = shape1->connectors()[gp1];
if(shape2)
point2 = shape1->connectors()[gp2];
zIndex = shape1->zIndex() + 1;
if(shape2) {
point2 = shape2->connectors()[gp2];
zIndex = qMax(zIndex, shape2->zIndex() + 1);
}
}
KoShape * const shape1;
......@@ -45,10 +48,7 @@ public:
QPointF point1, point2;
int gluePointIndex1;
int gluePointIndex2;
/*
Properties like ConnectionType
*/
int zIndex;
};
KoShapeConnection::KoShapeConnection(KoShape *from, int gp1, KoShape *to, int gp2)
......@@ -92,3 +92,31 @@ KoShape *KoShapeConnection::shape2() const {
return d->shape2;
}
int KoShapeConnection::zIndex() const {
return d->zIndex;
}
void KoShapeConnection::setZIndex(int index) {
d->zIndex = index;
}
int KoShapeConnection::gluePointIndex1() const {
return d->gluePointIndex1;
}
int KoShapeConnection::gluePointIndex2() const {
return d->gluePointIndex2;
}
QPointF KoShapeConnection::gluePoint1() const {
return d->point1;
}
QPointF KoShapeConnection::gluePoint2() const {
return d->point2;
}
bool KoShapeConnection::compareConnectionZIndex(KoShapeConnection *c1, KoShapeConnection *c2) {
return c1->zIndex() < c2->zIndex();
}
......@@ -19,7 +19,9 @@
#ifndef KOSHAPECONNECTION_H
#define KOSHAPECONNECTION_H
#include <flake_export.h>
#include "flake_export.h"
#include <QPointF>
class KoShape;
class QPainter;
......@@ -42,6 +44,22 @@ public:
KoShape *shape1() const;
KoShape *shape2() const;
int zIndex() const;
void setZIndex(int index);
int gluePointIndex1() const;
int gluePointIndex2() const;
QPointF gluePoint1() const;
QPointF gluePoint2() const;
/**
* This is a method used to sort a list using the STL sorting methods.
* @param c1 the first connection
* @param c2 the second connection
*/
static bool compareConnectionZIndex(KoShapeConnection*c1, KoShapeConnection *c2);
private:
class Private;
Private * const d;
......
......@@ -137,14 +137,23 @@ void KoShapeManager::paint( QPainter &painter, const KoViewConverter &converter,
updateTree();
painter.setPen( Qt::NoPen );// painters by default have a black stroke, lets turn that off.
painter.setBrush( Qt::NoBrush );
QList<KoShapeConnection*> sortedConnections;
QList<KoShape*> sortedShapes;
if(painter.hasClipping())
sortedShapes = d->tree.intersects( converter.viewToDocument( painter.clipRegion().boundingRect() ) );
else
if(painter.hasClipping()) {
QRectF rect = converter.viewToDocument( painter.clipRegion().boundingRect() );
sortedShapes = d->tree.intersects( rect );
sortedConnections = d->connectionTree.intersects( rect );
}
else {
sortedShapes = shapes();
kWarning() << "KoShapeManager::paint Painting with a painter that has no clipping will lead to too much being painted and no connections being painted!\n";
}
qSort(sortedShapes.begin(), sortedShapes.end(), KoShape::compareShapeZIndex);
const QRegion clipRegion = painter.clipRegion();
qSort(sortedConnections.begin(), sortedConnections.end(), KoShapeConnection::compareConnectionZIndex);
QList<KoShapeConnection*>::iterator connectionIterator = sortedConnections.begin();
const QRegion clipRegion = painter.clipRegion();
foreach ( KoShape * shape, sortedShapes ) {
if(! shape->isVisible() || ( shape->parent() && ! shape->parent()->isVisible() ) )
continue;
......@@ -158,6 +167,13 @@ void KoShapeManager::paint( QPainter &painter, const KoViewConverter &converter,
if(clipRegion.intersect(shapeRegion).isEmpty())
continue;
}
while(connectionIterator != sortedConnections.end() && (*connectionIterator)->zIndex() < shape->zIndex()) {
painter.save();
(*connectionIterator)->paint( painter, converter );
painter.restore();
connectionIterator++;
}
painter.save();
painter.setMatrix( shape->transformationMatrix(&converter) * painter.matrix() );
......@@ -178,10 +194,11 @@ void KoShapeManager::paint( QPainter &painter, const KoViewConverter &converter,
painter.restore(); // for the matrix
}
foreach(KoShapeConnection *sc, d->connectionTree.intersects( clipRegion.boundingRect() ) ) {
while(connectionIterator != sortedConnections.end()) { // paint connections that are above the rest.
painter.save();
sc->paint( painter, converter );
(*connectionIterator)->paint( painter, converter );
painter.restore();
connectionIterator++;
}
#ifdef KOFFICE_RTREE_DEBUG
......
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