Improve sword bible integration to get first preverse and multiple verses
[kworship.git] / kworship / display / KwAbstractDisplay.cpp
blobffd7f3499e2b5c3aac94c8864c44ad6a5fa1ad4d
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file KwAbstractDisplay.cpp
22 * @brief Display interface class.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwAbstractDisplay.h"
28 #include <cassert>
31 * Constructors + destructors
34 /// Default constructor.
35 KwAbstractDisplay::KwAbstractDisplay()
36 : m_parent(0)
37 , m_children()
38 , m_displayResolution(800,600)
39 , m_layers()
43 /// Destructor.
44 KwAbstractDisplay::~KwAbstractDisplay()
46 /// Disconnect each of the children.
47 DisplayList::iterator it;
48 for (it = m_children.begin(); it != m_children.end(); ++it)
50 childDetachedEvent(*it);
51 assert((*it)->m_parent == this &&"Child not correctly parented");
52 (*it)->m_parent = 0;
53 (*it)->disconnectedEvent();
56 /// Disconnect from parent.
57 if (0 != m_parent)
59 m_parent->detachChild(this);
64 * Heirarchy management
67 /// Attach a child to this object.
68 void KwAbstractDisplay::attachChild(KwAbstractDisplay* child)
70 /// @note Potential MT/Callback issue. child is attached before it is brought up to date so it may need locking.
72 // Attach
73 assert(0 == child->m_parent);
74 child->m_parent = this;
75 m_children.push_back(child);
77 // Callbacks
78 childAttachedEvent(child);
80 // Bring child up to date
81 child->clearLayers();
82 child->setDisplayResolution(m_displayResolution);
83 LayerList::iterator it;
84 unsigned int counter = 0;
85 for (it = m_layers.begin(); it != m_layers.end(); ++it)
87 child->setLayer(counter, *it, true);
88 ++counter;
92 /// Detach a child from this object.
93 void KwAbstractDisplay::detachChild(KwAbstractDisplay* child)
95 DisplayList::iterator it;
96 it = m_children.begin();
97 while (it != m_children.end() && (*it) != child)
99 ++it;
101 assert(it != m_children.end());
102 m_children.erase(it);
104 childDetachedEvent(child);
105 assert((*it)->m_parent == this &&"Child not correctly parented");
106 child->m_parent = 0;
107 child->disconnectedEvent();
111 * Main interface
113 * These pretty much just call the equivalent event and pass the command on to
114 * the display's children.
117 /// Set the display resolution.
118 void KwAbstractDisplay::setDisplayResolution(QSize size)
120 // Callbacks
121 setDisplayResolutionEvent(size);
123 // Keep a record
124 m_displayResolution = size;
126 // Callbacks
127 DisplayList::iterator it;
128 for (it = m_children.begin(); it != m_children.end(); ++it)
130 (*it)->setDisplayResolution(size);
134 /// Clear the layers.
135 void KwAbstractDisplay::clearLayers()
137 // Callbacks
138 clearLayersEvent();
140 // Keep a record
141 m_layers.clear();
143 // Callbacks
144 DisplayList::iterator it;
145 for (it = m_children.begin(); it != m_children.end(); ++it)
147 (*it)->clearLayers();
151 /// Set the contents of a layer.
152 void KwAbstractDisplay::setLayer(unsigned int index, const KwAbstractLayer* layer, bool insert)
154 // Callbacks
155 setLayerEvent(index, layer, insert);
157 // Keep a record
158 m_layers.set(index, layer, insert);
160 // Callbacks
161 DisplayList::iterator displayIt;
162 for (displayIt = m_children.begin(); displayIt != m_children.end(); ++displayIt)
164 (*displayIt)->setLayer(index, layer, insert);
168 /// Remove a layer.
169 void KwAbstractDisplay::KwAbstractDisplay::removeLayer(unsigned int index)
171 // Callbacks
172 removeLayerEvent(index);
174 // Keep a record
175 m_layers.erase(index);
177 // Callbacks
178 DisplayList::iterator displayIt;
179 for (displayIt = m_children.begin(); displayIt != m_children.end(); ++displayIt)
181 (*displayIt)->removeLayer(index);
186 * Accessors
189 /// Get the cached display resolution.
190 QSize KwAbstractDisplay::getDisplayResolution() const
192 return m_displayResolution;
195 /// Get the highest level parent display.
196 KwAbstractDisplay* KwAbstractDisplay::getHighestParent()
198 if (m_parent)
200 return m_parent->getHighestParent();
202 else
204 return this;
209 * Access to layer data.
212 /// Get the number of cached layers.
213 unsigned int KwAbstractDisplay::getCachedLayerCount() const
215 return m_layers.size();
218 /// Get cached layer.
219 const KwAbstractLayer* KwAbstractDisplay::getCachedLayer(unsigned int index) const
221 LayerList::const_iterator it = m_layers.getLayerConstIterator(index);
222 assert(it != m_layers.end());
223 return *it;