-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmtthermo.cpp
More file actions
93 lines (76 loc) · 2.23 KB
/
mtthermo.cpp
File metadata and controls
93 lines (76 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "mtthermo.hpp"
#include <qwt_thermo.h>
#include <qwt_color_map.h>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QEvent>
#include <QDebug>
#include <QString>
/*
This was stolen from sysinfo.cpp from the qwt examples
*/
MtThermo::MtThermo(Qt::Orientation orientation, const QString &text, QWidget *parent, double value) :
QWidget(parent)
{
m_label = new QLabel( text, this );
//m_label->setFont( QFont( "Helvetica", 10 ) );
m_value = new QLabel("0.0",this);
//m_value->setFont(QFont("Helvectia",10));
m_value->setAlignment(Qt::AlignHCenter);
m_thermo = new QwtThermo( this );
m_thermo->setScale( 0.0, 80.0 );
m_thermo->setValue( value );
m_thermo->setPipeWidth( 6 );
m_thermo->setScaleMaxMajor( 6 );
m_thermo->setScaleMaxMinor( 5 );
m_thermo->setFillBrush( Qt::darkMagenta );
setColorMap(0.0, 0.40, 0.50);
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( 0 );
if ( orientation == Qt::Horizontal )
{
// setScalePosition?
m_thermo->setOrientation( orientation );
layout->addWidget( m_value );
layout->addWidget( m_thermo );
layout->addWidget( m_label );
}
else
{
// setScalePosition QwtThermo::LeftScale ?
m_label->setAlignment( Qt::AlignCenter );
m_thermo->setOrientation( orientation );
layout->addWidget( m_label, 0 );
layout->addWidget( m_thermo, 10, Qt::AlignHCenter );
layout->addWidget( m_value );
}
setLayout(layout);
}
void MtThermo::setValue(double value)
{
m_thermo->setValue(value);
QChar chr[] = {0x00b0}; // Degree symbol. U+00B0
QString str = QString::fromRawData(chr, sizeof(chr) / sizeof(QChar));
const QString format = QString("%1 %2").arg(QString::number(value,'f',1)).arg(str);
m_value->setText(format);
}
double MtThermo::value()const
{
return m_thermo->value();
}
void MtThermo::setColorMap(double blue, double yellow, double red)
{
QwtLinearColorMap *colorMap =
new QwtLinearColorMap( Qt::blue, Qt::red );
colorMap->addColorStop( blue, Qt::blue);
colorMap->addColorStop( yellow, Qt::yellow );
colorMap->addColorStop( red, Qt::red );
colorMap->setMode( QwtLinearColorMap::FixedColors );
m_thermo->setColorMap( colorMap );
}
void MtThermo::setScale(double min, double max)
{
m_thermo->setScale(min, max);
}