diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-05-10 03:08:35 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-05-10 03:08:35 +0000 |
commit | 6b3a7afaeff2f50eeb215fa88a2b6926e56c2060 (patch) | |
tree | 3eb68fed7565824501bf83a225e39e60a9778b09 | |
parent | 5635dd32308038cc5116b5e0d29a225ed61981f6 (diff) | |
download | knetload-6b3a7afaeff2f50eeb215fa88a2b6926e56c2060.tar.gz knetload-6b3a7afaeff2f50eeb215fa88a2b6926e56c2060.zip |
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/knetload@1124767 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
-rw-r--r-- | knetload/statdock.cpp | 62 | ||||
-rw-r--r-- | knetload/statdock.h | 3 |
2 files changed, 47 insertions, 18 deletions
diff --git a/knetload/statdock.cpp b/knetload/statdock.cpp index cc542df..16b6772 100644 --- a/knetload/statdock.cpp +++ b/knetload/statdock.cpp @@ -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 char* useLabel, StatPopup *parent, const char *name) : KSystemTray(parent,name), label(QString::fromUtf8(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 char* 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); } diff --git a/knetload/statdock.h b/knetload/statdock.h index 1c41dce..c3e715a 100644 --- a/knetload/statdock.h +++ b/knetload/statdock.h @@ -155,6 +155,9 @@ private: */ int i, j, tmpPos, oldUpper, oldLower; /**< Temporary variables used during computations. */ + +protected: + void resizeEvent ( QResizeEvent * ); }; #endif |