NorMIT-nav  18.04
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxRecordSessionWidget.h"
13 
14 #include <QPushButton>
15 #include <QLineEdit>
16 #include <QLabel>
17 #include <QVBoxLayout>
18 #include <QEvent>
19 #include "cxTime.h"
20 
21 #include "cxRecordSession.h"
22 #include "cxTrackingService.h"
23 #include "cxTypeConversions.h"
24 #include "cxAcquisitionService.h"
25 
26 namespace cx
27 {
29  AcquisitionService::TYPES context, QString category) :
30  BaseWidget(parent, "RecordSessionWidget", "Record Session"),
31  mAcquisitionService(base),
32  mInfoLabel(new QLabel("")),
33  mStartStopButton(new QPushButton(QIcon(":/icons/open_icon_library/media-record-3.png"), "Start")),
34  mCancelButton(new QPushButton(QIcon(":/icons/open_icon_library/process-stop-7.png"), "Cancel")),
35  mContext(context),
36  mCategory(category)
37 {
38  QVBoxLayout* layout = new QVBoxLayout(this);
39  layout->setMargin(0);
40  layout->addWidget(mInfoLabel);
41 
42  QHBoxLayout* buttonLayout = new QHBoxLayout();
43 
44  int buttonheight = mStartStopButton->sizeHint().height()*2.5;
45  mStartStopButton->setMinimumHeight(buttonheight);
46  mCancelButton->setMinimumHeight(buttonheight);
47 
48  buttonLayout->addWidget(mStartStopButton);
49  buttonLayout->addWidget(mCancelButton);
50  layout->addLayout(buttonLayout);
51  QString warningText;
52  warningText = "<font color=red>Note! This widget must be visible during active recording</font><br>";
53  QLabel* warningInfoLabel = new QLabel(warningText);
54  layout->addWidget(warningInfoLabel);
55 
56  connect(mAcquisitionService.get(), &AcquisitionService::stateChanged, this, &RecordSessionWidget::recordStateChangedSlot);
57 
58  mStartStopButton->setCheckable(true);
59  connect(mStartStopButton, &QPushButton::clicked, this, &RecordSessionWidget::startStopSlot);
60  connect(mCancelButton, &QPushButton::clicked, this, &RecordSessionWidget::cancelSlot);
61 
62  this->recordStateChangedSlot();
63 
64  connect(mAcquisitionService.get(), &AcquisitionService::usReadinessChanged, this, &RecordSessionWidget::onReadinessChanged);
65  this->onReadinessChanged();
66 }
67 
69 {}
70 
71 void RecordSessionWidget::onReadinessChanged()
72 {
73  this->setEnabled(mAcquisitionService->isReady(mContext));
74  mInfoLabel->setText(mAcquisitionService->getInfoText(mContext));
75 }
76 
77 void RecordSessionWidget::recordStateChangedSlot()
78 {
79  AcquisitionService::STATE state = mAcquisitionService->getState();
80 
81  mStartStopButton->blockSignals(true);
82 
83  switch (state)
84  {
86  mStartStopButton->setChecked(true);
87  mStartStopButton->setText("Stop");
88  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-playback-stop.png"));
89  mStartStopButton->setEnabled(true);
90  mCancelButton->setEnabled(true);
91  break;
93  mStartStopButton->setChecked(false);
94  mStartStopButton->setText("Start");
95  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
96  mStartStopButton->setEnabled(true);
97  mCancelButton->setEnabled(false);
98  break;
100  mStartStopButton->setChecked(false);
101  mStartStopButton->setText("Processing...");
102  mStartStopButton->setIcon(QIcon(":/icons/open_icon_library/media-record-3.png"));
103  mStartStopButton->setEnabled(false);
104  mCancelButton->setEnabled(false);
105  break;
106  }
107 
108  mStartStopButton->blockSignals(false);
109 }
110 
111 void RecordSessionWidget::startStopSlot(bool checked)
112 {
113  RecordSessionPtr session = mAcquisitionService->getSession(mCurrentSession);
114 
115  if (mAcquisitionService->getState()==AcquisitionService::sRUNNING)
116  mAcquisitionService->stopRecord();
117  else
118  mAcquisitionService->startRecord(mContext, mCategory, session);
119 
120 // mAcquisitionService->toggleRecord(mContext, mCategory);
121 }
122 
123 void RecordSessionWidget::cancelSlot()
124 {
125  mAcquisitionService->cancelRecord();
126 }
127 
129 {
130  mCurrentSession = uid;
131 }
132 
133 }
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:88
void setCurrentSession(QString uid)
set a session that the next recording adds to
RecordSessionWidget(AcquisitionServicePtr base, QWidget *parent, AcquisitionService::TYPES context, QString category)
Namespace for all CustusX production code.