283 lines
6.6 KiB
C++
283 lines
6.6 KiB
C++
#include "waypointsetting.h"
|
|
|
|
|
|
namespace mapcontrol {
|
|
|
|
WayPointSetting::WayPointSetting(MapGraphicItem *map, QColor background) : myMap(map), myColor(background)
|
|
{
|
|
this->setAcceptHoverEvents(true);
|
|
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
|
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
|
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
|
|
this->setFlag(QGraphicsItem::ItemIsFocusable,false);
|
|
|
|
opacity = 0.6;
|
|
|
|
connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
|
|
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
|
|
|
|
this->setZValue(7);
|
|
|
|
/*
|
|
btn_load = new WayPointButton(map);
|
|
btn_load->setParentItem(this);
|
|
btn_load->setGeometry(10,10,80,80);
|
|
btn_load->setText(tr("Load"));
|
|
connect(btn_load,&WayPointButton::clicked,[=]()
|
|
{
|
|
QFileDialog *dlg = new QFileDialog();
|
|
QString fileName = dlg->getOpenFileName(nullptr, tr("Selete Way Point File..."),
|
|
"./plan/",
|
|
tr("plan file (*.plan)"));
|
|
if(!fileName.isEmpty())
|
|
{
|
|
emit WPLoad(fileName);
|
|
}
|
|
});
|
|
|
|
|
|
btn_save = new WayPointButton(map);
|
|
btn_save->setParentItem(this);
|
|
btn_save->setGeometry(110,10,80,80);
|
|
btn_save->setText(tr("Save"));
|
|
connect(btn_save,&WayPointButton::clicked,[=]()
|
|
{
|
|
QFileDialog *dlg = new QFileDialog();
|
|
|
|
QString fileName = dlg->getSaveFileName(nullptr, tr("Selete Way Point File..."),
|
|
"./plan/",
|
|
tr("plan file (*.plan)"));
|
|
if(!fileName.isEmpty())
|
|
{
|
|
emit WPSave(fileName);
|
|
}
|
|
});
|
|
|
|
btn_upload = new WayPointButton(map);
|
|
btn_upload->setParentItem(this);
|
|
btn_upload->setGeometry(10,100,80,80);
|
|
btn_upload->setText(tr("Upload"));
|
|
connect(btn_upload,&WayPointButton::clicked,[=]()
|
|
{
|
|
emit WPUpload();
|
|
});
|
|
|
|
btn_download = new WayPointButton(map);
|
|
btn_download->setParentItem(this);
|
|
btn_download->setGeometry(110,100,80,80);
|
|
btn_download->setText(tr("Download"));
|
|
connect(btn_download,&WayPointButton::clicked,[=]()
|
|
{
|
|
emit WPDownload();
|
|
});
|
|
|
|
btn_insert = new WayPointButton(map);
|
|
btn_insert->setParentItem(this);
|
|
btn_insert->setGeometry(10,190,80,80);
|
|
btn_insert->setText(tr("insert"));
|
|
connect(btn_insert,&WayPointButton::clicked,[=]()
|
|
{
|
|
emit WPInsert();
|
|
});
|
|
|
|
btn_delete = new WayPointButton(map);
|
|
btn_delete->setParentItem(this);
|
|
btn_delete->setGeometry(110,190,80,80);
|
|
btn_delete->setText(tr("delete"));
|
|
connect(btn_delete,&WayPointButton::clicked,[=]()
|
|
{
|
|
emit WPDelete();
|
|
});
|
|
|
|
|
|
btn_last = new WayPointButton(map);
|
|
btn_last->setParentItem(this);
|
|
btn_last->setGeometry(10,280,80,80);
|
|
btn_last->setText(tr("last"));
|
|
connect(btn_last,&WayPointButton::clicked,[=]()
|
|
{
|
|
emit WPnearPoint(-1);
|
|
});
|
|
|
|
btn_next = new WayPointButton(map);
|
|
btn_next->setParentItem(this);
|
|
btn_next->setGeometry(110,280,80,80);
|
|
btn_next->setText(tr("next"));
|
|
connect(btn_next,&WayPointButton::clicked,[=]()
|
|
{
|
|
emit WPnearPoint(+1);
|
|
});
|
|
|
|
|
|
btn_group = new WayPointButton(map);
|
|
btn_group->setParentItem(this);
|
|
btn_group->setGeometry(10,10,80,80);
|
|
btn_group->setText(tr("Group"));
|
|
connect(btn_group,&WayPointButton::clicked,[=]()
|
|
{
|
|
|
|
});
|
|
*/
|
|
|
|
btn_tip = new WayPointButton(map);
|
|
btn_tip->setParentItem(this);
|
|
btn_tip->setGeometry(10,10,80,80);
|
|
btn_tip->setText(tr("Tip"));
|
|
connect(btn_tip,&WayPointButton::clicked,[=]()
|
|
{
|
|
if(btn_tip->Text() == tr("Tip"))
|
|
{
|
|
btn_tip->setText(tr("ShowTip"));
|
|
}
|
|
else
|
|
{
|
|
btn_tip->setText(tr("Tip"));
|
|
}
|
|
});
|
|
|
|
btn_ruler = new WayPointButton(map);
|
|
btn_ruler->setParentItem(this);
|
|
btn_ruler->setGeometry(10,100,80,80);
|
|
btn_ruler->setText(tr("Measure"));
|
|
connect(btn_ruler,&WayPointButton::clicked,[=](){
|
|
|
|
btn_ruler->setHighLight((btn_ruler->HighLight())?(false):(true));
|
|
emit WPRuler();
|
|
|
|
});
|
|
|
|
btn_table = new WayPointButton(map);
|
|
btn_table->setParentItem(this);
|
|
btn_table->setGeometry(10,190,80,80);
|
|
btn_table->setText(tr("Table"));
|
|
connect(btn_table,&WayPointButton::clicked,[=](){
|
|
|
|
btn_table->setHighLight((btn_table->HighLight())?(false):(true));
|
|
emit WPTable();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
QRectF WayPointSetting::boundingRect() const //鼠标可以操作的大小
|
|
{
|
|
return QRectF(0,0,100,280);
|
|
}
|
|
|
|
void WayPointSetting::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("黑体");//非衬线
|
|
painter->setFont(font);
|
|
|
|
//画底部
|
|
painter->save();
|
|
ePen.setColor(myColor);
|
|
painter->setPen(ePen);
|
|
painter->setBrush(myColor);
|
|
painter->setOpacity(opacity);
|
|
painter->drawRect(0,0,this->boundingRect().width(),this->boundingRect().height());
|
|
painter->restore();
|
|
|
|
|
|
}
|
|
|
|
|
|
void WayPointSetting::RefreshPos()
|
|
{
|
|
this->setPos(0,
|
|
0);
|
|
}
|
|
|
|
void WayPointSetting::setOpacitySlot(qreal opacity)
|
|
{
|
|
setOpacity(opacity);
|
|
}
|
|
|
|
|
|
|
|
|
|
void WayPointSetting::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
if (event->button() == Qt::LeftButton) {
|
|
isDragging = true;
|
|
|
|
}
|
|
}
|
|
|
|
void WayPointSetting::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
if (event->button() == Qt::LeftButton) {
|
|
isDragging = false;
|
|
}
|
|
|
|
}
|
|
void WayPointSetting::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
}
|
|
}
|
|
void WayPointSetting::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
if (isDragging) {
|
|
|
|
}
|
|
}
|
|
|
|
void WayPointSetting::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
|
|
//opacity = 0.6;
|
|
|
|
update();
|
|
}
|
|
|
|
void WayPointSetting::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
|
|
//opacity = 0.2;
|
|
update();
|
|
}
|
|
|
|
void WayPointSetting::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
}
|
|
|
|
void WayPointSetting::measureState(bool flag)
|
|
{
|
|
if(flag == true)
|
|
{
|
|
btn_ruler->setText(tr("Measuring"));
|
|
}
|
|
else
|
|
{
|
|
btn_ruler->setText(tr("Measure"));
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|