1
/***************************************************************************
2
* Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <QApplication>
26
# include <QGuiApplication>
27
# include <QMouseEvent>
30
#include "QGVNavStyleCAD.h"
34
using namespace TechDrawGui;
36
namespace TechDrawGui {
38
QGVNavStyleCAD::QGVNavStyleCAD(QGVPage* qgvp) :
43
QGVNavStyleCAD::~QGVNavStyleCAD()
47
void QGVNavStyleCAD::handleKeyReleaseEvent(QKeyEvent *event)
50
if ( ((event->key() == Qt::Key_Control) ||
51
(event->key() == Qt::Key_Shift)) && zoomingActive) {
57
if ((event->key() == Qt::Key_Control) && panningActive) {
63
void QGVNavStyleCAD::handleMousePressEvent(QMouseEvent *event)
65
// Base::Console().Message("QGVNSCAD::handleMousePressEvent() - button: %d\n", event->button());
66
if (event->button() == Qt::MiddleButton) {
67
startClick(Qt::MiddleButton); //for MMB center view
70
//zoom mode 2 Control + Shift + RMB click
71
if ((event->button() == Qt::RightButton) &&
72
QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
73
startClick(Qt::RightButton);
76
//pan mode 2 Control + RMB click
77
if ((event->button() == Qt::RightButton) &&
78
QApplication::keyboardModifiers() == Qt::ControlModifier) {
79
startClick(Qt::RightButton);
83
void QGVNavStyleCAD::handleMouseMoveEvent(QMouseEvent *event)
85
if (getViewer()->isBalloonPlacing()) {
86
balloonCursorMovement(event);
90
//if the mouse moves between press and release, then it isn't a click
96
//pan mode 1 - MMB + move
97
if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
102
startPan(event->pos());
107
//pan mode 2 - CNTL + RMB click + move
108
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
112
} else if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
114
startPan(event->pos());
118
//zoom mode 2 - CNTL + SHIFT + RMB click + move
119
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
120
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
122
zoom(mouseZoomFactor(event->pos()));
124
} else if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
125
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
127
startZoom(event->pos());
132
void QGVNavStyleCAD::handleMouseReleaseEvent(QMouseEvent *event)
134
// Base::Console().Message("QGVNSCAD::handleMouseReleaseEvent() - button: %d\n", event->button());
135
if (getViewer()->isBalloonPlacing()) {
136
placeBalloon(event->pos());
139
if (event->button() == Qt::MiddleButton) {
140
if (m_clickPending && (m_clickButton == Qt::MiddleButton)) {
142
getViewer()->centerOn(getViewer()->mapToScene(event->pos()));
145
//pan mode 1 hold MMB + mouse move
152
//zoom mode 2 Control + Shift + RMB click
153
if ((event->button() == Qt::RightButton) &&
154
QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
155
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
157
(m_clickButton == Qt::RightButton)) {
159
m_zoomPending = true;
164
//pan mode 2 starts with Control + RMB click
165
if ((event->button() == Qt::RightButton) &&
166
QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
168
(m_clickButton == Qt::RightButton)) {
175
bool QGVNavStyleCAD::allowContextMenu(QContextMenuEvent *event)
177
// Base::Console().Message("QGVNSCAD::allowContextMenu()\n");
178
if (event->reason() == QContextMenuEvent::Mouse) {
179
//must check for a button combination involving context menu button
180
if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ||
181
(QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
182
QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) ) {
183
//CNTL or CNTL+Shift down - don't allow context menu
190
} // namespace TechDrawGui