Warning, file /office/calligra/libs/flake/KoShapeContainerDefaultModel.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) 2006-2007, 2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
0004  * Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 
0022 #include "KoShapeContainerDefaultModel.h"
0023 
0024 #include "KoShapeContainer.h"
0025 
0026 class Q_DECL_HIDDEN KoShapeContainerDefaultModel::Private
0027 {
0028 public:
0029     class Relation
0030     {
0031     public:
0032         explicit Relation(KoShape *child)
0033         : inside(false),
0034         inheritsTransform(false),
0035         m_child(child)
0036         {}
0037 
0038         KoShape* child()
0039         {
0040             return m_child;
0041         }
0042 
0043         uint inside : 1; ///< if true, the child will be clipped by the parent.
0044         uint inheritsTransform : 1;
0045 
0046     private:
0047         KoShape *m_child;
0048     };
0049 
0050     ~Private()
0051     {
0052         qDeleteAll(relations);
0053     }
0054 
0055     Relation* findRelation(const KoShape *child) const
0056     {
0057         foreach (Relation *relation, relations) {
0058             if (relation->child() == child) {
0059                 return relation;
0060             }
0061         }
0062         return 0;
0063     }
0064 
0065 
0066     // TODO use a QMap<KoShape*, bool> instead this should speed things up a bit
0067     QList<Relation *> relations;
0068 };
0069 
0070 KoShapeContainerDefaultModel::KoShapeContainerDefaultModel()
0071 : d(new Private())
0072 {
0073 }
0074 
0075 KoShapeContainerDefaultModel::~KoShapeContainerDefaultModel()
0076 {
0077     delete d;
0078 }
0079 
0080 void KoShapeContainerDefaultModel::add(KoShape *child)
0081 {
0082     Private::Relation *r = new Private::Relation(child);
0083     d->relations.append(r);
0084 }
0085 
0086 void KoShapeContainerDefaultModel::proposeMove(KoShape *shape, QPointF &move)
0087 {
0088     KoShapeContainer *parent = shape->parent();
0089     bool allowedToMove = true;
0090     while (allowedToMove && parent) {
0091         allowedToMove = parent->isEditable();
0092         parent = parent->parent();
0093     }
0094     if (! allowedToMove) {
0095         move.setX(0);
0096         move.setY(0);
0097     }
0098 }
0099 
0100 
0101 void KoShapeContainerDefaultModel::setClipped(const KoShape *child, bool clipping)
0102 {
0103     Private::Relation *relation = d->findRelation(child);
0104     if (relation == 0)
0105         return;
0106     if (relation->inside == clipping)
0107         return;
0108     relation->child()->update(); // mark old canvas-location as in need of repaint (aggregated)
0109     relation->inside = clipping;
0110     relation->child()->notifyChanged();
0111     relation->child()->update(); // mark new area as in need of repaint
0112 }
0113 
0114 bool KoShapeContainerDefaultModel::isClipped(const KoShape *child) const
0115 {
0116     Private::Relation *relation = d->findRelation(child);
0117     return relation ? relation->inside: false;
0118 }
0119 
0120 void KoShapeContainerDefaultModel::remove(KoShape *child)
0121 {
0122     Private::Relation *relation = d->findRelation(child);
0123     if (relation == 0)
0124         return;
0125     d->relations.removeAll(relation);
0126     delete relation;
0127 }
0128 
0129 int KoShapeContainerDefaultModel::count() const
0130 {
0131     return d->relations.count();
0132 }
0133 
0134 QList<KoShape*> KoShapeContainerDefaultModel::shapes() const
0135 {
0136     QList<KoShape*> answer;
0137     foreach(Private::Relation *relation, d->relations) {
0138         answer.append(relation->child());
0139     }
0140     return answer;
0141 }
0142 
0143 bool KoShapeContainerDefaultModel::isChildLocked(const KoShape *child) const
0144 {
0145     return child->isGeometryProtected();
0146 }
0147 
0148 void KoShapeContainerDefaultModel::containerChanged(KoShapeContainer *, KoShape::ChangeType)
0149 {
0150 }
0151 
0152 void KoShapeContainerDefaultModel::setInheritsTransform(const KoShape *shape, bool inherit)
0153 {
0154     Private::Relation *relation = d->findRelation(shape);
0155     if (relation == 0)
0156         return;
0157     if (relation->inheritsTransform == inherit)
0158         return;
0159     relation->child()->update(); // mark old canvas-location as in need of repaint (aggregated)
0160     relation->inheritsTransform = inherit;
0161     relation->child()->notifyChanged();
0162     relation->child()->update(); // mark new area as in need of repaint
0163 }
0164 
0165 bool KoShapeContainerDefaultModel::inheritsTransform(const KoShape *shape) const
0166 {
0167     Private::Relation *relation = d->findRelation(shape);
0168     return relation ? relation->inheritsTransform: false;
0169 }
0170