File indexing completed on 2024-04-28 04:48:37
0001 /* 0002 SPDX-FileCopyrightText: 2005 Max Howell <max.howell@methylblue.com> 0003 SPDX-FileCopyrightText: 2007 Ian Monroe <ian@monroe.nu> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "fullScreenToolBarHandler.h" 0009 0010 #include "mainWindow.h" 0011 #include "videoWindow.h" 0012 0013 #include <QDebug> 0014 #include <QEvent> 0015 #include <QMouseEvent> 0016 0017 #include <KMainWindow> 0018 #include <KToolBar> 0019 0020 Dragon::FullScreenToolBarHandler::FullScreenToolBarHandler(KMainWindow *parent) 0021 : QObject(parent) 0022 , m_timer_id(0) 0023 , m_parent(parent) 0024 { 0025 parent->installEventFilter(this); 0026 0027 m_timer_id = startTimer(Dragon::VideoWindow::CURSOR_HIDE_TIMEOUT); // We want to hide automatically some time after fullscreening 0028 } 0029 0030 bool Dragon::FullScreenToolBarHandler::eventFilter(QObject * /*o*/, QEvent *e) 0031 { 0032 if (e->type() == QEvent::MouseMove) { 0033 if (m_timer_id) { 0034 qDebug() << "mouse move, killing timer"; 0035 killTimer(m_timer_id); 0036 m_timer_id = 0; 0037 } 0038 0039 QMouseEvent const *const me = (QMouseEvent *)e; 0040 0041 if (m_parent->toolBar()->geometry().contains(me->pos()) || static_cast<Dragon::MainWindow *>(Dragon::mainWindow())->volumeContains(me->pos())) { 0042 // no discussion here, mouse is in toolbar or volume slider area 0043 qDebug() << "mouse in toolbar area, show toolbar"; 0044 m_parent->toolBar()->show(); 0045 static_cast<Dragon::MainWindow *>(Dragon::mainWindow())->showVolume(true); 0046 } else if (m_parent->toolBar()->isHidden()) { 0047 qDebug() << "mouse moved while toolbar is hidden"; 0048 if (m_home.isNull()) { 0049 qDebug() << "set home"; 0050 m_home = me->pos(); // store the position where the mouse was when we saw it 0051 } else if ((m_home - me->pos()).manhattanLength() > 6) { 0052 // then cursor has moved far enough to trigger show toolbar 0053 qDebug() << "show toolbar"; 0054 m_parent->toolBar()->show(); 0055 static_cast<Dragon::MainWindow *>(Dragon::mainWindow())->showVolume(true); 0056 m_home = QPoint(); 0057 } else { 0058 qDebug() << "cursor hasn't moved far enough yet " << (m_home - me->pos()).manhattanLength(); 0059 // cursor hasn't moved far enough yet 0060 } 0061 } else { 0062 // reset the hide timer 0063 qDebug() << "mouse moved in video window while toolbar is shown, starting hide timer: " << Dragon::VideoWindow::CURSOR_HIDE_TIMEOUT; 0064 m_timer_id = startTimer(Dragon::VideoWindow::CURSOR_HIDE_TIMEOUT); 0065 } 0066 } else if (e->type() == QEvent::Resize) { 0067 // we aren't managed by mainWindow when at FullScreen 0068 videoWindow()->move(0, 0); 0069 videoWindow()->resize(((QWidget *)parent())->size()); 0070 videoWindow()->lower(); 0071 } else if (e->type() == QEvent::Leave) { 0072 // reset the hide timer 0073 m_timer_id = startTimer(Dragon::VideoWindow::CURSOR_HIDE_TIMEOUT); 0074 } 0075 0076 return false; 0077 } 0078 0079 void Dragon::FullScreenToolBarHandler::timerEvent(QTimerEvent *e) 0080 { 0081 killTimer(e->timerId()); // timers are NOT single-shot! 0082 m_timer_id = 0; 0083 0084 qDebug() << "hide timer triggered"; 0085 static_cast<Dragon::MainWindow *>(Dragon::mainWindow())->showVolume(false); 0086 m_parent->toolBar()->hide(); 0087 } 0088 0089 #include "moc_fullScreenToolBarHandler.cpp"