src/3rdparty/phonon/mmf/abstractvideooutput.cpp
changeset 19 fcece45ef507
child 14 c0432d11811c
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
       
     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 <coecntrl.h>
       
    32 
       
    33 QT_BEGIN_NAMESPACE
       
    34 
       
    35 using namespace Phonon;
       
    36 using namespace Phonon::MMF;
       
    37 
       
    38 /*! \class MMF::AbstractVideoOutput
       
    39   \internal
       
    40 */
       
    41 
       
    42 //-----------------------------------------------------------------------------
       
    43 // Constants
       
    44 //-----------------------------------------------------------------------------
       
    45 
       
    46 static const Phonon::VideoWidget::AspectRatio DefaultAspectRatio =
       
    47     Phonon::VideoWidget::AspectRatioAuto;
       
    48 static const Phonon::VideoWidget::ScaleMode DefaultScaleMode =
       
    49     Phonon::VideoWidget::FitInView;
       
    50 
       
    51 
       
    52 //-----------------------------------------------------------------------------
       
    53 // Constructor / destructor
       
    54 //-----------------------------------------------------------------------------
       
    55 
       
    56 MMF::AbstractVideoOutput::AbstractVideoOutput(QWidget *parent)
       
    57     :   QWidget(parent)
       
    58     ,   m_aspectRatio(DefaultAspectRatio)
       
    59     ,   m_scaleMode(DefaultScaleMode)
       
    60 {
       
    61 
       
    62 }
       
    63 
       
    64 MMF::AbstractVideoOutput::~AbstractVideoOutput()
       
    65 {
       
    66 
       
    67 }
       
    68 
       
    69 void MMF::AbstractVideoOutput::setVideoSize(const QSize &frameSize)
       
    70 {
       
    71     TRACE_CONTEXT(AbstractVideoOutput::setVideoSize, EVideoInternal);
       
    72     TRACE("oldSize %d %d newSize %d %d",
       
    73           m_videoFrameSize.width(), m_videoFrameSize.height(),
       
    74           frameSize.width(), frameSize.height());
       
    75 
       
    76     if (frameSize != m_videoFrameSize) {
       
    77         m_videoFrameSize = frameSize;
       
    78         updateGeometry();
       
    79     }
       
    80 }
       
    81 
       
    82 
       
    83 //-----------------------------------------------------------------------------
       
    84 // QWidget
       
    85 //-----------------------------------------------------------------------------
       
    86 
       
    87 QSize MMF::AbstractVideoOutput::sizeHint() const
       
    88 {
       
    89     // TODO: replace this with a more sensible default
       
    90     QSize result(320, 240);
       
    91 
       
    92     if (!m_videoFrameSize.isNull())
       
    93         result = m_videoFrameSize;
       
    94 
       
    95     return result;
       
    96 }
       
    97 
       
    98 
       
    99 //-----------------------------------------------------------------------------
       
   100 // Public functions
       
   101 //-----------------------------------------------------------------------------
       
   102 
       
   103 RWindowBase* MMF::AbstractVideoOutput::videoWindow() const
       
   104 {
       
   105     CCoeControl *control = internalWinId();
       
   106     if (!control)
       
   107         control = effectiveWinId();
       
   108 
       
   109     RWindowBase *window = 0;
       
   110     if (control)
       
   111         window = control->DrawableWindow();
       
   112 
       
   113     return window;
       
   114 }
       
   115 
       
   116 QSize MMF::AbstractVideoOutput::videoWindowSize() const
       
   117 {
       
   118     QSize result;
       
   119     if (RWindowBase *const window = videoWindow())
       
   120         result = qt_TSize2QSize(window->Size());
       
   121     return result;
       
   122 }
       
   123 
       
   124 Phonon::VideoWidget::AspectRatio MMF::AbstractVideoOutput::aspectRatio() const
       
   125 {
       
   126     return m_aspectRatio;
       
   127 }
       
   128 
       
   129 void MMF::AbstractVideoOutput::setAspectRatio
       
   130     (Phonon::VideoWidget::AspectRatio aspectRatio)
       
   131 {
       
   132     if (m_aspectRatio != aspectRatio) {
       
   133         m_aspectRatio = aspectRatio;
       
   134         emit aspectRatioChanged();
       
   135     }
       
   136 }
       
   137 
       
   138 Phonon::VideoWidget::ScaleMode MMF::AbstractVideoOutput::scaleMode() const
       
   139 {
       
   140     return m_scaleMode;
       
   141 }
       
   142 
       
   143 void MMF::AbstractVideoOutput::setScaleMode
       
   144     (Phonon::VideoWidget::ScaleMode scaleMode)
       
   145 {
       
   146     if (m_scaleMode != scaleMode) {
       
   147         m_scaleMode = scaleMode;
       
   148         emit scaleModeChanged();
       
   149     }
       
   150 }
       
   151 
       
   152 
       
   153 //-----------------------------------------------------------------------------
       
   154 // Private functions
       
   155 //-----------------------------------------------------------------------------
       
   156 
       
   157 void MMF::AbstractVideoOutput::dump() const
       
   158 {
       
   159 #ifndef QT_NO_DEBUG
       
   160     TRACE_CONTEXT(AbstractVideoOutput::dump, EVideoInternal);
       
   161 
       
   162     QScopedPointer<ObjectDump::QVisitor> visitor(new ObjectDump::QVisitor);
       
   163     visitor->setPrefix("Phonon::MMF"); // to aid searchability of logs
       
   164     ObjectDump::addDefaultAnnotators(*visitor);
       
   165     TRACE("Dumping tree from leaf 0x%08x:", this);
       
   166     ObjectDump::dumpTreeFromLeaf(*this, *visitor);
       
   167 
       
   168     QScopedPointer<ObjectDump::QDumper> dumper(new ObjectDump::QDumper);
       
   169     dumper->setPrefix("Phonon::MMF"); // to aid searchability of logs
       
   170     ObjectDump::addDefaultAnnotators(*dumper);
       
   171     TRACE_0("Dumping AbstractVideoOutput:");
       
   172     dumper->dumpObject(*this);
       
   173 #endif
       
   174 }
       
   175 
       
   176 QT_END_NAMESPACE
       
   177