Qt Virtual Chart Table (QVCT)
CDeviceDetailView.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 <QHBoxLayout>
21 #include <QLabel>
22 #include <QPushButton>
23 #include <QScrollArea>
24 #include <QStackedWidget>
25 #include <QVBoxLayout>
26 #include <QTabWidget>
27 #include <QWidget>
28 
29 // QVCT
30 #include "QVCTRuntime.hpp"
32 #include "devices/CDevice.hpp"
33 
34 
35 //------------------------------------------------------------------------------
36 // CONSTRUCTORS / DESTRUCTOR
37 //------------------------------------------------------------------------------
38 
40  : COverlayObjectDetailView( _pqParent )
41  , bIgnoreUpdate( true )
42 {
44 }
45 
47 {
48  // Create the buttons
49  // ... edit
50  pqPushButtonEdit = new QPushButton( QIcon( ":icons/32x32/edit.png" ), "" );
51  pqPushButtonEdit->setMaximumSize( 36, 34 );
52  pqPushButtonEdit->setToolTip( tr("Edit this device's configuration") );
53  pqPushButtonEdit->setEnabled( false );
54  QWidget::connect( pqPushButtonEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
55  // ... delete
56  pqPushButtonDelete = new QPushButton( QIcon( ":icons/32x32/delete.png" ), "" );
57  pqPushButtonDelete->setMaximumSize( 36, 34 );
58  pqPushButtonDelete->setToolTip( tr("Delete this device") );
59  pqPushButtonDelete->setEnabled( false );
60  QWidget::connect( pqPushButtonDelete, SIGNAL( clicked() ), this, SLOT( slotDelete() ) );
61  // ... stop
62  pqPushButtonStop = new QPushButton( QIcon( ":icons/32x32/stop.png" ), "" );
63  pqPushButtonStop->setMaximumSize( 36, 34 );
64  pqPushButtonStop->setToolTip( tr("Stop this device") );
65  pqPushButtonStop->setCheckable( true );
66  pqPushButtonStop->setEnabled( false );
67  QWidget::connect( pqPushButtonStop, SIGNAL( clicked() ), this, SLOT( slotStop() ) );
68  // ... pause
69  pqPushButtonPause = new QPushButton( QIcon( ":icons/32x32/pause.png" ), "" );
70  pqPushButtonPause->setMaximumSize( 36, 34 );
71  pqPushButtonPause->setToolTip( tr("Pause this device") );
72  pqPushButtonPause->setCheckable( true );
73  pqPushButtonPause->setEnabled( false );
74  QWidget::connect( pqPushButtonPause, SIGNAL( clicked() ), this, SLOT( slotPause() ) );
75  // ... start
76  pqPushButtonStart = new QPushButton( QIcon( ":icons/32x32/start.png" ), "" );
77  pqPushButtonStart->setMaximumSize( 36, 34 );
78  pqPushButtonStart->setToolTip( tr("Start this device") );
79  pqPushButtonStart->setCheckable( true );
80  pqPushButtonStart->setEnabled( false );
81  QWidget::connect( pqPushButtonStart, SIGNAL( clicked() ), this, SLOT( slotStart() ) );
82 
83  // Create layout
84  QVBoxLayout* __pqVBoxLayout = new QVBoxLayout();
85 
86  // Add header
87  QFont __qFontHeader;
88  __qFontHeader.setPixelSize( 16 );
89  __qFontHeader.setBold( true );
90  QHBoxLayout* __pqHBoxLayoutHeader = new QHBoxLayout();
91  QLabel* __pqLabelIcon = new QLabel();
92  __pqLabelIcon->setPixmap( QPixmap( ":icons/32x32/device.png" ) );
93  __pqLabelIcon->setToolTip( tr("Device") );
94  __pqHBoxLayoutHeader->addWidget( __pqLabelIcon, 0, Qt::AlignTop );
95  poTextName = new COverlayText();
96  poTextName->setToolTip( tr("Name") );
97  poTextName->setFont( __qFontHeader );
98  poTextName->setWordWrap( true );
99  __pqHBoxLayoutHeader->addWidget( poTextName, 1 );
100  __pqVBoxLayout->addLayout( __pqHBoxLayoutHeader );
101 
102  // Add data
103  QFont __qFontData;
104  QTabWidget* __poTabWidget = new QTabWidget();
105  __poTabWidget->setTabPosition( QTabWidget::South );
106  __poTabWidget->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
107 
108  // ... summary
109  QWidget* __poWidgetSummary = new QWidget();
110  QVBoxLayout* __pqVBoxLayoutSummary = new QVBoxLayout();
111  __qFontData.setPixelSize( 20 );
112  poTextDriver = new COverlayText();
113  poTextDriver->setToolTip( tr("Driver") );
114  poTextDriver->setFont( __qFontData );
115  poTextDriver->setIndent( 10 );
116  poTextDriver->setAlignment( Qt::AlignHCenter );
118  __pqVBoxLayoutSummary->addWidget( poTextDriver, 0 );
120  pqLabelActivity->setToolTip( tr("Activity") );
121  pqLabelActivity->setFont( __qFontData );
122  pqLabelActivity->setIndent( 10 );
123  pqLabelActivity->setAlignment( Qt::AlignHCenter );
124  __pqVBoxLayoutSummary->addWidget( pqLabelActivity, 1 );
125  __poWidgetSummary->setLayout( __pqVBoxLayoutSummary );
126  __poTabWidget->addTab( __poWidgetSummary, tr("Summary") );
127 
128  // ... [end]
129  __pqVBoxLayout->addWidget( __poTabWidget, 1 );
130 
131  // Add separator
132  QFrame* __pqFrameSeparator = new QFrame();
133  __pqFrameSeparator->setFrameStyle( QFrame::HLine | QFrame::Sunken );
134  __pqVBoxLayout->addWidget( __pqFrameSeparator );
135 
136  // Add buttons
137  QHBoxLayout* __pqHBoxLayoutButtons = new QHBoxLayout();
138  __pqHBoxLayoutButtons->addWidget( pqPushButtonEdit, 0, Qt::AlignLeft );
139  __pqHBoxLayoutButtons->addWidget( pqPushButtonDelete, 1, Qt::AlignLeft );
140  __pqHBoxLayoutButtons->addWidget( pqPushButtonStop, 1, Qt::AlignRight );
141  __pqHBoxLayoutButtons->addWidget( pqPushButtonPause, 0, Qt::AlignRight );
142  __pqHBoxLayoutButtons->addWidget( pqPushButtonStart, 0, Qt::AlignRight );
143  __pqVBoxLayout->addLayout( __pqHBoxLayoutButtons );
144 
145  // Set the layout
146  COverlayObjectDetailView::setLayout( __pqVBoxLayout );
147 
148 }
149 
150 
151 //------------------------------------------------------------------------------
152 // METHODS: COverlayObjectDetailView (implement/override)
153 //------------------------------------------------------------------------------
154 
156 {
157  if( !poOverlayObject ) return;
158  CDevice* __poDevice = (CDevice*)poOverlayObject;
159  poTextName->setText( __poDevice->getName() );
161  pqLabelActivity->setText( "" );
162 
163  // ... buttons
164  bIgnoreUpdate = true;
165  pqPushButtonStop->setChecked( __poDevice->getOperatingMode() == CDevice::STOP );
166  pqPushButtonPause->setChecked( __poDevice->getOperatingMode() == CDevice::PAUSE );
167  pqPushButtonStart->setChecked( __poDevice->getOperatingMode() == CDevice::START );
168  bIgnoreUpdate = false;
169 }
170 
172 {
175  pqLabelActivity->setText( "" );
176 }
177 
179 {
180  if( poOverlayObject )
181  {
182  pqPushButtonEdit->setEnabled( true );
183  pqPushButtonDelete->setEnabled( true );
184  pqPushButtonStop->setEnabled( true );
185  pqPushButtonPause->setEnabled( true );
186  pqPushButtonStart->setEnabled( true );
187  QObject::connect( (CDevice*)poOverlayObject, SIGNAL( signalOperatingMode(CDevice::EOperatingMode) ), this, SLOT( slotOperatingMode(CDevice::EOperatingMode) ) );
188  QObject::connect( (CDevice*)poOverlayObject, SIGNAL( signalActivity() ), this, SLOT( slotActivity() ) );
189  bIgnoreUpdate = false;
190  }
191 }
192 
194 {
195  if( poOverlayObject ) QObject::disconnect( (CDevice*)poOverlayObject, 0, this, 0 );
196  pqPushButtonEdit->setEnabled( false );
197  pqPushButtonDelete->setEnabled( false );
198  pqPushButtonStop->setEnabled( false );
199  pqPushButtonPause->setEnabled( false );
200  pqPushButtonStart->setEnabled( false );
201  bIgnoreUpdate = true;
202 }
203 
204 
205 //------------------------------------------------------------------------------
206 // METHODS
207 //------------------------------------------------------------------------------
208 
209 //
210 // SLOTS
211 //
212 
214 {
215  pqPushButtonStop->setChecked( _eOperatingMode == CDevice::STOP );
216  pqPushButtonPause->setChecked( _eOperatingMode == CDevice::PAUSE );
217  pqPushButtonStart->setChecked( _eOperatingMode == CDevice::START );
218 }
219 
221 {
222  static double __fdTimestampLast = 0;
223  double __fdTimestampNow = microtime();
224  if( __fdTimestampNow - __fdTimestampLast < 0.1 ) return;
225  pqLabelActivity->setText( pqLabelActivity->text() == "\\" ? "/" : "\\" );
226  __fdTimestampLast = __fdTimestampNow;
227 }
228 
230 {
231  if( !poOverlayObject ) return;
232  ((CDevice*)poOverlayObject)->showEdit();
233 }
234 
236 {
237  if( !poOverlayObject ) return;
238  if( !QVCTRuntime::useMainWindow()->deleteConfirm( poOverlayObject->getName() ) ) return;
239  QMutex* __pqMutexDataChange = QVCTRuntime::useMutexDataChange();
240  __pqMutexDataChange->lock();
241  CDeviceOverlay* __poDeviceOverlay = QVCTRuntime::useDeviceOverlay();
242  CDevice* __poDevice = (CDevice*)poOverlayObject;
243  __poDeviceOverlay->removeChild( __poDevice );
244  delete __poDevice;
245  QTreeWidgetItem* __pqTreeWidgetItem = __poDeviceOverlay->currentItem();
246  if( __pqTreeWidgetItem ) __poDeviceOverlay->showDetail( __pqTreeWidgetItem );
247  __pqMutexDataChange->unlock();
248 }
249 
251 {
252  if( !poOverlayObject || bIgnoreUpdate ) return;
253  ((CDevice*)poOverlayObject)->setOperatingMode( CDevice::STOP );
254  refreshContent();
255 }
256 
258 {
259  if( !poOverlayObject || bIgnoreUpdate ) return;
260  ((CDevice*)poOverlayObject)->setOperatingMode( CDevice::PAUSE );
261  refreshContent();
262 }
263 
265 {
266  if( !poOverlayObject || bIgnoreUpdate ) return;
267  ((CDevice*)poOverlayObject)->setOperatingMode( CDevice::START );
268  refreshContent();
269 }
bool bIgnoreUpdate
Flag that disables checkable buttons update.
void slotPause()
[UI:Slot] Slot to pause the device
void slotEdit()
[UI:Slot] Slot to edit the device configuration
void slotActivity()
[Slot] Slot to handle activity signal emitted by device
QPushButton * pqPushButtonStart
[UI:Button] Start
void slotOperatingMode(CDevice::EOperatingMode _eOperatingMode)
[Slot] Slot to handle operating mode changes
virtual void resetContent()
Resets (clears) the content of the underlying widget.
CDeviceDetailView(QWidget *_pqParent=0)
virtual void enableContent()
Enables the content (controls) of the underlying widget.
QPushButton * pqPushButtonDelete
[UI:Button] Delete
void slotStart()
[UI:Slot] Start to start the device
QPushButton * pqPushButtonEdit
[UI:Button] Edit
virtual void disableContent()
Disables the content (controls) of the underlying widget.
QLabel * pqLabelActivity
[UI:Label] Activity
void slotDelete()
[UI:Slot] Slot to delete the device
void constructLayout()
Constructs the layout of the user-interface.
QPushButton * pqPushButtonPause
[UI:Button] Pause
void slotStop()
[UI:Slot] Slot to stop the device
COverlayText * poTextName
[UI:Label] Name
virtual void refreshContent()
Refreshes the content of the underlying widget.
QPushButton * pqPushButtonStop
[UI:Button] Stop
COverlayText * poTextDriver
[UI:Label] Driver
static QString toName(EDriver _eDriver)
Returns the human-readable name corresponding to the given device driver ID.
[UI] Device overlay container
virtual void showDetail(const QTreeWidgetItem *_pqTreeWidgetItem) const
Displays the given overlay object's details (in the appropriate widget/view)
Generic navigation device (GPS, speedometer, compass, etc.)
Definition: CDevice.hpp:43
virtual CDeviceDriver::EDriver getDriver() const =0
Returns the device's driver ID.
EOperatingMode
Device operating mode (stop, start, pause)
Definition: CDevice.hpp:58
@ PAUSE
Definition: CDevice.hpp:58
@ STOP
Definition: CDevice.hpp:58
@ START
Definition: CDevice.hpp:58
virtual EOperatingMode getOperatingMode()
Returns the device's operating mode.
Definition: CDevice.hpp:132
[UI] Generic overlay object's detail view
COverlayObject * poOverlayObject
Overlay object being displayed.
QString getName() const
Returns this object's name.
[UI] Overlay-specific text label
void setText(const QString &_rqsText)
[override] QLabel::setText( const QString& )
void resetText()
Resets (clears) the underlying QLabel's text.
static CDeviceOverlay * useDeviceOverlay()
static QMutex * useMutexDataChange()
static CMainWindow * useMainWindow()
double microtime()
Returns the system time with microseconds resolution, in seconds.
Definition: main.cpp:30