logplus/WellLogUI/src/TipPop.cpp

110 lines
2.3 KiB
C++

#include "TipPop.h"
#include <QRegion>
#include <QPolygon>
#include <QRect>
#include <QLine>
#include <QPainter>
#include <QPainterPath>
#include <QCursor>
#include <QDebug>
#include <QLabel>
#include <QHBoxLayout>
#include <QSpacerItem>
#define TIP_WIDTH 110
#define TIP_HEIGHT 45
#define TIP_CONTENTWIDTH 80
#define TIP_BORDER 2
#define TIP_LINECOUNT 5
#define TIP_RIGHTMARGIN 2
TipPop::TipPop(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(TIP_WIDTH,TIP_HEIGHT);
m_Lst=new QLine[TIP_LINECOUNT];
init();
}
TipPop::~TipPop()
{
delete []m_Lst;
}
void TipPop::init()
{
QPolygon polygon;
int offset=TIP_WIDTH-TIP_CONTENTWIDTH;
QRect newRect=this->rect().adjusted(0,0,-offset,0);
QPoint centerP=QPoint(TIP_WIDTH,newRect.center().y());
m_Lst[0]=QLine(newRect.topLeft(),newRect.bottomLeft());
m_Lst[1]=QLine(newRect.bottomLeft(),newRect.bottomRight());
m_Lst[2]=QLine(newRect.topRight(),centerP);
m_Lst[3]=QLine(centerP,newRect.bottomRight());
m_Lst[4]=QLine(newRect.topRight(),newRect.topLeft());
QLine line;
for(int i=0;i<TIP_LINECOUNT;i++)
{
line=m_Lst[i];
polygon<<line.p1()<<line.p2();
}
QRegion region(polygon);
this->setMask(region);
QLabel *lbl=new QLabel(this);
lbl->setObjectName("deplbl");
QFont font;
font.setPixelSize(9);
font.setBold(true);
lbl->setFont(font);
lbl->setStyleSheet("color:white");
lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
QHBoxLayout *vLayout=new QHBoxLayout(this);
vLayout->addWidget(lbl);
QSpacerItem *item=new QSpacerItem(1,1,QSizePolicy::Expanding);
vLayout->addSpacerItem(item);
vLayout->setContentsMargins(0,0,0,0);
}
void TipPopdrawBorder()
{
}
void TipPop::moveCursorPoint(const float &dept)
{
QPoint point= QCursor::pos();
int posX=point.x()-width()-TIP_RIGHTMARGIN;
int posY=point.y()-height()/2.0;
this->setGeometry(QRect(posX,posY,width(),height()));
m_dept=dept;
QLabel* lbl=this->findChild<QLabel*>("deplbl");
lbl->setText(QString(" MD:%1").arg(m_dept));
QFont ft( "Microsoft YaHei", 9, 75);
lbl->setFont(ft);
update();
}
void TipPop::paintEvent(QPaintEvent *)
{
QPainter paint;
paint.begin(this);
int val=TIP_BORDER;
paint.save();
paint.setPen(Qt::NoPen);
paint.setBrush(QColor(75,75,75,100));/*Qt::lightGray*/
paint.drawRect(rect());
paint.restore();
paint.end();
}