Qt Virtual Chart Table (QVCT)
CTimeView.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 // C/C++
20 #include <cmath>
21 
22 // QT
23 #include <QBoxLayout>
24 #include <QDateTime>
25 #include <QDockWidget>
26 #include <QLabel>
27 #include <QWidget>
28 
29 // QVCT
30 #include "QVCTRuntime.hpp"
31 #include "CTimeView.hpp"
32 
33 
34 //------------------------------------------------------------------------------
35 // CONSTRUCTORS / DESTRUCTOR
36 //------------------------------------------------------------------------------
37 
38 CTimeView::CTimeView( QWidget* _pqParent )
39  : QDockWidget( tr("System Time"), _pqParent )
40 {
41  QDockWidget::setObjectName( "SystemTime" ); // required to save main window's state
42  QDockWidget::setAllowedAreas( Qt::AllDockWidgetAreas );
44  QObject::connect( this, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT( slotLocationChanged(Qt::DockWidgetArea) ) );
45  QObject::connect( this, SIGNAL(topLevelChanged(bool)), this, SLOT( slotTopLevelChanged(bool) ) );
46 }
47 
49 {
50  // Create holder widget and layout
51  pqWidget = new QWidget();
52  pqWidget->setStyleSheet( ".QWidget { BACKGROUND-COLOR: rgba(0,0,0,255); } .QLabel { COLOR: rgba(255,255,255,255); }" );
53  pqBoxLayout = new QBoxLayout( QBoxLayout::LeftToRight );
54  pqBoxLayout->setContentsMargins( 5, 5, 5, 5 );
55 
56  // Add data
57  // ... date/time
58  pqLabelDate = new QLabel();
59  pqLabelDate->setToolTip( tr("Date") );
60  pqLabelDate->setAlignment( Qt::AlignCenter );
61  pqBoxLayout->addWidget( pqLabelDate );
62  pqLabelTime = new QLabel();
63  pqLabelTime->setToolTip( tr("Time") );
64  pqLabelTime->setAlignment( Qt::AlignCenter );
65  pqBoxLayout->addWidget( pqLabelTime );
66  pqLabelTime2 = new QLabel();
67  pqLabelTime2->setToolTip( tr("Time (alternate timezone)") );
68  pqLabelTime2->setAlignment( Qt::AlignCenter );
69  pqBoxLayout->addWidget( pqLabelTime2 );
70 
71  // Finalize
72  pqWidget->setLayout( pqBoxLayout );
73  QDockWidget::setWidget( pqWidget );
74 }
75 
76 
77 //------------------------------------------------------------------------------
78 // METHODS: QWidget (override)
79 //------------------------------------------------------------------------------
80 
81 void CTimeView::resizeEvent( QResizeEvent* _pqResizeEvent )
82 {
83  int __iWidth = pqWidget->width();
84  int __iHeight = pqWidget->height();
85  int __iFontSize;
86  if( pqBoxLayout->direction() == QBoxLayout::LeftToRight ) __iFontSize = std::min( 0.6*__iHeight, 0.05*__iWidth );
87  else __iFontSize = std::min( 0.225*__iHeight, 0.15*__iWidth );
88  if( __iFontSize < 20 ) __iFontSize = 20;
89  QFont __qFontData;
90  __qFontData.setPixelSize( __iFontSize );
91  __qFontData.setBold( true );
92  pqLabelDate->setFont( __qFontData );
93  pqLabelTime->setFont( __qFontData );
94  pqLabelTime2->setFont( __qFontData );
95  QDockWidget::resizeEvent( _pqResizeEvent );
96 }
97 
98 
99 //------------------------------------------------------------------------------
100 // METHODS
101 //------------------------------------------------------------------------------
102 
103 //
104 // SLOTS
105 //
106 
107 void CTimeView::slotLocationChanged( Qt::DockWidgetArea _qDockWidgetArea )
108 {
109  if( _qDockWidgetArea == Qt::TopDockWidgetArea || _qDockWidgetArea == Qt::BottomDockWidgetArea )
110  {
111  pqBoxLayout->setDirection( QBoxLayout::LeftToRight );
112  // pqWidget->setMaximumHeight( 50 );
113  }
114  else
115  {
116  pqBoxLayout->setDirection( QBoxLayout::TopToBottom );
117  // pqWidget->setMaximumHeight( 150 );
118  }
119 }
120 
121 void CTimeView::slotTopLevelChanged( bool _bTopLevel )
122 {
123  if( _bTopLevel )
124  {
125  pqBoxLayout->setDirection( QBoxLayout::TopToBottom );
126  // pqWidget->setMaximumHeight( 150 );
127  }
128 }
129 
130 //
131 // OTHER
132 //
133 
135 {
136  if( !QWidget::isVisible() ) return;
137  QDateTime __qDateTime = QDateTime::currentDateTime();
138  double __fdTime = __qDateTime.toUTC().toTime_t()+__qDateTime.time().msec()/1000.0;
139  pqLabelDate->setText( CUnitDate::toString( __fdTime ) );
140  pqLabelTime->setText( CUnitTime::toString( __fdTime ) );
141  pqLabelTime2->setText( "("+CUnitTime::toString( __fdTime, true )+")" );
142 }
void refreshContent()
Refreshes the content of the underlying widget.
Definition: CTimeView.cpp:134
QLabel * pqLabelTime
[UI:Label] Time
Definition: CTimeView.hpp:53
CTimeView(QWidget *_pqParent=0)
Definition: CTimeView.cpp:38
QWidget * pqWidget
[UI:Widget] Container widget
Definition: CTimeView.hpp:46
QBoxLayout * pqBoxLayout
[UI:Layout] Layout
Definition: CTimeView.hpp:48
void slotLocationChanged(Qt::DockWidgetArea _qDockWidgetArea)
Slot to handle dock area change.
Definition: CTimeView.cpp:107
void constructLayout()
Constructs the layout of the user-interface.
Definition: CTimeView.cpp:48
void slotTopLevelChanged(bool _bTopLevel)
Slot to handle floating change.
Definition: CTimeView.cpp:121
virtual void resizeEvent(QResizeEvent *_pqResizeEvent)
Definition: CTimeView.cpp:81
QLabel * pqLabelTime2
[UI:Label] Time (alternate timezone)
Definition: CTimeView.hpp:55
QLabel * pqLabelDate
[UI:Label] Date
Definition: CTimeView.hpp:51
static QString toString(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
Definition: CUnitDate.cpp:71
static QString toString(double _fdValue, CUnitTimeZone::EUnit _eUnitTimeZone, EUnit _eUnit, int _iPrecision=0)
Returns the formatted represention of the given value, using the specified format/unit and decimal pr...
Definition: CUnitTime.cpp:79