/
pi_coder
/
ByteMachine
Обзор
Документация
Войти
/
pi_coder
/
ByteMachine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/nodes/forms/form_skip_node.cpp
298 строк
11 KB
pimenov-and
Восстановление функционала старой версии
28 июл 2026, 20:04
28 июл 2026, 20:04
98412d0
Код
Авторство
О чём код?
//////////////////////////////////////////////////////////////// // ByteMachine // Форма для настройки узла Skip //////////////////////////////////////////////////////////////// #include "form_skip_node.h" #include "../show_node_state.h" #include "global_settings.h" #include "icons.h" //============================================================== // Конструктор с параметрами //============================================================== FormSkipNode::FormSkipNode(SkipNode *node, QWidget *parent) : QWidget{parent} { Q_ASSERT(node != nullptr); ui_.setupUi(this); setNode(node); setConnections(); correctColorScheme(); #ifdef Q_OS_WASM const QFont font{"Segoe UI", 10}; setFont(font); ui_.labelName_->setFont(font); ui_.lineEditName_->setFont(font); ui_.labelByteCount_->setFont(font); ui_.spinBoxByteCount_->setFont(font); ui_.labelDirection_->setFont(font); ui_.comboBoxDirection_->setFont(font); ui_.checkBoxBypass_->setFont(font); ui_.labelComment_->setFont(font); ui_.lineEditComment_->setFont(font); ui_.labelState_->setFont(font); ui_.plainTextEditState_->setFont(font); #endif // Q_OS_WASM } //============================================================== // Функция вызывается при изменении свойств узла //============================================================== void FormSkipNode::slotChangedNodeProp(PropValue value) { // Имя if (value.name == "name") { const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); } // Количество байтов else if (value.name == "byteCount") { const qint32 byteCount = node_->byteCount(); ui_.spinBoxByteCount_->setValue(byteCount); const bool isByteCountModified = node_->isByteCountModified(); ui_.pushBtnResetByteCount_->setEnabled(isByteCountModified); } // Направление else if (value.name == "direction") { const DirectionTypes direction = node_->direction(); const int directionIndex = directionTypeToInt(direction); Q_ASSERT(directionIndex != -1); ui_.comboBoxDirection_->setCurrentIndex(directionIndex); const bool isDirectionModified = node_->isDirectionModified(); ui_.pushBtnResetDirection_->setEnabled(isDirectionModified); } // Признак пропуска else if (value.name == "bypass") { const bool isBypass = node_->isBypass(); ui_.checkBoxBypass_->setChecked(isBypass); const bool isBypassModified = node_->isBypassModified(); ui_.pushBtnResetBypass_->setEnabled(isBypassModified); } // Комментарий else if (value.name == "comment") { const QString comment = node_->comment(); ui_.lineEditComment_->setText(comment); ui_.lineEditComment_->setToolTip(comment); const bool isCommentChanged = node_->isCommentModified(); ui_.pushBtnResetComment_->setEnabled(isCommentChanged); } } //============================================================== // Функция вызывается при изменении состояния узла //============================================================== void FormSkipNode::slotChangedNodeState(const NodeStateInfo &stateInfo) { showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Функция вызывается при завершении редактирования имени //============================================================== void FormSkipNode::slotEditingFinishedName() { const QString name = ui_.lineEditName_->text(); node_->setName(name); } //============================================================== // Задание количества байтов //============================================================== void FormSkipNode::slotChangedByteCount(int count) { node_->setByteCount(count); } //============================================================== // Сброс количества байтов //============================================================== void FormSkipNode::slotResetByteCount() { node_->resetByteCount(); ui_.spinBoxByteCount_->setFocus(); } //============================================================== // Задание направления //============================================================== void FormSkipNode::slotChangedDirection(int index) { if (index == -1) { return; } const DirectionTypes direction = intToDirectionType(index); Q_ASSERT(!isUnknown(direction)); node_->setDirection(direction); } //============================================================== // Сброс направления //============================================================== void FormSkipNode::slotResetDirection() { node_->resetDirection(); ui_.comboBoxDirection_->setFocus(); } //============================================================== // Функция вызывается при изменении признака пропуска //============================================================== void FormSkipNode::slotChangedBypass(int state) { const bool isBypass = static_cast<bool>(state); node_->setBypass(isBypass); } //============================================================== // Сброс признака пропуска узла //============================================================== void FormSkipNode::slotResetBypass() { node_->resetBypass(); ui_.checkBoxBypass_->setFocus(); } //============================================================== // Функция вызывается при завершении редактирования комментария //============================================================== void FormSkipNode::slotEditingFinishedComment() { const QString comment = ui_.lineEditComment_->text(); node_->setComment(comment); } //============================================================== // Сброс комментария //============================================================== void FormSkipNode::slotResetComment() { node_->resetComment(); ui_.lineEditComment_->setFocus(); } //============================================================== // Функция вызывается при изменении состояния формы //============================================================== void FormSkipNode::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui_.retranslateUi(this); } else if (event->type() == QEvent::PaletteChange) { correctColorScheme(); } QWidget::changeEvent(event); } //============================================================== // Задание узла //============================================================== void FormSkipNode::setNode(SkipNode *node) { Q_ASSERT(node != nullptr); node_ = node; // Задание имени const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); // Задание количества получаемых байт const qint32 byteCount = node_->byteCount(); ui_.spinBoxByteCount_->setValue(byteCount); const bool isByteCountModified = node_->isByteCountModified(); ui_.pushBtnResetByteCount_->setEnabled(isByteCountModified); // Задание направления const DirectionTypes direction = node_->direction(); const int directionIndex = directionTypeToInt(direction); Q_ASSERT(directionIndex != -1); ui_.comboBoxDirection_->setCurrentIndex(directionIndex); const bool isDirectionModified = node_->isDirectionModified(); ui_.pushBtnResetDirection_->setEnabled(isDirectionModified); // Задание признака пропуска узла const bool isBypass = node_->isBypass(); ui_.checkBoxBypass_->setChecked(isBypass); const bool isBypassChecked = node_->isBypassModified(); ui_.pushBtnResetBypass_->setEnabled(isBypassChecked); // Задание комментария const QString comment = node_->comment(); ui_.lineEditComment_->setText(comment); ui_.lineEditComment_->setToolTip(comment); const bool isCommentModified = node_->isCommentModified(); ui_.pushBtnResetComment_->setEnabled(isCommentModified); // Задание состояния узла const NodeStateInfo stateInfo = node_->stateInfo(); showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Задание соединений //============================================================== void FormSkipNode::setConnections() { connect(node_, &SkipNode::sigChangedProp, this, &FormSkipNode::slotChangedNodeProp); connect(node_, &SkipNode::sigChangedState, this, &FormSkipNode::slotChangedNodeState); connect(ui_.lineEditName_, &QLineEdit::editingFinished, this, &FormSkipNode::slotEditingFinishedName); connect(ui_.spinBoxByteCount_, qOverload<int>(&QSpinBox::valueChanged), this, &FormSkipNode::slotChangedByteCount); connect(ui_.pushBtnResetByteCount_, &QPushButton::clicked, this, &FormSkipNode::slotResetByteCount); connect(ui_.comboBoxDirection_, qOverload<int>(&QComboBox::currentIndexChanged), this, &FormSkipNode::slotChangedDirection); connect(ui_.pushBtnResetDirection_, &QPushButton::clicked, this, &FormSkipNode::slotResetDirection); connect(ui_.checkBoxBypass_, &QCheckBox::stateChanged, this, &FormSkipNode::slotChangedBypass); connect(ui_.pushBtnResetBypass_, &QPushButton::clicked, this, &FormSkipNode::slotResetBypass); connect(ui_.lineEditComment_, &QLineEdit::editingFinished, this, &FormSkipNode::slotEditingFinishedComment); connect(ui_.pushBtnResetComment_, &QPushButton::clicked, this, &FormSkipNode::slotResetComment); } //============================================================== // Корректировка цветовой схемы //============================================================== void FormSkipNode::correctColorScheme() { const ColorThemes theme = globalSettings()->colorTheme(); const QPixmap resetIcon = Icons::resetValue(theme); ui_.pushBtnResetByteCount_->setIcon(resetIcon); ui_.pushBtnResetDirection_->setIcon(resetIcon); ui_.pushBtnResetBypass_->setIcon(resetIcon); ui_.pushBtnResetComment_->setIcon(resetIcon); }