1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program 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 General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include "mplayerwindow.h"
21
#include "desktopinfo.h"
36
Screen::Screen(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f )
38
setMouseTracking(TRUE);
39
setFocusPolicy( Qt::NoFocus );
40
setMinimumSize( QSize(0,0) );
42
cursor_pos = QPoint(0,0);
43
last_cursor_pos = QPoint(0,0);
45
QTimer *timer = new QTimer(this);
46
connect( timer, SIGNAL(timeout()), this, SLOT(checkMousePos()) );
50
setAttribute(Qt::WA_NoSystemBackground);
51
//setAttribute(Qt::WA_StaticContents);
52
//setAttribute( Qt::WA_OpaquePaintEvent );
53
setAttribute(Qt::WA_PaintOnScreen);
54
setAttribute(Qt::WA_PaintUnclipped);
55
//setAttribute(Qt::WA_PaintOutsidePaintEvent);
61
void Screen::paintEvent( QPaintEvent * e ) {
62
//qDebug("Screen::paintEvent");
63
QPainter painter(this);
64
painter.eraseRect( e->rect() );
65
//painter.fillRect( e->rect(), QColor(255,0,0) );
69
void Screen::checkMousePos() {
70
//qDebug("Screen::checkMousePos");
72
if ( cursor_pos == last_cursor_pos ) {
73
//qDebug(" same pos");
74
if (cursor().shape() != Qt::BlankCursor) {
75
//qDebug(" hiding mouse cursor");
76
setCursor(QCursor(Qt::BlankCursor));
79
last_cursor_pos = cursor_pos;
83
void Screen::mouseMoveEvent( QMouseEvent * e ) {
84
//qDebug("Screen::mouseMoveEvent");
85
//qDebug(" pos: x: %d y: %d", e->pos().x(), e->pos().y() );
86
cursor_pos = e->pos();
88
if (cursor().shape() != Qt::ArrowCursor) {
89
//qDebug(" showing mouse cursor" );
90
setCursor(QCursor(Qt::ArrowCursor));
94
/* ---------------------------------------------------------------------- */
96
MplayerLayer::MplayerLayer(QWidget* parent, Qt::WindowFlags f)
99
allow_clearing = true;
103
MplayerLayer::~MplayerLayer() {
106
void MplayerLayer::allowClearingBackground(bool b) {
107
qDebug("MplayerLayer::allowClearingBackground: %d", b);
111
void MplayerLayer::paintEvent( QPaintEvent * e ) {
112
//qDebug("MplayerLayer::paintEvent: allow_clearing: %d", allow_clearing);
113
if (allow_clearing || !playing) {
114
//qDebug("MplayerLayer::paintEvent: painting");
115
Screen::paintEvent(e);
119
void MplayerLayer::playingStarted() {
120
qDebug("MplayerLayer::playingStarted");
125
void MplayerLayer::playingStopped() {
126
qDebug("MplayerLayer::playingStopped");
131
/* ---------------------------------------------------------------------- */
133
MplayerWindow::MplayerWindow(QWidget* parent, Qt::WindowFlags f)
134
: Screen(parent, f) , allow_video_movement(false)
140
setAutoFillBackground(true);
141
Helper::setBackgroundColor( this, QColor(0,0,0) );
143
mplayerlayer = new MplayerLayer( this );
144
mplayerlayer->setAutoFillBackground(TRUE);
146
logo = new QLabel( mplayerlayer );
147
logo->setAutoFillBackground(TRUE);
148
logo->setAttribute(Qt::WA_PaintOnScreen); // Otherwise the logo is not visible in Qt 4.4
149
Helper::setBackgroundColor( logo, QColor(0,0,0) );
151
QVBoxLayout * mplayerlayerLayout = new QVBoxLayout( mplayerlayer );
152
mplayerlayerLayout->addWidget( logo, 0, Qt::AlignHCenter | Qt::AlignVCenter );
154
aspect = (double) 4 / 3;
157
setSizePolicy( QSizePolicy::Expanding , QSizePolicy::Expanding );
158
setFocusPolicy( Qt::StrongFocus );
160
installEventFilter(this);
161
mplayerlayer->installEventFilter(this);
162
//logo->installEventFilter(this);
164
retranslateStrings();
167
MplayerWindow::~MplayerWindow() {
171
void MplayerWindow::setColorKey( QColor c ) {
172
Helper::setBackgroundColor( mplayerlayer, c );
176
void MplayerWindow::retranslateStrings() {
177
//qDebug("MplayerWindow::retranslateStrings");
179
logo->setPixmap( Images::icon("background") );
183
void MplayerWindow::showLogo( bool b)
185
if (b) logo->show(); else logo->hide();
189
void MplayerWindow::changePolicy() {
190
setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Preferred );
194
void MplayerWindow::setResolution( int w, int h)
199
//mplayerlayer->move(1,1);
204
void MplayerWindow::resizeEvent( QResizeEvent * /* e */)
206
/*qDebug("MplayerWindow::resizeEvent: %d, %d",
207
e->size().width(), e->size().height() );*/
213
setZoom(zoom_factor);
217
void MplayerWindow::setMonitorAspect(double asp) {
221
void MplayerWindow::setAspect( double asp) {
223
if (monitoraspect!=0) {
224
aspect = aspect / monitoraspect * DesktopInfo::desktop_aspectRatio(this);
230
void MplayerWindow::updateVideoWindow()
233
mplayerlayer->resize(size());
237
//qDebug("MplayerWindow::updateVideoWindow");
239
//qDebug("aspect= %f", aspect);
241
int w_width = size().width();
242
int w_height = size().height();
244
int pos1_w = w_width;
245
int pos1_h = w_width / aspect + 0.5;
247
int pos2_h = w_height;
248
int pos2_w = w_height * aspect + 0.5;
250
//qDebug("pos1_w: %d, pos1_h: %d", pos1_w, pos1_h);
251
//qDebug("pos2_w: %d, pos2_h: %d", pos2_w, pos2_h);
257
if (pos1_h <= w_height) {
262
y = (w_height - h) /2;
268
x = (w_width - w) /2;
271
mplayerlayer->move(x,y);
272
mplayerlayer->resize(w, h);
279
//qDebug( "w_width: %d, w_height: %d", w_width, w_height);
280
//qDebug("w: %d, h: %d", w,h);
284
void MplayerWindow::mouseReleaseEvent( QMouseEvent * e) {
285
qDebug( "MplayerWindow::mouseReleaseEvent" );
287
if (e->button() == Qt::LeftButton) {
292
if (e->button() == Qt::MidButton) {
294
emit middleClicked();
297
if (e->button() == Qt::XButton1) {
299
emit xbutton1Clicked();
302
if (e->button() == Qt::XButton2) {
304
emit xbutton2Clicked();
307
if (e->button() == Qt::RightButton) {
309
//emit rightButtonReleased( e->globalPos() );
317
void MplayerWindow::mouseDoubleClickEvent( QMouseEvent * e ) {
318
if (e->button() == Qt::LeftButton) {
320
emit doubleClicked();
326
void MplayerWindow::wheelEvent( QWheelEvent * e ) {
327
qDebug("MplayerWindow::wheelEvent: delta: %d", e->delta());
330
if (e->orientation() == Qt::Vertical) {
336
qDebug("MplayerWindow::wheelEvent: horizontal event received, doing nothing");
340
bool MplayerWindow::eventFilter( QObject * /*watched*/, QEvent * event ) {
341
//qDebug("MplayerWindow::eventFilter");
343
if ( (event->type() == QEvent::MouseMove) ||
344
(event->type() == QEvent::MouseButtonRelease) )
346
QMouseEvent *mouse_event = static_cast<QMouseEvent *>(event);
347
mouse_position = mouse_event->pos();
348
//qDebug("pos: %d %d", mouse_position.x(), mouse_position.y());
350
if (event->type() == QEvent::MouseMove) {
351
emit mouseMoved(mouse_event->pos());
358
QSize MplayerWindow::sizeHint() const {
359
//qDebug("MplayerWindow::sizeHint");
360
return QSize( video_width, video_height );
363
QSize MplayerWindow::minimumSizeHint () const {
367
void MplayerWindow::setOffsetX( int d) {
369
mplayerlayer->move( orig_x + offset_x, mplayerlayer->y() );
372
int MplayerWindow::offsetX() { return offset_x; }
374
void MplayerWindow::setOffsetY( int d) {
376
mplayerlayer->move( mplayerlayer->x(), orig_y + offset_y );
379
int MplayerWindow::offsetY() { return offset_y; }
381
void MplayerWindow::setZoom( double d) {
391
if (zoom_factor != 1.0) {
396
x = (width() - w) / 2;
397
y = (height() -h) / 2;
400
mplayerlayer->move(x,y);
401
mplayerlayer->resize(w,h);
404
double MplayerWindow::zoom() { return zoom_factor; }
406
void MplayerWindow::moveLayer( int offset_x, int offset_y ) {
407
int x = mplayerlayer->x();
408
int y = mplayerlayer->y();
410
mplayerlayer->move( x + offset_x, y + offset_y );
413
void MplayerWindow::moveLeft() {
414
if ((allow_video_movement) || (mplayerlayer->x()+mplayerlayer->width() > width() ))
418
void MplayerWindow::moveRight() {
419
if ((allow_video_movement) || ( mplayerlayer->x() < 0 ))
423
void MplayerWindow::moveUp() {
424
if ((allow_video_movement) || (mplayerlayer->y()+mplayerlayer->height() > height() ))
428
void MplayerWindow::moveDown() {
429
if ((allow_video_movement) || ( mplayerlayer->y() < 0 ))
433
void MplayerWindow::incZoom() {
434
setZoom( zoom_factor + ZOOM_STEP );
437
void MplayerWindow::decZoom() {
438
double zoom = zoom_factor - ZOOM_STEP;
439
if (zoom < ZOOM_MIN) zoom = ZOOM_MIN;
443
// Language change stuff
444
void MplayerWindow::changeEvent(QEvent *e) {
445
if (e->type() == QEvent::LanguageChange) {
446
retranslateStrings();
448
QWidget::changeEvent(e);
452
#include "moc_mplayerwindow.cpp"