2020-05-23 17:30:46 +08:00
|
|
|
#include "AltitudeItem.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace mapcontrol {
|
|
|
|
|
|
|
|
|
|
AltitudeItem::AltitudeItem(MapGraphicItem *map, QColor background) : myMap(map), myColor(background)
|
|
|
|
|
{
|
2020-06-01 18:25:33 +08:00
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
|
|
|
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
|
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
2020-05-23 17:30:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
|
|
|
|
|
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
|
|
|
|
|
|
|
|
|
|
this->setZValue(4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QRectF AltitudeItem::boundingRect() const //鼠标可以操作的大小
|
|
|
|
|
{
|
2020-05-27 19:39:59 +08:00
|
|
|
return QRectF(0,0,20,150);
|
2020-05-23 17:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AltitudeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(option);
|
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
|
|
|
|
|
2020-05-25 21:45:13 +08:00
|
|
|
QPen ePen;
|
|
|
|
|
ePen.setWidth(1);
|
|
|
|
|
|
|
|
|
|
if (this->isSelected()) {
|
|
|
|
|
ePen.setColor(QColor("#008B00"));
|
|
|
|
|
painter->setBrush(QColor("#008B00"));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ePen.setColor(QColor("#8B4500"));
|
|
|
|
|
painter->setBrush(QColor("#8B4500"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->setPen(ePen);
|
|
|
|
|
painter->drawEllipse(0,0,20,20);
|
|
|
|
|
|
|
|
|
|
ePen.setColor(QColor("#FFFFFF"));
|
|
|
|
|
painter->setPen(ePen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFont font;
|
|
|
|
|
font.setWeight(QFont::ExtraLight);
|
|
|
|
|
font.setFamily("Arial");//非衬线
|
|
|
|
|
font.setPixelSize(12);
|
|
|
|
|
painter->setFont(font);
|
|
|
|
|
painter->drawText(0,0,20,20,Qt::AlignCenter,QString::number(0));
|
2020-05-23 17:30:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AltitudeItem::RefreshPos()
|
|
|
|
|
{
|
2020-05-27 19:39:59 +08:00
|
|
|
this->setPos(0,myMap->boundingRect().height() - this->boundingRect().height());
|
2020-05-23 17:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AltitudeItem::setOpacitySlot(qreal opacity)
|
|
|
|
|
{
|
|
|
|
|
setOpacity(opacity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AltitudeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "mousePressEvent";
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
|
|
|
|
|
|
}
|
2020-05-27 19:39:59 +08:00
|
|
|
|
|
|
|
|
qDebug() << event;
|
|
|
|
|
|
2020-06-01 18:25:33 +08:00
|
|
|
QGraphicsItem::mousePressEvent(event);
|
2020-05-23 17:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AltitudeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "mouseReleaseEvent";
|
|
|
|
|
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
|
|
|
|
|
|
}
|
2020-06-01 18:25:33 +08:00
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
2020-05-23 17:44:38 +08:00
|
|
|
|
2020-05-23 17:30:46 +08:00
|
|
|
}
|
|
|
|
|
void AltitudeItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void AltitudeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (isDragging) {
|
2020-05-27 19:39:59 +08:00
|
|
|
//this->setPos(event->pos());
|
2020-05-23 17:30:46 +08:00
|
|
|
}
|
2020-06-01 18:25:33 +08:00
|
|
|
QGraphicsItem::mouseMoveEvent(event);
|
2020-05-23 17:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|