From 26fa00c5f232f2213f50bb6e19620676c3afc94e Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 7 Mar 2017 21:22:34 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gui/packet/mainwindow.cpp | 44 +++++++++++++++++++++++++++++++++++-------- app/gui/packet/tablevalue.cpp | 39 ++++++++++++++++++++------------------ app/gui/packet/tablevalue.h | 10 +++------- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/app/gui/packet/mainwindow.cpp b/app/gui/packet/mainwindow.cpp index ee29c28..25b9874 100644 --- a/app/gui/packet/mainwindow.cpp +++ b/app/gui/packet/mainwindow.cpp @@ -22,30 +22,58 @@ MainWindow::MainWindow(QWidget *parent) : connect(sock, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); ui->controlTable->setRowCount(sizeof(oven_control_t) / sizeof(U16)); - ui->controlTable->setColumnCount(3); - ui->controlTable->setHorizontalHeaderLabels(QString("Address,Value,Description").split(",")); + ui->controlTable->setColumnCount(4); + ui->controlTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(",")); for (int row = 0; row < ui->controlTable->rowCount(); row++) { - ui->controlTable->setItem(row, 0, new QTableWidgetItem(QString("").sprintf("0x%04X", row))); + QTableWidgetItem *witem = new QTableWidgetItem(QString("").sprintf("0x%04X", row)); + witem->setTextAlignment(Qt::AlignCenter); + + ui->controlTable->setItem(row, 0, witem); + TableValue *item = new TableValue; item->setText("0x0000"); + item->setMargin(3); + item->setAlignment(Qt::AlignCenter); ui->controlTable->setCellWidget(row, 1, item); + + item = new TableValue; + item->setText("0"); + item->setMargin(3); + item->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->controlTable->setCellWidget(row, 2, item); } + ui->controlTable->resizeColumnToContents(0); + ui->controlTable->resizeColumnToContents(1); + ui->stateTable->setRowCount(sizeof(oven_state_t) / sizeof(U16)); - ui->stateTable->setColumnCount(3); - ui->stateTable->setHorizontalHeaderLabels(QString("Address,Value,Description").split(",")); + ui->stateTable->setColumnCount(4); + ui->stateTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(",")); for (int row = 0; row < ui->stateTable->rowCount(); row++) { - ui->stateTable->setItem(row, 0, new QTableWidgetItem(QString().sprintf("0x%04X", row))); + QTableWidgetItem *witem = new QTableWidgetItem(QString("").sprintf("0x%04X", row)); + witem->setTextAlignment(Qt::AlignCenter); + ui->stateTable->setItem(row, 0, witem); TableValue *item = new TableValue; item->setText("0x0000"); + item->setMargin(3); + item->setAlignment(Qt::AlignCenter); ui->stateTable->setCellWidget(row, 1, item); + + item = new TableValue; + item->setText("0"); + item->setMargin(3); + item->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + ui->stateTable->setCellWidget(row, 2, item); } + + ui->stateTable->resizeColumnToContents(0); + ui->stateTable->resizeColumnToContents(1); } MainWindow::~MainWindow() @@ -107,7 +135,7 @@ void MainWindow::updateControl(oven_control_t *control) { *(base + row) = o; TableValue *val = (TableValue *) ui->controlTable->cellWidget(row, 1); - val->setText(QString().sprintf("0x%04X", o)); + val->setText(QString().sprintf("0x%04X - %d", o, o)); } } } @@ -124,7 +152,7 @@ void MainWindow::updateState(oven_state_t *state) { *(base + row) = o; TableValue *val = (TableValue *) ui->stateTable->cellWidget(row, 1); - val->setText(QString().sprintf("0x%04X", o)); + val->setText(QString().sprintf("0x%04X - %d", o, o)); } } } diff --git a/app/gui/packet/tablevalue.cpp b/app/gui/packet/tablevalue.cpp index d022d4c..3e5970c 100644 --- a/app/gui/packet/tablevalue.cpp +++ b/app/gui/packet/tablevalue.cpp @@ -4,31 +4,34 @@ #include +TableValue::TableValue() +{ +// timer.setSingleShot(true); + connect(&animationTimer, SIGNAL(timeout()), this, SLOT(updateColor())); +// connect(&timer, SIGNAL(timeout()), &animationTimer, SLOT(stop())); +// connect(&timer, SIGNAL(timeout()), this, SLOT(updateColor())); +// setAutoFillBackground(true); +} + void TableValue::setText(const QString &str) { QLabel::setText(str); - timer.start(2000); + time = QTime::currentTime().addSecs(2); animationTimer.start(33); - updateColor(); +// updateColor(); } void TableValue::updateColor() { - int remain = timer.remainingTime(); - if (remain < 0) - remain = 0; - - if (remain > 2000) - remain = 2000; - - qreal percentage = ((qreal) remain / 2000) * 0.5; - int b = 255 * percentage; - if (b < 0) - b = 0; - - if (b > 255) - b = 255; - - setStyleSheet(QString().sprintf("background-color: rgba(255, 0, 0, %d); color: rgb(0, 0, 0)", b)); + int remain = qBound(0, QTime::currentTime().msecsTo(time), 2000); + int a = 255 * remain / 4000; + + if (a > 1) + setStyleSheet(QString().sprintf("background-color: rgba(255, 0, 0, %d)", a)); + else + { + setStyleSheet("background-color: rgba(255, 0, 0, 0)"); + animationTimer.stop(); + } } diff --git a/app/gui/packet/tablevalue.h b/app/gui/packet/tablevalue.h index 2696d31..8926423 100644 --- a/app/gui/packet/tablevalue.h +++ b/app/gui/packet/tablevalue.h @@ -6,23 +6,19 @@ #include #include #include +#include class TableValue : public QLabel { Q_OBJECT public: - explicit TableValue() - { - timer.setSingleShot(true); - connect(&animationTimer, SIGNAL(timeout()), this, SLOT(updateColor())); - connect(&timer, SIGNAL(timeout()), &animationTimer, SLOT(stop())); - connect(&timer, SIGNAL(timeout()), this, SLOT(updateColor())); - } + explicit TableValue(); void setText(const QString &text); private: + QTime time; QTimer timer; QTimer animationTimer; -- 2.1.4