|
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 #include "abstractvideorenderer.h" |
|
19 |
|
20 #include <QtGui/QApplication> |
|
21 #include <QtGui/QDesktopWidget> |
|
22 |
|
23 QT_BEGIN_NAMESPACE |
|
24 |
|
25 #ifndef QT_NO_PHONON_VIDEO |
|
26 |
|
27 namespace 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 |
|
118 QT_END_NAMESPACE |