/
pi_coder
/
ByteMachine
Обзор
Документация
Войти
/
pi_coder
/
ByteMachine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/nodes/forms/form_input_file_node.cpp
228 строк
8 KB
pimenov-and
Восстановление функционала старой версии
28 июл 2026, 20:04
28 июл 2026, 20:04
98412d0
Код
Авторство
О чём код?
//////////////////////////////////////////////////////////////// // ByteMachine // Виджет для настройки узла InFile //////////////////////////////////////////////////////////////// #include "form_input_file_node.h" #include "../show_node_state.h" #include "global_settings.h" #include "icons.h" #include <QFileDialog> //============================================================== // Конструктор с параметрами //============================================================== FormInputFileNode::FormInputFileNode(InputFileNode *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_.labelChangeFilePath_->setFont(font); ui_.lineEditFilePath_->setFont(font); ui_.pushBtnChangeFilePath_->setFont(font); ui_.labelComment_->setFont(font); ui_.lineEditComment_->setFont(font); ui_.labelState_->setFont(font); ui_.plainTextEditState_->setFont(font); #endif // Q_OS_WASM } //============================================================== // Функция вызывается при изменении свойств узла //============================================================== void FormInputFileNode::slotChangedNodeProp(PropValue value) { // Имя if (value.name == "name") { const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); } // Путь к файлу else if (value.name == "filePath") { const QString filePath = node_->filePath(); ui_.lineEditFilePath_->setText(filePath); ui_.lineEditFilePath_->setToolTip(filePath); const bool isFilePathChanged = node_->isFilePathModified(); ui_.pushBtnResetFilePath_->setEnabled(isFilePathChanged); } // Комментарий 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 FormInputFileNode::slotChangedNodeState(const NodeStateInfo &stateInfo) { showNodeState(stateInfo, ui_.plainTextEditState_); } //============================================================== // Функция вызывается при завершении редактирования имени //============================================================== void FormInputFileNode::slotEditingFinishedName() { const QString name = ui_.lineEditName_->text(); node_->setName(name); } //============================================================== // Функция вызывается при завершении редактирования пути к файлу //============================================================== void FormInputFileNode::slotEditingFinishedFilePath() { const QString path = ui_.lineEditFilePath_->text(); node_->setFilePath(path); } //============================================================== // Функция изменения пути к файлу //============================================================== void FormInputFileNode::slotChangedFilePath() { const QString caption = tr("Open File"); const QString dir = ui_.lineEditFilePath_->text(); const QString path = QFileDialog::getOpenFileName(this, caption, dir); if (!path.isEmpty()) { node_->setFilePath(path); } } //============================================================== // Функция сброса пути к файлу //============================================================== void FormInputFileNode::slotResetFilePath() { node_->resetFilePath(); ui_.lineEditFilePath_->setFocus(); } //============================================================== // Функция вызывается при изменении комментария //============================================================== void FormInputFileNode::slotEditingFinishedComment() { const QString comment = ui_.lineEditComment_->text(); node_->setComment(comment); } //============================================================== // Функция сброса комментария //============================================================== void FormInputFileNode::slotResetComment() { node_->resetComment(); ui_.lineEditComment_->setFocus(); } //============================================================== // Функция вызывается при изменении состояния формы //============================================================== void FormInputFileNode::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui_.retranslateUi(this); } else if (event->type() == QEvent::PaletteChange) { correctColorScheme(); } QWidget::changeEvent(event); } //============================================================== // Задание соединений //============================================================== void FormInputFileNode::setConnections() { connect(node_, &BaseNode::sigChangedProp, this, &FormInputFileNode::slotChangedNodeProp); connect(node_, &BaseNode::sigChangedState, this, &FormInputFileNode::slotChangedNodeState); connect(ui_.lineEditName_, &QLineEdit::editingFinished, this, &FormInputFileNode::slotEditingFinishedName); connect(ui_.lineEditFilePath_, &QLineEdit::editingFinished, this, &FormInputFileNode::slotEditingFinishedFilePath); connect(ui_.pushBtnChangeFilePath_, &QPushButton::clicked, this, &FormInputFileNode::slotChangedFilePath); connect(ui_.pushBtnResetFilePath_, &QPushButton::clicked, this, &FormInputFileNode::slotResetFilePath); connect(ui_.lineEditComment_, &QLineEdit::editingFinished, this, &FormInputFileNode::slotEditingFinishedComment); connect(ui_.pushBtnResetComment_, &QPushButton::clicked, this, &FormInputFileNode::slotResetComment); } //============================================================== // Задание узла //============================================================== void FormInputFileNode::setNode(InputFileNode *node) { Q_ASSERT(node != nullptr); node_ = node; // Задание имени const QString name = node_->name(); ui_.lineEditName_->setText(name); ui_.lineEditName_->setToolTip(name); // Задание пути к файлу const QString path = node_->filePath(); ui_.lineEditFilePath_->setText(path); ui_.lineEditFilePath_->setToolTip(path); const bool isFilePathModified = node_->isFilePathModified(); ui_.pushBtnResetFilePath_->setEnabled(isFilePathModified); // Задание комментария 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 FormInputFileNode::correctColorScheme() { const ColorThemes theme = globalSettings()->colorTheme(); const QPixmap resetIcon = Icons::resetValue(theme); ui_.pushBtnResetFilePath_->setIcon(resetIcon); ui_.pushBtnResetComment_->setIcon(resetIcon); }