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
|
#include "peripheralsview.h"
#include "ui_peripheralsview.h"
PeripheralsView::PeripheralsView(QWidget *parent) :
QWidget(parent),
ui(new Ui::PeripheralsView)
{
ui->setupUi(this);
connect(ui->dialRed, SIGNAL(valueChanged(int)), ui->spinRed, SLOT(setValue(int)));
connect(ui->dialGreen, SIGNAL(valueChanged(int)), ui->spinGreen, SLOT(setValue(int)));
connect(ui->dialBlue, SIGNAL(valueChanged(int)), ui->spinBlue, SLOT(setValue(int)));
connect(ui->spinRed, SIGNAL(valueChanged(int)), ui->dialRed, SLOT(setValue(int)));
connect(ui->spinGreen, SIGNAL(valueChanged(int)), ui->dialGreen, SLOT(setValue(int)));
connect(ui->spinBlue, SIGNAL(valueChanged(int)), ui->dialBlue, SLOT(setValue(int)));
}
PeripheralsView::~PeripheralsView()
{
delete ui;
}
void PeripheralsView::setup(const machine::PeripSpiLed *perip_spi_led) {
int val;
connect(ui->spinRed, SIGNAL(valueChanged(int)), perip_spi_led, SLOT(red_knob_update(int)));
connect(ui->spinGreen, SIGNAL(valueChanged(int)), perip_spi_led, SLOT(green_knob_update(int)));
connect(ui->spinBlue, SIGNAL(valueChanged(int)), perip_spi_led, SLOT(blue_knob_update(int)));
val = ui->spinRed->value();
ui->spinRed->setValue(val - 1);
ui->spinRed->setValue(val);
val = ui->spinGreen->value();
ui->spinGreen->setValue(val - 1);
ui->spinGreen->setValue(val);
val = ui->spinBlue->value();
ui->spinBlue->setValue(val - 1);
ui->spinBlue->setValue(val);
ui->labelRgb1->setAutoFillBackground(true);
ui->labelRgb2->setAutoFillBackground(true);
connect(perip_spi_led, SIGNAL(led_line_changed(uint)), this, SLOT(led_line_changed(uint)));
connect(perip_spi_led, SIGNAL(led_rgb1_changed(int)), this, SLOT(led_rgb1_changed(int)));
connect(perip_spi_led, SIGNAL(led_rgb2_changed(int)), this, SLOT(led_rgb2_changed(int)));
led_line_changed(0);
led_rgb1_changed(0);
led_rgb2_changed(0);
}
void PeripheralsView::led_line_changed(uint val) {
QString s, t;
s = QString::number(val, 16);
t.fill('0', 8 - s.count());
ui->lineEditHex->setText(t + s);
s = QString::number(val, 10);
ui->lineEditDec->setText(s);
s = QString::number(val, 2);
t.fill('0', 32 - s.count());
ui->lineEditBin->setText(t + s);
}
static void set_widget_background_color(QWidget *w, int val) {
int r = (val >> 16) & 0xff;
int g = (val >> 8) & 0xff;
int b = (val >> 0) & 0xff;
QPalette::ColorRole brole = w->backgroundRole();
QPalette pal = w->palette();
pal.setColor(brole, QColor(r, g, b));
w->setPalette(pal);
}
void PeripheralsView::led_rgb1_changed(int val) {
QString s, t;
s = QString::number(val, 16);
t.fill('0', 8 - s.count());
ui->lineEditRgb1->setText(t + s);
set_widget_background_color(ui->labelRgb1, val);
}
void PeripheralsView::led_rgb2_changed(int val) {
QString s, t;
s = QString::number(val, 16);
t.fill('0', 8 - s.count());
ui->lineEditRgb2->setText(t + s);
set_widget_background_color(ui->labelRgb2, val);
}
|