SIEdit/app/siview/panels/mxch.cpp

146 lines
3.6 KiB
C++
Raw Normal View History

#include "mxch.h"
#include <chunk.h>
#include <QFontDatabase>
#include <QGroupBox>
#include <QLabel>
using namespace si;
MxChPanel::MxChPanel(QWidget *parent) :
Panel(parent)
{
int row = 0;
auto flag_group = new QGroupBox(tr("Flags"));
layout()->addWidget(flag_group, row, 0, 1, 2);
{
auto flag_layout = new QGridLayout(flag_group);
int flag_row = 0;
flag_layout->addWidget(new QLabel(tr("Value")), flag_row, 0);
flag_edit_ = new QLineEdit();
flag_layout->addWidget(flag_edit_, flag_row, 1);
flag_row++;
auto split_chunk = new QCheckBox(tr("Split Chunk"));
2022-07-11 17:20:15 -04:00
split_chunk->setProperty("flag", MxCh::FLAG_SPLIT);
connect(split_chunk, &QCheckBox::clicked, this, &MxChPanel::FlagCheckBoxClicked);
flag_checkboxes_.append(split_chunk);
flag_layout->addWidget(split_chunk, flag_row, 0, 1, 2);
flag_row++;
auto end_chunk = new QCheckBox(tr("End Chunk"));
2022-07-11 17:20:15 -04:00
end_chunk->setProperty("flag", MxCh::FLAG_END);
connect(end_chunk, &QCheckBox::clicked, this, &MxChPanel::FlagCheckBoxClicked);
flag_checkboxes_.append(end_chunk);
flag_layout->addWidget(end_chunk, flag_row, 0, 1, 2);
flag_row++;
}
row++;
layout()->addWidget(new QLabel(tr("Object ID")), row, 0);
obj_edit_ = new QSpinBox();
obj_edit_->setMinimum(0);
obj_edit_->setMaximum(INT_MAX);
layout()->addWidget(obj_edit_, row, 1);
row++;
layout()->addWidget(new QLabel(tr("Millisecond Offset")), row, 0);
ms_offset_edit_ = new QSpinBox();
ms_offset_edit_->setMinimum(0);
ms_offset_edit_->setMaximum(INT_MAX);
layout()->addWidget(ms_offset_edit_, row, 1);
row++;
layout()->addWidget(new QLabel(tr("Data Size")), row, 0);
data_sz_edit_ = new QSpinBox();
data_sz_edit_->setMinimum(0);
data_sz_edit_->setMaximum(INT_MAX);
layout()->addWidget(data_sz_edit_, row, 1);
2022-07-11 04:48:50 -04:00
row++;
show_data_btn_ = new QPushButton(tr("Show Data"));
connect(show_data_btn_, &QPushButton::clicked, this, &MxChPanel::ShowDataField);
layout()->addWidget(show_data_btn_, row, 0, 1, 2);
data_edit_ = new QTextEdit();
data_edit_->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
layout()->addWidget(data_edit_, row, 0, 1, 2);
data_edit_->hide();
FinishLayout();
}
void MxChPanel::OnOpeningData(void *d)
{
Chunk *chunk = static_cast<Chunk*>(d);
2022-07-03 11:57:43 -04:00
flag_edit_->setText(QString::number(chunk->data("Flags"), 16));
obj_edit_->setValue(chunk->data("Object"));
ms_offset_edit_->setValue(chunk->data("Time"));
data_sz_edit_->setValue(chunk->data("DataSize"));
for (QCheckBox *cb : qAsConst(flag_checkboxes_)) {
2022-07-03 11:57:43 -04:00
cb->setChecked(cb->property("flag").toUInt() & chunk->data("Flags"));
}
}
void MxChPanel::OnClosingData(void *data)
{
/*bool ok;
u16 flags = flag_edit_->text().toUShort(&ok, 16);
if (ok) {
2022-07-03 11:57:43 -04:00
chunk->data("Flags") = flags;
}
2022-07-03 11:57:43 -04:00
chunk->data("Object") = u32(obj_edit_->value());
chunk->data("Time") = u32(ms_offset_edit_->value());
chunk->data("DataSize") = u32(data_sz_edit_->value());*/
2022-07-11 04:48:50 -04:00
show_data_btn_->show();
data_edit_->clear();
data_edit_->hide();
}
void MxChPanel::FlagCheckBoxClicked(bool e)
{
uint16_t flag = sender()->property("flag").toUInt();
bool ok;
uint16_t current = flag_edit_->text().toUShort(&ok, 16);
if (ok) {
if (e) {
current |= flag;
} else {
current &= ~flag;
}
flag_edit_->setText(QString::number(current, 16));
}
}
2022-07-11 04:48:50 -04:00
void MxChPanel::ShowDataField()
{
show_data_btn_->hide();
data_edit_->show();
Chunk *chunk = static_cast<Chunk*>(GetData());
const Data &data = chunk->data("Data");
QByteArray ba(data.data(), int(data.size()));
data_edit_->setPlainText(ba.toHex());
}