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

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

Loading…
Cancel
Save