summaryrefslogtreecommitdiffstats
path: root/kcpuload/kcpuload/statdock.h
blob: 35c402b54f7693b288c2234f825b74c2034ee4a2 (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

/***************************************************************************
 *                                                                         *
 *   KCPULoad and KNetLoad are copyright (c) 1999-2000, Markus Gustavsson  *
 *                                       (c) 2002, Ben Burton              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef __STATDOCK_H
#define __STATDOCK_H

#include <qcolor.h>
#include <ksystemtray.h>

class StatPopup;

/**
 * A system tray window that displays a recent history of readings.
 * A single application might have many of these windows.
 *
 * Two simultaneous sets of readings are supported; these will be
 * referred to as upper and lower readings.  When diagram splitting is
 * switched on, these readings will be displayed together on the diagram
 * with the upper readings shown above the lower readings.  When diagram
 * splitting is switched off, only the upper readings will be displayed.
 *
 * The parent window of a StatDock must be a StatPopup, which provides
 * all of the actions in this window's context menu.
 */
class StatDock : public KSystemTray {
    Q_OBJECT

public:
    /**
     * Fill style constants.
     */
    static const int fillLines;
    static const int fillBars;
    static const int fillShaded;

    /**
     * Colour constants.
     */
    static const QColor colorGrid;
    static const QColor colorGridInactive;
    static const QColor colorLabel;
    static const QColor colorLabelInactive;
    static const QColor colorLower;
    static const QColor colorLowerInactive;
    static const QColor colorBlack;

public:
    /**
     * Constructor and destructor.
     *
     * Note that the constructor will call parent->initDock().
     *
     * Parameter whichDock must be 0 or 1 to specify whether this dock
     * will become dock[0] or dock[1] in the given StatPopup parent.
     * Parameter useLabel should contain the label that will be drawn on
     * the diagram if labelling is enabled.
     */
    StatDock(int whichDock, const QString& useLabel, StatPopup *parent,
        const char *name = 0);
    ~StatDock();

    /**
     * Setting display options.
     */
    void setGrid(bool);
    void setActive(bool);
    void setSoft(bool);
    void setSplit(bool);
    void setLabelled(bool);
    void setLabel(const QString&);
    void setFill(int);
    void setColor(const QColor&);

public slots:
    /**
     * Clear the history of recent readings.
     * All readings will be reset to zero and the diagram will be
     * updated.
     */
    void clearHistory();

    /**
     * Add the given pair of readings as the most recent in our list.
     * The diagram will be updated accordingly.
     *
     * Each argument should be a percentage between 0 and 100.
     * The sum of both arguments must not exceed 100.
     *
     * If diagram splitting is switched off, the given lower reading
     * will be ignored completely and 0 will be used instead.
     *
     * @param upper the upper reading in this pair.
     * @param lower the lower reading in this pair.
     */
    void addPercentReading(int upper, int lower);

private:
    /**
     * Repaint this system tray window with a fresh diagram.
     */
    void paintEvent(QPaintEvent*);

private:
    /**
     * Display options.
     */
    bool grid;
        /**< Should the grid be displayed behind the diagram? */
    bool active;
        /**< Is this meter currently active? */
    bool soft;
        /**< Are we artificially modifying the readings to produce a
             soft curve? */
    bool split;
        /**< Are we displaying both upper and lower readings? */
    bool labelled;
        /**< Should this diagram be labelled? */
    QString label;
        /**< The specific label to draw on this diagram. */
    int fill;
        /**< Specifies which of the predefined fill styles to use. */
    QColor colorUpper;
        /**< Colour for displaying the upper readings. */
    QColor colorUpperInactive;
        /**< Colour for displaying the upper readings whilst the diagram
             is inactive. */

    /**
     * Stored readings.
     */
    int* bufUpper;
        /**< Stores our list of recent upper readings.
             This list begins at index (pos + 1) as the earliest reading
             and cycles around to index (pos) as the latest reading. */
    int* bufLower;
        /**< Stores our list of recent lower readings.
             This list begins at index (pos + 1) as the earliest reading
             and cycles around to index (pos) as the latest reading. */
    int pos;
        /**< The index in our arrays of the most recent reading. */


    /**
     * Temporaries.
     */
    int i, j, tmpPos, oldUpper, oldLower;
        /**< Temporary variables used during computations. */

protected:
    void resizeEvent ( QResizeEvent * );
};

#endif