File indexing completed on 2024-05-12 05:53:36
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "AutoScrollHandler.h" 0009 #include "../TerminalDisplay.h" 0010 #include <QAccessible> 0011 #include <QApplication> 0012 0013 using namespace Konsole; 0014 0015 AutoScrollHandler::AutoScrollHandler(QWidget *parent) 0016 : QObject(parent) 0017 { 0018 parent->installEventFilter(this); 0019 } 0020 0021 void AutoScrollHandler::timerEvent(QTimerEvent *event) 0022 { 0023 if (event->timerId() != _timerId) { 0024 return; 0025 } 0026 0027 auto *terminalDisplay = static_cast<TerminalDisplay *>(parent()); 0028 QMouseEvent mouseEvent(QEvent::MouseMove, 0029 widget()->mapFromGlobal(QCursor::pos()), 0030 QCursor::pos(), 0031 Qt::NoButton, 0032 Qt::LeftButton, 0033 terminalDisplay->usesMouseTracking() ? Qt::ShiftModifier : Qt::NoModifier); 0034 0035 QApplication::sendEvent(widget(), &mouseEvent); 0036 } 0037 0038 bool AutoScrollHandler::eventFilter(QObject *watched, QEvent *event) 0039 { 0040 Q_ASSERT(watched == parent()); 0041 Q_UNUSED(watched) 0042 0043 switch (event->type()) { 0044 case QEvent::MouseMove: { 0045 auto *mouseEvent = static_cast<QMouseEvent *>(event); 0046 bool mouseInWidget = widget()->rect().contains(mouseEvent->pos()); 0047 auto *terminalDisplay = static_cast<TerminalDisplay *>(parent()); 0048 if (mouseInWidget) { 0049 if (_timerId != 0) { 0050 killTimer(_timerId); 0051 } 0052 0053 _timerId = 0; 0054 } else { 0055 if ((_timerId == 0) && terminalDisplay->selectionState() != 0 && ((mouseEvent->buttons() & Qt::LeftButton) != 0U)) { 0056 _timerId = startTimer(100); 0057 } 0058 } 0059 0060 break; 0061 } 0062 case QEvent::MouseButtonRelease: { 0063 auto *mouseEvent = static_cast<QMouseEvent *>(event); 0064 if ((_timerId != 0) && ((mouseEvent->buttons() & ~Qt::LeftButton) != 0U)) { 0065 killTimer(_timerId); 0066 _timerId = 0; 0067 } 0068 break; 0069 } 0070 default: 0071 break; 0072 } 0073 0074 return false; 0075 } 0076 0077 #include "moc_AutoScrollHandler.cpp"