]> git.sesse.net Git - vlc/blob - bindings/phonon/vlc/videowidget.cpp
Phonon: synchronise with KDE HEAD, part 1
[vlc] / bindings / phonon / vlc / videowidget.cpp
1 /*****************************************************************************
2  * VLC backend for the Phonon library                                        *
3  * Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com>               *
4  * Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com>                *
5  * Copyright (C) 2009 Fathi Boudra <fabo@kde.org>                            *
6  *                                                                           *
7  * This program is free software; you can redistribute it and/or             *
8  * modify it under the terms of the GNU Lesser General Public                *
9  * License as published by the Free Software Foundation; either              *
10  * version 3 of the License, or (at your option) any later version.          *
11  *                                                                           *
12  * This program is distributed in the hope that it will be useful,           *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
15  * Lesser General Public License for more details.                           *
16  *                                                                           *
17  * You should have received a copy of the GNU Lesser General Public          *
18  * License along with this package; if not, write to the Free Software       *
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA *
20  *****************************************************************************/
21
22 #include "videowidget.h"
23
24 #include "mediaobject.h"
25 #include "vlcmediaobject.h"
26
27 #include "vlcloader.h"
28
29 #include <QtGui/QWidget>
30 #include <QtGui/QApplication>
31 #include <QtGui/QDesktopWidget>
32 #include <QtCore/QtDebug>
33
34 namespace Phonon
35 {
36 namespace VLC {
37
38 VideoWidget::VideoWidget(QWidget *p_parent)
39         : SinkNode(p_parent)
40 {
41     p_video_widget = new Widget(p_parent);
42
43     aspect_ratio = Phonon::VideoWidget::AspectRatioAuto;
44     scale_mode = Phonon::VideoWidget::FitInView;
45
46     b_filter_adjust_activated = false;
47     f_brightness = 0.0;
48     f_contrast = 0.0;
49     f_hue = 0.0;
50     f_saturation = 0.0;
51 }
52
53 VideoWidget::~VideoWidget()
54 {
55 }
56
57 void VideoWidget::connectToMediaObject(PrivateMediaObject *mediaObject)
58 {
59     SinkNode::connectToMediaObject(mediaObject);
60
61     connect(mediaObject, SIGNAL(videoWidgetSizeChanged(int, int)),
62             SLOT(videoWidgetSizeChanged(int, int)));
63
64     mediaObject->setVideoWidgetId(p_video_widget->winId());
65 }
66
67 Phonon::VideoWidget::AspectRatio VideoWidget::aspectRatio() const
68 {
69     return aspect_ratio;
70 }
71
72 // VLC accepted formats are x:y (4:3, 16:9, etc...) expressing the global image aspect
73 void VideoWidget::setAspectRatio(Phonon::VideoWidget::AspectRatio aspect)
74 {
75     // finish if no player
76     if (!vlc_current_media_player)
77         return;
78
79     aspect_ratio = aspect;
80
81     switch (aspect_ratio) {
82     case Phonon::VideoWidget::AspectRatioAuto: // Let the decoder find the aspect ratio automatically from the media file (this is the default)
83 //        p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "", vlc_exception);
84         vlcExceptionRaised();
85         break;
86     case Phonon::VideoWidget::AspectRatioWidget: // Fit the video into the widget making the aspect ratio depend solely on the size of the widget
87         // This way the aspect ratio is freely resizeable by the user
88 //        p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "", vlc_exception);
89         vlcExceptionRaised();
90         break;
91     case Phonon::VideoWidget::AspectRatio4_3:
92 //        p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "4:3", vlc_exception);
93         vlcExceptionRaised();
94         break;
95     case Phonon::VideoWidget::AspectRatio16_9:
96 //        p_libvlc_video_set_aspect_ratio(p_vlc_current_media_player, "16:9", vlc_exception);
97         vlcExceptionRaised();
98         break;
99     default:
100         qCritical() << __FUNCTION__ << "error: unsupported AspectRatio:" << (int) aspect_ratio;
101     }
102 }
103
104 Phonon::VideoWidget::ScaleMode VideoWidget::scaleMode() const
105 {
106     return scale_mode;
107 }
108
109 // The ScaleMode enumeration describes how to treat aspect ratio during resizing of video
110 void VideoWidget::setScaleMode(Phonon::VideoWidget::ScaleMode scale)
111 {
112     scale_mode = scale;
113     switch (scale_mode) {
114     case Phonon::VideoWidget::FitInView: // The video will be fitted to fill the view keeping aspect ratio
115         break;
116     case Phonon::VideoWidget::ScaleAndCrop: // The video is scaled
117         break;
118     default:
119         qWarning() << __FUNCTION__ << "unknow Phonon::VideoWidget::ScaleMode:" << scale_mode;
120     }
121 }
122
123 qreal VideoWidget::brightness() const
124 {
125     return f_brightness;
126 }
127
128 void VideoWidget::setBrightness(qreal brightness)
129 {
130     f_brightness = brightness;
131
132     // vlc takes brightness in range 0.0 - 2.0
133     if (vlc_current_media_player) {
134         if (!b_filter_adjust_activated) {
135 //            p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
136 //            vlcExceptionRaised();
137             b_filter_adjust_activated = true;
138         }
139 //        p_libvlc_video_set_brightness(p_vlc_current_media_player, f_brightness + 1.0, vlc_exception);
140 //        vlcExceptionRaised();
141     }
142 }
143
144 qreal VideoWidget::contrast() const
145 {
146     return f_contrast;
147 }
148
149 void VideoWidget::setContrast(qreal contrast)
150 {
151     f_contrast = contrast;
152
153     // vlc takes contrast in range 0.0 - 2.0
154     float f_contrast = contrast;
155     if (vlc_current_media_player) {
156         if (!b_filter_adjust_activated) {
157 //            p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
158 //            vlcExceptionRaised();
159             b_filter_adjust_activated = true;
160         }
161 //        p_libvlc_video_set_contrast(p_vlc_current_media_player, f_contrast + 1.0, vlc_exception);
162 //        vlcExceptionRaised();
163     }
164 }
165
166 qreal VideoWidget::hue() const
167 {
168     return f_hue;
169 }
170
171 void VideoWidget::setHue(qreal hue)
172 {
173     f_hue = hue;
174
175     // vlc takes hue in range 0 - 360 in integer
176     int i_hue = (f_hue + 1.0) * 180;
177     if (vlc_current_media_player) {
178         if (!b_filter_adjust_activated) {
179 //            p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
180 //            vlcExceptionRaised();
181             b_filter_adjust_activated = true;
182         }
183 //        p_libvlc_video_set_hue(p_vlc_current_media_player, i_hue, vlc_exception);
184 //        vlcExceptionRaised();
185     }
186
187 }
188
189 qreal VideoWidget::saturation() const
190 {
191     return f_saturation;
192 }
193
194 void VideoWidget::setSaturation(qreal saturation)
195 {
196     f_saturation = saturation;
197
198     // vlc takes brightness in range 0.0 - 3.0
199     if (vlc_current_media_player) {
200         if (!b_filter_adjust_activated) {
201 //            p_libvlc_video_filter_add(p_vlc_current_media_player, ADJUST, vlc_exception);
202 //            vlcExceptionRaised();
203             b_filter_adjust_activated = true;
204         }
205 //        p_libvlc_video_set_saturation(p_vlc_current_media_player, (f_saturation + 1.0) * 1.5, vlc_exception);
206 //        vlcExceptionRaised();
207     }
208 }
209
210 Widget * VideoWidget::widget()
211 {
212     return p_video_widget;
213 }
214
215 void VideoWidget::videoWidgetSizeChanged(int i_width, int i_height)
216 {
217     qDebug() << __FUNCTION__ << "video width" << i_width << "height:" << i_height;
218
219     // It resizes dynamically the widget and the main window
220     // Note: I didn't find another way
221
222     QSize videoSize(i_width, i_height);
223     videoSize.boundedTo(QApplication::desktop()->availableGeometry().size());
224
225     p_video_widget->hide();
226     p_video_widget->setVideoSize(videoSize);
227 #ifdef Q_OS_WIN
228     QWidget *p_parent = qobject_cast<QWidget *>(this->parent());
229     QSize previousSize = p_parent->minimumSize();
230     p_parent->setMinimumSize(videoSize);
231 #endif
232     p_video_widget->show();
233 #ifdef Q_OS_WIN
234     p_parent->setMinimumSize(previousSize);
235 #endif
236 }
237
238 }
239 } // Namespace Phonon::VLC