VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/graphics/QIGraphicsView.cpp@ 100347

Last change on this file since 100347 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: QIGraphicsView.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIGraphicsView class implementation.
4 */
5
6/*
7 * Copyright (C) 2015-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QScrollBar>
30#include <QTouchEvent>
31
32/* GUI includes: */
33#include "QIGraphicsView.h"
34
35/* Other VBox includes: */
36#include "iprt/assert.h"
37
38
39QIGraphicsView::QIGraphicsView(QWidget *pParent /* = 0 */)
40 : QGraphicsView(pParent)
41 , m_iVerticalScrollBarPosition(0)
42{
43 /* Enable multi-touch support: */
44 setAttribute(Qt::WA_AcceptTouchEvents);
45 viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
46}
47
48bool QIGraphicsView::event(QEvent *pEvent)
49{
50 /* Handle known event types: */
51 switch (pEvent->type())
52 {
53 case QEvent::TouchBegin:
54 {
55 /* Parse the touch event: */
56 QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent);
57 AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent));
58 /* For touch-screen event we have something special: */
59#ifdef VBOX_IS_QT6_OR_LATER /* QTouchDevice was consumed by QInputDevice in 6.0 */
60 if (pTouchEvent->device()->type() == QInputDevice::DeviceType::TouchScreen)
61#else
62 if (pTouchEvent->device()->type() == QTouchDevice::TouchScreen)
63#endif
64 {
65 /* Remember where the scrolling was started: */
66 m_iVerticalScrollBarPosition = verticalScrollBar()->value();
67 /* Allow further touch events: */
68 pEvent->accept();
69 /* Mark event handled: */
70 return true;
71 }
72 break;
73 }
74 case QEvent::TouchUpdate:
75 {
76 /* Parse the touch-event: */
77 QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent);
78 AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent));
79 /* For touch-screen event we have something special: */
80#ifdef VBOX_IS_QT6_OR_LATER /* QTouchDevice was consumed by QInputDevice in 6.0 */
81 if (pTouchEvent->device()->type() == QInputDevice::DeviceType::TouchScreen)
82#else
83 if (pTouchEvent->device()->type() == QTouchDevice::TouchScreen)
84#endif
85 {
86 /* Determine vertical shift (inverted): */
87 const QTouchEvent::TouchPoint point = pTouchEvent->touchPoints().first();
88 const int iShift = (int)(point.startPos().y() - point.pos().y());
89 /* Calculate new scroll-bar value according calculated shift: */
90 int iNewScrollBarValue = m_iVerticalScrollBarPosition + iShift;
91 /* Make sure new scroll-bar value is within the minimum/maximum bounds: */
92 iNewScrollBarValue = qMax(verticalScrollBar()->minimum(), iNewScrollBarValue);
93 iNewScrollBarValue = qMin(verticalScrollBar()->maximum(), iNewScrollBarValue);
94 /* Apply calculated scroll-bar shift finally: */
95 verticalScrollBar()->setValue(iNewScrollBarValue);
96 /* Mark event handled: */
97 return true;
98 }
99 break;
100 }
101 case QEvent::TouchEnd:
102 {
103 /* Parse the touch event: */
104 QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent);
105 AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent));
106 /* For touch-screen event we have something special: */
107#ifdef VBOX_IS_QT6_OR_LATER /* QTouchDevice was consumed by QInputDevice in 6.0 */
108 if (pTouchEvent->device()->type() == QInputDevice::DeviceType::TouchScreen)
109#else
110 if (pTouchEvent->device()->type() == QTouchDevice::TouchScreen)
111#endif
112 {
113 /* Reset the scrolling start position: */
114 m_iVerticalScrollBarPosition = 0;
115 /* Mark event handled: */
116 return true;
117 }
118 break;
119 }
120 default:
121 break;
122 }
123 /* Call to base-class: */
124 return QGraphicsView::event(pEvent);
125}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette