152 lines
3.8 KiB
C++
152 lines
3.8 KiB
C++
#include "formtracktop.h"
|
|
#include "ui_formtracktop.h"
|
|
|
|
#include "CallManage.h"
|
|
#include <QDebug>
|
|
#include <QMimeData>
|
|
#include <QPushButton>
|
|
#include <QVBoxLayout>
|
|
#include "geometryutils.h"
|
|
#include "formwell.h"
|
|
|
|
//曲线名称(单个)
|
|
FormTrackTop::FormTrackTop(QWidget *parent, QString strSlfName, QString strWellName, QString strTrackName, QString strLineName, QColor lineColor) :
|
|
FormBase(parent, strSlfName, strWellName),
|
|
ui(new Ui::FormTrackTop)
|
|
{
|
|
ui->setupUi(this);
|
|
m_parent = parent;
|
|
//
|
|
setAcceptDrops(true);
|
|
|
|
//m_pFWell = qobject_cast<FormWell*>(parent);
|
|
|
|
//m_strSlfName = strSlfName;
|
|
//m_strWellName = strWellName;
|
|
m_strTrackName = strTrackName;
|
|
|
|
m_font = QFont("微软雅黑", 10);
|
|
m_fontColor = QColor(0,0,0);
|
|
}
|
|
|
|
FormTrackTop::~FormTrackTop()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void FormTrackTop::setTrackName(QString strTName)
|
|
{
|
|
m_strTrackName = strTName;
|
|
update();
|
|
}
|
|
|
|
// void FormTrackTop::setBorderFlags(BorderFlags flags)
|
|
// {
|
|
// m_BorderFlags = flags;
|
|
// }
|
|
|
|
void FormTrackTop::setTrackTopPropert(QJsonObject topObj)
|
|
{
|
|
if (topObj.contains("Font"))
|
|
{
|
|
QJsonValue value = topObj.value("Font");
|
|
this->m_font.fromString(value.toString());
|
|
}
|
|
if (topObj.contains("FontColor"))
|
|
{
|
|
QJsonValue value = topObj.value("FontColor");
|
|
this->m_fontColor.setNamedColor(value.toString());
|
|
}
|
|
}
|
|
|
|
QJsonObject FormTrackTop::makeJson()
|
|
{
|
|
// 创建根对象
|
|
QJsonObject rootObj;
|
|
//
|
|
rootObj["WellName"] = m_strWellName; // 道名称
|
|
rootObj["TrackName"] = m_strTrackName; // 道名称
|
|
rootObj["TrackW"] = m_nTrackW; // 道宽
|
|
rootObj["Font"] = m_font.toString();
|
|
rootObj["FontColor"] = m_fontColor.name();
|
|
|
|
return rootObj;
|
|
}
|
|
|
|
void FormTrackTop::paintEvent(QPaintEvent* event)
|
|
{
|
|
FormBase::paintEvent(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)
|
|
|
|
bool bVer = false;
|
|
QString text = m_strTrackName;
|
|
QFontMetrics fm1(m_font);
|
|
QRect textRect = fm1.boundingRect(m_strTrackName);
|
|
if (textRect.width() > rect.width())
|
|
{
|
|
text = "";
|
|
for (int i = 0; i < m_strTrackName.size(); i++) {
|
|
if (!i)text += m_strTrackName.at(i);
|
|
else {
|
|
text += "\n";
|
|
text += m_strTrackName.at(i);
|
|
}
|
|
}
|
|
}
|
|
painter.drawText(rect.left(), rect.top(), rect.width(), rect.height(), Qt::AlignCenter, text);
|
|
|
|
//rect.setLeft(rect.left() + 1);
|
|
//rect.setTop(rect.top() + 1);
|
|
//// 3. 准备绘制边框
|
|
//painter.save();
|
|
//painter.setPen(QPen(m_pFWell->getBorderGridProperty().m_clor,
|
|
// m_pFWell->getBorderGridProperty().m_nWidth,
|
|
// (Qt::PenStyle)m_pFWell->getBorderGridProperty().m_nType)); // 颜色、宽度可自定义
|
|
|
|
//// 上边框
|
|
//if (m_BorderFlags & TopBorder) {
|
|
// painter.drawLine(rect.topLeft(), rect.topRight());
|
|
//}
|
|
//// 下边框
|
|
//if (m_BorderFlags & BottomBorder) {
|
|
// painter.drawLine(rect.bottomLeft(), rect.bottomRight());
|
|
//}
|
|
//// 左边框
|
|
//if (m_BorderFlags & LeftBorder) {
|
|
// painter.drawLine(rect.topLeft(), rect.bottomLeft());
|
|
//}
|
|
//// 右边框
|
|
//if (m_BorderFlags & RightBorder) {
|
|
// painter.drawLine(rect.topRight(), rect.bottomRight());
|
|
//}
|
|
|
|
//painter.restore();
|
|
|
|
|
|
|
|
}
|
|
|
|
//设置 道图例区高度(cm)
|
|
void FormTrackTop::setTrackHeight(double dTrackHeight)
|
|
{
|
|
FormWell *parent = (FormWell *)m_parent;
|
|
parent->setTrackHeight(this, dTrackHeight);
|
|
}
|
|
|
|
//获取 道图例区高度(cm)
|
|
double FormTrackTop::getTrackHeight()
|
|
{
|
|
double dTrackHeight = 2.0;
|
|
FormWell *parent = (FormWell *)m_parent;
|
|
dTrackHeight = parent->getTrackHeight(this);
|
|
return dTrackHeight;
|
|
}
|