NorMIT-nav  22.09
An IGT application
cxDisplayTimerWidget.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 "cxDisplayTimerWidget.h"
13 
14 #include <QTimer>
15 #include <QHBoxLayout>
16 #include <QLabel>
17 
18 namespace cx
19 {
20 
21 
22 DisplayTimerWidget::DisplayTimerWidget(QWidget* parent) : QWidget(parent),
23  mFontSize(8)
24 {
25  mTimer = new QTimer(this);
26  connect(mTimer, SIGNAL(timeout()), this, SLOT(timeoutSlot()));
27  mTimer->setInterval(1000);
28 
29  QHBoxLayout* layout = new QHBoxLayout(this);
30  layout->setMargin(0);
31 
32  mLabel = new QLabel;
33  layout->addWidget(mLabel);
34 }
35 
37 {
38  mFontSize = fontSize;
39 }
40 
42 {
43  if (mTimer->isActive())
44  return;
45  mStartTime = QDateTime::currentDateTime();
46  mTimer->start();
47  timeoutSlot();
48 }
49 
51 {
52  mTimer->stop();
53  this->printText("green");
54 }
55 
57 {
58  mTimer->stop();
59  this->printText("red");
60 }
61 
62 void DisplayTimerWidget::timeoutSlot()
63 {
64  this->printText("black");
65 }
66 
67 void DisplayTimerWidget::printText(QString color)
68 {
69  int secs = this->elaspedSeconds(); // SmStartTime.secsTo(QDateTime::currentDateTime());
70  mLabel->setText(QString("<font size=%1 color=%2><b>%3 s</b></font>").arg(mFontSize).arg(color).arg(secs));
71 }
72 
74 {
75  return mStartTime.secsTo(QDateTime::currentDateTime());
76 }
77 
78 
79 }
cx::DisplayTimerWidget::start
void start()
Definition: cxDisplayTimerWidget.cpp:41
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DisplayTimerWidget::setFontSize
void setFontSize(int fontSize)
Definition: cxDisplayTimerWidget.cpp:36
cx::DisplayTimerWidget::elaspedSeconds
int elaspedSeconds() const
Definition: cxDisplayTimerWidget.cpp:73
cxDisplayTimerWidget.h
cx::DisplayTimerWidget::DisplayTimerWidget
DisplayTimerWidget(QWidget *parent)
Definition: cxDisplayTimerWidget.cpp:22
cx::DisplayTimerWidget::failed
void failed()
Definition: cxDisplayTimerWidget.cpp:56
cx::DisplayTimerWidget::stop
void stop()
Definition: cxDisplayTimerWidget.cpp:50