#include "ShowCurve.h" #include "ui_ShowCurve.h" //#include "DrawAPicture.h" #include #include #include #include #include #include #include #include #include #include "geometryutils.h" #include "CallManage.h" #define R2LTIPS "请拖动数据表格纵向滑块即可完成深度初定位." #define EDITMODETIPS "正处于编辑模式单击右键以完成编辑." ShowCurve::ShowCurve(QWidget *parent) : QWidget(parent), m_pUI(new Ui::ShowCurve),vmax(-9999),vmin(-9999), mouseDepth(0), mouseValue(0), getBar(false), locked(true), hasTipsWidth(false) { val=NULL; m_pUI->setupUi(this); int w = width(); int h = height(); m_timer = new QTimer(); if(NULL != parent) { parent->setFixedSize(w,h); } thisParent = parent; m_view = new DrawCurveView(); m_pUI->pushButton->setEnabled(false); m_pUI->pushButton_2->setEnabled(false); m_pUI->pushButton_3->setEnabled(false); connect(CallManage::getInstance(), SIGNAL(sig_ValueChange(int, float)), this, SLOT(linkVerDeptSliderValueChange(int, float))); connect(m_pUI->verticalSlider,SIGNAL(valueChanged(int)),this,SLOT(onVerDeptSliderValueChange(int))); connect(m_view, SIGNAL(verticalSliderUP()), this, SLOT(SliderUP_SLOT())); connect(m_view, SIGNAL(verticalSliderDOWN()), this, SLOT(SliderDOWN_SLOT())); connect(m_view, SIGNAL(editModeTips()), this, SLOT(editModeTips_SLOT())); connect(m_pUI->deptEdit->lineEdit_Depth, SIGNAL(textChanged( QString )),this,SLOT(slotChangeDepth(QString))); connect(m_pUI->pushButtonScale, SIGNAL(clicked()), this, SLOT(slotChangeScale())); connect(m_pUI->pushButtonStretch, SIGNAL(clicked()), this, SLOT(slotStretch())); connect(m_pUI->pushButtonCompres, SIGNAL(clicked()), this, SLOT(slotCompres())); connect(m_pUI->pushButton, SIGNAL(clicked()), this, SLOT(editSig_SLOT())); connect(m_pUI->pushButton_2, SIGNAL(clicked()), this, SLOT(smoothSig_SLOT())); connect(m_pUI->pushButton_3, SIGNAL(clicked()), this, SLOT(angSig_SLOT())); connect(m_view, SIGNAL(enableEditButtons()), this, SLOT(editButtonsCon_SLOT())); connect(m_view, SIGNAL(unableEditButtons()), this, SLOT(unEditButtonsCon_SLOT())); //测试 // connect(m_pUI->pushButton_4, SIGNAL(clicked()), this, SLOT(testButton_SLOT())); QPixmap pushButton_5Pixmap; pushButton_5Pixmap.load(::GetImagePath() + "/UIMake/R2L.png"); m_pUI->pushButton_5->setFixedSize(pushButton_5Pixmap.width(), pushButton_5Pixmap.height()); m_pUI->pushButton_5->setIcon(pushButton_5Pixmap); m_pUI->pushButton_5->setIconSize(QSize(pushButton_5Pixmap.width(), pushButton_5Pixmap.height())); //m_pUI->pushButton_5->setFlat(true); connect(m_pUI->pushButton_5, SIGNAL(clicked()), this, SLOT(R2LButton_SLOT())); connect(m_view, SIGNAL(R2L()), this, SLOT(R2LMouse_SLOT())); connect(m_pUI->lineEdit_Value, SIGNAL(returnPressed()), this, SLOT(R2LButton_SLOT())); m_pUI->lineEdit_Value->setValidator(new QDoubleValidator(-9999999,9999999,6,this)); QPixmap pushButton_6Pixmap; pushButton_6Pixmap.load(::GetImagePath() + "/UIMake/L2RLock.png"); m_pUI->pushButton_6->setFixedSize(pushButton_6Pixmap.width(), pushButton_6Pixmap.height()); m_pUI->pushButton_6->setIcon(pushButton_6Pixmap); m_pUI->pushButton_6->setIconSize(QSize(pushButton_6Pixmap.width(), pushButton_6Pixmap.height())); //m_pUI->pushButton_6->setFlat(true); connect(m_pUI->pushButton_6, SIGNAL(clicked()), this, SLOT(lockChange_SLOT())); QPixmap sizeButtonPixmap; sizeButtonPixmap.load(::GetImagePath() + "/UIMake/UIButtonBig_o.png"); m_pUI->pushButtonStretch->setFixedSize(sizeButtonPixmap.width(), sizeButtonPixmap.height()); m_pUI->pushButtonStretch->setIcon(sizeButtonPixmap); m_pUI->pushButtonStretch->setIconSize(QSize(sizeButtonPixmap.width(), sizeButtonPixmap.height())); //m_pUI->pushButtonStretch->setStyleSheet("QPushButton:hover{background-color: rgb(254,164,134);}"); //m_pUI->pushButtonStretch->setFlat(true); sizeButtonPixmap.load(::GetImagePath() + "/UIMake/UIButtonSmall_o.png"); m_pUI->pushButtonCompres->setFixedSize(sizeButtonPixmap.width(), sizeButtonPixmap.height()); m_pUI->pushButtonCompres->setIcon(sizeButtonPixmap); m_pUI->pushButtonCompres->setIconSize(QSize(sizeButtonPixmap.width(), sizeButtonPixmap.height())); //m_pUI->pushButtonCompres->setFlat(true); tipsHeight = m_pUI->textBrowser->height(); //m_pUI->textBrowser->verticalScrollBar()->setVisible(false); //m_pUI->textBrowser->horizontalScrollBar()->setVisible(false); QPalette pa; pa.setColor(QPalette::WindowText, QColor(120,120,120)); m_pUI->textBrowser->setPalette(pa); } void ShowCurve::testButton_SLOT() { // DrawAPicture *t = new DrawAPicture(); // t->show(); } void ShowCurve::init() { CLogIO *logio=new CLogIO(); logio->Open(FileName.toStdString().c_str(),CSlfIO::modeRead); index=logio->OpenCurve(CurveName.toStdString().c_str()); if(index<0) { delete logio; return; } logio->GetCurveInfo(index,&curveinfo); sdep=curveinfo.StartDepth; edep=curveinfo.EndDepth; rlev=curveinfo.DepLevel; m_view->sdep = sdep; m_view->edep = edep; m_view->rlev = rlev; m_view->userPos = 0; m_view->fileName = FileName; m_view->curveName = CurveName; curDepth=sdep+(edep-sdep)/2.; count=(curveinfo.EndDepth-curveinfo.StartDepth)/curveinfo.DepLevel+1.5; val=new float[count]; logio->ReadCurve(index,curveinfo.StartDepth,count,&val[0]); logio->CloseCurve(index); delete logio; if(vmax==-9999 && vmin==-9999) if(!getValueRangeFromIni()){ vmax=vmin=val[0]; for(int i=1;ival[i])vmin=val[i]; } m_view->m_Xmax=vmax,m_view->m_Xmin=vmin; m_pUI->lineEdit_Xmax->setText(QString::number(vmax)); m_pUI->lineEdit_Xmax->setValidator(new QDoubleValidator(-9999999,9999999,6,this)); m_pUI->lineEdit_Xmin->setText(QString::number(vmin)); m_pUI->lineEdit_Xmin->setValidator(new QDoubleValidator(-9999999,9999999,6,this)); } m_view->setValues(val); m_view->factor=2; initVerMaxRange = 200; m_view->PageSize = int(count / initVerMaxRange + 100); if(m_view->PageSize < 500) m_view->PageSize=500; //m_view.PageSize=(int)(200./curveinfo.DepLevel+0.5); //for small rlev //if(curveinfo.DepLevel<0.005)m_view.PageSize/=100; //else if(curveinfo.DepLevel<0.05)m_view.PageSize/=10; QString title= QString( curveinfo.Name)+QString::fromUtf8("曲线预览"); m_pUI->label_WfName->setText(title); m_pUI->label_StartDepth->setText(QString::number(sdep)); m_pUI->label_EndDepth->setText(QString::number(edep)); m_pUI->deptEdit->lineEdit_Depth->setText(QString::number(curDepth)); m_pUI->deptEdit->lineEdit_Depth->setValidator(new QDoubleValidator(-9999999,9999999,6,this)); QPalette pal; m_pUI->widgetPlot->setStyleSheet("background:lightgray"); m_pUI->widgetPlot->setPalette(pal); m_view->setParent(m_pUI->widgetPlot); m_view->setCount(count); m_pUI->verticalSlider->setRange(0, initVerMaxRange); m_pUI->verticalSlider->setValue(initVerMaxRange / 2); } bool ShowCurve::getValueRangeFromIni() { QString curveFamilyFilePath = ::GetConfPath() + "CurveFamily.ini"; QFile curveFamilyFile(curveFamilyFilePath); if(!curveFamilyFile.open(QIODevice::ReadOnly | QIODevice::Text)) return false; bool finished = false; while(!curveFamilyFile.atEnd()) { QByteArray line = curveFamilyFile.readLine(); QString str(line); QStringList strList = str.split("="); if(strList[0] == CurveName) { strList = str.split(","); float minValue = strList[1].toFloat(); float maxValue = strList[2].toFloat(); if(minValue < -9999 || minValue > 9999) return false; if(maxValue < -9999 || maxValue > 9999) return false; if(maxValue <= minValue) return false; m_view->m_Xmax=maxValue,m_view->m_Xmin=minValue; m_pUI->lineEdit_Xmax->setText(QString::number(maxValue)); m_pUI->lineEdit_Xmax->setValidator(new QDoubleValidator(-9999999,9999999,6,this)); m_pUI->lineEdit_Xmin->setText(QString::number(minValue)); m_pUI->lineEdit_Xmin->setValidator(new QDoubleValidator(-9999999,9999999,6,this)); finished = true; break; } } curveFamilyFile.close(); return finished; } void ShowCurve::editSig_SLOT() { m_view->button_editIfBegin(); } void ShowCurve::smoothSig_SLOT() { m_view->button_smoothWin(); } void ShowCurve::angSig_SLOT() { m_view->button_AngAdjWin(); } void ShowCurve::editModeTips_SLOT() { if(!hasTipsWidth){ tipsWidth = m_pUI->textBrowser->width(); hasTipsWidth = true; } tipsText = QString::fromUtf8(EDITMODETIPS); m_pUI->textBrowser->setText(tipsText); m_pUI->textBrowser->setGeometry(QRect( m_pUI->textBrowser->x(), m_pUI->textBrowser->y(), tipsWidth, m_pUI->textBrowser->height())); connect(m_timer, SIGNAL(timeout()), SLOT(promptDisplay())); m_timer->setInterval(1000); m_timer->start(); return; } void ShowCurve::slotChangeDepth(const QString &text) { if(text.toFloat() < sdep || text.toFloat() > edep) { // m_pUI->lineEdit_Depth->setText(QString::number(curDepth)); return; } curDepth = text.toFloat(); if(curveinfo.EndDepth == curveinfo.StartDepth) { m_view->CurrentPos = 0; } else { m_view->CurrentPos = (curDepth - curveinfo.StartDepth) / (curveinfo.EndDepth - curveinfo.StartDepth) * count; } //m_pUI->lineEdit_Value->setText(QString::number(curDepth)); m_view->update(); } void ShowCurve::resizeEvent(QResizeEvent *resize) { QSize orgsize=this->size(); QWidget::resizeEvent(resize); if(resize->size().isValid()) { QSize changeSize=resize->size(); int width=changeSize.width()-orgsize.width(); int height= changeSize.height()-orgsize.height(); m_view->resize(changeSize.width()-150,changeSize.height()-100); m_view->initView(); m_view->update(); } } void ShowCurve::onVerDeptSliderValueChange(int value) { curDepth = edep - (edep-sdep) * value / initVerMaxRange; m_pUI->deptEdit->lineEdit_Depth->setText(QString::number(curDepth)); m_view->update(); curDepRange(); //setCurveTableForce(curDepth); } void ShowCurve::SliderUP_SLOT() { m_pUI->verticalSlider->setValue(m_pUI->verticalSlider->value() + 1); } void ShowCurve::SliderDOWN_SLOT() { m_pUI->verticalSlider->setValue(m_pUI->verticalSlider->value() - 1); } void ShowCurve::mouseMkChange(float depth, float value){ mouseDepth = depth; mouseValue = value; //m_pUI->lineEdit_Value->setText(QString::number(depth)); //m_pUI->lineEdit_curValue->setText(QString::number(value)); } void ShowCurve::lineEdit_curValue_Change(float v){ //m_pUI->lineEdit_curValue->setText(QString::number(v)); } //联动 void ShowCurve::linkVerDeptSliderValueChange(int value, float tipValue) { if(rlev <= 0 || edep == sdep || locked == false)return; m_pUI->deptEdit->lineEdit_Depth->setText(QString::number(tipValue)); m_pUI->lineEdit_Value->setText(QString::number(tipValue)); int pageNo = (edep - tipValue) / (edep-sdep) * initVerMaxRange + m_view->PageSize / 2 * rlev / ((edep-sdep)/initVerMaxRange); if(pageNo > initVerMaxRange) pageNo = initVerMaxRange; int curCount = (tipValue - sdep) / rlev + 0.5; //m_pUI->lineEdit_curValue->setText(QString::number(val[curCount])); m_pUI->verticalSlider->setValue(pageNo); onVerDeptSliderValueChange(pageNo); m_view->userCurrentPos = tipValue; m_view->update(); } void ShowCurve::setTableBro(QScrollBar *p) { getBar = true; tableBro = p; } void ShowCurve::setCurveTable(QTableWidget *t) { curveTable = t; } //改变刻度按钮槽 void ShowCurve::slotChangeScale() { m_view->m_Xmin=m_pUI->lineEdit_Xmin->text().toFloat(); m_view->m_Xmax=m_pUI->lineEdit_Xmax->text().toFloat(); m_view->update(); } void ShowCurve::slotStretch()//深度拉伸 { initVerMaxRange *= 1.5; if(initVerMaxRange == 1)initVerMaxRange=2; m_pUI->verticalSlider->setRange(0, initVerMaxRange); if(!m_pUI->pushButtonCompres->isEnabled()) m_pUI->pushButtonCompres->setEnabled(true); m_view->PageSize/=1.5; if(m_view->PageSize < 50) m_pUI->pushButtonStretch->setEnabled(false); m_view->update(); curDepRange(); } void ShowCurve::slotCompres()//深度压缩 { initVerMaxRange /= 1.5; if(initVerMaxRange / 1.5 <= 1) m_pUI->pushButtonCompres->setEnabled(false); m_pUI->verticalSlider->setRange(0, initVerMaxRange); if(!m_pUI->pushButtonStretch->isEnabled()) m_pUI->pushButtonStretch->setEnabled(true); m_view->PageSize*=1.5; m_view->update(); curDepRange(); } //改变绘制窗口的深度显示 void ShowCurve::curDepRange() { float cDR_value = m_pUI->verticalSlider->value(); float cDR_startDepth = edep - (edep-sdep) * cDR_value / initVerMaxRange; float cDR_endDepth = cDR_startDepth + m_view->PageSize * rlev; m_pUI->label_StartDepth->setText(QString::number(cDR_startDepth)); m_pUI->label_EndDepth->setText(QString::number(cDR_endDepth)); } void ShowCurve::showEvent(QShowEvent *sEvent) { QWidget::showEvent(sEvent); QRect rec=m_pUI->widgetPlot->geometry(); qDebug()<<"value:"<setGeometry(0,0,w,h); m_view->initView(); } ShowCurve::~ShowCurve() { delete m_pUI; if(val)delete []val; delete m_view; delete m_timer; } void ShowCurve::editButtonsCon_SLOT() { m_pUI->pushButton->setEnabled(true); m_pUI->pushButton_2->setEnabled(true); m_pUI->pushButton_3->setEnabled(true); } void ShowCurve::unEditButtonsCon_SLOT() { m_pUI->pushButton->setEnabled(false); m_pUI->pushButton_2->setEnabled(false); m_pUI->pushButton_3->setEnabled(false); } void ShowCurve::R2LButton_SLOT() { if(!getBar){ if(!hasTipsWidth){ tipsWidth = m_pUI->textBrowser->width(); hasTipsWidth = true; } tipsText = QString::fromUtf8(R2LTIPS); m_pUI->textBrowser->setText(tipsText); m_pUI->textBrowser->setGeometry(QRect( m_pUI->textBrowser->x(), m_pUI->textBrowser->y(), tipsWidth, m_pUI->textBrowser->height())); connect(m_timer, SIGNAL(timeout()), SLOT(promptDisplay())); m_timer->setInterval(1000); m_timer->start(); return; } //以输入框深度信息 float R2L_depthValue = m_pUI->lineEdit_Value->text().toFloat(); m_view->userCurrentPos = R2L_depthValue; int pageNo = (edep - R2L_depthValue) / (edep-sdep) * initVerMaxRange + m_view->PageSize / 2 * rlev / ((edep-sdep)/initVerMaxRange); if(pageNo > initVerMaxRange) pageNo = initVerMaxRange; m_pUI->verticalSlider->setValue(pageNo); int tv = tableBro->maximum(); float oneValue = (edep - sdep) / tv; int bv = (R2L_depthValue - sdep) / oneValue; tableBro->setValue(bv); setCurveTableForce(R2L_depthValue); } void ShowCurve::R2LMouse_SLOT() { if(!getBar) return; //以鼠标位置深度信息 m_view->userCurrentPos = mouseDepth; m_pUI->lineEdit_Value->setText(QString::number(mouseDepth)); //m_pUI->lineEdit_curValue->setText(QString::number(mouseValue)); int tv = tableBro->maximum(); float oneValue = (edep - sdep) / tv; int bv = (mouseDepth - sdep) / oneValue; tableBro->setValue(bv); setCurveTableForce(mouseDepth); } void ShowCurve::promptDisplay() { m_timer->stop(); //m_pUI->textBrowser->setText(tipsText); //m_pUI->textBrowser->windowOpacity QPropertyAnimation *tipsAnimation = new QPropertyAnimation(m_pUI->textBrowser, "geometry"); tipsAnimation->setDuration(2000); tipsAnimation->setStartValue(QRect( m_pUI->textBrowser->x(), m_pUI->textBrowser->y(), tipsWidth, m_pUI->textBrowser->height() )); tipsAnimation->setEndValue(QRect( m_pUI->textBrowser->x(), m_pUI->textBrowser->y(), 0, m_pUI->textBrowser->height() )); tipsAnimation->start(); connect(tipsAnimation, SIGNAL(finished()), this, SLOT(clearTips_SLOT())); } void ShowCurve::clearTips_SLOT() { m_pUI->textBrowser->setText(""); } void ShowCurve::setCurveTableForce(float dep) { float tv = tableBro->maximum(); float oneValue = (edep - sdep) / tv; int bv = (dep - sdep) / oneValue; float SCTF_r = bv / tv; int SCTF_pos = (curveTable->rowCount()+1) * SCTF_r; qDebug() << "setCurveTableForce" << QString::number(SCTF_pos); curveTable->selectRow(SCTF_pos); } void ShowCurve::lockChange_SLOT() { locked = !locked; if(locked){ QPixmap pushButton_6Pixmap; pushButton_6Pixmap.load(::GetImagePath() + "/UIMake/L2RLock.png"); m_pUI->pushButton_6->setFixedSize(pushButton_6Pixmap.width(), pushButton_6Pixmap.height()); m_pUI->pushButton_6->setIcon(pushButton_6Pixmap); m_pUI->pushButton_6->setIconSize(QSize(pushButton_6Pixmap.width(), pushButton_6Pixmap.height())); } else{ QPixmap pushButton_6Pixmap; pushButton_6Pixmap.load(::GetImagePath() + "/UIMake/L2RUnlock.png"); m_pUI->pushButton_6->setFixedSize(pushButton_6Pixmap.width(), pushButton_6Pixmap.height()); m_pUI->pushButton_6->setIcon(pushButton_6Pixmap); m_pUI->pushButton_6->setIconSize(QSize(pushButton_6Pixmap.width(), pushButton_6Pixmap.height())); } }