File: sysinfo.cpp

package info (click to toggle)
qwt 6.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 23,808 kB
  • sloc: cpp: 57,687; xml: 182; makefile: 32
file content (123 lines) | stat: -rw-r--r-- 3,891 bytes parent folder | download | duplicates (8)
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
113
114
115
116
117
118
119
120
121
122
123
#include <qapplication.h>
#include <qwidget.h>
#include <qfont.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qlayout.h>
#include <qwt_thermo.h>
#include <qwt_color_map.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->setOrientation( orientation );
        d_thermo->setScale( 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->setFillBrush( Qt::darkMagenta );

#if 0
        QwtLinearColorMap *colorMap =
            new QwtLinearColorMap( Qt::blue, Qt::red );

        colorMap->addColorStop( 0.2, Qt::yellow );
        colorMap->addColorStop( 0.3, Qt::cyan );
        colorMap->addColorStop( 0.4, Qt::green );
        colorMap->addColorStop( 0.5, Qt::magenta );
        colorMap->setMode( QwtLinearColorMap::FixedColors );
        d_thermo->setColorMap( colorMap );
#endif

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

        if ( orientation == Qt::Horizontal )
        {
            d_label->setAlignment( Qt::AlignCenter );
            d_thermo->setScalePosition( QwtThermo::LeadingScale );
            layout->addWidget( d_label );
            layout->addWidget( d_thermo );
        }
        else
        {
            d_label->setAlignment( Qt::AlignRight );
            d_thermo->setScalePosition( QwtThermo::TrailingScale );
            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 ) ) );
    info.show();

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