Qt Virtual Chart Table (QVCT)
CPointerOverlay.cpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Qt Virtual Chart Table (QVCT)
5  * Copyright (C) 2012 Cedric Dufour <http://cedric.dufour.name>
6  * Author: Cedric Dufour <http://cedric.dufour.name>
7  *
8  * The Qt Virtual Chart Table (QVCT) is free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Qt Virtual Chart Table (QVCT) is distributed in the hope
13  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU General Public License for more details.
17  */
18 
19 // QT
20 #include <QPainter>
21 #include <QTreeWidget>
22 #include <QTreeWidgetItem>
23 #include <QWidget>
24 
25 // QVCT
26 #include "QVCTRuntime.hpp"
27 #include "charts/CChart.hpp"
30 
31 
32 //------------------------------------------------------------------------------
33 // CONSTRUCTORS / DESTRUCTOR
34 //------------------------------------------------------------------------------
35 
37  : COverlayBase( tr("Pointer") )
38 {
40  QTreeWidgetItem::addChild( new CPointerPoint( tr("Mouse") ) );
41  QTreeWidgetItem::addChild( new CPointerPoint( tr("Target") ) );
42 }
43 
45 {
46  QTreeWidgetItem* __pqTreeWidgetItem = QTreeWidgetItem::takeChild( 0 );
47  while( __pqTreeWidgetItem )
48  {
49  delete (CPointerPoint*)__pqTreeWidgetItem;
50  __pqTreeWidgetItem = QTreeWidgetItem::takeChild( 0 );
51  }
52 }
53 
54 
55 //------------------------------------------------------------------------------
56 // METHODS: COverlay (implement/override)
57 //------------------------------------------------------------------------------
58 
59 void CPointerOverlay::drawContent( const CChart* _poChart, QPainter* _pqPainter ) const
60 {
61  if( !bVisible ) return;
62 
63  // Draw
64 
65  // ... mouse pointer
66  CPointerPoint* __poPointerPoint = (CPointerPoint*)QTreeWidgetItem::child( 0 );
67  __poPointerPoint->draw( _poChart, _pqPainter );
68 
69  // ... target
70  __poPointerPoint = (CPointerPoint*)QTreeWidgetItem::child( 1 );
71  __poPointerPoint->draw( _poChart, _pqPainter );
73  if( __poVesselPoint ) __poPointerPoint->drawLine( _poChart, _pqPainter, __poVesselPoint );
74 
75  // ... path
76  int __iCount = QTreeWidgetItem::childCount();
77  if( __iCount < 4 ) return;
78  CPointerPoint* __poPointerPathFrom = (CPointerPoint*)QTreeWidgetItem::child( 2 );
79  CPointerPoint* __poPointerPathTo = 0;
80  for( int __i = 3; __i < __iCount; __i++ )
81  {
82  __poPointerPathTo = (CPointerPoint*)QTreeWidgetItem::child( __i );
83  __poPointerPathFrom->drawLine( _poChart, _pqPainter, __poPointerPathTo );
84  __poPointerPathFrom = __poPointerPathTo;
85  }
86 }
87 
88 void CPointerOverlay::showDetail( const QTreeWidgetItem* _pqTreeWidgetItem ) const
89 {
90  if( !_pqTreeWidgetItem ) return;
91  switch( _pqTreeWidgetItem->type() )
92  {
93 
95  {
96  CPointerPoint* __poPointerPoint = (CPointerPoint*)_pqTreeWidgetItem;
97  __poPointerPoint->showDetail();
98  }
99  break;
100 
101  default:;
102 
103  }
104 }
105 
106 void CPointerOverlay::setPosition( const QTreeWidgetItem* _pqTreeWidgetItem ) const
107 {
108  if( _pqTreeWidgetItem->type() != COverlayObject::ITEM ) return;
109  CPointerPoint* __poPointerPoint = (CPointerPoint*)_pqTreeWidgetItem;
110  QVCTRuntime::useChartTable()->setGeoPosition( *__poPointerPoint );
111 }
112 
113 
114 //------------------------------------------------------------------------------
115 // METHODS
116 //------------------------------------------------------------------------------
117 
118 //
119 // GETTERS
120 //
121 
123 {
124  return QTreeWidgetItem::childCount() > 2;
125 }
126 
128 {
129  int __iCount = QTreeWidgetItem::childCount() - 3;
130  if( __iCount < 0 ) __iCount = 0;
131  return __iCount;
132 }
133 
134 //
135 // USERS
136 //
137 
139 {
140  return (CPointerPoint*)QTreeWidgetItem::child( 0 );
141 }
142 
144 {
145  return (CPointerPoint*)QTreeWidgetItem::child( 1 );
146 }
147 
148 //
149 // OTHER
150 //
151 
153 {
154  QColor __qColor = QVCTRuntime::useSettings()->getColorPointer();
155  __qColor.setAlpha( 128 );
156  qBrushMarker.setColor( __qColor );
157  __qColor.setAlpha( 192 );
158  qPenText.setColor( QColor::fromHsv( __qColor.hue(), __qColor.saturation(), std::min( 128, __qColor.value() ), 192 ) );
159  qPenMarker.setColor( __qColor );
160  qPenLine.setColor( __qColor );
161 }
162 
163 void CPointerOverlay::setPosition( const CChart* _poChart, const QPointF& _rqPointFScrPosition, bool _bTarget )
164 {
165  CDataPosition __oDataPosition = _poChart->toGeoPosition( _rqPointFScrPosition );
166  __oDataPosition.resetElevation();
167  setPosition( __oDataPosition, _bTarget );
168 }
169 
170 void CPointerOverlay::setPosition( const CDataPosition& _roDataPosition, bool _bTarget )
171 {
172  CPointerPoint* __poPointerPoint = (CPointerPoint*)QTreeWidgetItem::child( _bTarget ? 1 : 0 );
173  __poPointerPoint->setPosition( _roDataPosition );
174 }
175 
176 void CPointerOverlay::clearPosition( bool _bTarget )
177 {
178  CPointerPoint* __poPointerPoint = (CPointerPoint*)QTreeWidgetItem::child( _bTarget ? 1 : 0 );
179  __poPointerPoint->setPosition( CDataPosition::UNDEFINED );
180 }
181 
182 void CPointerOverlay::setPath( const CChart* _poChart, const QPointF& _rqPointFScrPosition )
183 {
184  CDataPosition __oDataPosition = _poChart->toGeoPosition( _rqPointFScrPosition );
185  __oDataPosition.resetElevation();
186  setPath( __oDataPosition );
187 }
188 
189 void CPointerOverlay::setPath( const CDataPosition& _roDataPosition )
190 {
191  if( _roDataPosition == CDataPosition::UNDEFINED ) return;
192  ((CPointerPoint*)QTreeWidgetItem::child( 0 ))->setPosition( _roDataPosition );
193  CPointerPoint* __poPointerPoint = new CPointerPoint( "Path"+QString::number( QTreeWidgetItem::childCount() ) );
194  __poPointerPoint->setPosition( _roDataPosition );
195  QTreeWidgetItem::addChild( __poPointerPoint );
196 }
197 
199 {
200  int __iCount = QTreeWidgetItem::childCount();
201  if( __iCount < 4 ) return 0.0;
202  CPointerPoint* __poPointerPathFrom = (CPointerPoint*)QTreeWidgetItem::child( 2 );
203  CPointerPoint* __poPointerPathTo = 0;
204  double __fdLength = 0;
205  for( int __i = 3; __i < __iCount; __i++ )
206  {
207  __poPointerPathTo = (CPointerPoint*)QTreeWidgetItem::child( __i );
208  __fdLength += CDataPosition::distanceRL( *__poPointerPathFrom, *__poPointerPathTo );
209  __poPointerPathFrom = __poPointerPathTo;
210  }
211  return __fdLength;
212 }
213 
215 {
216  int __iCount = QTreeWidgetItem::childCount();
217  if( __iCount < 4 ) return 0.0;
218  CPointerPoint* __poPointerPathFrom = (CPointerPoint*)QTreeWidgetItem::child( 2 );
219  CPointerPoint* __poPointerPathTo = (CPointerPoint*)QTreeWidgetItem::child( __iCount-1 );
220  return CDataPosition::distanceGC( *__poPointerPathFrom, *__poPointerPathTo );
221 }
222 
224 {
225  QTreeWidgetItem* __pqTreeWidgetItem = QTreeWidgetItem::takeChild( 2 );
226  while( __pqTreeWidgetItem )
227  {
228  delete (CPointerPoint*)__pqTreeWidgetItem;
229  __pqTreeWidgetItem = QTreeWidgetItem::takeChild( 2 );
230  }
231 }
CVesselPoint * getVesselPointSynchronize() const
Returns the vessel defined to synchronize the chart reference (geographical) position.
void setGeoPosition(const CDataPosition &_roGeoPosition, bool _bSkipCurrent=false)
Sets the reference chart (geographical) position.
[UI] Chart (view)
Definition: CChart.hpp:44
CDataPosition toGeoPosition(const QPointF &_rqPointFDrawPosition) const
Converts the given chart draw position to geographical position.
Definition: CChart.cpp:185
(Geographical) Position data [long,lat,elev]
static double distanceRL(const CDataPosition &_roPosition1, const CDataPosition &_roPosition2)
Returns the rhumb-line distance between two points, in meters.
static const CDataPosition UNDEFINED
Specific value for an undefined position.
void resetElevation()
Resets the elevation (to an undefined elevation)
void setPosition(double _fdLongitude, double _fdLatitude, double _fdElevation=UNDEFINED_ELEVATION)
Sets new coordinates.
static double distanceGC(const CDataPosition &_roPosition1, const CDataPosition &_roPosition2)
Returns the WGS84-corrected great-circle distance between two points, in meters.
Generic overlay base (non-widget)
virtual void drawLine(const CChart *_poChart, QPainter *_pqPainter, const COverlayPoint *_poOverlayPoint)
Draws a line (between this and the other specified point), including distance/bearing data.
QPen qPenLine
QPen used to draw lines on this overlay.
Definition: COverlay.hpp:91
QPen qPenText
QPen used to draw text on this overlay.
Definition: COverlay.hpp:76
bool bVisible
Overlay items' global visibility status.
Definition: COverlay.hpp:56
QBrush qBrushMarker
QBrush used to draw markers on this overlay.
Definition: COverlay.hpp:79
QPen qPenMarker
QPen used to draw markers on this overlay.
Definition: COverlay.hpp:82
void setPath(const CChart *_poChart, const QPointF &_rqPointFScrPosition)
Adds the given screen position to the pointer path.
double getPathLengthRL()
Returns the pointer path (rhumb-line) length along its segments.
virtual void setPosition(const QTreeWidgetItem *_pqTreeWidgetItem) const
Centers the chart on the given overlay object's position.
bool hasPath() const
Returns whether a pointer path has been defined.
int getPathSegments() const
Returns the quantity of segments along the pointer path (0 if no path is defined)
double getPathLengthGC()
Returns the equivalent (great-circle) length between the first and last position of the pointer path.
void importSettings()
Imports settings from the application's global settings.
CPointerPoint * usePointerTarget()
Returns the pointer point corresponding to the target.
virtual void drawContent(const CChart *_poChart, QPainter *_pqPainter) const
Draws this overlay's content.
void clearPath()
Clears the pointer path.
virtual ~CPointerOverlay()
void clearPosition(bool _bTarget=false)
Clears the mouse pointer or target.
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
CPointerPoint * usePointerPoint()
Returns the pointer point corresponding to the mouse pointer.
[UI] Pointer overlay point (item)
virtual void draw(const CChart *_poChart, QPainter *_pqPainter)
Draws this object (itself or its content)
virtual void showDetail()
Displays this object's details (in the appropriate widget/view)
QColor getColorPointer()
[Color] Returns the pointer overlay's base color
Definition: CSettings.hpp:412
[UI] Vessel overlay point (item) / vessel
static CChartTable * useChartTable()
static CSettings * useSettings()