logplus/logPlus/forminfo.cpp

499 lines
17 KiB
C++
Raw Normal View History

2025-10-29 17:23:30 +08:00
#include "forminfo.h"
#include "ui_forminfo.h"
#include "CallManage.h"
#include <QDebug>
#include <QMimeData>
#include <QPushButton>
#include <QVBoxLayout>
#include "geometryutils.h"
2025-10-29 17:23:30 +08:00
//曲线名称(单个)
FormInfo::FormInfo(QWidget *parent, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor) :
QWidget(parent),
ui(new Ui::FormInfo)
{
ui->setupUi(this);
//
setAcceptDrops(true);
m_strSlfName = strSlfName;
m_strWellName = strWellName;
m_strTrackName = strTrackName;
m_strLineName = strLineName;
m_lineColor = lineColor;
//
m_dWidth = 3;
2025-10-29 17:23:30 +08:00
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);
//左刻度
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLeftScale(QString, QString, QString, QString, QString, double)), this, SLOT(s_ChangeLeftScale(QString, QString, QString, QString, QString, double)));
2025-10-29 17:23:30 +08:00
//右刻度
connect(CallManage::getInstance(), SIGNAL(sig_ChangeRightScale(QString, QString, QString, QString, QString, double)), this, SLOT(s_ChangeRightScale(QString, QString, QString, QString, QString, double)));
//刻度类型
connect(CallManage::getInstance(), SIGNAL(sig_ChangeScaleType(QString, QString, QString, QString, QString, QString)), this, SLOT(s_ChangeScaleType(QString, QString, QString, QString, QString, QString)));
2025-10-29 17:23:30 +08:00
//颜色
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLineColor(QString, QString, QString, QString, QString, QColor)), this, SLOT(s_ChangeLineColor(QString, QString, QString, QString, QString, QColor)));
2025-10-29 17:23:30 +08:00
//线宽
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLineWidth(QString, QString, QString, QString, QString, double)), this, SLOT(s_ChangeLineWidth(QString, QString, QString, QString, QString, double)));
2025-10-29 17:23:30 +08:00
//线型
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLineStyle(QString, QString, QString, QString, QString, Qt::PenStyle)), this, SLOT(s_ChangeLineStyle(QString, QString, QString, QString, QString, Qt::PenStyle)));
2025-10-29 17:23:30 +08:00
//岩性填充-不填充
connect(CallManage::getInstance(), SIGNAL(sig_ClearFillMode(QString, QString, QString, QString, QString)), this, SLOT(s_ClearFillMode(QString, QString, QString, QString, QString)));
2025-10-29 17:23:30 +08:00
//岩性填充-填充
connect(CallManage::getInstance(), SIGNAL(sig_ChangeFillMode(QString, QString, QString, QString, QString, QString, QString, QColor, QString, QString, float, float, QString, QColor, QColor, QString, bool)),
this, SLOT(s_ChangeFillMode(QString, QString, QString, QString, QString, QString, QString, QColor, QString, QString, float, float, QString, QColor, QColor, QString, bool)));
2025-10-29 17:23:30 +08:00
}
FormInfo::~FormInfo()
{
delete ui;
}
QJsonObject FormInfo::makeJson()
{
// 创建根对象
QJsonObject rootObj;
//
QString slffilename=QString("");
int ind=m_strSlfName.lastIndexOf('\\');
int ind2=m_strSlfName.lastIndexOf('/');
if(ind2>ind) ind=ind2;
if(ind>-1) {
slffilename=m_strSlfName.mid(ind+1);
}
rootObj["SlfName"] = slffilename;
2025-10-29 17:23:30 +08:00
rootObj["WellName"] = m_strWellName;
rootObj["TrackName"] = m_strTrackName;
rootObj["LineName"] = m_strLineName;
rootObj["lineColorRed"] = m_lineColor.red();
rootObj["lineColorGreen"] = m_lineColor.green();
rootObj["lineColorBlue"] = m_lineColor.blue();
rootObj["lineColorAlpha"] = m_lineColor.alpha();
rootObj["Width"] = m_dWidth;
rootObj["lineStyle"] = m_lineStyle;
rootObj["vmax"] = m_vmax;
rootObj["vmin"] = m_vmin;
rootObj["ScaleType"] = m_strScaleType;
2025-10-29 17:23:30 +08:00
//岩性填充
rootObj["newFillMode"] = m_newFillMode;
rootObj["newHeadFill"] = m_newHeadFill;
rootObj["newTargetLine"] = m_newTargetLine;
2025-10-29 17:23:30 +08:00
rootObj["newFillType"] = m_newFillType;
//填充颜色
2025-10-29 17:23:30 +08:00
rootObj["newColorRed"] = m_newColor.red();
rootObj["newColorGreen"] = m_newColor.green();
rootObj["newColorBlue"] = m_newColor.blue();
rootObj["newColorAlpha"] = m_newColor.alpha();
rootObj["newLithosImage"] = m_newLithosImage;
rootObj["new_vMax"] = m_new_vMax;
rootObj["new_vMin"] = m_new_vMin;
//岩性前景色
rootObj["frontColorRed"] = m_frontColor.red();
rootObj["frontColorGreen"] = m_frontColor.green();
rootObj["frontColorBlue"] = m_frontColor.blue();
rootObj["frontColorAlpha"] = m_frontColor.alpha();
//岩性背景色
rootObj["backColorRed"] = m_backColor.red();
rootObj["backColorGreen"] = m_backColor.green();
rootObj["backColorBlue"] = m_backColor.blue();
rootObj["backColorAlpha"] = m_backColor.alpha();
2025-10-29 17:23:30 +08:00
return rootObj;
}
void FormInfo::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)
if(m_newFillMode=="无填充" || m_newHeadFill == "不绘制")
{
painter.setBrush(Qt::NoBrush);
}
else //if(m_newFillMode=="填充" && m_newHeadFill == "绘制")
2025-10-29 17:23:30 +08:00
{
if(m_newFillType == "岩性模式")
{
QColor oldFrontColor(0, 0, 0); // 原始颜色
QColor oldBackColor(255, 255, 255); // 原始颜色
//
QImage image(m_newLithosImage);
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
QColor pixelColor = QColor(image.pixel(x, y));
if (pixelColor == oldFrontColor) {
image.setPixelColor(x, y, m_frontColor); // 使用 setPixelColor 来设置新颜色
}
if (pixelColor == oldBackColor) {
image.setPixelColor(x, y, m_backColor); // 使用 setPixelColor 来设置新颜色
}
}
}
//
painter.setBrush(QBrush(QPixmap::fromImage(image)));
//painter.setBrush(QBrush(QPixmap(m_newLithosImage)));
2025-10-29 17:23:30 +08:00
//graph(0)->setBrush(QBrush(QPixmap(":/image/file.png")));
}
else if(m_newFillType == "颜色模式")
{
painter.setBrush(QBrush(m_newColor));
}
else if(m_newFillType == "成像化")
{
}
}
//painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
QRect rectRound(rect.left()+2,rect.top()+4, rect.width()-4, rect.height()-8);
2025-10-29 17:23:30 +08:00
painter.setPen(QPen(m_lineColor, m_dWidth, m_lineStyle));
//painter.drawRoundRect(rectRound);//利用画刷(颜色/岩性图片),画框
painter.drawRect(rectRound);
2025-10-29 17:23:30 +08:00
painter.setBrush(Qt::NoBrush); // 确保文字不被填充色遮挡
QFont font1("微软雅黑", 10, false, false); //fontSize 10
painter.setFont(font1);
painter.setPen(m_lineColor); // fontColor QColor(220, 220, 220)
//painter.drawText(rect.left() + 20, 30, m_strAliasName); // titleBarText QStringLiteral("动画")
//painter.drawText(rect, Qt::AlignCenter, m_strAliasName);
2025-11-18 14:04:31 +08:00
if(m_strAliasName == "")
{
painter.drawText(rect.left(), rect.top(), rect.width(), rect.height()/3, Qt::AlignCenter, m_strLineName);
}
else {
painter.drawText(rect.left(), rect.top(), rect.width(), rect.height()/3, Qt::AlignCenter, m_strAliasName);
}
2025-10-29 17:23:30 +08:00
if(m_strType=="waveObject")
{
//波列
int nIndex=11;
QVector<MyColorItem> colorList;
bool inpolation = true;
int iColorNum = 256;
int iColorNum_tmp = getSystemColor(nIndex, colorList, inpolation);
colorList=myInpolation(colorList,256);//重新扩展调色板
//头部绘制调色板
float scale = (float)(rect.width()-4) / (float)iColorNum;
QRectF rt7=QRectF(rect.left()+2, rect.top()+rect.height()/3, rect.width()-4, rect.height()/3);
for (int i= 0; i<iColorNum; i++)
{
float temp = (float)i * scale;
if(i)rt7.setLeft(rect.left()+2+temp);
else rt7.setLeft(rect.left()+2+temp+1);
temp = (float)(i+1) * scale;
rt7.setRight(rect.left()+2+temp);
QBrush HeadBrush =QBrush(colorList[i].color);
painter.fillRect(rt7,HeadBrush);
}
}
2025-10-29 17:23:30 +08:00
QFont font2("微软雅黑", 8, false, false);
painter.setFont(font2);
painter.setPen(m_lineColor);
//painter.drawText(rect.left() + 20, 55, m_strUnit);
//painter.drawText(rect.left() + 20, 80, QString::number(m_vmin)+" ~ "+QString::number(m_vmax));
if(m_strType=="curveObject")
{
//曲线
painter.drawText(rect.left(), rect.top()+rect.height()/3, rect.width(), rect.height()/3, Qt::AlignCenter, m_strUnit);
}
painter.drawText(rect.left(), rect.top()+rect.height()*2/3, rect.width(), rect.height()/3 ,Qt::AlignCenter, QString::number(m_vmin)+" ~ "+QString::number(m_vmax));
2025-10-29 17:23:30 +08:00
QWidget::paintEvent(event);
}
void FormInfo::dragEnterEvent(QDragEnterEvent* event)
{
qDebug() << "FormInfo 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); // 设置鼠标为不可添加状态
2025-10-29 17:23:30 +08:00
}
}
void FormInfo::dragMoveEvent(QDragMoveEvent* event)
{
qDebug() << "FormInfo dragMoveEvent";
// 可以在这里更新鼠标的位置,根据位置判断是否可以放置
// ...
//dragEnterEvent(event); // 可以使用相同的逻辑
//event->accept();
}
void FormInfo::dropEvent(QDropEvent* event)
{
qDebug() << "FormInfo dropEvent";
// 处理放置动作更新UI或数据
if (event->mimeData()->hasFormat("text/plain")) {
// 获取拖拽的数据
QString strExtern = event->mimeData()->text();
qDebug() << strExtern;
//
QStringList list = strExtern.split("#@@#");//QString字符串分割函数
if (list.size() > 3)
2025-10-29 17:23:30 +08:00
{
QString strSlfName = list[0];
QString strWellName = list[1];
QString strLineName = list[2];
QString strType = list[3];
2025-10-29 17:23:30 +08:00
qDebug() << "strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strLineName:" << strLineName << " strType:" << strType;
2025-10-29 17:23:30 +08:00
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);
}
2025-10-29 17:23:30 +08:00
// 接受拖拽事件
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
// 如果井名不正确,不接受拖拽事件
event->ignore();
}
}
else
{
// 如果数据格式不正确,不接受拖拽事件
event->ignore();
2025-10-29 17:23:30 +08:00
}
}
else
{
// 如果数据格式不正确,不接受拖拽事件
event->ignore();
}
// 恢复鼠标光标
//QApplication::restoreOverrideCursor();
}
//线宽
void FormInfo::setLineWidth(double dWidth)
{
m_dWidth = dWidth;
}
double FormInfo::getLineWidth()
{
return m_dWidth;
}
//线型
void FormInfo::setLineStyle(Qt::PenStyle lineStyle)
{
m_lineStyle = lineStyle;
}
Qt::PenStyle FormInfo::getLineStyle()
{
return m_lineStyle;
}
void FormInfo::setVMax(float vmax)
{
m_vmax = vmax;
}
float FormInfo::getVMax()
{
return m_vmax;
}
void FormInfo::setVMin(float vmin)
{
m_vmin = vmin;
}
float FormInfo::getVMin()
{
return m_vmin;
}
void FormInfo::setFrontColor(QColor frontColor)
{
m_frontColor = frontColor;
}
QColor FormInfo::getFrontColor()
{
return m_frontColor;
}
void FormInfo::setBackColor(QColor backColor)
{
m_backColor = backColor;
}
QColor FormInfo::getBackColor()
{
return m_backColor;
}
2025-10-29 17:23:30 +08:00
//属性-左刻度
void FormInfo::s_ChangeLeftScale(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double newLeftScale)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_vmin = newLeftScale;
update();
}
}
//属性-右刻度
void FormInfo::s_ChangeRightScale(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double newRightScale)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_vmax = newRightScale;
update();
}
}
//属性-刻度类型
void FormInfo::s_ChangeScaleType(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QString strScaleType)
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_strScaleType = strScaleType;
}
}
2025-10-29 17:23:30 +08:00
//属性-颜色
void FormInfo::s_ChangeLineColor(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_lineColor = lineColor;
update();
}
}
//属性-线宽
void FormInfo::s_ChangeLineWidth(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double width)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_dWidth = width;
update();
}
}
//属性-线型
void FormInfo::s_ChangeLineStyle(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, Qt::PenStyle lineStyle)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_lineStyle = lineStyle;
update();
}
}
//岩性填充-不填充
void FormInfo::s_ClearFillMode(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_newFillMode = "无填充";
update();
}
}
//岩性填充-填充
void FormInfo::s_ChangeFillMode(QString strUuid, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName,
2025-10-29 17:23:30 +08:00
QString newFillType, QString newTargetLine, QColor newColor, QString newLithosImage, QString newHeadFill,
float vMin, float vMax, QString strOtherScaleType, QColor frontColor, QColor backColor, QString newFillMode, bool bFillNow)
2025-10-29 17:23:30 +08:00
{
if(m_strUuid == strUuid &&
m_strSlfName == strSlfName &&
2025-10-29 17:23:30 +08:00
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_newFillType = newFillType;
m_newTargetLine = newTargetLine;
2025-10-29 17:23:30 +08:00
m_newColor = newColor;
m_newLithosImage = newLithosImage;
m_newHeadFill = newHeadFill;
m_new_vMin = vMin;
m_new_vMax = vMax;
m_strOtherScaleType = strOtherScaleType;
m_frontColor = frontColor;
m_backColor = backColor;
m_newFillMode = newFillMode;//"填充";
2025-10-29 17:23:30 +08:00
update();
}
}