File indexing completed on 2024-05-12 15:56:53
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2010 Thorsten Zachmann <zachmann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "KoTosContainerModel.h" 0008 0009 #include "KoTextShapeDataBase.h" 0010 #include "KoTosContainer.h" 0011 0012 #include <FlakeDebug.h> 0013 #include <QSizeF> 0014 0015 KoTosContainerModel::KoTosContainerModel() 0016 : m_textShape(0) 0017 { 0018 } 0019 0020 KoTosContainerModel::~KoTosContainerModel() 0021 { 0022 } 0023 0024 void KoTosContainerModel::add(KoShape *shape) 0025 { 0026 // make sure shape is a text shape 0027 KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(shape->userData()); 0028 Q_ASSERT(shapeData != 0); 0029 if (shapeData) { 0030 delete m_textShape; 0031 m_textShape = shape; 0032 } 0033 } 0034 0035 void KoTosContainerModel::remove(KoShape *shape) 0036 { 0037 Q_ASSERT(m_textShape == 0 || shape == m_textShape); 0038 if (shape == m_textShape) { 0039 m_textShape = 0; 0040 } 0041 } 0042 0043 void KoTosContainerModel::setClipped(const KoShape *shape, bool clipping) 0044 { 0045 Q_UNUSED(shape); 0046 Q_UNUSED(clipping); 0047 } 0048 0049 bool KoTosContainerModel::isClipped(const KoShape *shape) const 0050 { 0051 Q_UNUSED(shape); 0052 return false; 0053 } 0054 0055 void KoTosContainerModel::setInheritsTransform(const KoShape *shape, bool inherit) 0056 { 0057 Q_UNUSED(shape); 0058 Q_UNUSED(inherit); 0059 } 0060 0061 bool KoTosContainerModel::inheritsTransform(const KoShape *shape) const 0062 { 0063 Q_UNUSED(shape); 0064 return true; 0065 } 0066 0067 int KoTosContainerModel::count() const 0068 { 0069 return m_textShape != 0 ? 1 : 0; 0070 } 0071 0072 QList<KoShape*> KoTosContainerModel::shapes() const 0073 { 0074 QList<KoShape*> shapes; 0075 if (m_textShape) { 0076 shapes << m_textShape; 0077 } 0078 return shapes; 0079 } 0080 0081 void KoTosContainerModel::containerChanged(KoShapeContainer *container, KoShape::ChangeType type) 0082 { 0083 debugFlake << "change type:" << type << KoShape::SizeChanged << KoShape::ContentChanged; 0084 if (type != KoShape::SizeChanged && type != KoShape::ContentChanged) { 0085 return; 0086 } 0087 KoTosContainer *tosContainer = dynamic_cast<KoTosContainer*>(container); 0088 debugFlake << "tosContainer" << tosContainer; 0089 if (tosContainer) { 0090 debugFlake << "behaviour" << tosContainer->resizeBehavior() << KoTosContainer::TextFollowsPreferredTextRect; 0091 } 0092 if ( m_textShape && tosContainer && tosContainer->resizeBehavior() != KoTosContainer::TextFollowsPreferredTextRect ) { 0093 debugFlake << "change type setSize"; 0094 m_textShape->setSize(tosContainer->size()); 0095 } 0096 }