-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbeanpacketsplayerwindow.cpp
More file actions
161 lines (134 loc) · 4.92 KB
/
beanpacketsplayerwindow.cpp
File metadata and controls
161 lines (134 loc) · 4.92 KB
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
#include "beanpacketsplayermodel.h"
#include "beanpacketsplayerwindow.h"
#include "ui_beanpacketsplayerwindow.h"
#include <QCheckBox>
#include <QFileDialog>
#include <QDebug>
#include <QFileIconProvider>
#include <QStyle>
#include <QCommonStyle>
#include <QTimer>
#include <QThread>
BeanPacketsPlayerWindow::BeanPacketsPlayerWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::BeanPacketsPlayerWindow)
{
ui->setupUi(this);
ui->cbDelay->setChecked(true);
on_cbDelay_stateChanged(0); //kick style apply
QCommonStyle style;
ui->actionLoadFile->setIcon(style.standardIcon(QStyle::SP_DialogOpenButton));
ui->actionPlayPause->setIcon(style.standardIcon(QStyle::SP_MediaPlay));
ui->toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
ui->lineEdit->setValidator(new QIntValidator(0, 10000, this));
ui->lineEdit->setAlignment(Qt::AlignRight);
QTableView *table = ui->tablePackets;
playModel = new BeanPacketsPlayerModel(parent);
table->setModel(playModel);
int columnWidth = 30;
table->setColumnWidth(0, 30); //checkboxes
table->setColumnWidth(1, columnWidth * 4); // time
table->setColumnWidth(2, columnWidth);
table->setColumnWidth(3, columnWidth);
table->setColumnWidth(4, columnWidth);
table->setColumnWidth(5, columnWidth * 5);
table->setColumnWidth(6, columnWidth);
table->setColumnWidth(7, columnWidth);
table->setColumnWidth(8, columnWidth * 20);
// ui->tableLog->setColumnWidth(8, columnWidth * 20);
table->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
table->verticalHeader()->hide();
QHeaderView *verticalHeader = table->verticalHeader();
verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(20);
// QStringList m_TableHeader;
// m_TableHeader << "Dst" << "Msg" ;
// //table->setHorizontalHeaderLabels(m_TableHeader);
// table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
// table->resizeColumnsToContents();
// table->setColumnWidth(0, columnWidth*2);
// table->setColumnWidth(1, columnWidth*2);
// QCheckBox *cb = new QCheckBox;
// cb->setText("TODO");
// table->setCellWidget(1, 1, cb);
}
BeanPacketsPlayerWindow::~BeanPacketsPlayerWindow()
{
delete ui;
}
bool BeanPacketsPlayerWindow::getConnected()
{
return connected;
}
void BeanPacketsPlayerWindow::setConnected(bool value)
{
connected = value;
auto actions = ui->toolBar->actions();
if (actions.size() > 1) {
actions[1]->setEnabled(connected);
}
}
void BeanPacketsPlayerWindow::on_actionLoadFile_triggered()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::currentPath(),
tr("Dumps (*.txt *.csv)"));
qDebug() << "File fro open: " << fileName;
if (!fileName.isEmpty()) {
playModel->loadFromCSV(fileName);
}
}
void BeanPacketsPlayerWindow::on_cbDelay_stateChanged(int arg1)
{
//ui->lineEdit->setAutoFillBackground(true);
ui->lineEdit->setReadOnly(!ui->cbDelay->isChecked());
QPalette palette; // fixed it (need to initialize)
// palette.setColor(this->backgroundRole(), transparent); // for background (fixed)
// palette.setColor(this->foregroundRole(), fgrndColor); // for foreground
ui->lineEdit->setAutoFillBackground(true); // to allow to fill the background
// ui->lineEdit->setPalette(palette);
if (ui->cbDelay->isChecked()) {
palette.setColor(QPalette::Base,Qt::white);
ui->lineEdit->setPalette(palette);
} else {
palette.setColor(QPalette::Base, Qt::lightGray);
ui->lineEdit->setPalette(palette);
}
}
// TODO fix
void BeanPacketsPlayerWindow::on_actionPlayPause_triggered()
{
// if (!connected) {
// qWarning() << "Attempt to send packets while disconnected.";
// ui->statusbar->showMessage("Serial port is not connected!", 10000);
// return;
// }
// QSerialPort *serial = getSerialPort();
// QListIterator<BeanPacket*> i(playModel->getPackets());
// bool play = true;
// while (play) {
// int row = 1;
// while(i.hasNext()) {
// auto packet = i.next();
// packet->sendToSerialBin(serial);
// ui->tableView->selectRow(row);
// ui->tableView->scrollTo(playModel->index(row, 0));
// row++;
// //TODO fixup
// QThread::msleep(ui->lineEdit->text().toInt());
// // timer->setInterval(ui->lineEdit->text().toInt());
// // timer->start();
// }
// play = ui->cbRepeat->isChecked();
// }
}
// QSerialPort *BeanPacketsPlayerWindow::getSerialPort() {
// MainWindow window;
// foreach(QWidget *widget, qApp->topLevelWidgets()) {
// if (auto *mainWindow = dynamic_cast<MainWindow*>(widget)) {
// return mainWindow->getSerialPort();
// break;
// }
// }
// return nullptr;
// }