NorMIT-nav  18.04
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 
56 void DisplayTimerWidget::timeoutSlot()
57 {
58  this->printText("black");
59 }
60 
61 void DisplayTimerWidget::printText(QString color)
62 {
63  int secs = this->elaspedSeconds(); // SmStartTime.secsTo(QDateTime::currentDateTime());
64  mLabel->setText(QString("<font size=%1 color=%2><b>%3 s</b></font>").arg(mFontSize).arg(color).arg(secs));
65 }
66 
68 {
69  return mStartTime.secsTo(QDateTime::currentDateTime());
70 }
71 
72 
73 }
void setFontSize(int fontSize)
DisplayTimerWidget(QWidget *parent)
Namespace for all CustusX production code.