• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • arts
 

arts

  • arts
  • kde
kvideowidget.cpp
1/*
2 This file is part of KDE/aRts (Noatun) - xine integration
3 Copyright (C) 2002 Ewald Snel <ewald@rambo.its.tudelft.nl>
4 Copyright (C) 2002 Neil Stevens <neil@qualityassistant.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License version 2 as published by the Free Software Foundation.
9*/
10
11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15#include <time.h>
16#ifdef HAVE_USLEEP
17#include <unistd.h>
18#endif
19#include <tqaccel.h>
20#include <tqcursor.h>
21
22#if defined TQ_WS_X11 && ! defined K_WS_QTONLY
23#include <X11/Xlib.h>
24#include <X11/Xutil.h>
25#else
26#define XEvent void
27#endif
28
29#include <tdeaction.h>
30#include <tdelocale.h>
31#include "kvideowidget.h"
32
33
34class KFullscreenVideoWidget : public KVideoWidget
35{
36public:
37 KFullscreenVideoWidget( KVideoWidget *parent = 0, const char *name = 0 );
38
39protected:
40 virtual void windowActivationChange( bool );
41 virtual bool x11Event( XEvent *event );
42
43private:
44 KVideoWidget *videoWidget;
45};
46
47KFullscreenVideoWidget::KFullscreenVideoWidget( KVideoWidget *parent, const char *name )
48 : KVideoWidget( 0, name )
49{
50 this->videoWidget = parent;
51 setEraseColor( black );
52 setCursor(TQCursor(TQt::BlankCursor));
53}
54
55void KFullscreenVideoWidget::windowActivationChange( bool )
56{
57 if (!isActiveWindow())
58 {
59 videoWidget->setWindowed();
60 }
61}
62
63bool KFullscreenVideoWidget::x11Event( XEvent *event )
64{
65#if defined TQ_WS_X11 && ! defined K_WS_QTONLY
66 if (event->type == ClientMessage &&
67 event->xclient.message_type ==
68 XInternAtom( tqt_xdisplay(), "VPO_RESIZE_NOTIFY", False ))
69 {
70 videoWidget->resizeNotify( event->xclient.data.l[0], event->xclient.data.l[1] );
71 }
72#endif
73 return false;
74}
75
76KVideoWidget::KVideoWidget( KXMLGUIClient *clientParent, TQWidget *parent, const char *name, WFlags f )
77 : KXMLGUIClient( clientParent ),
78 TQWidget( parent, name, f )
79{
80 init();
81 // ???
82 TQString toolbarName = i18n("Video Toolbar");
83 setXML(TQString("<!DOCTYPE kpartgui>\n<kpartgui name=\"kvideowidget\" version=\"1\"><MenuBar><Menu name=\"edit\"><Separator/><Action name=\"double_size\"/><Action name=\"normal_size\"/><Action name=\"half_size\"/><Separator/><Action name=\"fullscreen_mode\"/></Menu></MenuBar><Toolbar name=\"VideoToolbar\"><text>Video Toolbar</text><Action name=\"fullscreen_mode\"/></Toolbar></kpartgui>"), true);
84}
85
86KVideoWidget::KVideoWidget( TQWidget *parent, const char *name, WFlags f )
87 : TQWidget( parent, name, f )
88{
89 init();
90}
91
92void KVideoWidget::init(void)
93{
94 setMinimumSize(0, 0);
95 setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) );
96 setFocusPolicy( TQWidget::ClickFocus );
97
98 fullscreenWidget = 0;
99 poVideo = Arts::VideoPlayObject::null();
100 videoWidth = 0;
101 videoHeight = 0;
102
103 // Setup actions
104 new TDEToggleAction( i18n("Fullscreen &Mode"), "view-fullscreen",
105 CTRL+SHIFT+Key_F, this, TQ_SLOT(fullscreenActivated()),
106 actionCollection(), "fullscreen_mode" );
107 new TDERadioAction( i18n("&Half Size"), ALT+Key_0,
108 this, TQ_SLOT(halfSizeActivated()),
109 actionCollection(), "half_size" );
110 new TDERadioAction( i18n("&Normal Size"), ALT+Key_1,
111 this, TQ_SLOT(normalSizeActivated()),
112 actionCollection(), "normal_size" );
113 new TDERadioAction( i18n("&Double Size"), ALT+Key_2,
114 this, TQ_SLOT(doubleSizeActivated()),
115 actionCollection(), "double_size" );
116
117 ((TDEToggleAction *)action( "half_size" ))->setExclusiveGroup( "KVideoWidget::zoom" );
118 ((TDEToggleAction *)action( "normal_size" ))->setExclusiveGroup( "KVideoWidget::zoom" );
119 ((TDEToggleAction *)action( "double_size" ))->setExclusiveGroup( "KVideoWidget::zoom" );
120
121 action("double_size")->setEnabled(false);
122 action("half_size")->setEnabled(false);
123 action("normal_size")->setEnabled(false);
124 action("fullscreen_mode")->setEnabled(false);
125}
126
127KVideoWidget::~KVideoWidget()
128{
129 if (isEmbedded())
130 {
131 poVideo.x11WindowId( -1 );
132 poVideo = Arts::VideoPlayObject::null();
133 }
134
135 delete fullscreenWidget;
136}
137
138void KVideoWidget::embed( Arts::VideoPlayObject vpo )
139{
140 bool enable;
141 if (vpo.isNull())
142 {
143 if (isEmbedded())
144 {
145 poVideo.x11WindowId( -1 );
146 poVideo = Arts::VideoPlayObject::null();
147 }
148
149 setBackgroundMode( PaletteBackground );
150 repaint();
151
152 // Resize GUI
153 videoWidth = 0;
154 videoHeight = 0;
155
156 if (isHalfSize() || isNormalSize() || isDoubleSize())
157 emit adaptSize( 0, 0 );
158
159 enable = false;
160 updateGeometry();
161 }
162 else
163 {
164 if (isEmbedded())
165 {
166 poVideo.x11WindowId( -1 );
167 }
168
169 poVideo = vpo;
170
171 // Don't reset fullscreen mode for video playlists
172 if (fullscreenWidget)
173 {
174 poVideo.x11WindowId( fullscreenWidget->winId() );
175 fullscreenWidget->setBackgroundMode( NoBackground );
176
177 setEraseColor( black );
178 }
179 else
180 {
181 poVideo.x11WindowId( winId() );
182 setBackgroundMode( NoBackground );
183 }
184 enable = true;
185 }
186 action("double_size")->setEnabled(enable);
187 action("half_size")->setEnabled(enable);
188 action("normal_size")->setEnabled(enable);
189 action("fullscreen_mode")->setEnabled(enable);
190}
191
192TQImage KVideoWidget::snapshot( Arts::VideoPlayObject vpo )
193{
194#if defined TQ_WS_X11 && ! defined K_WS_QTONLY
195 Window root;
196 Pixmap pixmap;
197 XImage *xImage;
198 unsigned int width, height, border, depth;
199 int x, y;
200
201 if (vpo.isNull() || (long)(pixmap = vpo.x11Snapshot()) == -1)
202 return TQImage();
203
204 // Get 32bit RGBA image data (stored in 1bpp pixmap)
205 XGetGeometry( tqt_xdisplay(), pixmap, &root, &x, &y, &width, &height, &border, &depth );
206
207 xImage = XGetImage( tqt_xdisplay(), pixmap, 0, 0, width, height, 1, XYPixmap );
208
209 if (xImage == 0)
210 {
211 XFreePixmap( tqt_xdisplay(), pixmap );
212 return TQImage();
213 }
214
215 // Convert 32bit RGBA image data into Qt image
216 TQImage qImage = TQImage( (uchar *)xImage->data, width/32, height, 32, (TQRgb *)0, 0, TQImage::IgnoreEndian ).copy();
217
218 // Free X11 resources and return Qt image
219 XDestroyImage( xImage );
220 XFreePixmap( tqt_xdisplay(), pixmap );
221
222 return qImage;
223#else
224 return 0;
225#endif
226}
227
228bool KVideoWidget::isEmbedded()
229{
230 return !poVideo.isNull();
231}
232
233bool KVideoWidget::isFullscreen()
234{
235 return ((TDEToggleAction *)action( "fullscreen_mode" ))->isChecked();
236}
237
238bool KVideoWidget::isHalfSize()
239{
240 return ((TDEToggleAction *)action( "half_size" ))->isChecked();
241}
242
243bool KVideoWidget::isNormalSize()
244{
245 return ((TDEToggleAction *)action( "normal_size" ))->isChecked();
246}
247
248bool KVideoWidget::isDoubleSize()
249{
250 return ((TDEToggleAction *)action( "double_size" ))->isChecked();
251}
252
253void KVideoWidget::setFullscreen()
254{
255 if (!isFullscreen())
256 {
257 ((TDEToggleAction *)action( "fullscreen_mode" ))->setChecked( true );
258 fullscreenActivated();
259 }
260}
261
262void KVideoWidget::setWindowed()
263{
264 if (isFullscreen())
265 {
266 ((TDEToggleAction *)action( "fullscreen_mode" ))->setChecked( false );
267 fullscreenActivated();
268 }
269}
270
271void KVideoWidget::setHalfSize()
272{
273 ((TDEToggleAction *)action( "half_size" ))->setChecked( true );
274 halfSizeActivated();
275}
276
277void KVideoWidget::setNormalSize()
278{
279 ((TDEToggleAction *)action( "normal_size" ))->setChecked( true );
280 normalSizeActivated();
281}
282
283void KVideoWidget::setDoubleSize()
284{
285 ((TDEToggleAction *)action( "double_size" ))->setChecked( true );
286 doubleSizeActivated();
287}
288
289TQSize KVideoWidget::sizeHint() const
290{
291 return TQSize( videoWidth, videoHeight );
292}
293
294int KVideoWidget::heightForWidth( int w ) const
295{
296 if(videoWidth == 0)
297 return 0;
298 else
299 return int( double(w)*double(videoHeight)/double(videoWidth) );
300}
301
302void KVideoWidget::mousePressEvent( TQMouseEvent *event )
303{
304 TQPoint pos = mapToGlobal( event->pos() );
305
306 emit mouseButtonPressed( event->button(), pos, event->state() );
307
308 // ### Remove in KDE4
309 if ( event->button() == TQt::RightButton )
310 emit rightButtonPressed( pos );
311}
312
313void KVideoWidget::mouseDoubleClickEvent( TQMouseEvent *event )
314{
315 emit mouseButtonDoubleClick( mapToGlobal( event->pos() ), event->state() );
316}
317
318void KVideoWidget::resizeEvent( TQResizeEvent *event )
319{
320 TQWidget::resizeEvent( event );
321
322 if (width() > minimumWidth() || height() > minimumHeight())
323 {
324 if (width() == TQMAX( (videoWidth / 2), minimumWidth() ) &&
325 height() == TQMAX( (videoHeight / 2), minimumHeight() ))
326 ((TDEToggleAction *)action( "half_size" ))->setChecked( true );
327 else if (width() == TQMAX( videoWidth, minimumWidth() ) &&
328 height() == TQMAX( videoHeight, minimumHeight() ))
329 ((TDEToggleAction *)action( "normal_size" ))->setChecked( true );
330 else if (width() == TQMAX( (2 * videoWidth), minimumWidth() ) &&
331 height() == TQMAX( (2 * videoHeight), minimumHeight() ))
332 ((TDEToggleAction *)action( "double_size" ))->setChecked( true );
333 else
334 {
335 ((TDEToggleAction *)action( "half_size" ))->setChecked( false );
336 ((TDEToggleAction *)action( "normal_size" ))->setChecked( false );
337 ((TDEToggleAction *)action( "double_size" ))->setChecked( false );
338 }
339 }
340}
341
342void KVideoWidget::resizeNotify( int width, int height )
343{
344 if(!isEmbedded()) return;
345
346 videoWidth = width;
347 videoHeight = height;
348
349 if (isHalfSize())
350 emit adaptSize( (videoWidth / 2), (videoHeight / 2) );
351 else if (isNormalSize())
352 emit adaptSize( videoWidth, videoHeight );
353 else if (isDoubleSize())
354 emit adaptSize( (2 * videoWidth), (2 * videoHeight) );
355
356 updateGeometry();
357}
358
359bool KVideoWidget::x11Event( XEvent *event )
360{
361#if defined TQ_WS_X11 && ! defined K_WS_QTONLY
362 if (event->type == ClientMessage &&
363 event->xclient.message_type ==
364 XInternAtom( tqt_xdisplay(), "VPO_RESIZE_NOTIFY", False ))
365 {
366 resizeNotify( event->xclient.data.l[0], event->xclient.data.l[1] );
367 }
368#endif
369 return false;
370}
371
372void KVideoWidget::fullscreenActivated()
373{
374 if (isFullscreen() == (fullscreenWidget != 0))
375 return;
376
377 if (isFullscreen())
378 {
379 fullscreenWidget = new KFullscreenVideoWidget( this );
380
381 // Interconnect mouse button signals
382 connect( fullscreenWidget, TQ_SIGNAL(mouseButtonPressed( int, const TQPoint &, int )),
383 this, TQ_SIGNAL(mouseButtonPressed( int, const TQPoint &, int)) );
384
385 connect( fullscreenWidget, TQ_SIGNAL(mouseButtonDoubleClick( const TQPoint &, int )),
386 this, TQ_SIGNAL(mouseButtonDoubleClick( const TQPoint &, int )) );
387
388 // ### Remove in KDE4
389 connect( fullscreenWidget, TQ_SIGNAL(rightButtonPressed(const TQPoint &)),
390 this, TQ_SIGNAL(rightButtonPressed(const TQPoint &)) );
391
392 // Leave fullscreen mode with <Escape> key
393 TQAccel *a = new TQAccel( fullscreenWidget );
394 a->connectItem( a->insertItem( Key_Escape ),
395 this, TQ_SLOT(setWindowed()) );
396
397 fullscreenWidget->setFocus();
398 fullscreenWidget->showFullScreen();
399
400 if (isEmbedded())
401 {
402 poVideo.x11WindowId( fullscreenWidget->winId() );
403 fullscreenWidget->setBackgroundMode( NoBackground );
404 }
405 }
406 else
407 {
408 if (isEmbedded())
409 {
410 poVideo.x11WindowId( winId() );
411 setBackgroundMode( NoBackground );
412 }
413
414 delete fullscreenWidget;
415 fullscreenWidget = 0;
416 }
417}
418
419void KVideoWidget::halfSizeActivated()
420{
421 if (isHalfSize())
422 {
423 if(isEmbedded()) emit adaptSize( (videoWidth / 2), (videoHeight / 2) );
424 setWindowed();
425 }
426}
427
428void KVideoWidget::normalSizeActivated()
429{
430 if (isNormalSize())
431 {
432 if(isEmbedded()) emit adaptSize( videoWidth, videoHeight );
433 setWindowed();
434 }
435}
436
437void KVideoWidget::doubleSizeActivated()
438{
439 if (isDoubleSize())
440 {
441 if(isEmbedded()) emit adaptSize( (2 * videoWidth), (2 * videoHeight) );
442 setWindowed();
443 }
444}
445
446#include "kvideowidget.moc"
KXMLGUIClient
TDERadioAction
TDEToggleAction
KNotifyClient::event
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED
TDEStdAccel::name
TQString name(StdAccel id)
TDEStdAccel::action
TQString action(StdAccel id)
tdelocale.h

arts

Skip menu "arts"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

arts

Skip menu "arts"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for arts by doxygen 1.9.4
This website is maintained by Timothy Pearson.