File: sysinfo.cpp

package info (click to toggle)
qwt5 5.2.2-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 13,340 kB
  • sloc: cpp: 32,645; makefile: 23; sh: 4
file content (112 lines) | stat: -rw-r--r-- 3,381 bytes parent folder | download | duplicates (6)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <qapplication.h>
#include <qwidget.h>
#include <qfont.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qlayout.h>
#include <qwt_thermo.h>

class ValueBar: public QWidget
{
public:
    ValueBar(Qt::Orientation orientation, 
            const QString &text, QWidget *parent, double value = 0.0):
        QWidget(parent)
    {
        d_label = new QLabel(text, this);
        d_label->setFont(QFont("Helvetica", 10));

        d_thermo = new QwtThermo(this);
        d_thermo->setRange(0.0,100.0);
        d_thermo->setValue(value);
        d_thermo->setFont(QFont("Helvetica", 8));
        d_thermo->setPipeWidth(6);
        d_thermo->setScaleMaxMajor(6);
        d_thermo->setScaleMaxMinor(5);
        d_thermo->setMargin(10);
        d_thermo->setFillColor(QColor("DarkMagenta"));

        QVBoxLayout *layout = new QVBoxLayout(this);
        layout->setMargin(0);
        layout->setSpacing(0);

        if ( orientation == Qt::Horizontal )
        {
            d_label->setAlignment(Qt::AlignCenter);
            d_thermo->setOrientation(orientation, QwtThermo::BottomScale);
            layout->addWidget(d_label);
            layout->addWidget(d_thermo);
        }
        else
        {
            d_label->setAlignment(Qt::AlignRight);
            d_thermo->setOrientation(orientation, QwtThermo::LeftScale);
            layout->addWidget(d_thermo, 10, Qt::AlignHCenter);
            layout->addWidget(d_label, 0);
        }
    }

    void setValue(double value)
    {
        d_thermo->setValue(value);
    }
private:
    QLabel *d_label;
    QwtThermo *d_thermo;
};

class SysInfo : public QFrame
{
public:
    SysInfo(QWidget *parent = NULL):
        QFrame(parent)
    {   
        QGroupBox *memBox = new QGroupBox("Memory Usage", this);
        memBox->setFont(QFont("Helvetica", 10));

        QVBoxLayout *memLayout = new QVBoxLayout(memBox);
        memLayout->setMargin(15);
        memLayout->setSpacing(5);

        Qt::Orientation o = Qt::Horizontal;
        memLayout->addWidget(new ValueBar(o, "Used", memBox, 57));
        memLayout->addWidget(new ValueBar(o, "Shared", memBox, 17));
        memLayout->addWidget(new ValueBar(o, "Cache", memBox, 30));
        memLayout->addWidget(new ValueBar(o, "Buffers", memBox, 22));
        memLayout->addWidget(new ValueBar(o, "Swap Used", memBox, 57));
        memLayout->addWidget(new QWidget(memBox), 10); // spacer

        QGroupBox *cpuBox = new QGroupBox("Cpu Usage", this);
        cpuBox->setFont(QFont("Helvetica", 10));

        QHBoxLayout *cpuLayout = new QHBoxLayout(cpuBox);
        cpuLayout->setMargin(15);
        cpuLayout->setSpacing(5);

        o = Qt::Vertical;
        cpuLayout->addWidget(new ValueBar(o, "User", cpuBox, 57));
        cpuLayout->addWidget(new ValueBar(o, "Total", cpuBox, 73));
        cpuLayout->addWidget(new ValueBar(o, "System", cpuBox, 16));
        cpuLayout->addWidget(new ValueBar(o, "Idle", cpuBox, 27));

        QHBoxLayout *layout = new QHBoxLayout(this);
        layout->setMargin(10);
        layout->addWidget(memBox, 10);
        layout->addWidget(cpuBox, 0);
    }
};

int main (int argc, char **argv)
{
    QApplication a(argc, argv);
    
    SysInfo info;
    info.resize(info.sizeHint().expandedTo(QSize(600, 400)));
#if QT_VERSION < 0x040000
    a.setMainWidget(&info);
#endif
    info.show();

    int rv = a.exec();
    return rv;
}