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"
22
#include "colorutils.h"
40
Screen::Screen(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f )
42
setMouseTracking(TRUE);
43
setFocusPolicy( Qt::NoFocus );
44
setMinimumSize( QSize(0,0) );
46
#if NEW_MOUSE_CHECK_POS
47
mouse_last_position = QPoint(0,0);
49
cursor_pos = QPoint(0,0);
50
last_cursor_pos = QPoint(0,0);
53
QTimer *timer = new QTimer(this);
54
connect( timer, SIGNAL(timeout()), this, SLOT(checkMousePos()) );
55
#if NEW_MOUSE_CHECK_POS
62
setAttribute(Qt::WA_NoSystemBackground);
63
//setAttribute(Qt::WA_StaticContents);
64
//setAttribute( Qt::WA_OpaquePaintEvent );
65
setAttribute(Qt::WA_PaintOnScreen);
66
setAttribute(Qt::WA_PaintUnclipped);
67
//setAttribute(Qt::WA_PaintOutsidePaintEvent);
73
void Screen::paintEvent( QPaintEvent * e ) {
74
//qDebug("Screen::paintEvent");
75
QPainter painter(this);
76
painter.eraseRect( e->rect() );
77
//painter.fillRect( e->rect(), QColor(255,0,0) );
80
#if NEW_MOUSE_CHECK_POS
81
void Screen::checkMousePos() {
82
//qDebug("Screen::checkMousePos");
83
QPoint pos = mapFromGlobal(QCursor::pos());
85
if (mouse_last_position != pos) {
86
setCursor(QCursor(Qt::ArrowCursor));
88
setCursor(QCursor(Qt::BlankCursor));
90
mouse_last_position = pos;
93
void Screen::checkMousePos() {
94
//qDebug("Screen::checkMousePos");
96
if ( cursor_pos == last_cursor_pos ) {
97
//qDebug(" same pos");
98
if (cursor().shape() != Qt::BlankCursor) {
99
//qDebug(" hiding mouse cursor");
100
setCursor(QCursor(Qt::BlankCursor));
103
last_cursor_pos = cursor_pos;
107
void Screen::mouseMoveEvent( QMouseEvent * e ) {
108
//qDebug("Screen::mouseMoveEvent");
109
//qDebug(" pos: x: %d y: %d", e->pos().x(), e->pos().y() );
110
cursor_pos = e->pos();
112
if (cursor().shape() != Qt::ArrowCursor) {
113
//qDebug(" showing mouse cursor" );
114
setCursor(QCursor(Qt::ArrowCursor));
119
/* ---------------------------------------------------------------------- */
121
MplayerLayer::MplayerLayer(QWidget* parent, Qt::WindowFlags f)
124
#if REPAINT_BACKGROUND_OPTION
125
repaint_background = true;
130
MplayerLayer::~MplayerLayer() {
133
#if REPAINT_BACKGROUND_OPTION
134
void MplayerLayer::setRepaintBackground(bool b) {
135
qDebug("MplayerLayer::setRepaintBackground: %d", b);
136
repaint_background = b;
139
void MplayerLayer::paintEvent( QPaintEvent * e ) {
140
//qDebug("MplayerLayer::paintEvent: allow_clearing: %d", allow_clearing);
141
if (repaint_background || !playing) {
142
//qDebug("MplayerLayer::paintEvent: painting");
143
Screen::paintEvent(e);
148
void MplayerLayer::playingStarted() {
149
qDebug("MplayerLayer::playingStarted");
154
void MplayerLayer::playingStopped() {
155
qDebug("MplayerLayer::playingStopped");
160
/* ---------------------------------------------------------------------- */
162
MplayerWindow::MplayerWindow(QWidget* parent, Qt::WindowFlags f)
163
: Screen(parent, f) , allow_video_movement(false)
169
setAutoFillBackground(true);
170
ColorUtils::setBackgroundColor( this, QColor(0,0,0) );
172
mplayerlayer = new MplayerLayer( this );
173
mplayerlayer->setAutoFillBackground(TRUE);
175
logo = new QLabel( mplayerlayer );
176
logo->setAutoFillBackground(TRUE);
177
#if QT_VERSION >= 0x040400
178
logo->setAttribute(Qt::WA_NativeWindow); // Otherwise the logo is not visible in Qt 4.4
180
logo->setAttribute(Qt::WA_PaintOnScreen); // Fixes the problem if compiled with Qt < 4.4
182
ColorUtils::setBackgroundColor( logo, QColor(0,0,0) );
184
QVBoxLayout * mplayerlayerLayout = new QVBoxLayout( mplayerlayer );
185
mplayerlayerLayout->addWidget( logo, 0, Qt::AlignHCenter | Qt::AlignVCenter );
187
aspect = (double) 4 / 3;
190
setSizePolicy( QSizePolicy::Expanding , QSizePolicy::Expanding );
191
setFocusPolicy( Qt::StrongFocus );
193
installEventFilter(this);
194
mplayerlayer->installEventFilter(this);
195
//logo->installEventFilter(this);
198
resize_timer = new QTimer(this);
199
resize_timer->setSingleShot(true);
200
resize_timer->setInterval(50);
201
connect( resize_timer, SIGNAL(timeout()), this, SLOT(resizeLater()) );
204
retranslateStrings();
207
MplayerWindow::~MplayerWindow() {
211
void MplayerWindow::setColorKey( QColor c ) {
212
ColorUtils::setBackgroundColor( mplayerlayer, c );
216
void MplayerWindow::retranslateStrings() {
217
//qDebug("MplayerWindow::retranslateStrings");
219
logo->setPixmap( Images::icon("background") );
223
void MplayerWindow::showLogo( bool b)
225
if (b) logo->show(); else logo->hide();
229
void MplayerWindow::changePolicy() {
230
setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Preferred );
234
void MplayerWindow::setResolution( int w, int h)
239
//mplayerlayer->move(1,1);
244
void MplayerWindow::resizeEvent( QResizeEvent * /* e */)
246
/*qDebug("MplayerWindow::resizeEvent: %d, %d",
247
e->size().width(), e->size().height() );*/
254
setZoom(zoom_factor);
256
resize_timer->start();
261
void MplayerWindow::resizeLater() {
266
setZoom(zoom_factor);
270
void MplayerWindow::setMonitorAspect(double asp) {
274
void MplayerWindow::setAspect( double asp) {
276
if (monitoraspect!=0) {
277
aspect = aspect / monitoraspect * DesktopInfo::desktop_aspectRatio(this);
283
void MplayerWindow::updateVideoWindow()
285
//qDebug("MplayerWindow::updateVideoWindow");
287
//qDebug("aspect= %f", aspect);
289
int w_width = size().width();
290
int w_height = size().height();
298
int pos1_w = w_width;
299
int pos1_h = w_width / aspect + 0.5;
301
int pos2_h = w_height;
302
int pos2_w = w_height * aspect + 0.5;
304
//qDebug("pos1_w: %d, pos1_h: %d", pos1_w, pos1_h);
305
//qDebug("pos2_w: %d, pos2_h: %d", pos2_w, pos2_h);
307
if (pos1_h <= w_height) {
312
y = (w_height - h) /2;
318
x = (w_width - w) /2;
322
mplayerlayer->move(x,y);
323
mplayerlayer->resize(w, h);
330
//qDebug( "w_width: %d, w_height: %d", w_width, w_height);
331
//qDebug("w: %d, h: %d", w,h);
335
void MplayerWindow::mouseReleaseEvent( QMouseEvent * e) {
336
qDebug( "MplayerWindow::mouseReleaseEvent" );
338
if (e->button() == Qt::LeftButton) {
343
if (e->button() == Qt::MidButton) {
345
emit middleClicked();
348
if (e->button() == Qt::XButton1) {
350
emit xbutton1Clicked();
353
if (e->button() == Qt::XButton2) {
355
emit xbutton2Clicked();
358
if (e->button() == Qt::RightButton) {
360
//emit rightButtonReleased( e->globalPos() );
368
void MplayerWindow::mouseDoubleClickEvent( QMouseEvent * e ) {
369
if (e->button() == Qt::LeftButton) {
371
emit doubleClicked();
377
void MplayerWindow::wheelEvent( QWheelEvent * e ) {
378
qDebug("MplayerWindow::wheelEvent: delta: %d", e->delta());
381
if (e->orientation() == Qt::Vertical) {
387
qDebug("MplayerWindow::wheelEvent: horizontal event received, doing nothing");
391
bool MplayerWindow::eventFilter( QObject * /*watched*/, QEvent * event ) {
392
//qDebug("MplayerWindow::eventFilter");
394
if ( (event->type() == QEvent::MouseMove) ||
395
(event->type() == QEvent::MouseButtonRelease) )
397
QMouseEvent *mouse_event = static_cast<QMouseEvent *>(event);
399
if (event->type() == QEvent::MouseMove) {
400
emit mouseMoved(mouse_event->pos());
407
QSize MplayerWindow::sizeHint() const {
408
//qDebug("MplayerWindow::sizeHint");
409
return QSize( video_width, video_height );
412
QSize MplayerWindow::minimumSizeHint () const {
416
void MplayerWindow::setOffsetX( int d) {
418
mplayerlayer->move( orig_x + offset_x, mplayerlayer->y() );
421
int MplayerWindow::offsetX() { return offset_x; }
423
void MplayerWindow::setOffsetY( int d) {
425
mplayerlayer->move( mplayerlayer->x(), orig_y + offset_y );
428
int MplayerWindow::offsetY() { return offset_y; }
430
void MplayerWindow::setZoom( double d) {
440
if (zoom_factor != 1.0) {
445
x = (width() - w) / 2;
446
y = (height() -h) / 2;
449
mplayerlayer->move(x,y);
450
mplayerlayer->resize(w,h);
453
double MplayerWindow::zoom() { return zoom_factor; }
455
void MplayerWindow::moveLayer( int offset_x, int offset_y ) {
456
int x = mplayerlayer->x();
457
int y = mplayerlayer->y();
459
mplayerlayer->move( x + offset_x, y + offset_y );
462
void MplayerWindow::moveLeft() {
463
if ((allow_video_movement) || (mplayerlayer->x()+mplayerlayer->width() > width() ))
467
void MplayerWindow::moveRight() {
468
if ((allow_video_movement) || ( mplayerlayer->x() < 0 ))
472
void MplayerWindow::moveUp() {
473
if ((allow_video_movement) || (mplayerlayer->y()+mplayerlayer->height() > height() ))
477
void MplayerWindow::moveDown() {
478
if ((allow_video_movement) || ( mplayerlayer->y() < 0 ))
482
void MplayerWindow::incZoom() {
483
setZoom( zoom_factor + ZOOM_STEP );
486
void MplayerWindow::decZoom() {
487
double zoom = zoom_factor - ZOOM_STEP;
488
if (zoom < ZOOM_MIN) zoom = ZOOM_MIN;
492
// Language change stuff
493
void MplayerWindow::changeEvent(QEvent *e) {
494
if (e->type() == QEvent::LanguageChange) {
495
retranslateStrings();
497
QWidget::changeEvent(e);
501
#include "moc_mplayerwindow.cpp"