MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkZoneProgressBar.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
15QmitkZoneProgressBar::QmitkZoneProgressBar(QString name, int maxRange, int warnRange, QWidget *parent)
16 : QProgressBar(parent), m_TextFormatValid(name), m_MaxRange(maxRange), m_WarnRange(warnRange),
17 m_ColorString("red"), m_WarnColorString("red"), m_BorderColorString("gray"),
18 m_StyleSheet("QProgressBar:horizontal {\nborder: 1px solid %1;\nborder-radius: 3px;\nbackground: white;\npadding: 1px;\ntext-align: center;\n}\nQProgressBar::chunk:horizontal {\nbackground: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 %2, stop: 0.8 %2, stop: 1 %3);\n}")
19{
20 this->setMinimum(0);
21 this->setMaximum(maxRange);
22
24}
25
27{
28 int adjustedValue = 0;
29 QString text;
30 QString startColor, stopColor;
31
32 // There Are now four possible outcomes
33 // 1) Needle is inside zone (bad news)
34 if (value < 0)
35 {
36 startColor = m_WarnColorString;
37 stopColor = m_WarnColorString;
38
39 text = m_TextFormatValid.arg(0) + " (VIOLATED)";
40 adjustedValue = m_MaxRange;
41 } // 2) Needle is close to zone
42 else if (value < m_WarnRange)
43 {
44 startColor = m_ColorString;
45 stopColor = m_WarnColorString;
46
47 text = m_TextFormatValid.arg(value);
48 adjustedValue = m_MaxRange - value;
49 } // 3) Needle is away from zone
50 else if (value < m_MaxRange)
51 {
52 startColor = m_ColorString;
53 stopColor = m_ColorString;
54
55 text = m_TextFormatValid.arg(value);
56 adjustedValue = m_MaxRange - value;
57 } // 4) Needle is far away from zone
58 else
59 {
60 startColor = m_ColorString;
61 stopColor = m_ColorString;
62
63 text = m_TextFormatValid.arg(value);
64 adjustedValue = 0;
65 }
66
67 this->setStyleSheet(m_StyleSheet.arg(m_BorderColorString, startColor, stopColor));
68 this->setFormat(text);
69 QProgressBar::setValue(adjustedValue);
70}
71
73{
74 this->setStyleSheet(m_StyleSheet.arg("#DD0000", "red", "red"));
75 this->setFormat(m_TextFormatInvalid);
76 QProgressBar::setValue(0);
77}
78
80{
81 m_TextFormatValid = format;
82}
83
85{
86 m_TextFormatInvalid = format;
87}
88
90{
91 m_ColorString = this->ColorToString(color);
92}
93
95{
96 m_WarnColorString = this->ColorToString(color);
97}
98
100{
101 m_BorderColorString = this->ColorToString(color);
102}
103
104void QmitkZoneProgressBar::UpdateStyleSheet(QString startColor, QString stopColor)
105{
106 this->setStyleSheet(m_StyleSheet.arg(m_BorderColorString, startColor, stopColor));
107}
108
110{
111 return QString("#%1%2%3").arg(static_cast<unsigned int>(color[0]*255), 2, 16, QChar('0'))
112 .arg(static_cast<unsigned int>(color[1]*255), 2, 16, QChar('0'))
113 .arg(static_cast<unsigned int>(color[2]*255), 2, 16, QChar('0'));
114}
void SetBorderColor(float color[3])
void setValueInvalid()
Can be called to indicate that there is currently no valid distance value available....
void SetTextFormatValid(QString format)
Setter for the text on the progress bar. Defaults to the string given as name to the constructor....
void SetColor(float color[3])
void SetTextFormatInvalid(QString format)
void SetWarnColor(float color[3])
QString ColorToString(float color[3])
void UpdateStyleSheet(QString startColor, QString stopColor)
QmitkZoneProgressBar(QString name, int maxRange, int warnRange, QWidget *parent=nullptr)
Initializes the progress bar with the given name, max range and warn range. The colors are set to def...