-
Notifications
You must be signed in to change notification settings - Fork 12
/
FrequencySpinBox.h
119 lines (92 loc) · 2.88 KB
/
FrequencySpinBox.h
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
110
111
112
113
114
115
116
117
118
119
//
// filename: description
// Copyright (C) 2018 Gonzalo José Carracedo Carballal
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>
//
#ifndef FREQUENCYSPINBOX_H
#define FREQUENCYSPINBOX_H
#include <QWidget>
namespace Ui {
class FrequencySpinBox;
}
class FrequencySpinBox : public QWidget
{
Q_OBJECT
public:
enum FrequencyUnitMultiplier {
Femto = -5,
Pico = -4,
Nano = -3,
Micro = -2,
Milli = -1,
None = 0,
Kilo,
Mega,
Giga,
Tera
};
private:
FrequencyUnitMultiplier m_unitMultiplier = None;
QString m_fUnits = "Hz";
bool m_autoUnitMultiplier = true;
qreal m_currValue = 0;
qreal m_max = 18e9;
qreal m_min = 0;
bool m_expectingFirstClick = false;
unsigned int m_uExtraDecimals = 0;
bool m_allowSubMultiples = false;
void connectAll();
void refreshUi();
qreal freqMultiplier() const;
QString freqSuffix() const;
void refreshUiEx(bool setValue);
void setFrequencyUnitMultiplierOnEdit(FrequencyUnitMultiplier);
public:
explicit FrequencySpinBox(QWidget *parent = nullptr);
~FrequencySpinBox();
virtual bool eventFilter(QObject *obj, QEvent *event) override;
void adjustUnitMultiplier();
void setValue(qreal);
qreal value() const;
void setMaximum(qreal);
qreal maximum() const;
void setMinimum(qreal);
qreal minimum() const;
void setExtraDecimals(unsigned int);
unsigned int extraDecimals() const;
void setSubMultiplesAllowed(bool);
bool subMultiplesAllowed() const;
void setAutoUnitMultiplierEnabled(bool);
bool autoUnitMultiplierEnabled() const;
void setFrequencyUnitMultiplier(FrequencyUnitMultiplier UnitMultiplier);
FrequencyUnitMultiplier frequencyUnitMultiplier() const;
void setUnits(QString const units);
QString units() const;
void setEditable(bool);
bool editable() const;
void incFrequencyUnitMultiplier();
void decFrequencyUnitMultiplier();
void setFocus();
signals:
void valueChanged(qreal freq);
public slots:
void onEditingFinished();
void onIncFreqUnitMultiplier();
void onDecFreqUnitMultiplier();
private:
Ui::FrequencySpinBox *ui;
};
#endif // FREQUENCYSPINBOX_H