diff options
Diffstat (limited to 'qtmips_gui/peripheralsview.cpp')
-rw-r--r-- | qtmips_gui/peripheralsview.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/qtmips_gui/peripheralsview.cpp b/qtmips_gui/peripheralsview.cpp index 231de90..655b101 100644 --- a/qtmips_gui/peripheralsview.cpp +++ b/qtmips_gui/peripheralsview.cpp @@ -38,4 +38,55 @@ void PeripheralsView::setup(const machine::PeripSpiLed *perip_spi_led) { 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); } |