src/3rdparty/phonon/mmf/videooutput_dsa.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 <QtCore/private/qcore_symbian_p.h> // for qt_TRect2QRect
       
    20 #include <QtGui/private/qwidget_p.h> // to access QWExtra
       
    21 #include <QResizeEvent>
       
    22 #include <QMoveEvent>
       
    23 
       
    24 #include <coemain.h> // for CCoeEnv
       
    25 
       
    26 #include "ancestormovemonitor.h"
       
    27 #include "utils.h"
       
    28 #include "videooutput_dsa.h"
       
    29 
       
    30 QT_BEGIN_NAMESPACE
       
    31 
       
    32 using namespace Phonon;
       
    33 using namespace Phonon::MMF;
       
    34 
       
    35 DsaVideoOutput::DsaVideoOutput(QWidget *parent)
       
    36     :   AbstractVideoOutput(parent)
       
    37     ,   m_ancestorMoveMonitor(0)
       
    38 {
       
    39     TRACE_CONTEXT(DsaVideoOutput::DsaVideoOutput, EVideoInternal);
       
    40     TRACE_ENTRY("parent 0x%08x", parent);
       
    41 
       
    42     setPalette(QPalette(Qt::black));
       
    43     setAttribute(Qt::WA_OpaquePaintEvent, true);
       
    44     setAttribute(Qt::WA_NoSystemBackground, true);
       
    45     setAutoFillBackground(false);
       
    46 
       
    47     qt_widget_private(this)->extraData()->nativePaintMode = QWExtra::ZeroFill;
       
    48     qt_widget_private(this)->extraData()->receiveNativePaintEvents = true;
       
    49 
       
    50     getVideoWindowScreenRect();
       
    51 
       
    52     dump();
       
    53 
       
    54     TRACE_EXIT_0();
       
    55 }
       
    56 
       
    57 DsaVideoOutput::~DsaVideoOutput()
       
    58 {
       
    59     TRACE_CONTEXT(DsaVideoOutput::~DsaVideoOutput, EVideoInternal);
       
    60     TRACE_ENTRY_0();
       
    61 
       
    62     m_ancestorMoveMonitor->unRegisterTarget(this);
       
    63 
       
    64     TRACE_EXIT_0();
       
    65 }
       
    66 
       
    67 //-----------------------------------------------------------------------------
       
    68 // Public functions
       
    69 //-----------------------------------------------------------------------------
       
    70 
       
    71 void MMF::DsaVideoOutput::setAncestorMoveMonitor(AncestorMoveMonitor *monitor)
       
    72 {
       
    73     m_ancestorMoveMonitor = monitor;
       
    74     registerForAncestorMoved();
       
    75 }
       
    76 
       
    77 const QRect& MMF::DsaVideoOutput::videoWindowScreenRect() const
       
    78 {
       
    79     return m_videoWindowScreenRect;
       
    80 }
       
    81 
       
    82 void MMF::DsaVideoOutput::ancestorMoved()
       
    83 {
       
    84     TRACE_CONTEXT(DsaVideoOutput::ancestorMoved, EVideoInternal);
       
    85     TRACE_ENTRY_0();
       
    86 
       
    87     RWindowBase *const window = videoWindow();
       
    88 
       
    89     if (window) {
       
    90         const TPoint newWindowPosSymbian = window->AbsPosition();
       
    91         const QPoint newWindowPos(newWindowPosSymbian.iX, newWindowPosSymbian.iY);
       
    92 
       
    93         if (newWindowPos != m_videoWindowScreenRect.topLeft()) {
       
    94             m_videoWindowScreenRect.moveTo(newWindowPos);
       
    95             emit videoWindowScreenRectChanged();
       
    96         }
       
    97     }
       
    98 
       
    99     TRACE_EXIT_0();
       
   100 }
       
   101 
       
   102 void MMF::DsaVideoOutput::beginNativePaintEvent(const QRect & /*controlRect*/)
       
   103 {
       
   104     emit beginVideoWindowNativePaint();
       
   105 }
       
   106 
       
   107 void MMF::DsaVideoOutput::endNativePaintEvent(const QRect & /*controlRect*/)
       
   108 {
       
   109     // Ensure that draw ops are executed into the WSERV output framebuffer
       
   110     CCoeEnv::Static()->WsSession().Flush();
       
   111 
       
   112     emit endVideoWindowNativePaint();
       
   113 }
       
   114 
       
   115 //-----------------------------------------------------------------------------
       
   116 // Private functions
       
   117 //-----------------------------------------------------------------------------
       
   118 
       
   119 void MMF::DsaVideoOutput::getVideoWindowScreenRect()
       
   120 {
       
   121     RWindowBase *const window = videoWindow();
       
   122     if (window)
       
   123         m_videoWindowScreenRect =
       
   124             qt_TRect2QRect(TRect(window->AbsPosition(), window->Size()));
       
   125 }
       
   126 
       
   127 void MMF::DsaVideoOutput::registerForAncestorMoved()
       
   128 {
       
   129     m_ancestorMoveMonitor->registerTarget(this);
       
   130 }
       
   131 
       
   132 void MMF::DsaVideoOutput::resizeEvent(QResizeEvent *event)
       
   133 {
       
   134     TRACE_CONTEXT(DsaVideoOutput::resizeEvent, EVideoInternal);
       
   135     TRACE("%d %d -> %d %d",
       
   136           event->oldSize().width(), event->oldSize().height(),
       
   137           event->size().width(), event->size().height());
       
   138 
       
   139     if (event->size() != event->oldSize()) {
       
   140         m_videoWindowScreenRect.setSize(event->size());
       
   141         emit videoWindowScreenRectChanged();
       
   142     }
       
   143 }
       
   144 
       
   145 void MMF::DsaVideoOutput::moveEvent(QMoveEvent *event)
       
   146 {
       
   147     TRACE_CONTEXT(DsaVideoOutput::moveEvent, EVideoInternal);
       
   148     TRACE("%d %d -> %d %d",
       
   149           event->oldPos().x(), event->oldPos().y(),
       
   150           event->pos().x(), event->pos().y());
       
   151 
       
   152     if (event->pos() != event->oldPos()) {
       
   153         m_videoWindowScreenRect.moveTo(event->pos());
       
   154         emit videoWindowScreenRectChanged();
       
   155     }
       
   156 }
       
   157 
       
   158 bool MMF::DsaVideoOutput::event(QEvent *event)
       
   159 {
       
   160     TRACE_CONTEXT(DsaVideoOutput::event, EVideoInternal);
       
   161 
       
   162     if (event->type() == QEvent::WinIdChange) {
       
   163         TRACE_0("WinIdChange");
       
   164         getVideoWindowScreenRect();
       
   165         emit videoWindowChanged();
       
   166         return true;
       
   167     } else if (event->type() == QEvent::ParentChange) {
       
   168         // Tell ancestor move monitor to update ancestor list for this widget
       
   169         registerForAncestorMoved();
       
   170         return true;
       
   171     } else {
       
   172         return QWidget::event(event);
       
   173     }
       
   174 }
       
   175 
       
   176 QT_END_NAMESPACE
       
   177