22 #if defined TQ_WS_X11 && ! defined K_WS_QTONLY
24 #include <X11/Xutil.h>
29 #include <tdeaction.h>
31 #include "kvideowidget.h"
34 class KFullscreenVideoWidget :
public KVideoWidget
37 KFullscreenVideoWidget( KVideoWidget *parent = 0,
const char *name = 0 );
40 virtual void windowActivationChange(
bool );
41 virtual bool x11Event( XEvent *event );
44 KVideoWidget *videoWidget;
47 KFullscreenVideoWidget::KFullscreenVideoWidget( KVideoWidget *parent,
const char *name )
48 : KVideoWidget( 0,
name )
50 this->videoWidget = parent;
51 setEraseColor( black );
52 setCursor(TQCursor(TQt::BlankCursor));
55 void KFullscreenVideoWidget::windowActivationChange(
bool )
57 if (!isActiveWindow())
59 videoWidget->setWindowed();
63 bool KFullscreenVideoWidget::x11Event( XEvent *event )
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 ))
70 videoWidget->resizeNotify(
event->xclient.data.l[0],
event->xclient.data.l[1] );
76 KVideoWidget::KVideoWidget(
KXMLGUIClient *clientParent, TQWidget *parent,
const char *name, WFlags f )
78 TQWidget( parent,
name, f )
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);
86 KVideoWidget::KVideoWidget( TQWidget *parent,
const char *name, WFlags f )
87 : TQWidget( parent,
name, f )
92 void KVideoWidget::init(
void)
95 setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) );
96 setFocusPolicy( TQWidget::ClickFocus );
99 poVideo = Arts::VideoPlayObject::null();
105 CTRL+SHIFT+Key_F,
this, TQ_SLOT(fullscreenActivated()),
106 actionCollection(),
"fullscreen_mode" );
108 this, TQ_SLOT(halfSizeActivated()),
109 actionCollection(),
"half_size" );
111 this, TQ_SLOT(normalSizeActivated()),
112 actionCollection(),
"normal_size" );
114 this, TQ_SLOT(doubleSizeActivated()),
115 actionCollection(),
"double_size" );
121 action(
"double_size")->setEnabled(
false);
122 action(
"half_size")->setEnabled(
false);
123 action(
"normal_size")->setEnabled(
false);
124 action(
"fullscreen_mode")->setEnabled(
false);
127 KVideoWidget::~KVideoWidget()
131 poVideo.x11WindowId( -1 );
132 poVideo = Arts::VideoPlayObject::null();
135 delete fullscreenWidget;
138 void KVideoWidget::embed( Arts::VideoPlayObject vpo )
145 poVideo.x11WindowId( -1 );
146 poVideo = Arts::VideoPlayObject::null();
149 setBackgroundMode( PaletteBackground );
156 if (isHalfSize() || isNormalSize() || isDoubleSize())
157 emit adaptSize( 0, 0 );
166 poVideo.x11WindowId( -1 );
172 if (fullscreenWidget)
174 poVideo.x11WindowId( fullscreenWidget->winId() );
175 fullscreenWidget->setBackgroundMode( NoBackground );
177 setEraseColor( black );
181 poVideo.x11WindowId( winId() );
182 setBackgroundMode( NoBackground );
186 action(
"double_size")->setEnabled(enable);
187 action(
"half_size")->setEnabled(enable);
188 action(
"normal_size")->setEnabled(enable);
189 action(
"fullscreen_mode")->setEnabled(enable);
192 TQImage KVideoWidget::snapshot( Arts::VideoPlayObject vpo )
194 #if defined TQ_WS_X11 && ! defined K_WS_QTONLY
198 unsigned int width, height, border, depth;
201 if (vpo.isNull() || (
long)(pixmap = vpo.x11Snapshot()) == -1)
205 XGetGeometry( tqt_xdisplay(), pixmap, &root, &x, &y, &width, &height, &border, &depth );
207 xImage = XGetImage( tqt_xdisplay(), pixmap, 0, 0, width, height, 1, XYPixmap );
211 XFreePixmap( tqt_xdisplay(), pixmap );
216 TQImage qImage = TQImage( (uchar *)xImage->data, width/32, height, 32, (TQRgb *)0, 0, TQImage::IgnoreEndian ).copy();
219 XDestroyImage( xImage );
220 XFreePixmap( tqt_xdisplay(), pixmap );
228 bool KVideoWidget::isEmbedded()
230 return !poVideo.isNull();
233 bool KVideoWidget::isFullscreen()
238 bool KVideoWidget::isHalfSize()
243 bool KVideoWidget::isNormalSize()
248 bool KVideoWidget::isDoubleSize()
253 void KVideoWidget::setFullscreen()
258 fullscreenActivated();
262 void KVideoWidget::setWindowed()
267 fullscreenActivated();
271 void KVideoWidget::setHalfSize()
277 void KVideoWidget::setNormalSize()
280 normalSizeActivated();
283 void KVideoWidget::setDoubleSize()
286 doubleSizeActivated();
289 TQSize KVideoWidget::sizeHint()
const
291 return TQSize( videoWidth, videoHeight );
294 int KVideoWidget::heightForWidth(
int w )
const
299 return int(
double(w)*
double(videoHeight)/
double(videoWidth) );
302 void KVideoWidget::mousePressEvent( TQMouseEvent *event )
304 TQPoint pos = mapToGlobal(
event->pos() );
306 emit mouseButtonPressed(
event->button(), pos,
event->state() );
309 if (
event->button() == TQt::RightButton )
310 emit rightButtonPressed( pos );
313 void KVideoWidget::mouseDoubleClickEvent( TQMouseEvent *event )
315 emit mouseButtonDoubleClick( mapToGlobal(
event->pos() ),
event->state() );
318 void KVideoWidget::resizeEvent( TQResizeEvent *event )
320 TQWidget::resizeEvent( event );
322 if (width() > minimumWidth() || height() > minimumHeight())
324 if (width() == TQMAX( (videoWidth / 2), minimumWidth() ) &&
325 height() == TQMAX( (videoHeight / 2), minimumHeight() ))
327 else if (width() == TQMAX( videoWidth, minimumWidth() ) &&
328 height() == TQMAX( videoHeight, minimumHeight() ))
330 else if (width() == TQMAX( (2 * videoWidth), minimumWidth() ) &&
331 height() == TQMAX( (2 * videoHeight), minimumHeight() ))
342 void KVideoWidget::resizeNotify(
int width,
int height )
344 if(!isEmbedded())
return;
347 videoHeight = height;
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) );
359 bool KVideoWidget::x11Event( XEvent *event )
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 ))
366 resizeNotify(
event->xclient.data.l[0],
event->xclient.data.l[1] );
372 void KVideoWidget::fullscreenActivated()
374 if (isFullscreen() == (fullscreenWidget != 0))
379 fullscreenWidget =
new KFullscreenVideoWidget(
this );
382 connect( fullscreenWidget, TQ_SIGNAL(mouseButtonPressed(
int,
const TQPoint &,
int )),
383 this, TQ_SIGNAL(mouseButtonPressed(
int,
const TQPoint &,
int)) );
385 connect( fullscreenWidget, TQ_SIGNAL(mouseButtonDoubleClick(
const TQPoint &,
int )),
386 this, TQ_SIGNAL(mouseButtonDoubleClick(
const TQPoint &,
int )) );
389 connect( fullscreenWidget, TQ_SIGNAL(rightButtonPressed(
const TQPoint &)),
390 this, TQ_SIGNAL(rightButtonPressed(
const TQPoint &)) );
393 TQAccel *a =
new TQAccel( fullscreenWidget );
394 a->connectItem( a->insertItem( Key_Escape ),
395 this, TQ_SLOT(setWindowed()) );
397 fullscreenWidget->setFocus();
398 fullscreenWidget->showFullScreen();
402 poVideo.x11WindowId( fullscreenWidget->winId() );
403 fullscreenWidget->setBackgroundMode( NoBackground );
410 poVideo.x11WindowId( winId() );
411 setBackgroundMode( NoBackground );
414 delete fullscreenWidget;
415 fullscreenWidget = 0;
419 void KVideoWidget::halfSizeActivated()
423 if(isEmbedded()) emit adaptSize( (videoWidth / 2), (videoHeight / 2) );
428 void KVideoWidget::normalSizeActivated()
432 if(isEmbedded()) emit adaptSize( videoWidth, videoHeight );
437 void KVideoWidget::doubleSizeActivated()
441 if(isEmbedded()) emit adaptSize( (2 * videoWidth), (2 * videoHeight) );
446 #include "kvideowidget.moc"
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED
TQString name(StdAccel id)
TQString action(StdAccel id)