1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
21 * @file KwAbstractDisplay.cpp
22 * @brief Display interface class.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwAbstractDisplay.h"
31 * Constructors + destructors
34 /// Default constructor.
35 KwAbstractDisplay::KwAbstractDisplay()
38 , m_displayResolution(800,600)
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");
53 (*it
)->disconnectedEvent();
56 /// Disconnect from 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.
73 assert(0 == child
->m_parent
);
74 child
->m_parent
= this;
75 m_children
.push_back(child
);
78 childAttachedEvent(child
);
80 // Bring child up to date
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);
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
)
101 assert(it
!= m_children
.end());
102 m_children
.erase(it
);
104 childDetachedEvent(child
);
105 assert((*it
)->m_parent
== this &&"Child not correctly parented");
107 child
->disconnectedEvent();
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
)
121 setDisplayResolutionEvent(size
);
124 m_displayResolution
= size
;
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()
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
)
155 setLayerEvent(index
, layer
, insert
);
158 m_layers
.set(index
, layer
, insert
);
161 DisplayList::iterator displayIt
;
162 for (displayIt
= m_children
.begin(); displayIt
!= m_children
.end(); ++displayIt
)
164 (*displayIt
)->setLayer(index
, layer
, insert
);
169 void KwAbstractDisplay::KwAbstractDisplay::removeLayer(unsigned int index
)
172 removeLayerEvent(index
);
175 m_layers
.erase(index
);
178 DisplayList::iterator displayIt
;
179 for (displayIt
= m_children
.begin(); displayIt
!= m_children
.end(); ++displayIt
)
181 (*displayIt
)->removeLayer(index
);
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()
200 return m_parent
->getHighestParent();
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());