AlarmTreeWidgetItem.cpp 3.09 KB
Newer Older
Giacomo Strangolino's avatar
Giacomo Strangolino committed
1
2
3
4
5
6
7
#include <AlarmTreeWidgetItem.h>
#include <QStringList>
#include <QDateTime>
#include <QTreeWidget>
#include <QtDebug>
#include <elettracolors.h>
#include <iostream>
8
#include <cumacros.h>
Giacomo Strangolino's avatar
Giacomo Strangolino committed
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

AlarmTreeWidgetItem::AlarmTreeWidgetItem(QTreeWidget *parent, QStringList &strings)
    : QTreeWidgetItem(parent, strings)
{
    m_init(strings);
}

AlarmTreeWidgetItem::AlarmTreeWidgetItem(QStringList &strings)
    : QTreeWidgetItem(strings)
{

    m_init(strings);
}

void AlarmTreeWidgetItem::m_init(QStringList& strings)
{
    _hide = false;

    if(strings.size() < 10)
    {
        for(int j = 0; j < 10 - strings.size(); j++)
            strings << "-";
    }

    setColor(strings.at(Status)/*, strings.at(SilencedMin).toInt()*/);

    update(strings);

    mHasMutedIcon = false;
    mNullIcon  = QIcon();
    mMutedIcon = QIcon(":icons/audio-volume-muted.png");
}

AlarmTreeWidgetItem::~AlarmTreeWidgetItem()
{

}

void AlarmTreeWidgetItem::setNew(bool isNew)
{
  QFont f = font(Alarm);
    f.setBold(isNew);
    setFont(Alarm, f);
}

void AlarmTreeWidgetItem::setColor(const QString& colorField)
{
    if(colorField.contains("ALARM"))
    {
        for(int j = 0; j < columnCount(); j++)
            setBackground(j, QColor(255,115,115));
    }
    else if(colorField.contains("WARNING"))
    {
        for(int j = 0; j < columnCount(); j++)
            setBackground(j, QBrush(EColor(Elettra::yellow)));
    }
    else
    {
        for(int j = 0; j < columnCount(); j++)
            setBackground(j, QBrush(EColor(Elettra::white)));
    }

}

void AlarmTreeWidgetItem::update(const QStringList &fields)
{
    QString colorField = fields.at(Status);
    QString levelField = fields.at(Level);
    int silenced = fields.at(SilencedMin).toInt();
    bool isNew = fields.last().toUpper() == "NEW";
    for(int i = 0; i < fields.size() && i < columnCount(); i++)
    {
        bool ok;
        QString field = fields.at(i);
        if(i == 0 && field.toUInt(&ok) && ok)
            field = QDateTime::fromTime_t(field.toUInt()).toString();
        if(text(i) != field)
            setText(i, field);
        if(colorField.contains("ALARM")) {
            if(levelField == "medium")
Giacomo Strangolino's avatar
Giacomo Strangolino committed
90
                setBackground(i, QColor(Qt::red));
Giacomo Strangolino's avatar
Giacomo Strangolino committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
            else if(levelField == "high") {
                setBackground(i, QBrush(EColor(Elettra::violet)));
            }
            else if(levelField == "low") {
                setBackground(i, QBrush(EColor(Elettra::orange)));
            }
            else if(levelField == "lowest") {
                setBackground(i, QBrush(EColor(Elettra::yellow)));
            }
        }
        else
        {
                setBackground(i, QBrush(EColor(Elettra::white)));
        }

    }

    QFont f = font(Alarm);
    f.setBold(isNew);
    setFont(Alarm, f);

    if(silenced > 0 && !mHasMutedIcon)
    {
        setIcon(SilencedMin, mMutedIcon);
        QColor c = background(SilencedMin).color();
        c.setAlpha(100);
        setBackground(SilencedMin, c);
        mHasMutedIcon = true;
    }
    else if(mHasMutedIcon && silenced < 0)
    {
        mHasMutedIcon = false;
        setIcon(SilencedMin, mNullIcon);
    }
}