[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 3 |
|
---|
| 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.
|
---|
| 8 |
|
---|
| 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.
|
---|
| 13 |
|
---|
| 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
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include "mplayerwindow.h"
|
---|
| 20 | #include "global.h"
|
---|
| 21 | #include "desktopinfo.h"
|
---|
| 22 | #include "colorutils.h"
|
---|
| 23 |
|
---|
| 24 | #ifndef MINILIB
|
---|
| 25 | #include "images.h"
|
---|
| 26 | #endif
|
---|
| 27 |
|
---|
| 28 | #include <QLabel>
|
---|
| 29 | #include <QTimer>
|
---|
| 30 | #include <QCursor>
|
---|
| 31 | #include <QEvent>
|
---|
| 32 | #include <QLayout>
|
---|
| 33 | #include <QPixmap>
|
---|
| 34 | #include <QPainter>
|
---|
[165] | 35 | #include <QApplication>
|
---|
[112] | 36 | #include <QTimer>
|
---|
[165] | 37 | #include <QDebug>
|
---|
[112] | 38 |
|
---|
[135] | 39 | #if LOGO_ANIMATION
|
---|
| 40 | #include <QPropertyAnimation>
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
[181] | 43 | //#define HANDLE_GESTURES
|
---|
| 44 |
|
---|
| 45 | #ifdef HANDLE_GESTURES
|
---|
| 46 | #include <QGestureEvent>
|
---|
| 47 | #include <QTapGesture>
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
[165] | 50 | Screen::Screen(QWidget* parent, Qt::WindowFlags f)
|
---|
| 51 | : QWidget(parent, f )
|
---|
| 52 | , check_mouse_timer(0)
|
---|
| 53 | , mouse_last_position(QPoint(0,0))
|
---|
| 54 | , autohide_cursor(false)
|
---|
| 55 | , autohide_interval(0)
|
---|
[112] | 56 | {
|
---|
[165] | 57 | setMouseTracking(true);
|
---|
[112] | 58 | setFocusPolicy( Qt::NoFocus );
|
---|
| 59 | setMinimumSize( QSize(0,0) );
|
---|
| 60 |
|
---|
| 61 | check_mouse_timer = new QTimer(this);
|
---|
| 62 | connect( check_mouse_timer, SIGNAL(timeout()), this, SLOT(checkMousePos()) );
|
---|
| 63 |
|
---|
| 64 | setAutoHideInterval(1000);
|
---|
| 65 | setAutoHideCursor(false);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | Screen::~Screen() {
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void Screen::setAutoHideCursor(bool b) {
|
---|
| 72 | qDebug("Screen::setAutoHideCursor: %d", b);
|
---|
| 73 |
|
---|
| 74 | autohide_cursor = b;
|
---|
| 75 | if (autohide_cursor) {
|
---|
| 76 | check_mouse_timer->setInterval(autohide_interval);
|
---|
| 77 | check_mouse_timer->start();
|
---|
| 78 | } else {
|
---|
| 79 | check_mouse_timer->stop();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void Screen::checkMousePos() {
|
---|
| 84 | //qDebug("Screen::checkMousePos");
|
---|
| 85 |
|
---|
| 86 | if (!autohide_cursor) {
|
---|
| 87 | setCursor(QCursor(Qt::ArrowCursor));
|
---|
| 88 | return;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | QPoint pos = mapFromGlobal(QCursor::pos());
|
---|
| 92 |
|
---|
| 93 | //qDebug("Screen::checkMousePos: x: %d, y: %d", pos.x(), pos.y());
|
---|
| 94 |
|
---|
| 95 | if (mouse_last_position != pos) {
|
---|
| 96 | setCursor(QCursor(Qt::ArrowCursor));
|
---|
| 97 | } else {
|
---|
| 98 | setCursor(QCursor(Qt::BlankCursor));
|
---|
| 99 | }
|
---|
| 100 | mouse_last_position = pos;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | void Screen::mouseMoveEvent( QMouseEvent * e ) {
|
---|
[165] | 104 | //qDebug("Screen::mouseMoveEvent");
|
---|
| 105 | emit mouseMoved(e->pos());
|
---|
| 106 |
|
---|
[112] | 107 | if (cursor().shape() != Qt::ArrowCursor) {
|
---|
| 108 | //qDebug(" showing mouse cursor" );
|
---|
| 109 | setCursor(QCursor(Qt::ArrowCursor));
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | void Screen::playingStarted() {
|
---|
| 114 | qDebug("Screen::playingStarted");
|
---|
| 115 | setAutoHideCursor(true);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | void Screen::playingStopped() {
|
---|
| 119 | qDebug("Screen::playingStopped");
|
---|
| 120 | setAutoHideCursor(false);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /* ---------------------------------------------------------------------- */
|
---|
| 124 |
|
---|
[165] | 125 | MplayerLayer::MplayerLayer(QWidget* parent, Qt::WindowFlags f)
|
---|
| 126 | : Screen(parent, f)
|
---|
[112] | 127 | #if REPAINT_BACKGROUND_OPTION
|
---|
[165] | 128 | , repaint_background(false)
|
---|
[112] | 129 | #endif
|
---|
[165] | 130 | , playing(false)
|
---|
| 131 | {
|
---|
[112] | 132 | }
|
---|
| 133 |
|
---|
| 134 | MplayerLayer::~MplayerLayer() {
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | #if REPAINT_BACKGROUND_OPTION
|
---|
| 138 | void MplayerLayer::setRepaintBackground(bool b) {
|
---|
| 139 | qDebug("MplayerLayer::setRepaintBackground: %d", b);
|
---|
| 140 | repaint_background = b;
|
---|
| 141 | }
|
---|
| 142 | #endif
|
---|
| 143 |
|
---|
| 144 | void MplayerLayer::playingStarted() {
|
---|
| 145 | qDebug("MplayerLayer::playingStarted");
|
---|
[181] | 146 | // repaint();
|
---|
[112] | 147 | playing = true;
|
---|
| 148 |
|
---|
[165] | 149 | #ifndef Q_OS_WIN
|
---|
[181] | 150 | if (!repaint_background) setUpdatesEnabled(false);
|
---|
[165] | 151 | #endif
|
---|
| 152 |
|
---|
[112] | 153 | Screen::playingStarted();
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | void MplayerLayer::playingStopped() {
|
---|
| 157 | qDebug("MplayerLayer::playingStopped");
|
---|
| 158 | playing = false;
|
---|
[165] | 159 |
|
---|
| 160 | #ifndef Q_OS_WIN
|
---|
[181] | 161 | setUpdatesEnabled(true);
|
---|
[165] | 162 | #endif
|
---|
| 163 |
|
---|
[181] | 164 | // repaint();
|
---|
[112] | 165 | Screen::playingStopped();
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /* ---------------------------------------------------------------------- */
|
---|
| 169 |
|
---|
[165] | 170 | MplayerWindow::MplayerWindow(QWidget* parent, Qt::WindowFlags f)
|
---|
| 171 | : Screen(parent, f)
|
---|
| 172 | , video_width(0)
|
---|
| 173 | , video_height(0)
|
---|
| 174 | , aspect((double) 4/3)
|
---|
| 175 | , monitoraspect(0)
|
---|
| 176 | , mplayerlayer(0)
|
---|
| 177 | , logo(0)
|
---|
| 178 | , offset_x(0)
|
---|
| 179 | , offset_y(0)
|
---|
| 180 | , zoom_factor(1.0)
|
---|
| 181 | , orig_x(0)
|
---|
| 182 | , orig_y(0)
|
---|
| 183 | , orig_width(0)
|
---|
| 184 | , orig_height(0)
|
---|
| 185 | , allow_video_movement(false)
|
---|
| 186 | #if DELAYED_RESIZE
|
---|
| 187 | , resize_timer(0)
|
---|
| 188 | #endif
|
---|
| 189 | , delay_left_click(false)
|
---|
| 190 | , left_click_timer(0)
|
---|
| 191 | , double_clicked(false)
|
---|
| 192 | #if LOGO_ANIMATION
|
---|
| 193 | , animated_logo(false)
|
---|
| 194 | #endif
|
---|
[176] | 195 | , corner_widget(0)
|
---|
| 196 | , drag_state(NOT_DRAGGING)
|
---|
| 197 | , start_drag(QPoint(0,0))
|
---|
| 198 | , mouse_drag_tracking(false)
|
---|
[112] | 199 | {
|
---|
[165] | 200 | mplayerlayer = new MplayerLayer(this);
|
---|
[156] | 201 | mplayerlayer->setObjectName("mplayerlayer");
|
---|
[112] | 202 |
|
---|
| 203 | logo = new QLabel( mplayerlayer );
|
---|
[181] | 204 | logo->setObjectName("mplayerwindowlogo");
|
---|
| 205 |
|
---|
| 206 | // Set colors
|
---|
| 207 | #ifdef CHANGE_WIDGET_COLOR
|
---|
| 208 | setAutoFillBackground(true);
|
---|
| 209 | ColorUtils::setBackgroundColor( this, QColor(0,0,0) );
|
---|
| 210 | mplayerlayer->setAutoFillBackground(true);
|
---|
[165] | 211 | logo->setAutoFillBackground(true);
|
---|
[112] | 212 | ColorUtils::setBackgroundColor( logo, QColor(0,0,0) );
|
---|
[181] | 213 | #else
|
---|
| 214 | setStyleSheet("MplayerWindow { background-color: black;}");
|
---|
| 215 | mplayerlayer->setStyleSheet("background-color: black;");
|
---|
| 216 | #endif
|
---|
[112] | 217 |
|
---|
| 218 | QVBoxLayout * mplayerlayerLayout = new QVBoxLayout( mplayerlayer );
|
---|
| 219 | mplayerlayerLayout->addWidget( logo, 0, Qt::AlignHCenter | Qt::AlignVCenter );
|
---|
| 220 |
|
---|
| 221 | setSizePolicy( QSizePolicy::Expanding , QSizePolicy::Expanding );
|
---|
| 222 | setFocusPolicy( Qt::StrongFocus );
|
---|
[181] | 223 |
|
---|
| 224 | //#ifdef HANDLE_GESTURES
|
---|
| 225 | grabGesture(Qt::TapGesture);
|
---|
| 226 | //#endif
|
---|
[112] | 227 |
|
---|
| 228 | installEventFilter(this);
|
---|
| 229 | mplayerlayer->installEventFilter(this);
|
---|
| 230 | //logo->installEventFilter(this);
|
---|
| 231 |
|
---|
| 232 | #if DELAYED_RESIZE
|
---|
| 233 | resize_timer = new QTimer(this);
|
---|
| 234 | resize_timer->setSingleShot(true);
|
---|
| 235 | resize_timer->setInterval(50);
|
---|
| 236 | connect( resize_timer, SIGNAL(timeout()), this, SLOT(resizeLater()) );
|
---|
| 237 | #endif
|
---|
| 238 |
|
---|
[165] | 239 | left_click_timer = new QTimer(this);
|
---|
| 240 | left_click_timer->setSingleShot(true);
|
---|
| 241 | left_click_timer->setInterval(qApp->doubleClickInterval()+10);
|
---|
| 242 | connect(left_click_timer, SIGNAL(timeout()), this, SIGNAL(leftClicked()));
|
---|
| 243 |
|
---|
[112] | 244 | retranslateStrings();
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | MplayerWindow::~MplayerWindow() {
|
---|
| 248 | }
|
---|
| 249 |
|
---|
[176] | 250 | void MplayerWindow::setCornerWidget(QWidget * w) {
|
---|
| 251 | corner_widget = w;
|
---|
| 252 |
|
---|
| 253 | QHBoxLayout * blayout = new QHBoxLayout;
|
---|
| 254 | blayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
|
---|
| 255 | blayout->addWidget(corner_widget);
|
---|
| 256 |
|
---|
| 257 | QVBoxLayout * layout = new QVBoxLayout(this);
|
---|
| 258 | layout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
---|
| 259 | layout->addLayout(blayout);
|
---|
| 260 | }
|
---|
| 261 |
|
---|
[112] | 262 | #if USE_COLORKEY
|
---|
| 263 | void MplayerWindow::setColorKey( QColor c ) {
|
---|
[181] | 264 | #ifdef CHANGE_WIDGET_COLOR
|
---|
[112] | 265 | ColorUtils::setBackgroundColor( mplayerlayer, c );
|
---|
[181] | 266 | #endif
|
---|
[112] | 267 | }
|
---|
| 268 | #endif
|
---|
| 269 |
|
---|
| 270 | void MplayerWindow::retranslateStrings() {
|
---|
| 271 | //qDebug("MplayerWindow::retranslateStrings");
|
---|
| 272 | #ifndef MINILIB
|
---|
| 273 | logo->setPixmap( Images::icon("background") );
|
---|
| 274 | #endif
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[124] | 277 | void MplayerWindow::setLogoVisible( bool b) {
|
---|
[181] | 278 | qDebug() << "MplayerWindow::setLogoVisible:" << b;
|
---|
| 279 |
|
---|
| 280 | #if REPAINT_BACKGROUND_OPTION
|
---|
| 281 | if (b) mplayerlayer->setUpdatesEnabled(true);
|
---|
| 282 | #endif
|
---|
| 283 |
|
---|
[176] | 284 | if (corner_widget) {
|
---|
| 285 | corner_widget->setVisible(b);
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[135] | 288 | #if !LOGO_ANIMATION
|
---|
[124] | 289 | logo->setVisible(b);
|
---|
[135] | 290 | #else
|
---|
| 291 | if (!animated_logo) {
|
---|
| 292 | logo->setVisible(b);
|
---|
| 293 | } else {
|
---|
| 294 | if (b) {
|
---|
| 295 | logo->show();
|
---|
| 296 | QPropertyAnimation * animation = new QPropertyAnimation(logo, "pos");
|
---|
| 297 | animation->setDuration(200);
|
---|
| 298 | animation->setEasingCurve(QEasingCurve::OutBounce);
|
---|
| 299 | animation->setStartValue(QPoint(logo->x(), 0 - logo->y()));
|
---|
| 300 | animation->setEndValue(logo->pos());
|
---|
| 301 | animation->start();
|
---|
| 302 | } else {
|
---|
| 303 | QPropertyAnimation * animation = new QPropertyAnimation(logo, "pos");
|
---|
| 304 | animation->setDuration(200);
|
---|
| 305 | animation->setEasingCurve(QEasingCurve::OutBounce);
|
---|
| 306 | animation->setEndValue(QPoint(width(), logo->y()));
|
---|
| 307 | animation->setStartValue(logo->pos());
|
---|
| 308 | animation->start();
|
---|
| 309 | connect(animation, SIGNAL(finished()), logo, SLOT(hide()));
|
---|
| 310 | //logo->hide();
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | #endif
|
---|
[112] | 314 | }
|
---|
| 315 |
|
---|
| 316 | /*
|
---|
| 317 | void MplayerWindow::changePolicy() {
|
---|
| 318 | setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Preferred );
|
---|
| 319 | }
|
---|
| 320 | */
|
---|
| 321 |
|
---|
| 322 | void MplayerWindow::setResolution( int w, int h)
|
---|
| 323 | {
|
---|
| 324 | video_width = w;
|
---|
| 325 | video_height = h;
|
---|
| 326 |
|
---|
| 327 | //mplayerlayer->move(1,1);
|
---|
| 328 | updateVideoWindow();
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 |
|
---|
| 332 | void MplayerWindow::resizeEvent( QResizeEvent * /* e */)
|
---|
| 333 | {
|
---|
| 334 | /*qDebug("MplayerWindow::resizeEvent: %d, %d",
|
---|
| 335 | e->size().width(), e->size().height() );*/
|
---|
| 336 |
|
---|
| 337 | #if !DELAYED_RESIZE
|
---|
| 338 | offset_x = 0;
|
---|
| 339 | offset_y = 0;
|
---|
| 340 |
|
---|
| 341 | updateVideoWindow();
|
---|
| 342 | setZoom(zoom_factor);
|
---|
| 343 | #else
|
---|
| 344 | resize_timer->start();
|
---|
| 345 | #endif
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | #if DELAYED_RESIZE
|
---|
| 349 | void MplayerWindow::resizeLater() {
|
---|
| 350 | offset_x = 0;
|
---|
| 351 | offset_y = 0;
|
---|
| 352 |
|
---|
| 353 | updateVideoWindow();
|
---|
| 354 | setZoom(zoom_factor);
|
---|
| 355 | }
|
---|
| 356 | #endif
|
---|
| 357 |
|
---|
| 358 | void MplayerWindow::setMonitorAspect(double asp) {
|
---|
| 359 | monitoraspect = asp;
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | void MplayerWindow::setAspect( double asp) {
|
---|
| 363 | aspect = asp;
|
---|
| 364 | if (monitoraspect!=0) {
|
---|
| 365 | aspect = aspect / monitoraspect * DesktopInfo::desktop_aspectRatio(this);
|
---|
| 366 | }
|
---|
| 367 | updateVideoWindow();
|
---|
| 368 | }
|
---|
| 369 |
|
---|
| 370 |
|
---|
| 371 | void MplayerWindow::updateVideoWindow()
|
---|
| 372 | {
|
---|
| 373 | //qDebug("MplayerWindow::updateVideoWindow");
|
---|
| 374 |
|
---|
| 375 | //qDebug("aspect= %f", aspect);
|
---|
| 376 |
|
---|
| 377 | int w_width = size().width();
|
---|
| 378 | int w_height = size().height();
|
---|
| 379 |
|
---|
| 380 | int w = w_width;
|
---|
| 381 | int h = w_height;
|
---|
| 382 | int x = 0;
|
---|
| 383 | int y = 0;
|
---|
| 384 |
|
---|
| 385 | if (aspect != 0) {
|
---|
| 386 | int pos1_w = w_width;
|
---|
| 387 | int pos1_h = w_width / aspect + 0.5;
|
---|
| 388 |
|
---|
| 389 | int pos2_h = w_height;
|
---|
| 390 | int pos2_w = w_height * aspect + 0.5;
|
---|
| 391 |
|
---|
| 392 | //qDebug("pos1_w: %d, pos1_h: %d", pos1_w, pos1_h);
|
---|
| 393 | //qDebug("pos2_w: %d, pos2_h: %d", pos2_w, pos2_h);
|
---|
| 394 |
|
---|
| 395 | if (pos1_h <= w_height) {
|
---|
| 396 | //qDebug("Pos1!");
|
---|
| 397 | w = pos1_w;
|
---|
| 398 | h = pos1_h;
|
---|
| 399 |
|
---|
| 400 | y = (w_height - h) /2;
|
---|
| 401 | } else {
|
---|
| 402 | //qDebug("Pos2!");
|
---|
| 403 | w = pos2_w;
|
---|
| 404 | h = pos2_h;
|
---|
| 405 |
|
---|
| 406 | x = (w_width - w) /2;
|
---|
| 407 | }
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | mplayerlayer->move(x,y);
|
---|
| 411 | mplayerlayer->resize(w, h);
|
---|
| 412 |
|
---|
| 413 | orig_x = x;
|
---|
| 414 | orig_y = y;
|
---|
| 415 | orig_width = w;
|
---|
| 416 | orig_height = h;
|
---|
| 417 |
|
---|
| 418 | //qDebug( "w_width: %d, w_height: %d", w_width, w_height);
|
---|
| 419 | //qDebug("w: %d, h: %d", w,h);
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 |
|
---|
| 423 | void MplayerWindow::mouseReleaseEvent( QMouseEvent * e) {
|
---|
[165] | 424 | qDebug( "MplayerWindow::mouseReleaseEvent" );
|
---|
[112] | 425 |
|
---|
| 426 | if (e->button() == Qt::LeftButton) {
|
---|
| 427 | e->accept();
|
---|
[165] | 428 | if (delay_left_click) {
|
---|
| 429 | if (!double_clicked) left_click_timer->start();
|
---|
| 430 | double_clicked = false;
|
---|
| 431 | } else {
|
---|
| 432 | emit leftClicked();
|
---|
| 433 | }
|
---|
[112] | 434 | }
|
---|
| 435 | else
|
---|
| 436 | if (e->button() == Qt::MidButton) {
|
---|
| 437 | e->accept();
|
---|
| 438 | emit middleClicked();
|
---|
| 439 | }
|
---|
| 440 | else
|
---|
| 441 | if (e->button() == Qt::XButton1) {
|
---|
| 442 | e->accept();
|
---|
| 443 | emit xbutton1Clicked();
|
---|
| 444 | }
|
---|
| 445 | else
|
---|
| 446 | if (e->button() == Qt::XButton2) {
|
---|
| 447 | e->accept();
|
---|
| 448 | emit xbutton2Clicked();
|
---|
| 449 | }
|
---|
| 450 | else
|
---|
| 451 | if (e->button() == Qt::RightButton) {
|
---|
| 452 | e->accept();
|
---|
| 453 | //emit rightButtonReleased( e->globalPos() );
|
---|
| 454 | emit rightClicked();
|
---|
| 455 | }
|
---|
| 456 | else {
|
---|
| 457 | e->ignore();
|
---|
| 458 | }
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | void MplayerWindow::mouseDoubleClickEvent( QMouseEvent * e ) {
|
---|
| 462 | if (e->button() == Qt::LeftButton) {
|
---|
| 463 | e->accept();
|
---|
[165] | 464 | if (delay_left_click) {
|
---|
| 465 | left_click_timer->stop();
|
---|
| 466 | double_clicked = true;
|
---|
| 467 | }
|
---|
[112] | 468 | emit doubleClicked();
|
---|
| 469 | } else {
|
---|
| 470 | e->ignore();
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | void MplayerWindow::wheelEvent( QWheelEvent * e ) {
|
---|
[165] | 475 | qDebug("MplayerWindow::wheelEvent: delta: %d", e->delta());
|
---|
| 476 | e->accept();
|
---|
[112] | 477 |
|
---|
| 478 | if (e->orientation() == Qt::Vertical) {
|
---|
| 479 | if (e->delta() >= 0)
|
---|
| 480 | emit wheelUp();
|
---|
| 481 | else
|
---|
| 482 | emit wheelDown();
|
---|
| 483 | } else {
|
---|
| 484 | qDebug("MplayerWindow::wheelEvent: horizontal event received, doing nothing");
|
---|
| 485 | }
|
---|
| 486 | }
|
---|
| 487 |
|
---|
[165] | 488 | bool MplayerWindow::eventFilter( QObject * object, QEvent * event ) {
|
---|
[181] | 489 | #ifdef HANDLE_GESTURES
|
---|
| 490 | if (event->type() == QEvent::Gesture) {
|
---|
| 491 | qDebug() << "MplayerWindow::eventFilter: event:" << event;
|
---|
| 492 | QGestureEvent * ge = static_cast<QGestureEvent*>(event);
|
---|
| 493 | qDebug() << "MplayerWindow::eventFilter: ge:" << ge;
|
---|
| 494 | if (QGesture * tap = ge->gesture(Qt::TapGesture)) {
|
---|
| 495 | QTapGesture * tg = static_cast<QTapGesture *>(tap);
|
---|
| 496 | qDebug() << "MplayerWindow::eventFilter: tg:" << tg;
|
---|
| 497 | event->setAccepted(true);
|
---|
| 498 | return false;
|
---|
| 499 | }
|
---|
| 500 | }
|
---|
| 501 | #endif
|
---|
| 502 |
|
---|
[176] | 503 | if (!mouse_drag_tracking)
|
---|
| 504 | return false;
|
---|
[112] | 505 |
|
---|
[176] | 506 | QEvent::Type type = event->type();
|
---|
| 507 | if (type != QEvent::MouseButtonPress
|
---|
| 508 | && type != QEvent::MouseButtonRelease
|
---|
| 509 | && type != QEvent::MouseMove)
|
---|
| 510 | return false;
|
---|
[139] | 511 |
|
---|
[176] | 512 | QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
---|
| 513 | if (!mouseEvent)
|
---|
| 514 | return false;
|
---|
[112] | 515 |
|
---|
[176] | 516 | if (mouseEvent->modifiers() != Qt::NoModifier) {
|
---|
| 517 | drag_state = NOT_DRAGGING;
|
---|
| 518 | return false;
|
---|
| 519 | }
|
---|
[139] | 520 |
|
---|
[176] | 521 | if (type == QEvent::MouseButtonPress) {
|
---|
| 522 | if (mouseEvent->button() != Qt::LeftButton) {
|
---|
| 523 | drag_state = NOT_DRAGGING;
|
---|
| 524 | return false;
|
---|
| 525 | }
|
---|
[165] | 526 |
|
---|
[176] | 527 | drag_state = START_DRAGGING;
|
---|
| 528 | start_drag = mouseEvent->globalPos();
|
---|
| 529 | // Don't filter, so others can have a look at it too
|
---|
| 530 | return false;
|
---|
| 531 | }
|
---|
[165] | 532 |
|
---|
[176] | 533 | if (type == QEvent::MouseButtonRelease) {
|
---|
| 534 | if (drag_state != DRAGGING || mouseEvent->button() != Qt::LeftButton) {
|
---|
| 535 | drag_state = NOT_DRAGGING;
|
---|
| 536 | return false;
|
---|
| 537 | }
|
---|
[165] | 538 |
|
---|
[176] | 539 | // Stop dragging and eat event
|
---|
| 540 | drag_state = NOT_DRAGGING;
|
---|
| 541 | event->accept();
|
---|
| 542 | return true;
|
---|
| 543 | }
|
---|
[165] | 544 |
|
---|
[176] | 545 | // type == QEvent::MouseMove
|
---|
| 546 | if (drag_state == NOT_DRAGGING)
|
---|
| 547 | return false;
|
---|
| 548 |
|
---|
| 549 | // buttons() note the s
|
---|
| 550 | if (mouseEvent->buttons() != Qt::LeftButton) {
|
---|
| 551 | drag_state = NOT_DRAGGING;
|
---|
| 552 | return false;
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | QPoint pos = mouseEvent->globalPos();
|
---|
| 556 | QPoint diff = pos - start_drag;
|
---|
| 557 | if (drag_state == START_DRAGGING) {
|
---|
| 558 | // Don't start dragging before moving at least DRAG_THRESHOLD pixels
|
---|
| 559 | if (abs(diff.x()) < DRAG_THRESHOLD && abs(diff.y()) < DRAG_THRESHOLD)
|
---|
| 560 | return false;
|
---|
| 561 |
|
---|
| 562 | drag_state = DRAGGING;
|
---|
| 563 | }
|
---|
| 564 |
|
---|
| 565 | emit mouseMovedDiff(diff);
|
---|
| 566 | start_drag = pos;
|
---|
| 567 | event->accept();
|
---|
| 568 | return true;
|
---|
[112] | 569 | }
|
---|
| 570 |
|
---|
| 571 | QSize MplayerWindow::sizeHint() const {
|
---|
| 572 | //qDebug("MplayerWindow::sizeHint");
|
---|
| 573 | return QSize( video_width, video_height );
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | QSize MplayerWindow::minimumSizeHint () const {
|
---|
| 577 | return QSize(0,0);
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | void MplayerWindow::setOffsetX( int d) {
|
---|
| 581 | offset_x = d;
|
---|
| 582 | mplayerlayer->move( orig_x + offset_x, mplayerlayer->y() );
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 | int MplayerWindow::offsetX() { return offset_x; }
|
---|
| 586 |
|
---|
| 587 | void MplayerWindow::setOffsetY( int d) {
|
---|
| 588 | offset_y = d;
|
---|
| 589 | mplayerlayer->move( mplayerlayer->x(), orig_y + offset_y );
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 | int MplayerWindow::offsetY() { return offset_y; }
|
---|
| 593 |
|
---|
| 594 | void MplayerWindow::setZoom( double d) {
|
---|
| 595 | zoom_factor = d;
|
---|
| 596 | offset_x = 0;
|
---|
| 597 | offset_y = 0;
|
---|
| 598 |
|
---|
| 599 | int x = orig_x;
|
---|
| 600 | int y = orig_y;
|
---|
| 601 | int w = orig_width;
|
---|
| 602 | int h = orig_height;
|
---|
| 603 |
|
---|
| 604 | if (zoom_factor != 1.0) {
|
---|
| 605 | w = w * zoom_factor;
|
---|
| 606 | h = h * zoom_factor;
|
---|
| 607 |
|
---|
| 608 | // Center
|
---|
| 609 | x = (width() - w) / 2;
|
---|
| 610 | y = (height() -h) / 2;
|
---|
| 611 | }
|
---|
| 612 |
|
---|
| 613 | mplayerlayer->move(x,y);
|
---|
| 614 | mplayerlayer->resize(w,h);
|
---|
| 615 | }
|
---|
| 616 |
|
---|
| 617 | double MplayerWindow::zoom() { return zoom_factor; }
|
---|
| 618 |
|
---|
| 619 | void MplayerWindow::moveLayer( int offset_x, int offset_y ) {
|
---|
| 620 | int x = mplayerlayer->x();
|
---|
| 621 | int y = mplayerlayer->y();
|
---|
| 622 |
|
---|
| 623 | mplayerlayer->move( x + offset_x, y + offset_y );
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | void MplayerWindow::moveLeft() {
|
---|
| 627 | if ((allow_video_movement) || (mplayerlayer->x()+mplayerlayer->width() > width() ))
|
---|
| 628 | moveLayer( -16, 0 );
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 | void MplayerWindow::moveRight() {
|
---|
| 632 | if ((allow_video_movement) || ( mplayerlayer->x() < 0 ))
|
---|
| 633 | moveLayer( +16, 0 );
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | void MplayerWindow::moveUp() {
|
---|
| 637 | if ((allow_video_movement) || (mplayerlayer->y()+mplayerlayer->height() > height() ))
|
---|
| 638 | moveLayer( 0, -16 );
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 | void MplayerWindow::moveDown() {
|
---|
| 642 | if ((allow_video_movement) || ( mplayerlayer->y() < 0 ))
|
---|
| 643 | moveLayer( 0, +16 );
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | void MplayerWindow::incZoom() {
|
---|
| 647 | setZoom( zoom_factor + ZOOM_STEP );
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 | void MplayerWindow::decZoom() {
|
---|
| 651 | double zoom = zoom_factor - ZOOM_STEP;
|
---|
| 652 | if (zoom < ZOOM_MIN) zoom = ZOOM_MIN;
|
---|
| 653 | setZoom( zoom );
|
---|
| 654 | }
|
---|
| 655 |
|
---|
| 656 | // Language change stuff
|
---|
| 657 | void MplayerWindow::changeEvent(QEvent *e) {
|
---|
| 658 | if (e->type() == QEvent::LanguageChange) {
|
---|
| 659 | retranslateStrings();
|
---|
| 660 | } else {
|
---|
[181] | 661 | Screen::changeEvent(e);
|
---|
[112] | 662 | }
|
---|
| 663 | }
|
---|
| 664 |
|
---|
| 665 | #include "moc_mplayerwindow.cpp"
|
---|