homeitem.cpp 3.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/**
******************************************************************************
*
* @file       homeitem.cpp
* @author     The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief      A graphicsItem representing a trail point
* @see        The GNU Public License (GPL) Version 3
* @defgroup   OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "homeitem.h"
namespace mapcontrol
{
    HomeItem::HomeItem(MapGraphicItem* map,OPMapWidget* parent):safe(true),map(map),mapwidget(parent),showsafearea(true),safearea(1000),altitude(0)
    {
        pic.load(QString::fromUtf8(":/markers/images/home2.svg"));
        pic=pic.scaled(30,30,Qt::IgnoreAspectRatio);
        this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true);
        localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition());
        this->setPos(localposition.X(),localposition.Y());
        this->setZValue(4);
        coord=internals::PointLatLng(50,50);
39 40 41 42

//        this->setFlag(QGraphicsItem::ItemIsMovable,true);
//        this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true);
//        this->setFlag(QGraphicsItem::ItemIsSelectable,true);
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    }

    void HomeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
        Q_UNUSED(option);
        Q_UNUSED(widget);
        painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic);
        if(showsafearea)
        {
            if(safe)
                painter->setPen(Qt::green);
            else
                painter->setPen(Qt::red);
            painter->drawEllipse(QPointF(0,0),localsafearea,localsafearea);
            //   painter->drawRect(QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2));
        }

    }
    QRectF HomeItem::boundingRect()const
    {
        if(!showsafearea)
            return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height());
        else
            return QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2);
    }


    int HomeItem::type()const
    {
        return Type;
    }
    void HomeItem::RefreshPos()
    {
        prepareGeometryChange();
        localposition=map->FromLatLngToLocal(coord);
        this->setPos(localposition.X(),localposition.Y());
        if(showsafearea)
            localsafearea=safearea/map->Projection()->GetGroundResolution(map->ZoomTotal(),coord.Lat());

    }

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
//    void HomeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
//    {
//        if(event->button()==Qt::LeftButton)
//        {
//            coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y());
//            QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + "   " + QString::number(coord.Lng(), 'f', 6);
//            qDebug() << "WP MOVE:" << coord_str << __FILE__ << __LINE__;
//            isDragging=false;
//            RefreshToolTip();

//            emit WPValuesChanged(this);
//        }
//        QGraphicsItem::mouseReleaseEvent(event);
//    }

99
}