FreeCAD

Форк
0
/
QGIGhostHighlight.cpp 
97 строк · 3.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2020 WandererFan <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 <QGraphicsSceneEvent>
26
#endif
27

28
#include <Mod/TechDraw/App/DrawUtil.h>
29

30
#include "QGIGhostHighlight.h"
31
#include "PreferencesGui.h"
32
#include "Rez.h"
33

34

35
using namespace TechDrawGui;
36
using namespace TechDraw;
37

38
QGIGhostHighlight::QGIGhostHighlight()
39
{
40
    setInteractive(true);
41
    m_dragging = false;
42

43
    //make the ghost very visible
44
    QFont f(Preferences::labelFontQString());
45
    double fontSize = Preferences::labelFontSizeMM();
46
    setFont(f, fontSize);
47
    setReference("drag");
48
    setStyle(Qt::SolidLine);
49
    setColor(prefSelectColor());
50
    setWidth(Rez::guiX(1.0));
51
    setRadius(10.0);         //placeholder
52
}
53

54
QGIGhostHighlight::~QGIGhostHighlight()
55
{
56

57
}
58

59
void QGIGhostHighlight::mousePressEvent(QGraphicsSceneMouseEvent * event)
60
{
61
//    Base::Console().Message("QGIGhostHighlight::mousePress() - %X\n", this);
62
    if ( (event->button() == Qt::LeftButton) &&
63
        (flags() & QGraphicsItem::ItemIsMovable) ) {
64
            m_dragging = true;
65
            event->accept();
66
    }
67
    QGIHighlight::mousePressEvent(event);
68
}
69

70
void QGIGhostHighlight::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
71
{
72
//    Base::Console().Message("QGIGhostHighlight::mouseRelease() - pos: %s scenePos: %s\n",
73
//                                 DrawUtil::formatVector(pos()).c_str(),
74
//                                 DrawUtil::formatVector(mapToScene(pos())).c_str());
75
    if (m_dragging) {
76
        m_dragging = false;
77
        Q_EMIT positionChange(scenePos());
78
        event->accept();
79
    }
80
    QGIHighlight::mouseReleaseEvent(event);
81
}
82

83
void QGIGhostHighlight::setInteractive(bool state)
84
{
85
    setFlag(QGraphicsItem::ItemIsSelectable, state);
86
    setFlag(QGraphicsItem::ItemIsMovable, state);
87
    setFlag(QGraphicsItem::ItemSendsScenePositionChanges, state);
88
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, state);
89
}
90

91
//radius should scaled, but not Rez::guix()
92
void QGIGhostHighlight::setRadius(double r)
93
{
94
    setBounds(-r, r, r, -r);
95
}
96

97
#include <Mod/TechDraw/Gui/moc_QGIGhostHighlight.cpp>
98

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

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

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

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