Part of batch commit to enable true tasktray resize support for Trinity applications

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kcpuload@1124766 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 14 years ago
parent 6976d64141
commit ed82ec1b37

@ -27,17 +27,22 @@ const QColor StatDock::colorLower(255, 255, 255);
const QColor StatDock::colorLowerInactive(125, 125, 125);
const QColor StatDock::colorBlack(0, 0, 0);
#define DOCK_SIZE 24
#define DOCK_SCALE 4.34783 // Approx. 100/23.
//#define DOCK_SIZE 24
#define DOCK_SIZE width()
#define DOCK_SCALE (100/(DOCK_SIZE-1))
#define SOFT_STEP 3
StatDock::StatDock(int whichDock, const QString& useLabel,
StatPopup *parent, const char *name) :
KSystemTray(parent,name),
label(useLabel),
bufUpper(new int[DOCK_SIZE]),
bufLower(new int[DOCK_SIZE]),
bufUpper(0),
bufLower(0),
pos(0) {
bufUpper = new int[DOCK_SIZE];
bufLower = new int[DOCK_SIZE];
// Initialise the stored readings.
for (i = 0; i < DOCK_SIZE; i++)
bufUpper[i] = bufLower[i] = 0;
@ -45,7 +50,7 @@ StatDock::StatDock(int whichDock, const QString& useLabel,
// Initialise the display.
parent->initDock(this, contextMenu(), whichDock);
setBackgroundColor(colorBlack);
resize(24, 24);
resize(DOCK_SIZE, DOCK_SIZE);
show();
}
@ -54,6 +59,28 @@ StatDock::~StatDock() {
delete[] bufLower;
}
void StatDock::resizeEvent ( QResizeEvent * )
{
// Honor Free Desktop specifications that allow for arbitrary system tray icon sizes
int* bufUpperOld;
int* bufLowerOld;
bufUpperOld = bufUpper;
bufLowerOld = bufLower;
bufUpper = new int[DOCK_SIZE];
bufLower = new int[DOCK_SIZE];
// Re-initialise the stored readings.
for (i = 0; i < DOCK_SIZE; i++)
bufUpper[i] = bufLower[i] = 0;
delete[] bufUpperOld;
delete[] bufLowerOld;
repaint();
}
void StatDock::setGrid(bool set) {
grid = set;
repaint();
@ -146,15 +173,14 @@ void StatDock::paintEvent(QPaintEvent*) {
// Start by drawing the grid.
if(grid) {
p.setPen((active) ? colorGrid : colorGridInactive);
p.drawLine(0, 4, 23, 4);
p.drawLine(0, 9, 23, 9);
p.drawLine(0, 14, 23, 14);
p.drawLine(0, 19, 23, 19);
for(i = (((DOCK_SIZE+1)/5)-1); i < (DOCK_SIZE-1); i=i+((DOCK_SIZE+1)/5)) {
p.drawLine(0, i, (DOCK_SIZE-1), i);
}
}
if(fill == fillShaded) {
// Shaded
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
for(j = 0; j <= bufUpper[tmpPos]; j++) {
if (bufUpper[tmpPos] == 0 || j == 0)
@ -179,7 +205,7 @@ void StatDock::paintEvent(QPaintEvent*) {
else
p.setPen(colorLower.dark((200 * bufLower[tmpPos]) / j));
p.drawPoint(i, 23 - j);
p.drawPoint(i, (DOCK_SIZE-1) - j);
}
}
}
@ -189,20 +215,20 @@ void StatDock::paintEvent(QPaintEvent*) {
// Draw the upper bars, then the lower to save on pen
// adjustments.
p.setPen(active ? colorUpper : colorUpperInactive);
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
p.drawLine(i, DOCK_SIZE - 1 - bufUpper[tmpPos] -
bufLower[tmpPos], i, DOCK_SIZE - 1 - bufLower[tmpPos]);
}
p.setPen(active ? colorLower : colorLowerInactive);
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
p.drawLine(i, DOCK_SIZE - 1 - bufLower[tmpPos],
i, DOCK_SIZE - 1);
}
} else {
p.setPen(active ? colorUpper : colorUpperInactive);
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
p.drawLine(i, DOCK_SIZE - 1 - bufUpper[tmpPos],
i, DOCK_SIZE - 1);
@ -214,19 +240,19 @@ void StatDock::paintEvent(QPaintEvent*) {
// Draw the upper line, then the lower to save on pen
// adjustments.
p.setPen(active ? colorUpper : colorUpperInactive);
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
p.drawPoint(i, DOCK_SIZE - 1 -
bufUpper[tmpPos] - bufLower[tmpPos]);
}
p.setPen(active ? colorLower : colorLowerInactive);
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
p.drawPoint(i, DOCK_SIZE - 1 - bufLower[tmpPos]);
}
} else {
p.setPen(active ? colorUpper : colorUpperInactive);
for(i = 0; i < 24; i++) {
for(i = 0; i < DOCK_SIZE; i++) {
tmpPos = (pos + i + 1) % DOCK_SIZE;
p.drawPoint(i, DOCK_SIZE - 1 - bufUpper[tmpPos]);
}
@ -235,7 +261,7 @@ void StatDock::paintEvent(QPaintEvent*) {
// Finally label the diagrams.
if(labelled) {
p.setFont(QFont("Helvetica", 8));
p.setFont(QFont( "Helvetica", ((8*DOCK_SIZE)/24) ));
p.setPen((active) ? colorLabel : colorLabelInactive);
p.drawText(rect(), AlignLeft | AlignTop, label);
}

@ -155,6 +155,9 @@ private:
*/
int i, j, tmpPos, oldUpper, oldLower;
/**< Temporary variables used during computations. */
protected:
void resizeEvent ( QResizeEvent * );
};
#endif

Loading…
Cancel
Save