-
Notifications
You must be signed in to change notification settings - Fork 12
/
Constellation.h
202 lines (165 loc) · 4.01 KB
/
Constellation.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//
// 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 CONSTELLATION_H
#define CONSTELLATION_H
#include <QFrame>
#include <cmath>
#include <complex.h>
#include <vector>
#include <tgmath.h>
#include <sigutils/types.h>
#include "ThrottleableWidget.h"
#define CONSTELLATION_DEFAULT_BACKGROUND_COLOR QColor(0, 0, 0)
#define CONSTELLATION_DEFAULT_FOREGROUND_COLOR QColor(255, 255, 255)
#define CONSTELLATION_DEFAULT_AXES_COLOR QColor(128, 128, 128)
#define CONSTELLATION_DEFAULT_HISTORY_SIZE 256
class Constellation : public ThrottleableWidget
{
Q_OBJECT
Q_PROPERTY(
unsigned int orderHint
READ getOrderHint
WRITE setOrderHint
NOTIFY orderHintChanged)
Q_PROPERTY(
QColor backgroundColor
READ getBackgroundColor
WRITE setBackgroundColor
NOTIFY backgroundColorChanged)
Q_PROPERTY(
QColor foregroundColor
READ getForegroundColor
WRITE setForegroundColor
NOTIFY foregroundColorChanged)
Q_PROPERTY(
QColor axesColor
READ getAxesColor
WRITE setAxesColor
NOTIFY axesColorChanged)
// Drawing area properties
QPixmap contentPixmap;
QPixmap axesPixmap;
QSize geometry;
// Data
std::vector<SUCOMPLEX> history;
unsigned int amount = 0;
unsigned int ptr = 0;
// Properties
QColor background;
QColor foreground;
QColor axes;
float zoom = .5f;
unsigned int bits = 2;
bool haveGeometry = false;
bool axesDrawn = false;
SUFLOAT gain = 1.414f;
// Cached data
int ox;
int oy;
int width;
int height;
// Private methods
QPoint floatToScreenPoint(float x, float y);
void recalculateDisplayData(void);
void drawMarkerAt(QPainter &curr, float x, float y);
void drawAxes(void);
void drawConstellation(void);
public:
void
setBackgroundColor(const QColor &c)
{
this->background = c;
this->axesDrawn = false;
this->invalidate();
emit backgroundColorChanged();
}
const QColor &
getBackgroundColor(void) const
{
return this->background;
}
void
setAxesColor(const QColor &c)
{
this->axes = c;
this->axesDrawn = false;
this->invalidate();
emit axesColorChanged();
}
const QColor &
getAxesColor(void) const
{
return this->axes;
}
void
setForegroundColor(const QColor &c)
{
this->foreground = c;
this->axesDrawn = false;
this->invalidate();
emit foregroundColorChanged();
}
const QColor &
getForegroundColor(void) const
{
return this->foreground;
}
void
setOrderHint(unsigned int bits)
{
if (this->bits != bits) {
this->bits = bits;
this->axesDrawn = false;
this->invalidate();
emit orderHintChanged();
}
}
unsigned int
getOrderHint(void) const
{
return this->bits;
}
void
getOrderHint(unsigned int &m_bits) const
{
m_bits = this->bits;
}
void
setGain(SUFLOAT gain)
{
this->gain = gain;
}
SUFLOAT
getGain(void) const
{
return this->gain;
}
void setHistorySize(unsigned int length);
void feed(const SUCOMPLEX *samples, unsigned int length);
void draw(void);
void paint(void);
Constellation(QWidget *parent = nullptr);
signals:
void orderHintChanged();
void backgroundColorChanged();
void foregroundColorChanged();
void axesColorChanged();
void axesUpdated();
};
#endif