FreeCAD

Форк
0
/
QGVNavStyleOpenSCAD.cpp 
156 строк · 4.8 Кб
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 <QGuiApplication>
26
# include <QMouseEvent>
27
#endif
28

29
#include "QGVNavStyleOpenSCAD.h"
30
#include "QGVPage.h"
31

32

33
using namespace TechDrawGui;
34

35
namespace TechDrawGui {
36

37
QGVNavStyleOpenSCAD::QGVNavStyleOpenSCAD(QGVPage *qgvp) :
38
    QGVNavStyle(qgvp)
39
{
40
}
41

42
QGVNavStyleOpenSCAD::~QGVNavStyleOpenSCAD()
43
{
44
}
45

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

55
void QGVNavStyleOpenSCAD::handleMousePressEvent(QMouseEvent *event)
56
{
57
    if (event->button() == Qt::RightButton) {
58
        startClick(Qt::RightButton);
59
    }
60
}
61

62
void QGVNavStyleOpenSCAD::handleMouseMoveEvent(QMouseEvent *event)
63
{
64
    if (getViewer()->isBalloonPlacing()) {
65
        balloonCursorMovement(event);
66
        return;
67
    }
68

69
    //if the mouse moves between press and release, then it isn't a click
70
    if (m_clickPending) {
71
        stopClick();
72
        return;
73
    }
74

75
    if (QGuiApplication::mouseButtons() & Qt::RightButton &&
76
        !QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
77
        //pan mode - RMB + move
78
        if (panningActive) {
79
            pan(event->pos());
80
        } else {
81
            startPan(event->pos());
82
        }
83
        event->accept();
84
    }
85

86
    if (QGuiApplication::mouseButtons() & Qt::MiddleButton) {
87
        //zoom mode 1 - MMB + move
88
        if (zoomingActive) {
89
            zoom(mouseZoomFactor(event->pos()));
90
        } else {
91
            startZoom(event->pos());
92
        }
93
        event->accept();
94
    }
95

96
    if ((QGuiApplication::mouseButtons() & Qt::RightButton) &&
97
         QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
98
        //zoom mode 2 - SHIFT + RMB + move
99
        if (zoomingActive) {
100
            zoom(mouseZoomFactor(event->pos()));
101
        } else {
102
            startZoom(event->pos());
103
        }
104
        event->accept();
105
    }
106
}
107

108
void QGVNavStyleOpenSCAD::handleMouseReleaseEvent(QMouseEvent *event)
109
{
110
    if (getViewer()->isBalloonPlacing()) {
111
        placeBalloon(event->pos());
112
    }
113

114
    if ((event->button() == Qt::RightButton) &&
115
         m_clickPending &&
116
        (m_clickButton == Qt::RightButton)) {
117
        stopClick();
118
        pseudoContextEvent();
119
        event->accept();
120
        return;
121
    }
122

123
    if ((event->button() == Qt::RightButton) && panningActive) {
124
        stopPan();
125
        event->accept();
126
    }
127

128
    if ((event->button() == Qt::RightButton) && zoomingActive) {
129
        stopZoom();
130
        event->accept();
131
    }
132

133
    if ((event->button() == Qt::MiddleButton) && zoomingActive) {
134
        stopZoom();
135
        event->accept();
136
    }
137
}
138

139
bool QGVNavStyleOpenSCAD::allowContextMenu(QContextMenuEvent *event)
140
{
141
//    Base::Console().Message("QGVNSCAD::allowContextMenu()\n");
142
    if (event->reason() == QContextMenuEvent::Mouse) {
143
        //must check for a button combination involving context menu button
144
        if (QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
145
            //Shift down - don't allow context menu
146
            return false;
147
        } else if (m_clickPending) {
148
            //context menu request to be handled by button release
149
            return false;
150
        }
151
    }
152
    return true;
153
}
154

155

156
}  // namespace TechDrawGui
157

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

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

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

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