| 1 |
/* This file is part of the KDE project. |
| 2 |
|
| 3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
|
| 5 |
This library is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU Lesser General Public License as published by |
| 7 |
the Free Software Foundation, either version 2.1 or 3 of the License. |
| 8 |
|
| 9 |
This library is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
*/ |
| 18 |
|
| 19 |
#include "abstractvideooutput.h" |
| 20 |
#include "utils.h" |
| 21 |
|
| 22 |
#ifndef QT_NO_DEBUG |
| 23 |
#include "objectdump.h" |
| 24 |
#endif |
| 25 |
|
| 26 |
#include <QtCore/private/qcore_symbian_p.h> // for qt_TSize2QSize |
| 27 |
|
| 28 |
#include <QMoveEvent> |
| 29 |
#include <QResizeEvent> |
| 30 |
|
| 31 |
#include <QApplication> // for QApplication::activeWindow |
| 32 |
|
| 33 |
#include <coecntrl.h> |
| 34 |
|
| 35 |
QT_BEGIN_NAMESPACE |
| 36 |
|
| 37 |
using namespace Phonon; |
| 38 |
using namespace Phonon::MMF; |
| 39 |
|
| 40 |
/*! \class MMF::AbstractVideoOutput |
| 41 |
\internal |
| 42 |
*/ |
| 43 |
|
| 44 |
//----------------------------------------------------------------------------- |
| 45 |
// Constants |
| 46 |
//----------------------------------------------------------------------------- |
| 47 |
|
| 48 |
static const Phonon::VideoWidget::AspectRatio DefaultAspectRatio = |
| 49 |
Phonon::VideoWidget::AspectRatioAuto; |
| 50 |
static const Phonon::VideoWidget::ScaleMode DefaultScaleMode = |
| 51 |
Phonon::VideoWidget::FitInView; |
| 52 |
|
| 53 |
|
| 54 |
//----------------------------------------------------------------------------- |
| 55 |
// Constructor / destructor |
| 56 |
//----------------------------------------------------------------------------- |
| 57 |
|
| 58 |
MMF::AbstractVideoOutput::AbstractVideoOutput(QWidget *parent) |
| 59 |
: QWidget(parent) |
| 60 |
, m_aspectRatio(DefaultAspectRatio) |
| 61 |
, m_scaleMode(DefaultScaleMode) |
| 62 |
{ |
| 63 |
// Ensure that this widget has a native window handle |
| 64 |
winId(); |
| 65 |
} |
| 66 |
|
| 67 |
MMF::AbstractVideoOutput::~AbstractVideoOutput() |
| 68 |
{ |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
void MMF::AbstractVideoOutput::setVideoSize(const QSize &frameSize) |
| 73 |
{ |
| 74 |
TRACE_CONTEXT(AbstractVideoOutput::setVideoSize, EVideoInternal); |
| 75 |
TRACE("oldSize %d %d newSize %d %d", |
| 76 |
m_videoFrameSize.width(), m_videoFrameSize.height(), |
| 77 |
frameSize.width(), frameSize.height()); |
| 78 |
|
| 79 |
if (frameSize != m_videoFrameSize) { |
| 80 |
m_videoFrameSize = frameSize; |
| 81 |
updateGeometry(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
//----------------------------------------------------------------------------- |
| 87 |
// QWidget |
| 88 |
//----------------------------------------------------------------------------- |
| 89 |
|
| 90 |
QSize MMF::AbstractVideoOutput::sizeHint() const |
| 91 |
{ |
| 92 |
// TODO: replace this with a more sensible default |
| 93 |
QSize result(320, 240); |
| 94 |
|
| 95 |
if (!m_videoFrameSize.isNull()) |
| 96 |
result = m_videoFrameSize; |
| 97 |
|
| 98 |
return result; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
//----------------------------------------------------------------------------- |
| 103 |
// Public functions |
| 104 |
//----------------------------------------------------------------------------- |
| 105 |
|
| 106 |
RWindowBase* MMF::AbstractVideoOutput::videoWindow() const |
| 107 |
{ |
| 108 |
CCoeControl *control = internalWinId(); |
| 109 |
if (!control) |
| 110 |
control = effectiveWinId(); |
| 111 |
|
| 112 |
RWindowBase *window = 0; |
| 113 |
if (control) |
| 114 |
window = control->DrawableWindow(); |
| 115 |
|
| 116 |
return window; |
| 117 |
} |
| 118 |
|
| 119 |
QSize MMF::AbstractVideoOutput::videoWindowSize() const |
| 120 |
{ |
| 121 |
QSize result; |
| 122 |
if (RWindowBase *const window = videoWindow()) |
| 123 |
result = qt_TSize2QSize(window->Size()); |
| 124 |
return result; |
| 125 |
} |
| 126 |
|
| 127 |
Phonon::VideoWidget::AspectRatio MMF::AbstractVideoOutput::aspectRatio() const |
| 128 |
{ |
| 129 |
return m_aspectRatio; |
| 130 |
} |
| 131 |
|
| 132 |
void MMF::AbstractVideoOutput::setAspectRatio |
| 133 |
(Phonon::VideoWidget::AspectRatio aspectRatio) |
| 134 |
{ |
| 135 |
if (m_aspectRatio != aspectRatio) { |
| 136 |
m_aspectRatio = aspectRatio; |
| 137 |
emit aspectRatioChanged(); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
Phonon::VideoWidget::ScaleMode MMF::AbstractVideoOutput::scaleMode() const |
| 142 |
{ |
| 143 |
return m_scaleMode; |
| 144 |
} |
| 145 |
|
| 146 |
void MMF::AbstractVideoOutput::setScaleMode |
| 147 |
(Phonon::VideoWidget::ScaleMode scaleMode) |
| 148 |
{ |
| 149 |
if (m_scaleMode != scaleMode) { |
| 150 |
m_scaleMode = scaleMode; |
| 151 |
emit scaleModeChanged(); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
//----------------------------------------------------------------------------- |
| 157 |
// Private functions |
| 158 |
//----------------------------------------------------------------------------- |
| 159 |
|
| 160 |
void MMF::AbstractVideoOutput::dump() const |
| 161 |
{ |
| 162 |
#ifndef QT_NO_DEBUG |
| 163 |
TRACE_CONTEXT(AbstractVideoOutput::dump, EVideoInternal); |
| 164 |
QScopedPointer<ObjectDump::QVisitor> visitor(new ObjectDump::QVisitor); |
| 165 |
visitor->setPrefix("Phonon::MMF"); // to aid searchability of logs |
| 166 |
ObjectDump::addDefaultAnnotators(*visitor); |
| 167 |
ObjectDump::dumpTreeFromLeaf(*this, *visitor); |
| 168 |
#endif |
| 169 |
} |
| 170 |
|
| 171 |
QT_END_NAMESPACE |