libs/flake
KoChildrenData.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 * Copyright (C) 2006-2007 Thomas Zander <zander@kde.org> 00003 * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net> 00004 * Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "KoChildrenData.h" 00023 00024 #include "KoShapeContainer.h" 00025 00026 class KoChildrenData::Private 00027 { 00028 public: 00029 class Relation 00030 { 00031 public: 00032 explicit Relation(KoShape *child) 00033 : m_inside(false) 00034 , m_child(child) 00035 {} 00036 00037 KoShape* child() 00038 { 00039 return m_child; 00040 } 00041 00042 bool m_inside; 00043 00044 private: 00045 KoShape *m_child; 00046 }; 00047 00048 ~Private() 00049 { 00050 qDeleteAll(relations); 00051 } 00052 00053 Relation* findRelation(const KoShape *child) const 00054 { 00055 foreach (Relation *relation, relations) { 00056 if (relation->child() == child) { 00057 return relation; 00058 } 00059 } 00060 return 0; 00061 } 00062 00063 00064 // TODO use a QMap<KoShape*, bool> instead this should speed things up a bit 00065 QList<Relation *> relations; 00066 }; 00067 00068 KoChildrenData::KoChildrenData() 00069 : d( new Private() ) 00070 { 00071 } 00072 00073 KoChildrenData::~KoChildrenData() 00074 { 00075 delete d; 00076 } 00077 00078 void KoChildrenData::add(KoShape *child) 00079 { 00080 Private::Relation *r = new Private::Relation(child); 00081 d->relations.append(r); 00082 } 00083 00084 void KoChildrenData::proposeMove(KoShape *shape, QPointF &move) 00085 { 00086 KoShapeContainer *parent = shape->parent(); 00087 bool allowedToMove = true; 00088 while (allowedToMove && parent) { 00089 allowedToMove = parent->isEditable(); 00090 parent = parent->parent(); 00091 } 00092 if (! allowedToMove) { 00093 move.setX( 0 ); 00094 move.setY( 0 ); 00095 } 00096 } 00097 00098 00099 void KoChildrenData::setClipping(const KoShape *child, bool clipping) 00100 { 00101 Private::Relation *relation = d->findRelation(child); 00102 if (relation == 0) 00103 return; 00104 if (relation->m_inside == clipping) 00105 return; 00106 relation->m_inside = clipping; 00107 relation->child()->update(); 00108 relation->child()->notifyChanged(); 00109 relation->child()->update(); 00110 } 00111 00112 bool KoChildrenData::childClipped(const KoShape *child) const 00113 { 00114 Private::Relation *relation = d->findRelation(child); 00115 return relation ? relation->m_inside: false; 00116 } 00117 00118 void KoChildrenData::remove(KoShape *child) 00119 { 00120 Private::Relation *relation = d->findRelation(child); 00121 if (relation == 0) 00122 return; 00123 d->relations.removeAll(relation); 00124 } 00125 00126 int KoChildrenData::count() const 00127 { 00128 return d->relations.count(); 00129 } 00130 00131 QList<KoShape*> KoChildrenData::childShapes() const 00132 { 00133 QList<KoShape*> answer; 00134 foreach(Private::Relation *relation, d->relations) { 00135 answer.append(relation->child()); 00136 } 00137 return answer; 00138 } 00139 00140 bool KoChildrenData::isChildLocked(const KoShape *child) const 00141 { 00142 return child->isGeometryProtected(); 00143 } 00144 00145 void KoChildrenData::containerChanged(KoShapeContainer *) 00146 { 00147 }
