Qt Virtual Chart Table (QVCT)
CVesselWidget.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 <QBoxLayout>
21 #include <QDockWidget>
22 #include <QFont>
23 #include <QString>
24 #include <QWidget>
25 
26 // QVCT
29 
30 
31 //------------------------------------------------------------------------------
32 // CONSTRUCTORS / DESTRUCTOR
33 //------------------------------------------------------------------------------
34 
35 CVesselWidget::CVesselWidget( const QString& _qsTitle, QWidget* _pqParent )
36  : QDockWidget( _qsTitle, _pqParent )
37  , poVesselPoint( 0 )
38 {
39  // Create holder widget and layout
40  pqWidget = new QWidget();
41  pqWidget->setStyleSheet( ".QWidget { BACKGROUND-COLOR: rgba(0,0,0,255); } .QLabel { COLOR: rgba(255,255,255,255); }" );
42  pqBoxLayout = new QBoxLayout( QBoxLayout::TopToBottom );
43  pqBoxLayout->setContentsMargins( 5, 5, 5, 5 );
44  pqWidget->setLayout( pqBoxLayout );
45  QDockWidget::setWidget( pqWidget );
46 }
47 
48 
49 //------------------------------------------------------------------------------
50 // METHODS: QWidget (override)
51 //------------------------------------------------------------------------------
52 
53 void CVesselWidget::resizeEvent( QResizeEvent* _pqResizeEvent )
54 {
55  int __iWidth = pqWidget->width();
56  int __iHeight = pqWidget->height();
57  int __iFontSize;
58  if( pqBoxLayout->direction() == QBoxLayout::LeftToRight ) __iFontSize = std::min( 0.6*__iHeight, 0.05*__iWidth );
59  else __iFontSize = std::min( 0.225*__iHeight, 0.15*__iWidth );
60  if( __iFontSize < 20 ) __iFontSize = 20;
61  QFont __qFont;
62  __qFont.setPixelSize( __iFontSize );
63  __qFont.setBold( true );
64  setFont( __qFont );
65  QDockWidget::resizeEvent( _pqResizeEvent );
66 }
67 
68 
69 //------------------------------------------------------------------------------
70 // METHODS
71 //------------------------------------------------------------------------------
72 
73 //
74 // SLOTS
75 //
76 
77 void CVesselWidget::slotDestroyed( QObject* _pqObject )
78 {
79  if( !_pqObject || (QObject*)poVesselPoint != _pqObject ) return;
81 }
82 
83 void CVesselWidget::slotLocationChanged( Qt::DockWidgetArea _qDockWidgetArea )
84 {
85  if( _qDockWidgetArea == Qt::TopDockWidgetArea || _qDockWidgetArea == Qt::BottomDockWidgetArea )
86  pqBoxLayout->setDirection( QBoxLayout::LeftToRight );
87  else
88  pqBoxLayout->setDirection( QBoxLayout::TopToBottom );
89 }
90 
91 void CVesselWidget::slotTopLevelChanged( bool _bTopLevel )
92 {
93  if( _bTopLevel ) pqBoxLayout->setDirection( QBoxLayout::TopToBottom );
94 }
95 
96 //
97 // SETTERS
98 //
99 
101 {
102  if( poVesselPoint == _poVesselPoint ) return;
103  poVesselPoint = _poVesselPoint;
104  QObject::connect( poVesselPoint, SIGNAL( destroyed(QObject*) ), this, SLOT( slotDestroyed(QObject*) ) );
105 }
106 
108 {
109  if( poVesselPoint ) QObject::disconnect( (QObject*)poVesselPoint, 0, this, 0 );
110  poVesselPoint = 0;
111  resetContent();
112 }
[UI] Vessel overlay point (item) / vessel
CVesselPoint * poVesselPoint
Overlay course being displayed.
void slotTopLevelChanged(bool _bTopLevel)
Slot to handle floating change.
void resetVesselPoint()
Resets (clears) the vessel used to synchronize the instruments display.
void setVesselPoint(CVesselPoint *_poVesselPoint)
Sets the vessel used to synchronize the instruments display.
virtual void setFont(QFont _qFont)=0
Sets the font for the content of the underlying widget.
virtual void resetContent()=0
Resets (clears) the content of the underlying widget.
void slotDestroyed(QObject *_pqObject)
Slot to handle object destruction.
virtual void resizeEvent(QResizeEvent *_pqResizeEvent)
CVesselWidget(const QString &_qsTitle, QWidget *_pqParent=0)
void slotLocationChanged(Qt::DockWidgetArea _qDockWidgetArea)
Slot to handle dock area change.
QBoxLayout * pqBoxLayout
[UI:Layout] Layout
QWidget * pqWidget
[UI:Widget] Container widget