Warning, file /office/calligra/libs/flake/KoTosContainerModel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "KoTosContainerModel.h"
0021 
0022 #include "KoTextShapeDataBase.h"
0023 #include "KoTosContainer.h"
0024 
0025 #include <FlakeDebug.h>
0026 #include <QSizeF>
0027 
0028 KoTosContainerModel::KoTosContainerModel()
0029 : m_textShape(0)
0030 {
0031 }
0032 
0033 KoTosContainerModel::~KoTosContainerModel()
0034 {
0035 }
0036 
0037 void KoTosContainerModel::add(KoShape *shape)
0038 {
0039     // make sure shape is a text shape
0040     KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(shape->userData());
0041     Q_ASSERT(shapeData != 0);
0042     if (shapeData) {
0043         m_textShape = shape;
0044     }
0045 }
0046 
0047 void KoTosContainerModel::remove(KoShape *shape)
0048 {
0049     Q_ASSERT(m_textShape == 0 || shape == m_textShape);
0050     if (shape == m_textShape) {
0051         m_textShape = 0;
0052     }
0053 }
0054 
0055 void KoTosContainerModel::setClipped(const KoShape *shape, bool clipping)
0056 {
0057     Q_UNUSED(shape);
0058     Q_UNUSED(clipping);
0059 }
0060 
0061 bool KoTosContainerModel::isClipped(const KoShape *shape) const
0062 {
0063     Q_UNUSED(shape)
0064     return false;
0065 }
0066 
0067 void KoTosContainerModel::setInheritsTransform(const KoShape *shape, bool inherit)
0068 {
0069     Q_UNUSED(shape);
0070     Q_UNUSED(inherit);
0071 }
0072 
0073 bool KoTosContainerModel::inheritsTransform(const KoShape *shape) const
0074 {
0075     Q_UNUSED(shape)
0076     return true;
0077 }
0078 
0079 bool KoTosContainerModel::isChildLocked(const KoShape *child) const
0080 {
0081     Q_ASSERT(child == m_textShape);
0082     Q_ASSERT(child->parent());
0083     // TODO do we need to guard this?
0084     return child->isGeometryProtected() || child->parent()->isGeometryProtected();
0085 }
0086 
0087 int KoTosContainerModel::count() const
0088 {
0089     return m_textShape != 0 ? 1 : 0;
0090 }
0091 
0092 QList<KoShape*> KoTosContainerModel::shapes() const
0093 {
0094     QList<KoShape*> shapes;
0095     if (m_textShape) {
0096         shapes << m_textShape;
0097     }
0098     return shapes;
0099 }
0100 
0101 void KoTosContainerModel::containerChanged(KoShapeContainer *container, KoShape::ChangeType type)
0102 {
0103     debugFlake << "change type:" << type << KoShape::SizeChanged << KoShape::ContentChanged;
0104     if (type != KoShape::SizeChanged && type != KoShape::ContentChanged) {
0105         return;
0106     }
0107     KoTosContainer *tosContainer = dynamic_cast<KoTosContainer*>(container);
0108     debugFlake << "tosContainer" << tosContainer;
0109     if (tosContainer) {
0110         debugFlake << "behaviour" << tosContainer->resizeBehavior() << KoTosContainer::TextFollowsPreferredTextRect;
0111     }
0112     if ( m_textShape && tosContainer && tosContainer->resizeBehavior() != KoTosContainer::TextFollowsPreferredTextRect ) {
0113         debugFlake << "change type setSize";
0114         m_textShape->setSize(tosContainer->size());
0115     }
0116 }