libs/flake
KoShapeGroup.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KoShapeGroup.h"
00022 #include "KoShapeContainerModel.h"
00023 #include "KoShapeLayer.h"
00024 #include "SimpleShapeContainerModel.h"
00025 #include "KoShapeSavingContext.h"
00026 #include "KoShapeLoadingContext.h"
00027 #include "KoXmlWriter.h"
00028 #include "KoXmlReader.h"
00029 #include "KoShapeRegistry.h"
00030 #include "KoShapeBorderModel.h"
00031 #include "KoShapeShadow.h"
00032
00033 #include <QPainter>
00034
00035 KoShapeGroup::KoShapeGroup()
00036 : KoShapeContainer(new SimpleShapeContainerModel())
00037 {
00038 setSize(QSizeF(0, 0));
00039 }
00040
00041 void KoShapeGroup::paintComponent(QPainter &painter, const KoViewConverter &converter)
00042 {
00043 Q_UNUSED(painter);
00044 Q_UNUSED(converter);
00045 }
00046
00047 bool KoShapeGroup::hitTest(const QPointF &position) const
00048 {
00049 Q_UNUSED(position);
00050 return false;
00051 }
00052
00053 void KoShapeGroup::childCountChanged()
00054 {
00055
00056 QRectF br = boundingRect();
00057 setAbsolutePosition(br.topLeft(), KoFlake::TopLeftCorner);
00058 setSize(br.size());
00059 }
00060
00061 void KoShapeGroup::saveOdf(KoShapeSavingContext & context) const
00062 {
00063 context.xmlWriter().startElement("draw:g");
00064 saveOdfAttributes(context, (OdfMandatories ^ OdfLayer) | OdfAdditionalAttributes);
00065 context.xmlWriter().addAttributePt("svg:y", position().y());
00066
00067 QList<KoShape*> shapes = childShapes();
00068 qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
00069
00070 foreach(KoShape* shape, shapes) {
00071 shape->saveOdf(context);
00072 }
00073
00074 saveOdfCommonChildElements(context);
00075 context.xmlWriter().endElement();
00076 }
00077
00078 bool KoShapeGroup::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context)
00079 {
00080 loadOdfAttributes(element, context, OdfMandatories | OdfAdditionalAttributes | OdfCommonChildElements);
00081
00082 KoXmlElement child;
00083 QMap<KoShapeLayer*, int> usedLayers;
00084 forEachElement(child, element) {
00085 KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf(child, context);
00086 KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape->parent());
00087 if (layer) {
00088 usedLayers[layer]++;
00089 }
00090 if (shape) {
00091 addChild(shape);
00092 }
00093 }
00094 KoShapeLayer *parent = 0;
00095 int maxUseCount = 0;
00096
00097 for (QMap<KoShapeLayer*, int>::const_iterator it(usedLayers.constBegin()); it != usedLayers.constEnd(); ++it) {
00098 if (it.value() > maxUseCount) {
00099 maxUseCount = it.value();
00100 parent = it.key();
00101 }
00102 }
00103 setParent(parent);
00104
00105 QRectF bound;
00106 bool boundInitialized = false;
00107 foreach(KoShape * shape, childShapes()) {
00108 if (! boundInitialized) {
00109 bound = shape->boundingRect();
00110 boundInitialized = true;
00111 } else
00112 bound = bound.united(shape->boundingRect());
00113 }
00114
00115 setSize(bound.size());
00116 setPosition(bound.topLeft());
00117
00118 foreach(KoShape * shape, childShapes())
00119 shape->setAbsolutePosition(shape->absolutePosition() - bound.topLeft());
00120
00121 return true;
00122 }
00123
00124 void KoShapeGroup::shapeChanged(ChangeType type, KoShape *shape)
00125 {
00126 Q_UNUSED(shape);
00127 switch( type )
00128 {
00129 case KoShape::BorderChanged:
00130 {
00131 KoShapeBorderModel * stroke = border();
00132 if( stroke ) {
00133 if( stroke->removeUser() )
00134 delete stroke;
00135 setBorder(0);
00136 }
00137 break;
00138 }
00139 case KoShape::ShadowChanged:
00140 {
00141 KoShapeShadow * shade = shadow();
00142 if( shade ) {
00143 if( shade->removeUser() )
00144 delete shade;
00145 setShadow(0);
00146 }
00147 break;
00148 }
00149 default:
00150 break;
00151 }
00152 }
|