Fraxinus  16.5.0-fx-rc3
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 {
50  AcquisitionService::TYPES context, QString category) :
51  BaseWidget(parent, "RecordSessionWidget", "Record Session"),
52  mAcquisitionService(base),
53  mInfoLabel(new QLabel("")),
54  mStartStopButton(new QPushButton(QIcon(":/icons/open_icon_library/media-record-3.png"), "Start")),
55  mCancelButton(new QPushButton(QIcon(":/icons/open_icon_library/process-stop-7.png"), "Cancel")),
56  mContext(context),
57  mCategory(category)
58 {
59  QVBoxLayout* layout = new QVBoxLayout(this);
60  layout->setMargin(0);
61  layout->addWidget(mInfoLabel);
62 
63  QHBoxLayout* buttonLayout = new QHBoxLayout();
64 
65  int buttonheight = mStartStopButton->sizeHint().height()*2.5;
66  mStartStopButton->setMinimumHeight(buttonheight);
67  mCancelButton->setMinimumHeight(buttonheight);
68 
69  buttonLayout->addWidget(mStartStopButton);
70  buttonLayout->addWidget(mCancelButton);
71  layout->addLayout(buttonLayout);
72 
73  connect(mAcquisitionService.get(), &AcquisitionService::stateChanged, this, &RecordSessionWidget::recordStateChangedSlot);
74 
75  mStartStopButton->setCheckable(true);
76  connect(mStartStopButton, &QPushButton::clicked, this, &RecordSessionWidget::startStopSlot);
77  connect(mCancelButton, &QPushButton::clicked, this, &RecordSessionWidget::cancelSlot);
78 
79  this->recordStateChangedSlot();
80 
81  connect(mAcquisitionService.get(), &AcquisitionService::usReadinessChanged, this, &RecordSessionWidget::onReadinessChanged);
82  this->onReadinessChanged();
83 }
84 
86 {}
87 
88 void RecordSessionWidget::onReadinessChanged()
89 {
90  this->setEnabled(mAcquisitionService->isReady(mContext));
91  mInfoLabel->setText(mAcquisitionService->getInfoText(mContext));
92 }
93 
94 void RecordSessionWidget::recordStateChangedSlot()
95 {
96  AcquisitionService::STATE state = mAcquisitionService->getState();
97 
98  mStartStopButton->blockSignals(true);
99 
100  switch (state)
101  {
103  mStartStopButton->setChecked(true);
104  mStartStopButton->setText("Stop");
105  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-playback-stop.png"));
106  mStartStopButton->setEnabled(true);
107  mCancelButton->setEnabled(true);
108  break;
110  mStartStopButton->setChecked(false);
111  mStartStopButton->setText("Start");
112  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
113  mStartStopButton->setEnabled(true);
114  mCancelButton->setEnabled(false);
115  break;
117  mStartStopButton->setChecked(false);
118  mStartStopButton->setText("Processing...");
119  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
120  mStartStopButton->setEnabled(false);
121  mCancelButton->setEnabled(false);
122  break;
123  }
124 
125  mStartStopButton->blockSignals(false);
126 }
127 
128 void RecordSessionWidget::startStopSlot(bool checked)
129 {
130  RecordSessionPtr session = mAcquisitionService->getSession(mCurrentSession);
131 
132  if (mAcquisitionService->getState()==AcquisitionService::sRUNNING)
133  mAcquisitionService->stopRecord();
134  else
135  mAcquisitionService->startRecord(mContext, mCategory, session);
136 
137 // mAcquisitionService->toggleRecord(mContext, mCategory);
138 }
139 
140 void RecordSessionWidget::cancelSlot()
141 {
142  mAcquisitionService->cancelRecord();
143 }
144 
146 {
147  mCurrentSession = uid;
148 }
149 
150 }
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
boost::shared_ptr< class RecordSession > RecordSessionPtr
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
void setCurrentSession(QString uid)
set a session that the next recording adds to
RecordSessionWidget(AcquisitionServicePtr base, QWidget *parent, AcquisitionService::TYPES context, QString category)