岩心图片 鼠标操作
This commit is contained in:
parent
9c8725eaed
commit
228bb896d0
|
|
@ -5968,12 +5968,39 @@ void PropertyWidget::changedMCalsProperty(QString strProperty, QVariant varVal)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//void initDrawImageProperty(FormInfo *formInfo);
|
||||
//void changedDrawImageProperty(QString strProName, QVariant val);
|
||||
|
||||
void PropertyWidget::initDrawImageProperty(FormInfo *formInfo)
|
||||
{
|
||||
_CreateVariantPropertyItem("数据", "名称", formInfo->m_strAliasName, QVariant::String);
|
||||
_CreateVariantPropertyItem("数据", "选择曲线", formInfo->m_strSlfName, QVariant::String);
|
||||
_CreateVariantPropertyItem("数据", "显示单位", formInfo->m_strUnit, QVariant::String);
|
||||
_CreateVariantPropertyItem("数据", "最小值", formInfo->m_strUnit, QVariant::String);
|
||||
_CreateVariantPropertyItem("数据", "最大值", formInfo->m_strUnit, QVariant::String);
|
||||
|
||||
_CreateVariantPropertyItem("通常", "例区高度(cm)", formInfo->m_strUnit, QVariant::String);
|
||||
|
||||
_CreateVariantPropertyItem("字体", "曲线名称", formInfo->m_strAliasNameFont, QVariant::Font);
|
||||
_CreateVariantPropertyItem("字体", "曲线单位", formInfo->m_strUnitFont, QVariant::Font);
|
||||
_CreateVariantPropertyItem("字体", "颜色", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
|
||||
_CreateVariantPropertyItem("三维", "三维显示", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
_CreateVariantPropertyItem("三维", "俯视角度", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
_CreateVariantPropertyItem("三维", "微调旋转角度", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
_CreateVariantPropertyItem("三维", "显示方位", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
|
||||
QStringList listType;
|
||||
listType.append("线性");
|
||||
listType.append("对数");
|
||||
_CreateEnumPropertyItem("显示设置", "坐标类型", formInfo->m_pl_fontScale, listType);
|
||||
QStringList listType2;
|
||||
listType2.append("线性");
|
||||
listType2.append("对数");
|
||||
_CreateEnumPropertyItem("显示设置", "配色方案", formInfo->m_pl_fontScale, listType2);
|
||||
_CreateVariantPropertyItem("显示设置", "背景值", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
_CreateVariantPropertyItem("显示设置", "滤波方式", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
_CreateVariantPropertyItem("显示设置", "NxN(N取奇数)", formInfo->m_pl_fontScale, QVariant::Font);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ void YxzpDialog::onSelectImage()
|
|||
this,
|
||||
"选择图片",
|
||||
QDir::homePath(),
|
||||
"JPG 图片 (*.jpg *.jpeg)"
|
||||
"JPG 图片 (*.jpg *.jpeg *.png)"
|
||||
);
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
|
|
|
|||
|
|
@ -1921,12 +1921,12 @@ void QMyCustomPlot::onEditImage()
|
|||
double left_Low = this->xAxis->pixelToCoord(bottom);
|
||||
|
||||
//追加判断,避免框选重叠
|
||||
TransparentDraggableGujing *pDraggableRect =NULL;
|
||||
TransparentDraggableImage *pDraggableRect =NULL;
|
||||
{
|
||||
QMap<QString,QObject *>::Iterator it = m_mapDraggable_Gujing.begin();
|
||||
while( it != m_mapDraggable_Gujing.end() )
|
||||
QMap<QString,QObject *>::Iterator it = m_mapDraggable_Image.begin();
|
||||
while( it != m_mapDraggable_Image.end() )
|
||||
{
|
||||
pDraggableRect = (TransparentDraggableGujing*)it.value();
|
||||
pDraggableRect = (TransparentDraggableImage*)it.value();
|
||||
//
|
||||
QCPRange tmpRange = pDraggableRect->getRange();
|
||||
if(tmpRange.lower >= left_Low && tmpRange.upper <= right_Hight)
|
||||
|
|
@ -1955,6 +1955,10 @@ void QMyCustomPlot::onEditImage()
|
|||
{
|
||||
imagePath = dlg.getImagePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加岩心图片
|
||||
this->addImageToPlot(left_Low, right_Hight, imagePath, 0, 100);
|
||||
|
|
@ -8556,6 +8560,8 @@ void QMyCustomPlot::onOpenEditResult()
|
|||
this->selectionRect()->setPen(Qt::NoPen);
|
||||
this->setInteractions(QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables | QCP::iMultiSelect); // 轴、图例、图表可以被选择,并且是多选的方式
|
||||
this->setSelectionRectMode(QCP::srmSelect); // 鼠标框选
|
||||
|
||||
onEditImage();
|
||||
}
|
||||
|
||||
void QMyCustomPlot::onCloseEditResult()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "transparentdraggableimage.h"
|
||||
// TransparentDraggableImage.cpp
|
||||
#include "transparentdraggableimage.h"
|
||||
#include "PropertyWidget.h"
|
||||
|
||||
|
||||
|
|
@ -365,6 +366,14 @@ void TransparentDraggableImage::initRect()
|
|||
//mItemTitle->position->setType(QCPItemPosition::ptAxisRectRatio);
|
||||
mItemTitle->position->setCoords(0.5, 0);
|
||||
mItemTitle->setLayer("overlay");
|
||||
|
||||
mDragLine = new QCPItemStraightLine(mPlot);
|
||||
mDragLine->setPen(QPen(Qt::red, 1));
|
||||
mDragLine->setVisible(false);
|
||||
|
||||
mDragLine2 = new QCPItemStraightLine(mPlot);
|
||||
mDragLine2->setPen(QPen(Qt::red, 1));
|
||||
mDragLine2->setVisible(false);
|
||||
}
|
||||
|
||||
void TransparentDraggableImage::updateHandles()
|
||||
|
|
@ -394,60 +403,14 @@ void TransparentDraggableImage::onDelRect()
|
|||
|
||||
void TransparentDraggableImage::onMousePress(QMouseEvent *event)
|
||||
{
|
||||
if(event->button() != Qt::LeftButton)//右键
|
||||
if(event->button() != Qt::LeftButton)
|
||||
{
|
||||
// double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
||||
// QCPRange currentRange = getRange();
|
||||
// if(mLeftHandle->selectTest(event->pos(), false) < 5) {
|
||||
// mDragMode = DragNone;
|
||||
// }
|
||||
// else if(mRightHandle->selectTest(event->pos(), false) < 5) {
|
||||
// mDragMode = DragNone;
|
||||
// }
|
||||
// //else if(x >= currentRange.lower && x <= currentRange.upper) {
|
||||
// else if(y >= currentRange.lower && y <= currentRange.upper) {
|
||||
// mDragMode = DragNone;
|
||||
// }
|
||||
// else {
|
||||
// mDragMode = DragNone;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// //event->accept();
|
||||
// // 显示属性
|
||||
// double low = mRect->topLeft->coords().x();
|
||||
// double hight = mRect->bottomRight->coords().x();
|
||||
// double left = getLeft();
|
||||
// double width = getWidth();
|
||||
// QColor borderColor = this->m_BorderColor; // 边框颜色
|
||||
// Qt::PenStyle borderStyle = this->m_BorderStyle; // 边框线型
|
||||
// int borderWidth = this->m_BorderWidth; // 边框线宽(像素)
|
||||
// PropertyService()->initImageItemProperty(this, low, hight, m_Result, left, width,borderColor,borderStyle,borderWidth);
|
||||
|
||||
// QMenu menu(nullptr);
|
||||
// QAction *delAction = menu.addAction("删除框图");
|
||||
// //delAction->installEventFilter(this);
|
||||
// connect(delAction, &QAction::triggered, this, &TransparentDraggableImage::onDelRect);
|
||||
// // QAction* pItem = menu.exec(event->globalPos());
|
||||
// // if(pItem == delAction)
|
||||
// // {
|
||||
// // //event->accept();
|
||||
// // int ii=0;
|
||||
// // ii++;
|
||||
// // }
|
||||
// menu.exec(event->globalPos());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
event->accept();
|
||||
|
||||
// 检查点击了哪个部分
|
||||
//double x = mPlot->xAxis->pixelToCoord(event->pos().x());
|
||||
//double y = mPlot->yAxis->pixelToCoord(event->pos().y());
|
||||
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());//x轴展示深度
|
||||
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
QCPRange currentRange = getRange();
|
||||
|
||||
if(mLeftHandle->selectTest(event->pos(), false) < 5) {
|
||||
|
|
@ -456,19 +419,20 @@ void TransparentDraggableImage::onMousePress(QMouseEvent *event)
|
|||
else if(mRightHandle->selectTest(event->pos(), false) < 5) {
|
||||
mDragMode = DragRight;
|
||||
}
|
||||
//else if(x >= currentRange.lower && x <= currentRange.upper) {
|
||||
else if(y >= currentRange.lower && y <= currentRange.upper) {
|
||||
mDragMode = DragRect;
|
||||
}
|
||||
else {
|
||||
mDragMode = DragNone;
|
||||
// 点击空白区域:进入纯参考线模式
|
||||
mDragMode = DragReferenceOnly;
|
||||
mDragStartY = y;
|
||||
mDragStartRange = currentRange; // 虽然不会用于移动,但保持记录
|
||||
mPlot->m_selectItem = this;
|
||||
return;
|
||||
}
|
||||
|
||||
//mDragStartX = x;
|
||||
mDragStartY = y;
|
||||
mDragStartRange = currentRange;
|
||||
|
||||
mPlot->m_selectItem = this;
|
||||
}
|
||||
|
||||
|
|
@ -478,45 +442,58 @@ void TransparentDraggableImage::onMouseMove(QMouseEvent *event)
|
|||
|
||||
event->accept();
|
||||
|
||||
//double x = mPlot->xAxis->pixelToCoord(event->pos().x());
|
||||
//double dx = x - mDragStartX;
|
||||
double currentY = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
double dy = currentY - mDragStartY;
|
||||
|
||||
double y = mPlot->xAxis->pixelToCoord(event->pos().y());
|
||||
double dy = y - mDragStartY;
|
||||
// 无论哪种模式(只要不是 DragNone),都显示参考线
|
||||
if(mDragMode == DragReferenceOnly)
|
||||
{
|
||||
mDragLine->point1->setCoords(mDragStartY, 0);
|
||||
mDragLine->point2->setCoords(mDragStartY, 1);
|
||||
mDragLine->setVisible(true);
|
||||
mDragLine2->point1->setCoords(currentY, 0);
|
||||
mDragLine2->point2->setCoords(currentY, 1);
|
||||
mDragLine2->setVisible(true);
|
||||
mPlot->replot();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
qDebug() << "DragReferenceOnly: startY=" << mDragStartY << " currentY=" << currentY;
|
||||
qDebug() << "Y range:" << mPlot->yAxis->range().lower << "->" << mPlot->yAxis->range().upper;
|
||||
|
||||
// 如果是纯参考线模式,不修改矩形范围,仅刷新显示即可
|
||||
if(mDragMode == DragReferenceOnly) {
|
||||
mPlot->replot();
|
||||
return;
|
||||
}
|
||||
|
||||
// 以下是原有的范围调整逻辑(DragLeft / DragRight / DragRect)
|
||||
QCPRange newRange = mDragStartRange;
|
||||
|
||||
switch(mDragMode) {
|
||||
case DragLeft: {
|
||||
//double proposedLeft = mDragStartRange.lower + dx;
|
||||
double proposedLeft = mDragStartRange.lower + dy;
|
||||
// 确保不超出轴范围且不使宽度小于最小值
|
||||
newRange.lower = qBound(
|
||||
//mPlot->xAxis->range().lower,
|
||||
getMyLower(),
|
||||
proposedLeft,
|
||||
mDragStartRange.upper - mMinWidth);
|
||||
break;
|
||||
}
|
||||
case DragRight: {
|
||||
//double proposedRight = mDragStartRange.upper + dx;
|
||||
double proposedRight = mDragStartRange.upper + dy;
|
||||
// 确保不超出轴范围且不使宽度小于最小值
|
||||
newRange.upper = qBound(
|
||||
mDragStartRange.lower + mMinWidth,
|
||||
proposedRight,
|
||||
getMyUpper());
|
||||
//mPlot->xAxis->range().upper);
|
||||
break;
|
||||
}
|
||||
case DragRect: {
|
||||
double width = mDragStartRange.size();
|
||||
//double center = mDragStartRange.center() + dx;
|
||||
double center = mDragStartRange.center() + dy;
|
||||
newRange.lower = center - width/2;
|
||||
newRange.upper = center + width/2;
|
||||
|
||||
// 检查是否超出轴范围
|
||||
if(newRange.lower < getMyLower()) {
|
||||
newRange.lower = getMyLower();
|
||||
newRange.upper = newRange.lower + width;
|
||||
|
|
@ -525,38 +502,19 @@ void TransparentDraggableImage::onMouseMove(QMouseEvent *event)
|
|||
newRange.upper = getMyUpper();
|
||||
newRange.lower = newRange.upper - width;
|
||||
}
|
||||
// QCPRange axisRange = mPlot->xAxis->range();
|
||||
// if(newRange.lower < axisRange.lower) {
|
||||
// newRange.lower = axisRange.lower;
|
||||
// newRange.upper = newRange.lower + width;
|
||||
// }
|
||||
// else if(newRange.upper > axisRange.upper) {
|
||||
// newRange.upper = axisRange.upper;
|
||||
// newRange.lower = newRange.upper - width;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// //取整数(方便显示统计,左右边界整数显示。)
|
||||
// newRange.lower = (int)newRange.lower;
|
||||
// QCPRange rangeByFile = mPlot->xAxis->range();
|
||||
// if (std::fabs(rangeByFile.upper - (int)newRange.upper) >= 1.0)
|
||||
// {
|
||||
// newRange.upper = (int)newRange.upper;
|
||||
// }
|
||||
|
||||
// 最终确保宽度不小于最小值(针对整体拖动的情况)
|
||||
// 确保宽度不小于最小值
|
||||
if(newRange.size() < mMinWidth) {
|
||||
if(mDragMode == DragRect) {
|
||||
// 如果是整体拖动,保持中心点不变
|
||||
double center = newRange.center();
|
||||
newRange.lower = center - mMinWidth/2;
|
||||
newRange.upper = center + mMinWidth/2;
|
||||
} else {
|
||||
// 如果是边界拖动,强制设置最小宽度
|
||||
if(mDragMode == DragLeft) {
|
||||
newRange.lower = newRange.upper - mMinWidth;
|
||||
} else if(mDragMode == DragRight) {
|
||||
|
|
@ -570,32 +528,35 @@ void TransparentDraggableImage::onMouseMove(QMouseEvent *event)
|
|||
|
||||
void TransparentDraggableImage::onMouseRelease(QMouseEvent *event)
|
||||
{
|
||||
// 先隐藏参考线(无论何种模式)
|
||||
mDragLine->setVisible(false);
|
||||
mDragLine2->setVisible(false);
|
||||
|
||||
if(event->button() == Qt::LeftButton && mDragMode != DragNone) {
|
||||
event->accept();
|
||||
// 显示属性
|
||||
|
||||
// 纯参考线模式:不弹属性框,直接重置模式并返回
|
||||
if(mDragMode == DragReferenceOnly) {
|
||||
mDragMode = DragNone;
|
||||
mPlot->replot();
|
||||
return;
|
||||
}
|
||||
|
||||
// 原有属性面板逻辑
|
||||
double low = mRect->topLeft->coords().x();
|
||||
double hight = mRect->bottomRight->coords().x();
|
||||
double left = this->getLeft();
|
||||
double width = this->getWidth();
|
||||
QColor borderColor = this->m_BorderColor; // 边框颜色
|
||||
Qt::PenStyle borderStyle = this->m_BorderStyle; // 边框线型
|
||||
int borderWidth = this->m_BorderWidth; // 边框线宽(像素)
|
||||
QColor borderColor = this->m_BorderColor;
|
||||
Qt::PenStyle borderStyle = this->m_BorderStyle;
|
||||
int borderWidth = this->m_BorderWidth;
|
||||
PropertyService()->initImageItemProperty(this, low, hight, m_Result, left, width, borderColor, borderStyle, borderWidth);
|
||||
|
||||
|
||||
//避免二次绘制框图
|
||||
mPlot->m_bDrawRect = false;
|
||||
//emit rangeChanged(getRange());
|
||||
mDragMode = DragNone;
|
||||
//取消选中状态
|
||||
// QCPDataSelection emptySelection;
|
||||
// mPlot->graph(0)->setSelection(emptySelection);
|
||||
// mPlot->replot();
|
||||
|
||||
//取消选中框
|
||||
mPlot->selectionRect()->cancel();
|
||||
mPlot->replot();
|
||||
mPlot->selectionRect()->mActive=true;
|
||||
mPlot->selectionRect()->mActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef TRANSPARENTDRAGGABLEIMAGE_H
|
||||
// TransparentDraggableImage.h
|
||||
#ifndef TRANSPARENTDRAGGABLEIMAGE_H
|
||||
#define TRANSPARENTDRAGGABLEIMAGE_H
|
||||
|
||||
#include <QObject>
|
||||
|
|
@ -69,6 +70,9 @@ public:
|
|||
Qt::PenStyle getBorderStyle();
|
||||
int getBorderWidth();
|
||||
|
||||
QCPItemStraightLine* mDragLine = NULL;
|
||||
QCPItemStraightLine* mDragLine2 = NULL;
|
||||
|
||||
signals:
|
||||
void rangeChanged(QCPRange newRange);
|
||||
|
||||
|
|
@ -96,9 +100,8 @@ private:
|
|||
QString m_strUuid = "";
|
||||
QString m_Result;
|
||||
|
||||
enum DragMode { DragNone, DragLeft, DragRight, DragRect };
|
||||
enum DragMode { DragNone, DragLeft, DragRight, DragRect, DragItem, DragReferenceOnly };
|
||||
DragMode mDragMode = DragNone;
|
||||
//double mDragStartX = 0;
|
||||
double mDragStartY = 0;
|
||||
QCPRange mDragStartRange;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user