/
pi_coder
/
ByteMachine
Обзор
Документация
Войти
/
pi_coder
/
ByteMachine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/nodes/forms/form_paint_node.cpp
247 строк
9 KB
pimenov-and
Восстановление функционала старой версии
28 июл 2026, 20:04
28 июл 2026, 20:04
98412d0
Код
Авторство
О чём код?
//////////////////////////////////////////////////////////////// // ByteMachine // Форма для настройки узла Paint //////////////////////////////////////////////////////////////// #include "form_paint_node.h" #include "nodes/show_node_state.h" #include "global_settings.h" #include "icons.h" //============================================================== // Конструктор с параметрами //============================================================== FormPaintNode::FormPaintNode(PaintNode *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_.labelScaleInNode_->setFont(font); ui_.spinBoxScaleInNode_->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 FormPaintNode::slotChangedNodeProp(PropValue value) { // Имя if (value.name == "name") { const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); } // Масштабирование при рисовании в узле else if (value.name == "scaleInNode") { const int scaleInNode = node_->scaleInNode(); ui_.spinBoxScaleInNode_->setValue(scaleInNode); const bool isScaleInNodeModified = node_->isScaleInNodeModified(); ui_.pushBtnResetScaleInNode_->setEnabled(isScaleInNodeModified); } // Признак пропуска узла 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 FormPaintNode::slotChangedNodeState(const NodeStateInfo &stateInfo) { showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Функция вызывается при завершении редактирования имени //============================================================== void FormPaintNode::slotEditingFinishedName() { const QString name = ui_.lineEditName_->text(); node_->setName(name); } //============================================================== // Функция вызывается при изменении масштаба внутри узла //============================================================== void FormPaintNode::slotChangedScaleInNode(int scale) { node_->setScaleInNode(scale); } //============================================================== // Сброс масштабирования при рисовании в узле //============================================================== void FormPaintNode::slotResetScaleInNode() { node_->resetScaleInNode(); ui_.spinBoxScaleInNode_->setFocus(); } //============================================================== // Функция вызывается при изменении признака пропуска узла //============================================================== void FormPaintNode::slotChangedBypass(int state) { const bool bypass = static_cast<bool>(state); node_->setBypass(bypass); } //============================================================== // Сброс признака пропуска узла //============================================================== void FormPaintNode::slotResetBypass() { node_->resetBypass(); ui_.checkBoxBypass_->setFocus(); } //============================================================== // Функция вызывается при завершении редактирования комментария //============================================================== void FormPaintNode::slotEditingFinishedComment() { const QString comment = ui_.lineEditComment_->text(); node_->setComment(comment); } //============================================================== // Сброс комментария //============================================================== void FormPaintNode::slotResetComment() { node_->resetComment(); ui_.lineEditComment_->setFocus(); } //============================================================== // Функция вызывается при изменении состояния формы //============================================================== void FormPaintNode::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui_.retranslateUi(this); } else if (event->type() == QEvent::PaletteChange) { correctColorScheme(); } QWidget::changeEvent(event); } //============================================================== // Задание узла //============================================================== void FormPaintNode::setNode(PaintNode *node) { Q_ASSERT(node != nullptr); node_ = node; // Задание имени const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); // Задание масштаба вывода изображения const int scaleInNode = node->scaleInNode(); Q_ASSERT((scaleInNode >= 0) && (scaleInNode <= 100)); ui_.spinBoxScaleInNode_->setValue(scaleInNode); const bool isScaleInNodeModified = node_->isScaleInNodeModified(); ui_.pushBtnResetScaleInNode_->setEnabled(isScaleInNodeModified); // Задание признака пропуска узла const bool isBypass = node->isBypass(); ui_.checkBoxBypass_->setChecked(isBypass); const bool isPaintInNodeModified = node_->isBypassModified(); ui_.pushBtnResetBypass_->setEnabled(isPaintInNodeModified); // Задание комментария const QString comment = node->comment(); ui_.lineEditComment_->setText(comment); ui_.lineEditComment_->setToolTip(comment); const bool isCommentModified = node->isCommentModified(); ui_.pushBtnResetComment_->setEnabled(isCommentModified); // Задание состояния showNodeState(node_->stateInfo(), ui_.plainTextEditState_); } //============================================================== // Задание соединений //============================================================== void FormPaintNode::setConnections() { connect(node_, &PaintNode::sigChangedProp, this, &FormPaintNode::slotChangedNodeProp); connect(node_, &PaintNode::sigChangedState, this, &FormPaintNode::slotChangedNodeState); connect(ui_.lineEditName_, &QLineEdit::editingFinished, this, &FormPaintNode::slotEditingFinishedName); connect(ui_.spinBoxScaleInNode_, qOverload<int>(&QSpinBox::valueChanged), this, &FormPaintNode::slotChangedScaleInNode); connect(ui_.pushBtnResetScaleInNode_, &QPushButton::clicked, this, &FormPaintNode::slotResetScaleInNode); connect(ui_.checkBoxBypass_, &QCheckBox::stateChanged, this, &FormPaintNode::slotChangedBypass); connect(ui_.pushBtnResetBypass_, &QPushButton::clicked, this, &FormPaintNode::slotResetBypass); connect(ui_.lineEditComment_, &QLineEdit::editingFinished, this, &FormPaintNode::slotEditingFinishedComment); connect(ui_.pushBtnResetComment_, &QPushButton::clicked, this, &FormPaintNode::slotResetComment); } //============================================================== // Корректировка цветовой схемы //============================================================== void FormPaintNode::correctColorScheme() { const ColorThemes theme = globalSettings()->colorTheme(); const QPixmap resetIcon = Icons::resetValue(theme); ui_.pushBtnResetScaleInNode_->setIcon(resetIcon); ui_.pushBtnResetBypass_->setIcon(resetIcon); ui_.pushBtnResetComment_->setIcon(resetIcon); }