Warning, file /office/calligra/libs/textlayout/AnchorStrategy.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) 2007, 2009, 2010 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2011 Matus Hanzes <matus.hanzes@ixonos.com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "AnchorStrategy.h" 0022 0023 #include "KoTextShapeContainerModel.h" 0024 #include "KoTextLayoutRootArea.h" 0025 0026 #include <KoShapeContainer.h> 0027 0028 #include <TextLayoutDebug.h> 0029 0030 0031 0032 AnchorStrategy::AnchorStrategy(KoShapeAnchor *anchor, KoTextLayoutRootArea *rootArea) 0033 : m_anchor(anchor) 0034 , m_rootArea(rootArea) 0035 , m_model(0) 0036 , m_pageRect(0,0,10,10) 0037 , m_pageContentRect(0,0,10,10) 0038 , m_paragraphRect(0,0,0,0) 0039 , m_pageNumber(0) 0040 { 0041 } 0042 0043 AnchorStrategy::~AnchorStrategy() 0044 { 0045 if (m_model) 0046 m_model->removeAnchor(m_anchor); 0047 } 0048 0049 void AnchorStrategy::detachFromModel() 0050 { 0051 m_model = 0; 0052 } 0053 0054 QRectF AnchorStrategy::pageRect() const 0055 { 0056 return m_pageRect; 0057 } 0058 0059 void AnchorStrategy::setPageRect(const QRectF &pageRect) 0060 { 0061 m_pageRect = pageRect; 0062 } 0063 0064 QRectF AnchorStrategy::pageContentRect() const 0065 { 0066 return m_pageContentRect; 0067 } 0068 0069 void AnchorStrategy::setPageContentRect(const QRectF &pageContentRect) 0070 { 0071 m_pageContentRect = pageContentRect; 0072 } 0073 0074 QRectF AnchorStrategy::paragraphRect() const 0075 { 0076 return m_paragraphRect; 0077 } 0078 0079 void AnchorStrategy::setParagraphRect(const QRectF ¶graphRect) 0080 { 0081 m_paragraphRect = paragraphRect; 0082 } 0083 0084 QRectF AnchorStrategy::paragraphContentRect() const 0085 { 0086 return m_paragraphContentRect; 0087 } 0088 0089 void AnchorStrategy::setParagraphContentRect(const QRectF ¶graphContentRect) 0090 { 0091 m_paragraphContentRect = paragraphContentRect; 0092 } 0093 0094 QRectF AnchorStrategy::layoutEnvironmentRect() const 0095 { 0096 return m_layoutEnvironmentRect; 0097 } 0098 0099 void AnchorStrategy::setLayoutEnvironmentRect(const QRectF &layoutEnvironmentRect) 0100 { 0101 m_layoutEnvironmentRect = layoutEnvironmentRect; 0102 } 0103 0104 int AnchorStrategy::pageNumber() const 0105 { 0106 return m_pageNumber; 0107 } 0108 0109 void AnchorStrategy::setPageNumber(int pageNumber) 0110 { 0111 m_pageNumber = pageNumber; 0112 } 0113 0114 void AnchorStrategy::updateContainerModel() 0115 { 0116 KoShape *shape = m_anchor->shape(); 0117 0118 KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(m_rootArea->associatedShape()); 0119 if (container == 0) { 0120 if (m_model) 0121 m_model->removeAnchor(m_anchor); 0122 m_model = 0; 0123 shape->setParent(0); 0124 return; 0125 } 0126 0127 KoTextShapeContainerModel *theModel = dynamic_cast<KoTextShapeContainerModel*>(container->model()); 0128 if (theModel != m_model) { 0129 if (m_model) 0130 m_model->removeAnchor(m_anchor); 0131 if (shape->parent() != container) { 0132 if (shape->parent()) { 0133 shape->parent()->removeShape(shape); 0134 } 0135 container->addShape(shape); 0136 } 0137 m_model = theModel; 0138 m_model->addAnchor(m_anchor); 0139 } 0140 Q_ASSERT(m_model == theModel); 0141 }