1 /**********************************************************************************************
2     Copyright (C) 2014 Oliver Eichler <oliver.eichler@gmx.de>
3     Copyright (C) 2017 Norbert Truchsess <norbert.truchsess@t-online.de>
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 **********************************************************************************************/
19 
20 
21 #include "canvas/CCanvas.h"
22 #include "CMainWindow.h"
23 #include "gis/CGisWorkspace.h"
24 #include "gis/wpt/CGisItemWpt.h"
25 #include "gis/wpt/CProjWpt.h"
26 #include "gis/wpt/CScrOptWptRadius.h"
27 #include "helpers/CDraw.h"
28 #include "mouse/CScrOptSemaphoreLocker.h"
29 #include "mouse/IMouse.h"
30 
31 #include <QtWidgets>
32 
CScrOptWptRadius(CGisItemWpt * wpt,const QPoint & point,IMouse * parent)33 CScrOptWptRadius::CScrOptWptRadius(CGisItemWpt* wpt, const QPoint& point, IMouse* parent)
34     : IScrOpt(parent)
35     , key(wpt->getKey())
36 {
37     setupUi(this);
38     setOrigin(point);
39     label->setFont(CMainWindow::self().getMapFont());
40 
41     qreal proximity = wpt->getProximity();
42     if(proximity == NOFLOAT)
43     {
44         proximity = 0.;
45     }
46 
47     QString val, unit;
48     IUnit::self().meter2distance(proximity, val, unit);
49     label->setText(QString("%1%2").arg(val, unit));
50 
51     adjustSize();
52 
53     toolNogoArea->setChecked(wpt->isNogo());
54 
55     anchor = wpt->getPointCloseBy(point);
56     moveTo(anchor.toPoint());
57     show();
58 
59     connect(toolDelete, &QToolButton::clicked, this, &CScrOptWptRadius::slotDelete);
60     connect(toolEdit, &QToolButton::clicked, this, &CScrOptWptRadius::slotEdit);
61     connect(toolNogoArea, &QToolButton::clicked, this, &CScrOptWptRadius::slotNogoArea);
62 
63     adjustSize();
64 }
65 
~CScrOptWptRadius()66 CScrOptWptRadius::~CScrOptWptRadius()
67 {
68 }
69 
slotDelete()70 void CScrOptWptRadius::slotDelete()
71 {
72     CScrOptSemaphoreLocker lock(*this);
73     CGisWorkspace::self().deleteWptRadius(key);
74     close();
75 }
76 
slotNogoArea()77 void CScrOptWptRadius::slotNogoArea()
78 {
79     CScrOptSemaphoreLocker lock(*this);
80     CGisWorkspace::self().toggleNogoItem(key);
81     close();
82 }
83 
slotEdit()84 void CScrOptWptRadius::slotEdit()
85 {
86     CScrOptSemaphoreLocker lock(*this);
87     CGisWorkspace::self().editWptRadius(key);
88     close();
89 }
90 
draw(QPainter & p)91 void CScrOptWptRadius::draw(QPainter& p)
92 {
93     IGisItem* item = CGisWorkspace::self().getItemByKey(key);
94     if(nullptr == item)
95     {
96         close();
97         return;
98     }
99     item->drawHighlight(p);
100 
101     CDraw::bubble(p, geometry(), anchor.toPoint(), backgroundColor);
102 }
103