-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
QGVNavStyleTouchpad.cpp
129 lines (110 loc) · 3.98 KB
/
QGVNavStyleTouchpad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/***************************************************************************
* Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QApplication>
# include <QGuiApplication>
# include <QMouseEvent>
#endif
#include "QGVNavStyleTouchpad.h"
#include "QGVPage.h"
using namespace TechDrawGui;
namespace TechDrawGui {
QGVNavStyleTouchpad::QGVNavStyleTouchpad(QGVPage *qgvp) :
QGVNavStyle(qgvp)
{
}
QGVNavStyleTouchpad::~QGVNavStyleTouchpad()
{
}
void QGVNavStyleTouchpad::handleKeyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_PageUp) {
zoomIn();
event->accept();
return;
}
if (event->key() == Qt::Key_PageDown) {
zoomOut();
event->accept();
return;
}
QGVNavStyle::handleKeyPressEvent(event);
}
void QGVNavStyleTouchpad::handleKeyReleaseEvent(QKeyEvent *event)
{
// Q_UNUSED(event)
if (event->key() == Qt::Key_Shift) {
if (panningActive) {
stopPan();
}
if (zoomingActive) {
stopZoom();
}
event->accept();
}
if (event->key() == Qt::Key_Control) {
stopZoom();
event->accept();
}
}
void QGVNavStyleTouchpad::handleMouseMoveEvent(QMouseEvent *event)
{
if (getViewer()->isBalloonPlacing()) {
balloonCursorMovement(event);
return;
}
if (QApplication::keyboardModifiers() == Qt::ShiftModifier) {
//if shift is down then we are panning
if (panningActive) {
pan(event->pos());
} else {
startPan(event->pos());
}
event->accept();
return;
}
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) ) {
//if control and shift are down, then we are zooming
if (zoomingActive) {
zoom(mouseZoomFactor(event->pos()));
} else {
startZoom(event->pos());
}
event->accept();
return;
}
// if the mouse moves, but we are not zooming or panning, then we should make
// sure that zoom and pan are turned off.
stopPan();
stopZoom();
}
void QGVNavStyleTouchpad::setAnchor()
{
//this navigation style can not anchor under mouse since mouse is moving as part of zoom action
if (m_viewer) {
m_viewer->setResizeAnchor(QGraphicsView::AnchorViewCenter);
m_viewer->setTransformationAnchor(QGraphicsView::AnchorViewCenter);
}
}
} //namespace TechDrawGui