#include "geographicspolygonitem.h" #include "../qtviewer_planetosm/osmtiles/viewer_interface.h" #include #include #include #include "geographicsscene.h" #include "qtvplugin_geomarker.h" namespace QTVP_GEOMARKER{ geoGraphicsPolygonItem::geoGraphicsPolygonItem( QString name, QTVOSM::viewer_interface * pVi,const QPolygonF & lla_polygon) :QGraphicsPolygonItem(0) ,geoItemBase(name,QTVP_GEOMARKER::ITEAMTYPE_POLYGON,pVi) { assert(vi()!=0); m_llap = lla_polygon; unwarrp(); QPolygonF wp; foreach (const QPointF & pt, m_llap) { double px,py; vi()->CV_LLA2World(pt.y(),pt.x(),&px,&py); wp< 180) m_lon2 -= 360; m_llap[i].setX(m_lon2); } } void geoGraphicsPolygonItem::adjust_coords(int nNewLevel) { if (vi() && nNewLevel != level()) { /** Since the map is zooming from level() to current level, * the map size zoom ratio can be calculated using pow below. * We can get new coord for current zoom level by multiplicative. */ double ratio = pow(2.0,(nNewLevel - level())); QPolygonF p = this->polygon(); int sz = p.size(); for (int i=0;isetPolygon(p); } } void geoGraphicsPolygonItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= nullptr*/) { if (vi()) { const int cv = vi()->level(); if (cv!=level()) { adjust_coords(cv); setLevel(cv); } } QGraphicsPolygonItem::paint(painter,option,widget); } QRectF geoGraphicsPolygonItem::boundingRect() const { QRectF rect = QGraphicsPolygonItem::boundingRect(); auto v = vi(); if (v && v->level()!=level()) { double ratio = pow(2.0,(v->level() - level())); QPointF center = rect.center(); rect.setRect(center.x() * ratio - rect.width()/2, center.y() * ratio - rect.height()/2, rect.width(), rect.height()); } return rect; } void geoGraphicsPolygonItem::mousePressEvent(QGraphicsSceneMouseEvent * event) { QGraphicsPolygonItem::mousePressEvent(event); //if (wantMouseHoverEvent()==false) { bool bshow = this->props_visible(); this->show_props(!bshow); } //post enent QMap map_evt; geoGraphicsScene * pscene = dynamic_cast(this->scene()); if (pscene) { QObject * pPlg = pscene->parent(); if (pPlg) { qtvplugin_geomarker * pMarker = dynamic_cast(pPlg) ; if (pMarker) { map_evt["source"] = pMarker->get_name(); map_evt["destin"] = "ALL"; if (event->buttons() & Qt::LeftButton) map_evt["name"] = "ITEM_LBUTTON_CLICKED"; else if (event->buttons() & Qt::RightButton) map_evt["name"] = "ITEM_RBUTTON_CLICKED"; else if (event->buttons() & Qt::MidButton) map_evt["name"] = "ITEM_MBUTTON_CLICKED"; else map_evt["name"] = "ITEM_BUTTON_CLICKED"; map_evt["id"] = this->item_name(); vi()->post_event(map_evt); } } } } void geoGraphicsPolygonItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { QGraphicsPolygonItem::hoverEnterEvent(event); //this->show_props(true); //post enent QMap map_evt; geoGraphicsScene * pscene = dynamic_cast(this->scene()); if (pscene) { QObject * pPlg = pscene->parent(); if (pPlg) { qtvplugin_geomarker * pMarker = dynamic_cast(pPlg) ; if (pMarker) { map_evt["source"] = pMarker->get_name(); map_evt["destin"] = "ALL"; map_evt["name"] = "ITEM_MOUSE_ENTER"; map_evt["id"] = this->item_name(); vi()->post_event(map_evt); } } } } void geoGraphicsPolygonItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * event) { QGraphicsPolygonItem::hoverLeaveEvent(event); //this->show_props(false); //post enent QMap map_evt; geoGraphicsScene * pscene = dynamic_cast(this->scene()); if (pscene) { QObject * pPlg = pscene->parent(); if (pPlg) { qtvplugin_geomarker * pMarker = dynamic_cast(pPlg) ; if (pMarker) { map_evt["source"] = pMarker->get_name(); map_evt["destin"] = "ALL"; map_evt["name"] = "ITEM_MOUSE_LEAVE"; map_evt["id"] = this->item_name(); vi()->post_event(map_evt); } } } } void geoGraphicsPolygonItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) { QGraphicsPolygonItem::mouseDoubleClickEvent(event); //post enent QMap map_evt; geoGraphicsScene * pscene = dynamic_cast(this->scene()); if (pscene) { QObject * pPlg = pscene->parent(); if (pPlg) { qtvplugin_geomarker * pMarker = dynamic_cast(pPlg) ; if (pMarker) { map_evt["source"] = pMarker->get_name(); map_evt["destin"] = "ALL"; if (event->buttons() & Qt::LeftButton) map_evt["name"] = "ITEM_LBUTTON_DBLCLICKED"; else if (event->buttons() & Qt::RightButton) map_evt["name"] = "ITEM_RBUTTON_DBLCLICKED"; else if (event->buttons() & Qt::MidButton) map_evt["name"] = "ITEM_MBUTTON_DBLCLICKED"; else map_evt["name"] = "ITEM_BUTTON_DBLCLICKED"; map_evt["id"] = this->item_name(); vi()->post_event(map_evt); } } } } QPointF geoGraphicsPolygonItem::label_pos() { QPolygonF p = this->polygon(); int sz = p.size(); double x = 0, y = 0; for (int i=0;iCV_LLA2World(pt.y(),pt.x(),&px,&py); wp<