File size: 3,858 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***************************************************************************
 *   Copyright (c) 2022 WandererFan <wandererfan@gmail.com>                *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/

#ifndef COMPASSWIDGET_H
#define COMPASSWIDGET_H

#include <QDoubleSpinBox>
#include <QKeyEvent>
#include <QSize>
#include <QWidget>

QT_BEGIN_NAMESPACE
class QLabel;
class QHBoxLayout;
class QPushButton;
class QVBoxLayout;
QT_END_NAMESPACE

namespace Gui {
class QuantitySpinBox;
}

namespace TechDrawGui
{

class CompassDialWidget;

class CompassWidget: public QWidget
{
    Q_OBJECT
    Q_PROPERTY(double angle READ dialAngle WRITE setDialAngle NOTIFY angleChanged)

public:
    CompassWidget(QWidget* parent = nullptr);
    ~CompassWidget() override = default;

    QSize sizeHint() const override;
    QSize minimumSizeHint() const override;
    bool eventFilter(QObject* target, QEvent* event) override;
    void retranslateUi();
    double dialAngle() const { return m_angle; }
    double value() const { return m_angle; }
    double positiveValue() { return m_angle < 0.0 ? m_angle + 360.0 : m_angle; }
    void setDialAngle(double newAngle);
    void setAdvanceIncrement(double newIncrement);
    double advanceIncrement() const { return m_advanceIncrement; }

Q_SIGNALS:
    void angleChanged(double angle);
    void angleSet(double angle);

public Q_SLOTS:
    void slotChangeAngle(double angle) { setDialAngle(angle); }
    void slotSpinBoxEnter(double newAngle);
    void resetAngle() { setDialAngle(0.0); }//conventional angles
    void setToEast() { setDialAngle(0.0); }
    void setToNorth() { setDialAngle(90.0); }
    void setToWest() { setDialAngle(180.0); }
    void setToSouth() { setDialAngle(270.0); }
    void slotCWAdvance();
    void slotCCWAdvance();

protected:
    void paintEvent(QPaintEvent* event) override;
    void buildWidget();
    double changeAngleConvention(double CWY) const;

private:
    QRect m_rect;
    int m_minimumWidth;
    int m_minimumHeight;
    int m_defaultMargin;
    double m_angle;
    double m_advanceIncrement;

    QVBoxLayout* compassLayout;
    QHBoxLayout* compassDialLayout;
    QHBoxLayout* compassControlLayout;

    CompassDialWidget* compassDial;
    //    DoubleSpinBoxNoEnter* dsbAngle;
    Gui::QuantitySpinBox* dsbAngle;
    QLabel* compassControlLabel;
    QPushButton* pbCWAdvance;
    QPushButton* pbCCWAdvance;
};

}//namespace TechDrawGui
#endif// COMPASSWIDGET_H