FreeCAD

Форк
0
/
QGVNavStyleCAD.cpp 
190 строк · 6.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com>               *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <QApplication>
26
# include <QGuiApplication>
27
# include <QMouseEvent>
28
#endif
29

30
#include "QGVNavStyleCAD.h"
31
#include "QGVPage.h"
32

33

34
using namespace TechDrawGui;
35

36
namespace TechDrawGui {
37

38
QGVNavStyleCAD::QGVNavStyleCAD(QGVPage* qgvp) :
39
    QGVNavStyle(qgvp)
40
{
41
}
42

43
QGVNavStyleCAD::~QGVNavStyleCAD()
44
{
45
}
46

47
void QGVNavStyleCAD::handleKeyReleaseEvent(QKeyEvent *event)
48
{
49
    //zoom mode 2
50
    if ( ((event->key() == Qt::Key_Control) ||
51
          (event->key() == Qt::Key_Shift)) && zoomingActive) {
52
        stopZoom();
53
        event->accept();
54
    }
55

56
    //pan mode 2
57
    if ((event->key() == Qt::Key_Control) && panningActive) {
58
        stopPan();
59
        event->accept();
60
    }
61
}
62

63
void QGVNavStyleCAD::handleMousePressEvent(QMouseEvent *event)
64
{
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
68
    }
69

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);
74
    }
75

76
    //pan mode 2 Control + RMB click
77
    if ((event->button() == Qt::RightButton) &&
78
        QApplication::keyboardModifiers() == Qt::ControlModifier) {
79
        startClick(Qt::RightButton);
80
    }
81
}
82

83
void QGVNavStyleCAD::handleMouseMoveEvent(QMouseEvent *event)
84
{
85
    if (getViewer()->isBalloonPlacing()) {
86
        balloonCursorMovement(event);
87
        return;
88
    }
89

90
    //if the mouse moves between press and release, then it isn't a click
91
    if (m_clickPending) {
92
        stopClick();
93
        return;
94
    }
95

96
    //pan mode 1 - MMB + move
97
    if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
98
        if (panningActive) {
99
            pan(event->pos());
100
            event->accept();
101
        } else {
102
            startPan(event->pos());
103
            event->accept();
104
        }
105
    }
106

107
    //pan mode 2 - CNTL + RMB click + move
108
    if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
109
        panningActive) {
110
        pan(event->pos());
111
        event->accept();
112
    } else if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
113
        m_panPending) {
114
        startPan(event->pos());
115
        event->accept();
116
    }
117

118
    //zoom mode 2 - CNTL + SHIFT + RMB click + move
119
    if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
120
        QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
121
        zoomingActive) {
122
        zoom(mouseZoomFactor(event->pos()));
123
        event->accept();
124
    } else if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
125
        QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) &&
126
        m_zoomPending) {
127
        startZoom(event->pos());
128
        event->accept();
129
    }
130
}
131

132
void QGVNavStyleCAD::handleMouseReleaseEvent(QMouseEvent *event)
133
{
134
//    Base::Console().Message("QGVNSCAD::handleMouseReleaseEvent() - button: %d\n", event->button());
135
    if (getViewer()->isBalloonPlacing()) {
136
        placeBalloon(event->pos());
137
    }
138

139
    if (event->button() == Qt::MiddleButton) {
140
        if (m_clickPending && (m_clickButton == Qt::MiddleButton)) {
141
            stopClick();
142
            getViewer()->centerOn(getViewer()->mapToScene(event->pos()));
143
            event->accept();
144
        }
145
        //pan mode 1 hold MMB + mouse move
146
        if (panningActive) {
147
            stopPan();
148
            event->accept();
149
        }
150
    }
151

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) &&
156
         m_clickPending &&
157
        (m_clickButton == Qt::RightButton)) {
158
        stopClick();
159
        m_zoomPending = true;
160
        event->accept();
161
        return;
162
    }
163

164
    //pan mode 2 starts with Control + RMB click
165
    if ((event->button() == Qt::RightButton) &&
166
         QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
167
         m_clickPending &&
168
        (m_clickButton == Qt::RightButton)) {
169
        stopClick();
170
        m_panPending = true;
171
        event->accept();
172
    }
173
}
174

175
bool QGVNavStyleCAD::allowContextMenu(QContextMenuEvent *event)
176
{
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
184
            return false;
185
        }
186
    }
187
    return true;
188
}
189

190
}  // namespace TechDrawGui
191

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.