-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOdometer.cpp
More file actions
170 lines (146 loc) · 4.48 KB
/
Odometer.cpp
File metadata and controls
170 lines (146 loc) · 4.48 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (c) 2016-2021 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include <Pothos/Framework.hpp>
#include "indicator.h"
#include <QVariant>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QMouseEvent>
/***********************************************************************
* |PothosDoc Odometer
*
* The odometer is a numeric entry widget with spin controls for each digit.
* Click on the top half of a digit to increase its value by one,
* and clock on the bottom half of a digit to decrease its value by one.
* The odometer can also be used for display via the setValue slot.
*
* |category /Widgets
* |keywords spin frequency
*
* |param title The name of the value displayed by this widget
* |default "Digit Value"
* |widget StringEntry()
*
* |param fontSize[Font Size] The font size for the digits in the widget.
* |default 12
* |widget SpinBox(minimum=8)
* |preview disable
*
* |param size The number of configurable digits in the widget.
* |default 10
* |widget SpinBox(minimum=1)
* |preview disable
*
* |param value The initial value of this odometer.
* |default 123456789
*
* |param minimum The minimum value of this odometer.
* |default 0.0
*
* |param maximum The maximum value of this odometer.
* |default 1e9
*
* |mode graphWidget
* |factory /widgets/odometer()
* |setter setTitle(title)
* |setter setFontSize(fontSize)
* |setter setSize(size)
* |setter setValueMin(minimum)
* |setter setValueMax(maximum)
* |setter setValue(value)
**********************************************************************/
class Odometer : public QGroupBox, public Pothos::Block
{
Q_OBJECT
public:
static Block *make(void)
{
return new Odometer();
}
Odometer(void):
_indicator(new Indicator())
{
_indicator->setFrameShape(QFrame::NoFrame);
_indicator->setFrameShadow(QFrame::Plain);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(QMargins());
layout->addWidget(_indicator);
this->setStyleSheet("QGroupBox {font-weight: bold;}");
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, setTitle));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, setFontSize));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, setSize));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, widget));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, value));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, setValue));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, setValueMin));
this->registerCall(this, POTHOS_FCN_TUPLE(Odometer, setValueMax));
this->registerSignal("valueChanged");
connect(_indicator, &Indicator::valueChanged, this, &Odometer::handleValueChanged);
}
QWidget *widget(void)
{
return this;
}
void setTitle(const QString &title)
{
QMetaObject::invokeMethod(this, "handleSetTitle", Qt::QueuedConnection, Q_ARG(QString, title));
}
void setFontSize(const int size)
{
QMetaObject::invokeMethod(_indicator, "setFontSize", Qt::QueuedConnection, Q_ARG(int, size));
}
void setSize(const int size)
{
QMetaObject::invokeMethod(_indicator, "setSize", Qt::QueuedConnection, Q_ARG(int, size));
}
qint64 value(void) const
{
return _indicator->value();
}
void setValue(const qint64 value)
{
_indicator->setValue(value);
}
void setValueMin(const qint64 value)
{
_indicator->setValueMin(value);
}
void setValueMax(const qint64 value)
{
_indicator->setValueMax(value);
}
void activate(void)
{
//emit current value when design becomes active
this->emitSignal("valueChanged", this->value());
}
public slots:
QVariant saveState(void) const
{
return qlonglong(this->value());
}
void restoreState(const QVariant &state)
{
this->setValue(state.toLongLong());
}
private slots:
void handleValueChanged(const qint64 value)
{
this->emitSignal("valueChanged", value);
}
void handleSetTitle(const QString &title)
{
QGroupBox::setTitle(title);
}
protected:
void mousePressEvent(QMouseEvent *event)
{
QGroupBox::mousePressEvent(event);
event->ignore(); //allows for dragging from QGroupBox title
}
private:
Indicator *_indicator;
};
static Pothos::BlockRegistry registerOdometer(
"/widgets/odometer", &Odometer::make);
#include "Odometer.moc"