CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRecordSessionWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxRecordSessionWidget.h"
34 
35 #include <QPushButton>
36 #include <QLineEdit>
37 #include <QLabel>
38 #include <QVBoxLayout>
39 #include <QEvent>
40 #include "cxTime.h"
41 
42 #include "cxRecordSession.h"
43 #include "cxTrackingService.h"
44 #include "cxTypeConversions.h"
45 #include "cxAcquisitionService.h"
46 
47 namespace cx
48 {
49 RecordSessionWidget::RecordSessionWidget(AcquisitionServicePtr base, QWidget* parent, QString defaultDescription, bool requireUsReady) :
50  BaseWidget(parent, "RecordSessionWidget", "Record Session"),
51  mAcquisitionService(base),
52  mInfoLabel(new QLabel("")),
53  mStartStopButton(new QPushButton(QIcon(":/icons/open_icon_library/media-record-3.png"), "Start")),
54  mCancelButton(new QPushButton(QIcon(":/icons/open_icon_library/process-stop-7.png"), "Cancel")),
55  mDescriptionLine(new QLineEdit(defaultDescription)),
56  mRequireUsReady(requireUsReady)
57 {
58  QVBoxLayout* layout = new QVBoxLayout(this);
59  layout->setMargin(0);
60  mDescriptionLabel = new QLabel("Description:");
61  layout->addWidget(mInfoLabel);
62  layout->addWidget(mDescriptionLabel);
63  layout->addWidget(mDescriptionLine);
64 
65  QHBoxLayout* buttonLayout = new QHBoxLayout();
66 
67  int buttonheight = mStartStopButton->sizeHint().height()*2.5;
68  mStartStopButton->setMinimumHeight(buttonheight);
69  mCancelButton->setMinimumHeight(buttonheight);
70 
71  buttonLayout->addWidget(mStartStopButton);
72  buttonLayout->addWidget(mCancelButton);
73  layout->addLayout(buttonLayout);
74 
75  connect(mAcquisitionService.get(), &AcquisitionService::stateChanged, this, &RecordSessionWidget::recordStateChangedSlot);
76 
77  mStartStopButton->setCheckable(true);
78  connect(mStartStopButton, &QPushButton::clicked, this, &RecordSessionWidget::startStopSlot);
79  connect(mCancelButton, &QPushButton::clicked, this, &RecordSessionWidget::cancelSlot);
80 
81  this->recordStateChangedSlot();
82 
83  if (mRequireUsReady)
84  {
85  connect(mAcquisitionService.get(), &AcquisitionService::usReadinessChanged, this, &RecordSessionWidget::usReadinessChangedSlot);
86  this->usReadinessChangedSlot();
87  }
88 }
89 
90 void RecordSessionWidget::setReady(bool val, QString text)
91 {
92  this->setEnabled(val);
93  mInfoLabel->setText(text);
94 }
95 
97 {
98  mDescriptionLine->setVisible(value);
99  mDescriptionLabel->setVisible(value);
100 }
101 
103 {}
104 
106 {
107  mDescriptionLine->setText(text);
108 }
109 
110 void RecordSessionWidget::usReadinessChangedSlot()
111 {
112  this->setEnabled(mAcquisitionService->isReady());
113  mInfoLabel->setText(mAcquisitionService->getInfoText());
114 }
115 
116 void RecordSessionWidget::recordStateChangedSlot()
117 {
118  AcquisitionService::STATE state = mAcquisitionService->getState();
119 
120  mStartStopButton->blockSignals(true);
121 
122  switch (state)
123  {
125  mStartStopButton->setChecked(true);
126  mStartStopButton->setText("Stop");
127  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-playback-stop.png"));
128  mStartStopButton->setEnabled(true);
129  mCancelButton->setEnabled(true);
130  break;
132  mStartStopButton->setChecked(false);
133  mStartStopButton->setText("Start");
134  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
135  mStartStopButton->setEnabled(true);
136  mCancelButton->setEnabled(false);
137  break;
139  mStartStopButton->setChecked(false);
140  mStartStopButton->setText("Processing...");
141  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
142  mStartStopButton->setEnabled(false);
143  mCancelButton->setEnabled(false);
144  break;
145  }
146 
147  mStartStopButton->blockSignals(false);
148 }
149 
150 void RecordSessionWidget::startStopSlot(bool checked)
151 {
152  mAcquisitionService->toggleRecord();
153 }
154 
155 void RecordSessionWidget::cancelSlot()
156 {
157  mAcquisitionService->cancelRecord();
158 }
159 
160 }
RecordSessionWidget(AcquisitionServicePtr base, QWidget *parent, QString defaultDescription="Record Session", bool requireUsReady=true)
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
void setReady(bool val, QString text)
deprecated: use readinessChangedSlot instead.
void setDescriptionVisibility(bool value)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108