1 /* This file is part of the KDE project
2    Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 
20 #include "KoTosContainerModel.h"
21 
22 #include "KoTextShapeDataBase.h"
23 #include "KoTosContainer.h"
24 
25 #include <FlakeDebug.h>
26 #include <QSizeF>
27 
KoTosContainerModel()28 KoTosContainerModel::KoTosContainerModel()
29 : m_textShape(0)
30 {
31 }
32 
~KoTosContainerModel()33 KoTosContainerModel::~KoTosContainerModel()
34 {
35 }
36 
add(KoShape * shape)37 void KoTosContainerModel::add(KoShape *shape)
38 {
39     // make sure shape is a text shape
40     KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(shape->userData());
41     Q_ASSERT(shapeData != 0);
42     if (shapeData) {
43         delete m_textShape;
44         m_textShape = shape;
45     }
46 }
47 
remove(KoShape * shape)48 void KoTosContainerModel::remove(KoShape *shape)
49 {
50     Q_ASSERT(m_textShape == 0 || shape == m_textShape);
51     if (shape == m_textShape) {
52         m_textShape = 0;
53     }
54 }
55 
setClipped(const KoShape * shape,bool clipping)56 void KoTosContainerModel::setClipped(const KoShape *shape, bool clipping)
57 {
58     Q_UNUSED(shape);
59     Q_UNUSED(clipping);
60 }
61 
isClipped(const KoShape * shape) const62 bool KoTosContainerModel::isClipped(const KoShape *shape) const
63 {
64     Q_UNUSED(shape)
65     return false;
66 }
67 
setInheritsTransform(const KoShape * shape,bool inherit)68 void KoTosContainerModel::setInheritsTransform(const KoShape *shape, bool inherit)
69 {
70     Q_UNUSED(shape);
71     Q_UNUSED(inherit);
72 }
73 
inheritsTransform(const KoShape * shape) const74 bool KoTosContainerModel::inheritsTransform(const KoShape *shape) const
75 {
76     Q_UNUSED(shape)
77     return true;
78 }
79 
count() const80 int KoTosContainerModel::count() const
81 {
82     return m_textShape != 0 ? 1 : 0;
83 }
84 
shapes() const85 QList<KoShape*> KoTosContainerModel::shapes() const
86 {
87     QList<KoShape*> shapes;
88     if (m_textShape) {
89         shapes << m_textShape;
90     }
91     return shapes;
92 }
93 
containerChanged(KoShapeContainer * container,KoShape::ChangeType type)94 void KoTosContainerModel::containerChanged(KoShapeContainer *container, KoShape::ChangeType type)
95 {
96     debugFlake << "change type:" << type << KoShape::SizeChanged << KoShape::ContentChanged;
97     if (type != KoShape::SizeChanged && type != KoShape::ContentChanged) {
98         return;
99     }
100     KoTosContainer *tosContainer = dynamic_cast<KoTosContainer*>(container);
101     debugFlake << "tosContainer" << tosContainer;
102     if (tosContainer) {
103         debugFlake << "behaviour" << tosContainer->resizeBehavior() << KoTosContainer::TextFollowsPreferredTextRect;
104     }
105     if ( m_textShape && tosContainer && tosContainer->resizeBehavior() != KoTosContainer::TextFollowsPreferredTextRect ) {
106         debugFlake << "change type setSize";
107         m_textShape->setSize(tosContainer->size());
108     }
109 }
110