FreeCAD

Форк
0
/
QGVNavStyleTouchpad.cpp 
129 строк · 4.0 Кб
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 "QGVNavStyleTouchpad.h"
31
#include "QGVPage.h"
32

33

34
using namespace TechDrawGui;
35

36
namespace TechDrawGui {
37

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

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

47
void QGVNavStyleTouchpad::handleKeyPressEvent(QKeyEvent *event)
48
{
49
    if (event->key() == Qt::Key_PageUp) {
50
        zoomIn();
51
        event->accept();
52
        return;
53
    }
54

55
    if (event->key() == Qt::Key_PageDown) {
56
        zoomOut();
57
        event->accept();
58
        return;
59
    }
60

61
    QGVNavStyle::handleKeyPressEvent(event);
62
}
63

64
void QGVNavStyleTouchpad::handleKeyReleaseEvent(QKeyEvent *event)
65
{
66
//    Q_UNUSED(event)
67
    if (event->key() == Qt::Key_Shift) {
68
        if (panningActive) {
69
            stopPan();
70
        }
71
        if (zoomingActive) {
72
            stopZoom();
73
        }
74
        event->accept();
75
    }
76

77
    if (event->key() == Qt::Key_Control) {
78
        stopZoom();
79
        event->accept();
80
    }
81

82
}
83

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

91
    if (QApplication::keyboardModifiers() == Qt::ShiftModifier) {
92
        //if shift is down then we are panning
93
        if (panningActive) {
94
            pan(event->pos());
95
        } else {
96
            startPan(event->pos());
97
        }
98
        event->accept();
99
        return;
100
    }
101

102
    if (QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier) &&
103
        QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) ) {
104
        //if control and shift are down, then we are zooming
105
        if (zoomingActive) {
106
            zoom(mouseZoomFactor(event->pos()));
107
        } else {
108
            startZoom(event->pos());
109
        }
110
        event->accept();
111
        return;
112
    }
113

114
    // if the mouse moves, but we are not zooming or panning, then we should make
115
    // sure that zoom and pan are turned off.
116
    stopPan();
117
    stopZoom();
118
}
119

120
void QGVNavStyleTouchpad::setAnchor()
121
{
122
    //this navigation style can not anchor under mouse since mouse is moving as part of zoom action
123
    if (m_viewer) {
124
        m_viewer->setResizeAnchor(QGraphicsView::AnchorViewCenter);
125
        m_viewer->setTransformationAnchor(QGraphicsView::AnchorViewCenter);
126
    }
127
}
128

129
}  //namespace TechDrawGui
130

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

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

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

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