logplus/logPlus/forminfo.cpp

399 lines
12 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>
//曲线名称(单个)
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 = 2;
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, double)), this, SLOT(s_ChangeLeftScale(QString, QString, QString, QString, double)));
//右刻度
connect(CallManage::getInstance(), SIGNAL(sig_ChangeRightScale(QString, QString, QString, QString, double)), this, SLOT(s_ChangeRightScale(QString, QString, QString, QString, double)));
//颜色
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLineColor(QString, QString, QString, QString, QColor)), this, SLOT(s_ChangeLineColor(QString, QString, QString, QString, QColor)));
//线宽
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLineWidth(QString, QString, QString, QString, double)), this, SLOT(s_ChangeLineWidth(QString, QString, QString, QString, double)));
//线型
connect(CallManage::getInstance(), SIGNAL(sig_ChangeLineStyle(QString, QString, QString, QString, Qt::PenStyle)), this, SLOT(s_ChangeLineStyle(QString, QString, QString, QString, Qt::PenStyle)));
//岩性填充-不填充
connect(CallManage::getInstance(), SIGNAL(sig_ClearFillMode(QString, QString, QString, QString)), this, SLOT(s_ClearFillMode(QString, QString, QString, QString)));
//岩性填充-填充
connect(CallManage::getInstance(), SIGNAL(sig_ChangeFillMode(QString, QString, QString, QString, QString, QString, QColor, QString, QString, float, float, QColor, QColor)),
this, SLOT(s_ChangeFillMode(QString, QString, QString, QString, QString, QString, QColor, QString, QString, float, float, QColor, QColor)));
2025-10-29 17:23:30 +08:00
}
FormInfo::~FormInfo()
{
delete ui;
}
QJsonObject FormInfo::makeJson()
{
// 创建根对象
QJsonObject rootObj;
//
rootObj["SlfName"] = m_strSlfName;
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["newFillMode"] = m_newFillMode;
rootObj["newHeadFill"] = m_newHeadFill;
rootObj["newFillType"] = m_newFillType;
rootObj["newColorRed"] = m_newColor.red();
rootObj["newColorGreen"] = m_newColor.green();
rootObj["newColorBlue"] = m_newColor.blue();
rootObj["newColorAlpha"] = m_newColor.alpha();
rootObj["newLithosImage"] = m_newLithosImage;
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 == "绘制")
{
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()-3, rect.height()-4);
painter.setPen(QPen(m_lineColor, m_dWidth, m_lineStyle));
painter.drawRoundRect(rectRound);//利用画刷(颜色/岩性图片),画框
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_strLineName); // titleBarText QStringLiteral("动画")
QFont font2("微软雅黑", 8, false, false);
painter.setFont(font2);
painter.setPen(m_lineColor);
painter.drawText(rect.left() + 20, 80, QString::number(m_vmin)+" ~ "+QString::number(m_vmax));
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); // 设置鼠标为不可添加状态
}
}
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() > 2)
{
QString strSlfName = list[0];
QString strWellName = list[1];
QString strLineName = list[2];
qDebug() << "strSlfName:" << strSlfName<< " strWellName:" << strWellName<< " strLineName:" << strLineName;
if(m_strWellName == strWellName)
{
//新建曲线
emit CallManage::getInstance()->sig_AddLine(strSlfName, strWellName, m_strTrackName, strLineName);
// 接受拖拽事件
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
// 如果井名不正确,不接受拖拽事件
event->ignore();
}
}
else
{
// 如果数据格式不正确,不接受拖拽事件
event->ignore();
}
}
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 strSlfName, QString strWellName, QString strTrackName, QString strLineName, double newLeftScale)
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_vmin = newLeftScale;
update();
}
}
//属性-右刻度
void FormInfo::s_ChangeRightScale(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double newRightScale)
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_vmax = newRightScale;
update();
}
}
//属性-颜色
void FormInfo::s_ChangeLineColor(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor)
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_lineColor = lineColor;
update();
}
}
//属性-线宽
void FormInfo::s_ChangeLineWidth(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, double width)
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_dWidth = width;
update();
}
}
//属性-线型
void FormInfo::s_ChangeLineStyle(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, Qt::PenStyle lineStyle)
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_lineStyle = lineStyle;
update();
}
}
//岩性填充-不填充
void FormInfo::s_ClearFillMode(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName)
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_newFillMode = "无填充";
update();
}
}
//岩性填充-填充
void FormInfo::s_ChangeFillMode(QString strSlfName, QString strWellName, QString strTrackName, QString strLineName,
QString newFillType, QString newTargetLine, QColor newColor, QString newLithosImage, QString newHeadFill,
float vMin, float vMax, QColor frontColor, QColor backColor)
2025-10-29 17:23:30 +08:00
{
if(m_strSlfName == strSlfName &&
m_strWellName == strWellName &&
m_strTrackName == strTrackName &&
m_strLineName == strLineName)
{
m_newFillMode = "填充";
m_newHeadFill = newHeadFill;
m_newFillType = newFillType;
m_newColor = newColor;
m_newLithosImage = newLithosImage;
m_frontColor = frontColor;
m_backColor = backColor;
2025-10-29 17:23:30 +08:00
update();
}
}