Changed style background.image.src from QPixmap to KwResourceLink and implemented...
[kworship.git] / kworship / display / KwBackgroundManager.cpp
blob7240c61ea9c0ce3cb659cbee2041583dfb9f1556
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 KwBackgroundManager.cpp
22 * @brief Background manager.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwBackgroundManager.h"
27 #include "KwDisplayStyles.h"
29 #include "KwImageLayer.h"
30 #include "KwVideoLayer.h"
32 #include <phonon/mediaobject.h>
33 #include <phonon/audiooutput.h>
36 * Constructors + destructors
39 /// Default constructor.
40 KwBackgroundManager::KwBackgroundManager(KwMediaManager* mediaManager)
41 : KwAbstractDisplayManager()
42 , m_mediaManager(mediaManager)
43 , m_imageLayer(0)
44 , m_videoLayer(0)
48 /// Destructor.
49 KwBackgroundManager::~KwBackgroundManager()
51 clear();
55 * Main interface
58 /// Apply the styles in a scope.
59 void KwBackgroundManager::applyStyles(KwCssScope* scope)
61 KwResourceLink image = KwDisplayStyles::background::image::src(scope);
62 if (image.isNull())
64 // Set background if applicable
65 setPlain(KwDisplayStyles::background::brush(scope));
67 else
69 /// @todo Get the actual file from resource link instead of assuming its a url.
70 setImage(QPixmap(image.url().toLocalFile()));
74 /// Clear the background.
75 void KwBackgroundManager::clear()
77 m_display.clearLayers();
78 delete m_imageLayer;
79 delete m_videoLayer;
80 m_imageLayer = 0;
81 m_videoLayer = 0;
84 /// Set background to a brush.
85 void KwBackgroundManager::setPlain(QBrush brush)
87 clear();
88 m_imageLayer = new KwImageLayer(brush);
89 m_display.setLayer(0, m_imageLayer, true);
92 /// Set the background to an image.
93 void KwBackgroundManager::setImage(const QPixmap& pixmap)
95 clear();
96 m_imageLayer = new KwImageLayer(pixmap);
97 m_display.setLayer(0, m_imageLayer, true);
100 /// Set the background up for video.
101 void KwBackgroundManager::setVideo()
103 // Make sure the background video layer is set up
104 if (0 == m_videoLayer)
106 clear();
107 m_videoLayer = new KwVideoLayer(m_mediaManager);
108 m_display.setLayer(0, m_videoLayer, true);