Changeset 163 for smplayer/vendor/current/src/mplayerwindow.cpp
- Timestamp:
- May 15, 2014, 7:53:54 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/vendor/current/src/mplayerwindow.cpp
r154 r163 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 3Ricardo Villalba <rvm@users.sourceforge.net>2 Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 33 33 #include <QPixmap> 34 34 #include <QPainter> 35 36 #if DELAYED_RESIZE 35 #include <QApplication> 37 36 #include <QTimer> 38 # endif37 #include <QDebug> 39 38 40 39 #if LOGO_ANIMATION … … 42 41 #endif 43 42 44 Screen::Screen(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f ) 43 Screen::Screen(QWidget* parent, Qt::WindowFlags f) 44 : QWidget(parent, f ) 45 , check_mouse_timer(0) 46 , mouse_last_position(QPoint(0,0)) 47 , autohide_cursor(false) 48 , autohide_interval(0) 45 49 { 46 setMouseTracking( TRUE);50 setMouseTracking(true); 47 51 setFocusPolicy( Qt::NoFocus ); 48 52 setMinimumSize( QSize(0,0) ); 49 53 50 mouse_last_position = QPoint(0,0);51 52 54 check_mouse_timer = new QTimer(this); 53 55 connect( check_mouse_timer, SIGNAL(timeout()), this, SLOT(checkMousePos()) ); 54 56 55 // Change attributes56 setAttribute(Qt::WA_NoSystemBackground);57 //setAttribute(Qt::WA_StaticContents);58 //setAttribute( Qt::WA_OpaquePaintEvent );59 setAttribute(Qt::WA_PaintOnScreen);60 setAttribute(Qt::WA_PaintUnclipped);61 //setAttribute(Qt::WA_PaintOutsidePaintEvent);62 63 57 setAutoHideInterval(1000); 64 58 setAutoHideCursor(false); … … 66 60 67 61 Screen::~Screen() { 68 }69 70 void Screen::paintEvent( QPaintEvent * e ) {71 //qDebug("Screen::paintEvent");72 QPainter painter(this);73 painter.eraseRect( e->rect() );74 //painter.fillRect( e->rect(), QColor(255,0,0) );75 62 } 76 63 … … 108 95 109 96 void Screen::mouseMoveEvent( QMouseEvent * e ) { 97 //qDebug("Screen::mouseMoveEvent"); 98 emit mouseMoved(e->pos()); 99 110 100 if (cursor().shape() != Qt::ArrowCursor) { 111 101 //qDebug(" showing mouse cursor" ); … … 126 116 /* ---------------------------------------------------------------------- */ 127 117 128 MplayerLayer::MplayerLayer(QWidget* parent, Qt::WindowFlags f) 129 : Screen(parent, f) 118 MplayerLayer::MplayerLayer(QWidget* parent, Qt::WindowFlags f) 119 : Screen(parent, f) 120 #if REPAINT_BACKGROUND_OPTION 121 , repaint_background(false) 122 #endif 123 , playing(false) 130 124 { 131 #if REPAINT_BACKGROUND_OPTION 132 repaint_background = true; 133 #endif 134 playing = false; 125 #ifndef Q_OS_WIN 126 #if QT_VERSION < 0x050000 127 setAttribute(Qt::WA_OpaquePaintEvent); 128 #if QT_VERSION >= 0x040400 129 setAttribute(Qt::WA_NativeWindow); 130 #endif 131 setAttribute(Qt::WA_PaintUnclipped); 132 setAttribute(Qt::WA_PaintOnScreen); 133 #endif 134 #endif 135 135 } 136 136 … … 145 145 146 146 void MplayerLayer::paintEvent( QPaintEvent * e ) { 147 //qDebug("MplayerLayer::paintEvent: allow_clearing: %d", allow_clearing);147 //qDebug("MplayerLayer::paintEvent: repaint_background: %d", repaint_background); 148 148 if (repaint_background || !playing) { 149 149 //qDebug("MplayerLayer::paintEvent: painting"); 150 Screen::paintEvent(e); 150 QPainter painter(this); 151 painter.eraseRect( e->rect() ); 152 //painter.fillRect( e->rect(), QColor(255,0,0) ); 151 153 } 152 154 } … … 158 160 playing = true; 159 161 162 #ifndef Q_OS_WIN 163 #if QT_VERSION >= 0x050000 164 setAttribute(Qt::WA_PaintOnScreen); 165 #endif 166 #endif 167 160 168 Screen::playingStarted(); 161 169 } … … 164 172 qDebug("MplayerLayer::playingStopped"); 165 173 playing = false; 174 175 #ifndef Q_OS_WIN 176 #if QT_VERSION >= 0x050000 177 setAttribute(Qt::WA_PaintOnScreen, false); 178 #endif 179 #endif 180 166 181 repaint(); 167 168 182 Screen::playingStopped(); 169 183 } … … 171 185 /* ---------------------------------------------------------------------- */ 172 186 173 MplayerWindow::MplayerWindow(QWidget* parent, Qt::WindowFlags f) 174 : Screen(parent, f) , allow_video_movement(false) 187 MplayerWindow::MplayerWindow(QWidget* parent, Qt::WindowFlags f) 188 : Screen(parent, f) 189 , video_width(0) 190 , video_height(0) 191 , aspect((double) 4/3) 192 , monitoraspect(0) 193 , mplayerlayer(0) 194 , logo(0) 195 , offset_x(0) 196 , offset_y(0) 197 , zoom_factor(1.0) 198 , orig_x(0) 199 , orig_y(0) 200 , orig_width(0) 201 , orig_height(0) 202 , allow_video_movement(false) 203 #if DELAYED_RESIZE 204 , resize_timer(0) 205 #endif 206 , delay_left_click(false) 207 , left_click_timer(0) 208 , double_clicked(false) 209 #if LOGO_ANIMATION 210 , animated_logo(false) 211 #endif 212 , mouse_drag_tracking(false) 213 , isMoving(false) 214 , startDrag(QPoint(0,0)) 175 215 { 176 offset_x = 0;177 offset_y = 0;178 zoom_factor = 1.0;179 180 216 setAutoFillBackground(true); 181 217 ColorUtils::setBackgroundColor( this, QColor(0,0,0) ); 182 218 183 mplayerlayer = new MplayerLayer( this);219 mplayerlayer = new MplayerLayer(this); 184 220 mplayerlayer->setObjectName("mplayerlayer"); 185 mplayerlayer->setAutoFillBackground( TRUE);221 mplayerlayer->setAutoFillBackground(true); 186 222 187 223 logo = new QLabel( mplayerlayer ); 188 logo->setAutoFillBackground(TRUE); 189 #if QT_VERSION >= 0x040400 190 logo->setAttribute(Qt::WA_NativeWindow); // Otherwise the logo is not visible in Qt 4.4 191 #else 192 logo->setAttribute(Qt::WA_PaintOnScreen); // Fixes the problem if compiled with Qt < 4.4 193 #endif 224 logo->setObjectName("mplayerwindow logo"); 225 logo->setAutoFillBackground(true); 194 226 ColorUtils::setBackgroundColor( logo, QColor(0,0,0) ); 195 227 196 228 QVBoxLayout * mplayerlayerLayout = new QVBoxLayout( mplayerlayer ); 197 229 mplayerlayerLayout->addWidget( logo, 0, Qt::AlignHCenter | Qt::AlignVCenter ); 198 199 aspect = (double) 4 / 3;200 monitoraspect = 0;201 230 202 231 setSizePolicy( QSizePolicy::Expanding , QSizePolicy::Expanding ); … … 213 242 connect( resize_timer, SIGNAL(timeout()), this, SLOT(resizeLater()) ); 214 243 #endif 244 245 left_click_timer = new QTimer(this); 246 left_click_timer->setSingleShot(true); 247 left_click_timer->setInterval(qApp->doubleClickInterval()+10); 248 connect(left_click_timer, SIGNAL(timeout()), this, SIGNAL(leftClicked())); 215 249 216 250 retranslateStrings(); … … 370 404 371 405 void MplayerWindow::mouseReleaseEvent( QMouseEvent * e) { 372 406 qDebug( "MplayerWindow::mouseReleaseEvent" ); 373 407 374 408 if (e->button() == Qt::LeftButton) { 375 409 e->accept(); 376 emit leftClicked(); 410 if (delay_left_click) { 411 if (!double_clicked) left_click_timer->start(); 412 double_clicked = false; 413 } else { 414 emit leftClicked(); 415 } 377 416 } 378 417 else … … 405 444 if (e->button() == Qt::LeftButton) { 406 445 e->accept(); 446 if (delay_left_click) { 447 left_click_timer->stop(); 448 double_clicked = true; 449 } 407 450 emit doubleClicked(); 408 451 } else { … … 412 455 413 456 void MplayerWindow::wheelEvent( QWheelEvent * e ) { 414 415 457 qDebug("MplayerWindow::wheelEvent: delta: %d", e->delta()); 458 e->accept(); 416 459 417 460 if (e->orientation() == Qt::Vertical) { … … 425 468 } 426 469 427 bool MplayerWindow::eventFilter( QObject * watched, QEvent * event ) { 428 //qDebug("MplayerWindow::eventFilter: watched: %s", watched->objectName().toUtf8().constData()); 429 430 if ( (event->type() == QEvent::MouseMove) || 431 (event->type() == QEvent::MouseButtonRelease) ) 432 { 433 QMouseEvent *mouse_event = static_cast<QMouseEvent *>(event); 434 435 if (event->type() == QEvent::MouseMove) { 436 QPoint pos = mouse_event->pos(); 437 if (watched->objectName()=="mplayerlayer") { 438 QWidget *widget = static_cast<QWidget *>(watched); 439 pos = widget->mapToParent(pos); 440 } 441 emit mouseMoved(pos); 442 443 if ( mouse_event->buttons().testFlag(Qt::LeftButton)) { 444 emit mouseMovedDiff( mouse_event->globalPos() - mouse_press_pos); 445 mouse_press_pos = mouse_event->globalPos(); 446 /* qDebug("MplayerWindow::eventFilter: mouse_press_pos: x: %d y: %d", mouse_press_pos.x(), mouse_press_pos.y()); */ 447 } 448 } 449 } 450 451 if (event->type() == QEvent::MouseButtonPress) { 452 QMouseEvent *mouse_event = static_cast<QMouseEvent *>(event); 453 mouse_press_pos = mouse_event->globalPos(); 454 } 455 456 return false; 470 /* the code in eventFilter is based on dragmovecharm.cpp, under license GPL 2 or 3: 471 https://qt.gitorious.org/qt-labs/graphics-dojo/source/8000ca3b229344ed2ba2ae81ed5ebaee86e9d63a:dragmove/dragmovecharm.cpp 472 */ 473 bool MplayerWindow::eventFilter( QObject * object, QEvent * event ) { 474 //qDebug() << "MplayerWindow::eventFilter" << object; 475 476 if (!mouse_drag_tracking) return false; 477 478 QWidget * w = qobject_cast<QWidget*>(object); 479 if (!w) return false; 480 481 QEvent::Type type = event->type(); 482 if (type != QEvent::MouseButtonPress && type != QEvent::MouseButtonRelease && type != QEvent::MouseMove) { 483 return false; 484 } 485 486 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event); 487 if (!mouseEvent || mouseEvent->modifiers() != Qt::NoModifier) { 488 return false; 489 } 490 Qt::MouseButton button = mouseEvent->button(); 491 492 bool consumed = false; 493 494 if (type == QEvent::MouseButtonPress && button == Qt::LeftButton) { 495 startDrag = mouseEvent->globalPos(); 496 //qDebug() << "MplayerWindow::eventFilter: startDrag:" << startDrag << "obj:" << object->objectName(); 497 isMoving = true; 498 event->accept(); 499 consumed = true; 500 } 501 502 if (type == QEvent::MouseButtonRelease) { 503 startDrag = QPoint(0, 0); 504 isMoving = false; 505 } 506 507 if (type == QEvent::MouseMove && isMoving) { 508 QPoint pos = mouseEvent->globalPos(); 509 QPoint diff = pos - startDrag; 510 //qDebug() << "MplayerWindow:eventFilter: diff" << diff << "obj:" << object->objectName(); 511 emit mouseMovedDiff(diff); 512 startDrag = pos; 513 consumed = true; 514 } 515 516 return consumed; 457 517 } 458 518
Note:
See TracChangeset
for help on using the changeset viewer.