#ifndef SINGLERELAY_H #define SINGLERELAY_H #include #include #include #include #include "data_config.h" #include "config_mgr.h" #include "singlerelay_data.h" namespace Ui { class SingleRelay; } class DropTextEdit : public QTextEdit { Q_OBJECT public: DropTextEdit(QWidget *parent = nullptr) : QTextEdit(parent) { setAcceptDrops(true); } public slots: protected: void dragEnterEvent(QDragEnterEvent *event) override { if (event->mimeData()->hasFormat("application/x-custom")) { event->acceptProposedAction(); } else { event->ignore(); } } void dragMoveEvent(QDragMoveEvent *event) override { if (event->mimeData()->hasFormat("application/x-custom")) { event->acceptProposedAction(); } else { event->ignore(); } } void dropEvent(QDropEvent *event) override { if (!this->toPlainText().isEmpty()) { event->ignore(); return; } if (event->mimeData()->hasFormat("application/x-custom")) { QByteArray data = event->mimeData()->data("application/x-custom"); QDataStream stream(&data, QIODevice::ReadOnly); QString visibleText, userData; stream >> visibleText >> userData; // 解析显示文本和 UserRole 数据 qDebug() << visibleText << userData; QString text = QString::fromUtf8(data); QTextCursor cursor = this->textCursor(); this->setTextCursor(cursor); QString html = QString("%2 ") .arg(userData.toHtmlEscaped(), visibleText.toHtmlEscaped()); cursor.insertHtml(html); event->acceptProposedAction(); } else { event->ignore(); } } }; class SingleRelay : public QDialog { Q_OBJECT public: explicit SingleRelay(int slot,int cardtype,QWidget *parent = nullptr); ~SingleRelay(); int slot_no; CardType car_type; private slots: void keyPressEvent(QKeyEvent *event); void on_pushButton_cancel_clicked(); void OnButtonGroup(QAbstractButton *); void on_pushButton_enter_clicked(); void on_pushButton_backspace_clicked(); void on_pushButton_clr_clicked(); void on_pushButton_confirm_clicked(); void onComboBoxIndexChanged(int index); private: Ui::SingleRelay *ui; QButtonGroup * btnGroup_slot = nullptr; DraggableListWidget *list_widget_available = nullptr; DropTextEdit *textEdit_relay = nullptr; std::shared_ptr single_relay_nok_data = nullptr; int current_index; QMap channelNameMap; void Init(); }; #endif // SINGLERELAY_H