CustusX  15.3.4-beta
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 
91 {
92  return "<html>"
93  "<h3>Record session.</h3>"
94  "<p>Lets you record a session of some kind.</p>"
95  "<p><i></i></p>"
96  "</html>";
97 }
98 
99 void RecordSessionWidget::setReady(bool val, QString text)
100 {
101  this->setEnabled(val);
102  mInfoLabel->setText(text);
103 }
104 
106 {
107  mDescriptionLine->setVisible(value);
108  mDescriptionLabel->setVisible(value);
109 }
110 
112 {}
113 
115 {
116  mDescriptionLine->setText(text);
117 }
118 
119 void RecordSessionWidget::usReadinessChangedSlot()
120 {
121  this->setEnabled(mAcquisitionService->isReady());
122  mInfoLabel->setText(mAcquisitionService->getInfoText());
123 }
124 
125 void RecordSessionWidget::recordStateChangedSlot()
126 {
127  AcquisitionService::STATE state = mAcquisitionService->getState();
128 
129  mStartStopButton->blockSignals(true);
130 
131  switch (state)
132  {
134  mStartStopButton->setChecked(true);
135  mStartStopButton->setText("Stop");
136  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-playback-stop.png"));
137  mStartStopButton->setEnabled(true);
138  mCancelButton->setEnabled(true);
139  break;
141  mStartStopButton->setChecked(false);
142  mStartStopButton->setText("Start");
143  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
144  mStartStopButton->setEnabled(true);
145  mCancelButton->setEnabled(false);
146  break;
148  mStartStopButton->setChecked(false);
149  mStartStopButton->setText("Processing...");
150  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
151  mStartStopButton->setEnabled(false);
152  mCancelButton->setEnabled(false);
153  break;
154  }
155 
156  mStartStopButton->blockSignals(false);
157 }
158 
159 void RecordSessionWidget::startStopSlot(bool checked)
160 {
161  mAcquisitionService->toggleRecord();
162 }
163 
164 void RecordSessionWidget::cancelSlot()
165 {
166  mAcquisitionService->cancelRecord();
167 }
168 
169 }
RecordSessionWidget(AcquisitionServicePtr base, QWidget *parent, QString defaultDescription="Record Session", bool requireUsReady=true)
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
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