source: trunk/src/3rdparty/phonon/ds9/abstractvideorenderer.cpp

Last change on this file was 561, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 3.6 KB
Line 
1/* This file is part of the KDE project.
2
3Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5This library is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 2.1 or 3 of the License.
8
9This library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU Lesser General Public License for more details.
13
14You should have received a copy of the GNU Lesser General Public License
15along with this library. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "abstractvideorenderer.h"
19
20#include <QtGui/QApplication>
21#include <QtGui/QDesktopWidget>
22
23QT_BEGIN_NAMESPACE
24
25#ifndef QT_NO_PHONON_VIDEO
26
27namespace Phonon
28{
29 namespace DS9
30 {
31
32 AbstractVideoRenderer::AbstractVideoRenderer() :
33 m_dstX(0), m_dstY(0), m_dstWidth(0), m_dstHeight(0),
34 m_active(false)
35 {
36 }
37
38 AbstractVideoRenderer::~AbstractVideoRenderer()
39 {
40 }
41
42 Filter AbstractVideoRenderer::getFilter() const
43 {
44 return m_filter;
45 }
46
47 QSize AbstractVideoRenderer::sizeHint() const
48 {
49 QSize s = videoSize();
50 if (s.isNull()) {
51 s = QSize(640, 480).boundedTo( QApplication::desktop()->availableGeometry().size() );
52 }
53 return s;
54 }
55
56 void AbstractVideoRenderer::setActive(bool b)
57 {
58 m_active = b;
59 }
60
61 bool AbstractVideoRenderer::isActive() const
62 {
63 return m_active;
64 }
65
66 void AbstractVideoRenderer::internalNotifyResize(const QSize &size, const QSize &videoSize,
67 Phonon::VideoWidget::AspectRatio aspectRatio, Phonon::VideoWidget::ScaleMode scaleMode)
68 {
69 //update the video rects
70 qreal ratio = -1.;
71 const int videoWidth = videoSize.width(),
72 videoHeight = videoSize.height();
73
74 switch(aspectRatio)
75 {
76 case Phonon::VideoWidget::AspectRatioAuto:
77 {
78 //preserve the aspect ratio of the video
79 ratio = qreal(videoWidth) / qreal(videoHeight);
80 }
81 break;
82 case Phonon::VideoWidget::AspectRatio4_3:
83 ratio = qreal(4. / 3.);
84 break;
85 case Phonon::VideoWidget::AspectRatio16_9:
86 ratio = qreal(16. / 9.);
87 break;
88 case Phonon::VideoWidget::AspectRatioWidget:
89 default:
90 break;
91 }
92
93 const qreal realWidth = size.width(),
94 realHeight = size.height();
95
96 //reinitialization
97 m_dstWidth = size.width();
98 m_dstHeight = size.height();
99 m_dstX = m_dstY = 0;
100
101 if (ratio > 0) {
102 if ((realWidth / realHeight > ratio && scaleMode == Phonon::VideoWidget::FitInView)
103 || (realWidth / realHeight < ratio && scaleMode == Phonon::VideoWidget::ScaleAndCrop)) {
104 //the height is correct, let's change the width
105 m_dstWidth = qRound(realHeight * ratio);
106 m_dstX = qRound((realWidth - realHeight * ratio) / 2.);
107 } else {
108 m_dstHeight = qRound(realWidth / ratio);
109 m_dstY = qRound((realHeight - realWidth / ratio) / 2.);
110 }
111 }
112 }
113 }
114}
115
116#endif //QT_NO_PHONON_EFFECT
117
118QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.