2024-12-18 16:46:39 +08:00
|
|
|
#ifndef SINGLERELAY_H
|
|
|
|
#define SINGLERELAY_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
2025-04-17 20:33:26 +08:00
|
|
|
#include <QTextEdit>
|
2025-04-19 16:25:33 +08:00
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include "data_config.h"
|
|
|
|
#include "config_mgr.h"
|
|
|
|
#include "singlerelay_data.h"
|
2024-12-18 16:46:39 +08:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class SingleRelay;
|
|
|
|
}
|
|
|
|
|
2025-04-17 20:33:26 +08:00
|
|
|
class DropTextEdit : public QTextEdit {
|
2025-04-19 16:25:33 +08:00
|
|
|
Q_OBJECT
|
2025-04-17 20:33:26 +08:00
|
|
|
public:
|
|
|
|
DropTextEdit(QWidget *parent = nullptr) : QTextEdit(parent) {
|
|
|
|
setAcceptDrops(true);
|
|
|
|
}
|
2025-04-19 16:25:33 +08:00
|
|
|
public slots:
|
|
|
|
|
2025-04-17 20:33:26 +08:00
|
|
|
protected:
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override {
|
2025-04-19 16:25:33 +08:00
|
|
|
if (event->mimeData()->hasFormat("application/x-custom")) {
|
2025-04-17 20:33:26 +08:00
|
|
|
event->acceptProposedAction();
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dragMoveEvent(QDragMoveEvent *event) override {
|
2025-04-19 16:25:33 +08:00
|
|
|
if (event->mimeData()->hasFormat("application/x-custom")) {
|
2025-04-17 20:33:26 +08:00
|
|
|
event->acceptProposedAction();
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dropEvent(QDropEvent *event) override {
|
2025-04-19 16:25:33 +08:00
|
|
|
if (!this->toPlainText().isEmpty()) {
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (event->mimeData()->hasFormat("application/x-custom")) {
|
|
|
|
QByteArray data = event->mimeData()->data("application/x-custom");
|
2025-04-23 17:13:05 +08:00
|
|
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
|
|
|
QString visibleText, userData;
|
|
|
|
stream >> visibleText >> userData; // 解析显示文本和 UserRole 数据
|
|
|
|
qDebug() << visibleText << userData;
|
2025-04-19 16:25:33 +08:00
|
|
|
QString text = QString::fromUtf8(data);
|
|
|
|
|
|
|
|
QTextCursor cursor = this->textCursor();
|
|
|
|
this->setTextCursor(cursor);
|
|
|
|
|
2025-04-23 17:13:05 +08:00
|
|
|
QString html = QString("<span data-key='%1' style='color:black;'>%2</span> ")
|
|
|
|
.arg(userData.toHtmlEscaped(), visibleText.toHtmlEscaped());
|
2025-04-19 16:25:33 +08:00
|
|
|
cursor.insertHtml(html);
|
2025-04-17 20:33:26 +08:00
|
|
|
event->acceptProposedAction();
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2025-04-19 16:25:33 +08:00
|
|
|
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<SingleRelayDataNOK> single_relay_nok_data = nullptr;
|
|
|
|
int current_index;
|
2025-04-23 17:13:05 +08:00
|
|
|
QMap<QString, QString> channelNameMap;
|
|
|
|
|
2025-04-19 16:25:33 +08:00
|
|
|
void Init();
|
|
|
|
};
|
|
|
|
|
2024-12-18 16:46:39 +08:00
|
|
|
#endif // SINGLERELAY_H
|