228 lines
5.8 KiB
C++
228 lines
5.8 KiB
C++
#include "FormTrackTop.h"
|
||
#include "ui_FormTrackTop.h"
|
||
|
||
#include "CallManage.h"
|
||
#include <QDebug>
|
||
#include <QMimeData>
|
||
#include <QPushButton>
|
||
#include <QVBoxLayout>
|
||
#include "geometryutils.h"
|
||
|
||
//曲线名称(单个)
|
||
FormTrackTop::FormTrackTop(QWidget *parent, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor) :
|
||
QWidget(parent),
|
||
ui(new Ui::FormTrackTop)
|
||
{
|
||
ui->setupUi(this);
|
||
//
|
||
setAcceptDrops(true);
|
||
|
||
m_strSlfName = strSlfName;
|
||
m_strWellName = strWellName;
|
||
m_strTrackName = strTrackName;
|
||
m_strLineName = strLineName;
|
||
m_lineColor = lineColor;
|
||
//
|
||
m_dWidth = 3;
|
||
m_lineStyle = Qt::SolidLine;
|
||
m_newFillMode = "无填充";
|
||
m_newHeadFill = "不绘制";
|
||
// //
|
||
// QPushButton *button = new QPushButton("Drag Me", this);
|
||
// QVBoxLayout *layout = new QVBoxLayout(this);
|
||
// layout->addWidget(button);
|
||
// setLayout(layout);
|
||
// // 设置拖拽功能
|
||
// setWindowFlags(Qt::FramelessWindowHint | Qt::Window);
|
||
// setAttribute(Qt::WA_TranslucentBackground);
|
||
|
||
|
||
m_font = QFont("微软雅黑", 10);
|
||
m_fontColor = QColor(0,0,0);
|
||
}
|
||
|
||
FormTrackTop::~FormTrackTop()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
QJsonObject FormTrackTop::makeJson()
|
||
{
|
||
// 创建根对象
|
||
QJsonObject rootObj;
|
||
//
|
||
rootObj["WellName"] = m_strWellName;
|
||
rootObj["TrackName"] = m_strTrackName;
|
||
rootObj["Font"] = m_font.toString();
|
||
rootObj["FontColor"] = m_fontColor.name();
|
||
|
||
return rootObj;
|
||
}
|
||
|
||
void FormTrackTop::paintEvent(QPaintEvent* event)
|
||
{
|
||
QPainter painter(this);
|
||
QRect rect = this->rect();
|
||
//背景透明
|
||
painter.fillRect(rect.left(), rect.top(), rect.width(), rect.height(), QColor(0, 0, 0, 0)); //QColor(67, 67, 67, 100)
|
||
|
||
painter.setBrush(Qt::NoBrush); // 确保文字不被填充色遮挡
|
||
painter.setFont(m_font);
|
||
painter.setPen(m_fontColor); // fontColor QColor(220, 220, 220)
|
||
painter.drawText(rect.left(), rect.top(), rect.width(), rect.height(), Qt::AlignCenter, m_strTrackName);
|
||
|
||
QWidget::paintEvent(event);
|
||
}
|
||
|
||
void FormTrackTop::dragEnterEvent(QDragEnterEvent* event)
|
||
{
|
||
qDebug() << "FormTrackTop dragEnterEvent";
|
||
|
||
const QMimeData* mimeData = event->mimeData();
|
||
// 检查拖拽的数据类型,确定是否接受拖拽
|
||
if (event->mimeData()->hasFormat("text/plain")) {
|
||
event->acceptProposedAction();
|
||
//QApplication::setOverrideCursor(Qt::PointingHandCursor); // 设置鼠标为可添加状态
|
||
}
|
||
else
|
||
{
|
||
event->ignore();
|
||
//QApplication::setOverrideCursor(Qt::ForbiddenCursor); // 设置鼠标为不可添加状态
|
||
}
|
||
}
|
||
|
||
void FormTrackTop::dragMoveEvent(QDragMoveEvent* event)
|
||
{
|
||
qDebug() << "FormTrackTop dragMoveEvent";
|
||
|
||
// 可以在这里更新鼠标的位置,根据位置判断是否可以放置
|
||
// ...
|
||
//dragEnterEvent(event); // 可以使用相同的逻辑
|
||
//event->accept();
|
||
}
|
||
|
||
void FormTrackTop::dropEvent(QDropEvent* event)
|
||
{
|
||
qDebug() << "FormTrackTop dropEvent";
|
||
|
||
// 处理放置动作,更新UI或数据
|
||
if (event->mimeData()->hasFormat("text/plain")) {
|
||
// 获取拖拽的数据
|
||
QString strExtern = event->mimeData()->text();
|
||
qDebug() << strExtern;
|
||
//
|
||
QStringList list = strExtern.split("#@@#");//QString字符串分割函数
|
||
if (list.size() > 3)
|
||
{
|
||
QString strSlfName = list[0];
|
||
QString strWellName = list[1];
|
||
QString strLineName = list[2];
|
||
QString strType = list[3];
|
||
|
||
qDebug() << "strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strLineName:" << strLineName << " strType:" << strType;
|
||
|
||
if(m_strWellName == strWellName)
|
||
{
|
||
if(strType=="curveObject")
|
||
{
|
||
//新建曲线
|
||
emit CallManage::getInstance()->sig_AddLine(m_strUuid, strSlfName, strWellName, m_strTrackName, strLineName);
|
||
}
|
||
else if(strType=="waveObject")
|
||
{
|
||
//新建波列
|
||
emit CallManage::getInstance()->sig_AddWave(m_strUuid, strSlfName, strWellName, m_strTrackName, strLineName);
|
||
}
|
||
else if(strType=="tableObject")
|
||
{
|
||
//新建表格曲线
|
||
emit CallManage::getInstance()->sig_AddTableLine(m_strUuid, strSlfName, strWellName, m_strTrackName, strLineName);
|
||
}
|
||
// 接受拖拽事件
|
||
event->setDropAction(Qt::MoveAction);
|
||
event->accept();
|
||
}
|
||
else
|
||
{
|
||
// 如果井名不正确,不接受拖拽事件
|
||
event->ignore();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 如果数据格式不正确,不接受拖拽事件
|
||
event->ignore();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// 如果数据格式不正确,不接受拖拽事件
|
||
event->ignore();
|
||
}
|
||
// 恢复鼠标光标
|
||
//QApplication::restoreOverrideCursor();
|
||
}
|
||
|
||
//线宽
|
||
void FormTrackTop::setLineWidth(double dWidth)
|
||
{
|
||
m_dWidth = dWidth;
|
||
}
|
||
|
||
double FormTrackTop::getLineWidth()
|
||
{
|
||
return m_dWidth;
|
||
}
|
||
|
||
//线型
|
||
void FormTrackTop::setLineStyle(Qt::PenStyle lineStyle)
|
||
{
|
||
m_lineStyle = lineStyle;
|
||
}
|
||
|
||
Qt::PenStyle FormTrackTop::getLineStyle()
|
||
{
|
||
return m_lineStyle;
|
||
}
|
||
|
||
void FormTrackTop::setVMax(float vmax)
|
||
{
|
||
m_vmax = vmax;
|
||
}
|
||
|
||
float FormTrackTop::getVMax()
|
||
{
|
||
return m_vmax;
|
||
}
|
||
|
||
void FormTrackTop::setVMin(float vmin)
|
||
{
|
||
m_vmin = vmin;
|
||
}
|
||
|
||
float FormTrackTop::getVMin()
|
||
{
|
||
return m_vmin;
|
||
}
|
||
|
||
void FormTrackTop::setFrontColor(QColor frontColor)
|
||
{
|
||
m_frontColor = frontColor;
|
||
}
|
||
|
||
QColor FormTrackTop::getFrontColor()
|
||
{
|
||
return m_frontColor;
|
||
}
|
||
|
||
void FormTrackTop::setBackColor(QColor backColor)
|
||
{
|
||
m_backColor = backColor;
|
||
}
|
||
|
||
QColor FormTrackTop::getBackColor()
|
||
{
|
||
return m_backColor;
|
||
}
|
||
|