Commit 26fa00c5f232f2213f50bb6e19620676c3afc94e
1 parent
c427bc0a3a
Exists in
master
and in
2 other branches
출력 형식 변경
Showing
3 changed files
with
60 additions
and
33 deletions
Show diff stats
app/gui/packet/mainwindow.cpp
@@ -22,30 +22,58 @@ MainWindow::MainWindow(QWidget *parent) : | @@ -22,30 +22,58 @@ MainWindow::MainWindow(QWidget *parent) : | ||
22 | connect(sock, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); | 22 | connect(sock, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); |
23 | 23 | ||
24 | ui->controlTable->setRowCount(sizeof(oven_control_t) / sizeof(U16)); | 24 | ui->controlTable->setRowCount(sizeof(oven_control_t) / sizeof(U16)); |
25 | - ui->controlTable->setColumnCount(3); | ||
26 | - ui->controlTable->setHorizontalHeaderLabels(QString("Address,Value,Description").split(",")); | 25 | + ui->controlTable->setColumnCount(4); |
26 | + ui->controlTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(",")); | ||
27 | 27 | ||
28 | for (int row = 0; row < ui->controlTable->rowCount(); row++) | 28 | for (int row = 0; row < ui->controlTable->rowCount(); row++) |
29 | { | 29 | { |
30 | - ui->controlTable->setItem(row, 0, new QTableWidgetItem(QString("").sprintf("0x%04X", row))); | 30 | + QTableWidgetItem *witem = new QTableWidgetItem(QString("").sprintf("0x%04X", row)); |
31 | + witem->setTextAlignment(Qt::AlignCenter); | ||
32 | + | ||
33 | + ui->controlTable->setItem(row, 0, witem); | ||
34 | + | ||
31 | 35 | ||
32 | TableValue *item = new TableValue; | 36 | TableValue *item = new TableValue; |
33 | item->setText("0x0000"); | 37 | item->setText("0x0000"); |
38 | + item->setMargin(3); | ||
39 | + item->setAlignment(Qt::AlignCenter); | ||
34 | ui->controlTable->setCellWidget(row, 1, item); | 40 | ui->controlTable->setCellWidget(row, 1, item); |
41 | + | ||
42 | + item = new TableValue; | ||
43 | + item->setText("0"); | ||
44 | + item->setMargin(3); | ||
45 | + item->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | ||
46 | + ui->controlTable->setCellWidget(row, 2, item); | ||
35 | } | 47 | } |
36 | 48 | ||
49 | + ui->controlTable->resizeColumnToContents(0); | ||
50 | + ui->controlTable->resizeColumnToContents(1); | ||
51 | + | ||
37 | ui->stateTable->setRowCount(sizeof(oven_state_t) / sizeof(U16)); | 52 | ui->stateTable->setRowCount(sizeof(oven_state_t) / sizeof(U16)); |
38 | - ui->stateTable->setColumnCount(3); | ||
39 | - ui->stateTable->setHorizontalHeaderLabels(QString("Address,Value,Description").split(",")); | 53 | + ui->stateTable->setColumnCount(4); |
54 | + ui->stateTable->setHorizontalHeaderLabels(QString("Addr,Value,Value,Description").split(",")); | ||
40 | 55 | ||
41 | for (int row = 0; row < ui->stateTable->rowCount(); row++) | 56 | for (int row = 0; row < ui->stateTable->rowCount(); row++) |
42 | { | 57 | { |
43 | - ui->stateTable->setItem(row, 0, new QTableWidgetItem(QString().sprintf("0x%04X", row))); | 58 | + QTableWidgetItem *witem = new QTableWidgetItem(QString("").sprintf("0x%04X", row)); |
59 | + witem->setTextAlignment(Qt::AlignCenter); | ||
60 | + ui->stateTable->setItem(row, 0, witem); | ||
44 | 61 | ||
45 | TableValue *item = new TableValue; | 62 | TableValue *item = new TableValue; |
46 | item->setText("0x0000"); | 63 | item->setText("0x0000"); |
64 | + item->setMargin(3); | ||
65 | + item->setAlignment(Qt::AlignCenter); | ||
47 | ui->stateTable->setCellWidget(row, 1, item); | 66 | ui->stateTable->setCellWidget(row, 1, item); |
67 | + | ||
68 | + item = new TableValue; | ||
69 | + item->setText("0"); | ||
70 | + item->setMargin(3); | ||
71 | + item->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | ||
72 | + ui->stateTable->setCellWidget(row, 2, item); | ||
48 | } | 73 | } |
74 | + | ||
75 | + ui->stateTable->resizeColumnToContents(0); | ||
76 | + ui->stateTable->resizeColumnToContents(1); | ||
49 | } | 77 | } |
50 | 78 | ||
51 | MainWindow::~MainWindow() | 79 | MainWindow::~MainWindow() |
@@ -107,7 +135,7 @@ void MainWindow::updateControl(oven_control_t *control) | @@ -107,7 +135,7 @@ void MainWindow::updateControl(oven_control_t *control) | ||
107 | { | 135 | { |
108 | *(base + row) = o; | 136 | *(base + row) = o; |
109 | TableValue *val = (TableValue *) ui->controlTable->cellWidget(row, 1); | 137 | TableValue *val = (TableValue *) ui->controlTable->cellWidget(row, 1); |
110 | - val->setText(QString().sprintf("0x%04X", o)); | 138 | + val->setText(QString().sprintf("0x%04X - %d", o, o)); |
111 | } | 139 | } |
112 | } | 140 | } |
113 | } | 141 | } |
@@ -124,7 +152,7 @@ void MainWindow::updateState(oven_state_t *state) | @@ -124,7 +152,7 @@ void MainWindow::updateState(oven_state_t *state) | ||
124 | { | 152 | { |
125 | *(base + row) = o; | 153 | *(base + row) = o; |
126 | TableValue *val = (TableValue *) ui->stateTable->cellWidget(row, 1); | 154 | TableValue *val = (TableValue *) ui->stateTable->cellWidget(row, 1); |
127 | - val->setText(QString().sprintf("0x%04X", o)); | 155 | + val->setText(QString().sprintf("0x%04X - %d", o, o)); |
128 | } | 156 | } |
129 | } | 157 | } |
130 | } | 158 | } |
app/gui/packet/tablevalue.cpp
@@ -4,31 +4,34 @@ | @@ -4,31 +4,34 @@ | ||
4 | 4 | ||
5 | #include <QtDebug> | 5 | #include <QtDebug> |
6 | 6 | ||
7 | +TableValue::TableValue() | ||
8 | +{ | ||
9 | +// timer.setSingleShot(true); | ||
10 | + connect(&animationTimer, SIGNAL(timeout()), this, SLOT(updateColor())); | ||
11 | +// connect(&timer, SIGNAL(timeout()), &animationTimer, SLOT(stop())); | ||
12 | +// connect(&timer, SIGNAL(timeout()), this, SLOT(updateColor())); | ||
13 | +// setAutoFillBackground(true); | ||
14 | +} | ||
15 | + | ||
7 | void TableValue::setText(const QString &str) | 16 | void TableValue::setText(const QString &str) |
8 | { | 17 | { |
9 | QLabel::setText(str); | 18 | QLabel::setText(str); |
10 | - timer.start(2000); | 19 | + time = QTime::currentTime().addSecs(2); |
11 | animationTimer.start(33); | 20 | animationTimer.start(33); |
12 | 21 | ||
13 | - updateColor(); | 22 | +// updateColor(); |
14 | } | 23 | } |
15 | 24 | ||
16 | void TableValue::updateColor() | 25 | void TableValue::updateColor() |
17 | { | 26 | { |
18 | - int remain = timer.remainingTime(); | ||
19 | - if (remain < 0) | ||
20 | - remain = 0; | ||
21 | - | ||
22 | - if (remain > 2000) | ||
23 | - remain = 2000; | ||
24 | - | ||
25 | - qreal percentage = ((qreal) remain / 2000) * 0.5; | ||
26 | - int b = 255 * percentage; | ||
27 | - if (b < 0) | ||
28 | - b = 0; | ||
29 | - | ||
30 | - if (b > 255) | ||
31 | - b = 255; | ||
32 | - | ||
33 | - setStyleSheet(QString().sprintf("background-color: rgba(255, 0, 0, %d); color: rgb(0, 0, 0)", b)); | 27 | + int remain = qBound(0, QTime::currentTime().msecsTo(time), 2000); |
28 | + int a = 255 * remain / 4000; | ||
29 | + | ||
30 | + if (a > 1) | ||
31 | + setStyleSheet(QString().sprintf("background-color: rgba(255, 0, 0, %d)", a)); | ||
32 | + else | ||
33 | + { | ||
34 | + setStyleSheet("background-color: rgba(255, 0, 0, 0)"); | ||
35 | + animationTimer.stop(); | ||
36 | + } | ||
34 | } | 37 | } |
app/gui/packet/tablevalue.h
@@ -6,23 +6,19 @@ | @@ -6,23 +6,19 @@ | ||
6 | #include <QLabel> | 6 | #include <QLabel> |
7 | #include <QTableWidgetItem> | 7 | #include <QTableWidgetItem> |
8 | #include <QTimer> | 8 | #include <QTimer> |
9 | +#include <QTime> | ||
9 | 10 | ||
10 | class TableValue : public QLabel | 11 | class TableValue : public QLabel |
11 | { | 12 | { |
12 | Q_OBJECT | 13 | Q_OBJECT |
13 | 14 | ||
14 | public: | 15 | public: |
15 | - explicit TableValue() | ||
16 | - { | ||
17 | - timer.setSingleShot(true); | ||
18 | - connect(&animationTimer, SIGNAL(timeout()), this, SLOT(updateColor())); | ||
19 | - connect(&timer, SIGNAL(timeout()), &animationTimer, SLOT(stop())); | ||
20 | - connect(&timer, SIGNAL(timeout()), this, SLOT(updateColor())); | ||
21 | - } | 16 | + explicit TableValue(); |
22 | 17 | ||
23 | void setText(const QString &text); | 18 | void setText(const QString &text); |
24 | 19 | ||
25 | private: | 20 | private: |
21 | + QTime time; | ||
26 | QTimer timer; | 22 | QTimer timer; |
27 | QTimer animationTimer; | 23 | QTimer animationTimer; |
28 | 24 |