VirtualBox

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

Last change on this file since 104158 was 101565, checked in by vboxsync, 16 months ago

FE/Qt: bugref:10450: Somehow missed part of r159640.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: QIGraphicsView.cpp 101565 2023-10-24 00:08: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 if (pTouchEvent->device()->type() == QInputDevice::DeviceType::TouchScreen)
60 {
61 /* Remember where the scrolling was started: */
62 m_iVerticalScrollBarPosition = verticalScrollBar()->value();
63 /* Allow further touch events: */
64 pEvent->accept();
65 /* Mark event handled: */
66 return true;
67 }
68 break;
69 }
70 case QEvent::TouchUpdate:
71 {
72 /* Parse the touch-event: */
73 QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent);
74 AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent));
75 /* For touch-screen event we have something special: */
76 if (pTouchEvent->device()->type() == QInputDevice::DeviceType::TouchScreen)
77 {
78 /* Determine vertical shift (inverted): */
79 const QEventPoint point = pTouchEvent->points().first();
80 const int iShift = (int)(point.pressPosition().y() - point.position().y());
81 /* Calculate new scroll-bar value according calculated shift: */
82 int iNewScrollBarValue = m_iVerticalScrollBarPosition + iShift;
83 /* Make sure new scroll-bar value is within the minimum/maximum bounds: */
84 iNewScrollBarValue = qMax(verticalScrollBar()->minimum(), iNewScrollBarValue);
85 iNewScrollBarValue = qMin(verticalScrollBar()->maximum(), iNewScrollBarValue);
86 /* Apply calculated scroll-bar shift finally: */
87 verticalScrollBar()->setValue(iNewScrollBarValue);
88 /* Mark event handled: */
89 return true;
90 }
91 break;
92 }
93 case QEvent::TouchEnd:
94 {
95 /* Parse the touch event: */
96 QTouchEvent *pTouchEvent = static_cast<QTouchEvent*>(pEvent);
97 AssertPtrReturn(pTouchEvent, QGraphicsView::event(pEvent));
98 /* For touch-screen event we have something special: */
99 if (pTouchEvent->device()->type() == QInputDevice::DeviceType::TouchScreen)
100 {
101 /* Reset the scrolling start position: */
102 m_iVerticalScrollBarPosition = 0;
103 /* Mark event handled: */
104 return true;
105 }
106 break;
107 }
108 default:
109 break;
110 }
111 /* Call to base-class: */
112 return QGraphicsView::event(pEvent);
113}
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