界面绘制完成

This commit is contained in:
hm
2022-04-01 21:37:32 +08:00
parent 98a02885ce
commit 7492424716
8 changed files with 571 additions and 506 deletions
+197
View File
@@ -0,0 +1,197 @@
#include "waypointbutton.h"
namespace mapcontrol {
WayPointButton::WayPointButton(MapGraphicItem *parent) : myMap(parent)
{
this->setAcceptHoverEvents(true);
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
this->setAcceptedMouseButtons(Qt::LeftButton);
connect(parent, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
connect(parent, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
this->setZValue(8);//在幕布上面
position.setX(0);
position.setY(0);
position.setWidth(100);
position.setHeight(100);
}
QRectF WayPointButton::boundingRect() const //鼠标可以操作的大小
{
return QRectF(0,0,position.width(),position.height());
}
void WayPointButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setRenderHint(QPainter::Antialiasing, true);
QPen ePen;
ePen.setWidth(1);
QFont font;
font.setPixelSize(15);//不随着屏幕分辨率改变而改变
font.setFamily("Arial");//非衬线
painter->setFont(font);
//画底部
painter->save();
ePen.setColor(QColor("#2EFE64"));
painter->setPen(ePen);
painter->setBrush(QColor("#2EFE64"));
painter->setOpacity(opacity);
painter->drawRoundedRect(0,0,this->boundingRect().width(),this->boundingRect().height(),10,10);
painter->restore();
painter->save();
ePen.setColor(QColor("#000000"));
painter->setPen(ePen);
painter->drawText(0,0,this->boundingRect().width(),this->boundingRect().height(),Qt::AlignCenter,text);
painter->restore();
}
void WayPointButton::RefreshPos()
{
this->setPos(position.x(),
position.y());
}
void WayPointButton::setOpacitySlot(qreal opacity)
{
setOpacity(opacity);
}
void WayPointButton::setPosition(int x,int y)
{
position.setX(x);
position.setY(y);
RefreshPos();
update();
}
void WayPointButton::resize(int width,int height)
{
position.setWidth(width);
position.setHeight(height);
RefreshPos();
update();
}
void WayPointButton::setGeometry(QRect rect)
{
position.setX(rect.x());
position.setY(rect.y());
position.setWidth(rect.width());
position.setHeight(rect.height());
update();
}
void WayPointButton::setGeometry(int x,int y,int w,int h)
{
position.setX(x);
position.setY(y);
position.setWidth(w);
position.setHeight(h);
update();
}
void WayPointButton::setText(QString t)
{
text = t;
update();
}
QString WayPointButton::Text(void)
{
return text;
}
void WayPointButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug() << "press";
if (event->button() == Qt::LeftButton) {
isDragging = true;
}
}
void WayPointButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug() << "release";
if (event->button() == Qt::LeftButton) {
isDragging = false;
}
}
void WayPointButton::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug() << "double clicked";
if (event->button() == Qt::LeftButton) {
}
}
void WayPointButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (isDragging) {
}
}
void WayPointButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
qDebug() << "enter";
opacity = 0.8;
update();
}
void WayPointButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
qDebug() << "leave";
opacity = 0.5;
update();
}
void WayPointButton::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
qDebug() << "move";
}
}