diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-05-11 20:07:47 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-05-11 20:07:47 +0000 |
commit | 0ab338256011c6b29494f9f69a2fba2afc147e16 (patch) | |
tree | 7642dd2c85d721bec502f1921931e9b7543471d0 /src | |
parent | 6ff0dec9104d593c7466d348c6eb34c343e3481e (diff) | |
download | knutclient-0ab338256011c6b29494f9f69a2fba2afc147e16.tar.gz knutclient-0ab338256011c6b29494f9f69a2fba2afc147e16.zip |
Honor Free Desktop tray icon resize requests
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/knutclient@1125602 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src')
-rwxr-xr-x | src/knutdock.cpp | 152 | ||||
-rwxr-xr-x | src/knutdock.h | 14 |
2 files changed, 91 insertions, 75 deletions
diff --git a/src/knutdock.cpp b/src/knutdock.cpp index 13d0d87..9626f3b 100755 --- a/src/knutdock.cpp +++ b/src/knutdock.cpp @@ -1,7 +1,7 @@ /*************************************************************************** knutdock.cpp - description ------------------- - begin : Út zari 23 2003 + begin : �t zari 23 2003 copyright : (C) 2003 by Daniel Prynych email : Daniel.Prynych@alo.cz ***************************************************************************/ @@ -45,7 +45,7 @@ KNutDock::KNutDock(KNutVarData::upsInfoDef* activeUpsInfo, KNutVarData::SettingD m_upsRecords = upsRecords; m_activeUpsInfo = activeUpsInfo; -//saves backgroundcolor of kicker +//saves backgroundcolor of kicker backgroundColor = paletteBackgroundColor(); m_typeOfIcon = m_settingData->typeOfKIcon; @@ -78,7 +78,7 @@ KNutDock::KNutDock(KNutVarData::upsInfoDef* activeUpsInfo, KNutVarData::SettingD initImage(); - changeKIcon(); // this function calls function repaintIcon + changeKIcon(); // this function calls function repaintIcon } @@ -96,6 +96,11 @@ KNutDock::~KNutDock(){ delete m_menu; } +void KNutDock::resizeEvent ( QResizeEvent * ){ + initImage(); + changeKIcon(); // this function calls function repaintIcon + } + void KNutDock::changeUps (void) { m_upsServerMenu->clear(); @@ -176,7 +181,7 @@ void KNutDock::repaintDock (const bool always) { QString nutStringVar; int myRuntimeValue; int myUpsLoadValue; - int myStatusValue; + int myStatusValue; int myStatusBatValue; int myBatteryChargeValue; bool repaintNow = false; @@ -188,7 +193,7 @@ void KNutDock::repaintDock (const bool always) { if (m_activeUpsInfo->upsNet == 0) { repaint(); return;} - m_dataOkOld=m_dataOk; + m_dataOkOld=m_dataOk; if ((m_activeUpsInfo->upsNet->getState() == KNutNet::Connected) // paints icons with information values && (!m_activeUpsInfo->netError)) { @@ -211,7 +216,7 @@ void KNutDock::repaintDock (const bool always) { switch (m_typeOfIcon) { case generalKI: -// *********STATUS**************** +// *********STATUS**************** if (myStatusValue !=m_statusValue ) { m_statusValue = myStatusValue; paintStatus(m_statusValue); @@ -219,7 +224,7 @@ void KNutDock::repaintDock (const bool always) { } // **********RUNTIME*********** - myStatusBatValue = myStatusValue & KNutNet::OB; // OB = UPS runs on battery + myStatusBatValue = myStatusValue & KNutNet::OB; // OB = UPS runs on battery if ((myRuntimeValue != m_runtimeValue) || (myStatusBatValue != m_statusBatValue)) { // when runtime is changed or flags OB is changed we must repaint icons // when OB is changed same items in icon will change color @@ -367,11 +372,11 @@ void KNutDock::repaintDock (const bool always) { if ((m_activeUpsInfo->upsNet->getState() == KNutNet::Connecting) || (m_activeUpsInfo->upsNet->getState() == KNutNet::HostLookup)) m_dataOk = connecting; - else m_dataOk = idle; - } + else m_dataOk = idle; + } if ((m_dataOk != m_dataOkOld) or always) { toolTip(0, -1, 0, 0); - m_dataOkOld=m_dataOk; + m_dataOkOld=m_dataOk; if (m_dataOk == connecting) setPixmap(m_connectPix); else { if (m_dataOk == error) setPixmap(m_errorPix); @@ -436,7 +441,7 @@ void KNutDock::toolTip (int runtime, int status, int batteryCharge, int upsLoad if (status & KNutNet::OFF) { text += i18n("UPS Of line"); } - } + } } if (status & KNutNet::LB) { @@ -575,18 +580,18 @@ void KNutDock::paintEvent (QPaintEvent *e) { // painter.begin(); if (m_statusValue & KNutNet::OL) { // ONLINE - icon of UPS painter.setPen(Qt::black); - paintNumbers (m_upsLoadValue, -2, 15, &painter ); + paintNumbers (m_upsLoadValue, (width()/-11), ((float) width()/(float) 1.46666666667), &painter, ((float) width()/(float) 22) ); } else { // OFFLINE icon of battery if (m_batteryChargeValue != knc::numberVarError) { if (m_batteryChargeValue < 40) painter.setPen(Qt::red); else painter.setPen(Qt::black); - paintNumbers(m_batteryChargeValue,-2,16,&painter); + paintNumbers(m_batteryChargeValue,(width()/-11),((float) width()/(float) 1.375),&painter, ((float) width()/(float) 22)); } else { painter.setPen(Qt::black); - paintDash (3,16,&painter); - paintDash (8,16,&painter); + paintDash (((float) width()/(float) 7.33333333333),((float) width()/(float) 1.375),&painter, ((float) width()/(float) 22)); + paintDash (((float) width()/(float) 2.75),((float) width()/(float) 1.375),&painter, ((float) width()/(float) 22)); } } // painter.end(); @@ -660,12 +665,12 @@ void KNutDock::paintCharge (int charge ) { if (charge != knc::numberVarError) { if (charge < 40) paint.setPen(Qt::red); else paint.setPen(Qt::black); - paintNumbers(charge,8,2,&paint); + paintNumbers(charge,8,2,&paint, 1); } else { paint.setPen(Qt::black); - paintDash (13,2,&paint); - paintDash (18,2,&paint); + paintDash (13,2,&paint, 1); + paintDash (18,2,&paint, 1); } } else { @@ -673,7 +678,7 @@ void KNutDock::paintCharge (int charge ) { if (charge != knc::numberVarError) { if (charge < 40) paint.setPen(Qt::red); else paint.setPen(Qt::black); - paintNumbers(charge,-2,16,&paint); + paintNumbers(charge,-2,16,&paint, 1); if (charge < 40) paint.setPen(Qt::red); else { @@ -688,8 +693,8 @@ void KNutDock::paintCharge (int charge ) { } else { paint.setPen(Qt::black); - paintDash (3,16,&paint); - paintDash (8,16,&paint); + paintDash (3,16,&paint, 1); + paintDash (8,16,&paint, 1); } } @@ -777,16 +782,16 @@ void KNutDock::paintRuntime (int runtime, int status ) { int min = abs(runtime/60); int sec = runtime - (min*60); - paintNumber(1,11, abs(min/10) ,&paint); - paintNumber(6,11,min-((abs(min/10))*10) ,&paint); - paintNumber(13,11, abs(sec/10) ,&paint); - paintNumber(18,11,sec-((abs(sec/10))*10) ,&paint); + paintNumber(1,11, abs(min/10) ,&paint, 1); + paintNumber(6,11,min-((abs(min/10))*10) ,&paint, 1); + paintNumber(13,11, abs(sec/10) ,&paint, 1); + paintNumber(18,11,sec-((abs(sec/10))*10) ,&paint, 1); } else { - paintDash (1,11,&paint); - paintDash (6,11,&paint); - paintDash (13,11,&paint); - paintDash (18,11,&paint); + paintDash (1,11,&paint, 1); + paintDash (6,11,&paint, 1); + paintDash (13,11,&paint, 1); + paintDash (18,11,&paint, 1); } paint.drawLine (11,12,11,13); paint.drawLine (11,15,11,16); @@ -828,7 +833,7 @@ void KNutDock::paintLoad (int load ) { -void KNutDock::paintNumbers (int numbers, int x, int y, QPainter* p ) { +void KNutDock::paintNumbers (int numbers, int x, int y, QPainter* p, float sizeMult ) { bool first = false; if (numbers > 199) numbers = 199; @@ -836,87 +841,96 @@ void KNutDock::paintNumbers (int numbers, int x, int y, QPainter* p ) { if (numbers != knc::numberVarError) { if (numbers > 99) { - paintNumber (x,y,1,p); + paintNumber (x,y,1,p,sizeMult); numbers -= 100; first=true; } int second = abs (numbers/10); int third = numbers - (second * 10); - if ((second != 0) || (first)) paintNumber (x+5,y,second,p); - paintNumber (x+10,y,third,p); + if ((second != 0) || (first)) paintNumber (((float) x+(5*sizeMult)),y,second,p,sizeMult); + paintNumber (((float) x+(10*sizeMult)),y,third,p,sizeMult); } else { p->setPen(Qt::black); - paintDash (x+5,y,p); - paintDash (x+10,y,p); + paintDash (((float) x+(5*sizeMult)),y,p,sizeMult); + paintDash (((float) x+(10*sizeMult)),y,p,sizeMult); } } -void KNutDock::paintDash (int x, int y, QPainter *p) { - - p->drawLine(x,y+3,x+3,y+3); +void KNutDock::paintDash (int x, int y, QPainter *p, float sizeMult) { + QPen oldPen = p->pen(); + QPen newPen; + newPen.setWidth(((float) (oldPen.width()+1)*sizeMult)-1); + p->setPen(newPen); + p->drawLine(x,((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(3*sizeMult))); + p->setPen(oldPen); } -void KNutDock::paintNumber (int x, int y, int number, QPainter *p) { +void KNutDock::paintNumber (int x, int y, int number, QPainter *p, float sizeMult) { // x and y are left top corner + QPen oldPen = p->pen(); + QPen newPen; + newPen.setWidth(((float) (oldPen.width()+1)*sizeMult)-1); + p->setPen(newPen); if ((number > -1) && (number < 10)) { // painting - kreslim switch (number) { case 0: - p->drawRect(x,y,4,7); + p->drawRect(x,y,((float) 4*sizeMult),((float) 7*sizeMult)); break; case 1: - p->drawLine (x+3,y,x+3,y+6); + p->drawLine (((float) x+(3*sizeMult)),y,((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); break; case 2: - p->drawLine(x,y,x+3,y); - p->lineTo(x+3,y+3); - p->lineTo(x,y+3); - p->lineTo(x,y+6); - p->lineTo(x+3,y+6); + p->drawLine(x,y,((float) x+(3*sizeMult)),y); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(3*sizeMult))); + p->lineTo(x,((float) y+(3*sizeMult))); + p->lineTo(x,((float) y+(6*sizeMult))); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); break; case 3: - p->drawLine(x,y,x+3,y); - p->lineTo(x+3,y+6); - p->lineTo(x,y+6); - p->drawLine(x,y+3,x+3,y+3); + p->drawLine(x,y,((float) x+(3*sizeMult)),y); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); + p->lineTo(x,((float) y+(6*sizeMult))); + p->drawLine(x,((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(3*sizeMult))); break; case 4: - p->drawLine(x,y,x,y+3); - p->lineTo(x+3,y+3); - p->drawLine (x+3,y,x+3,y+6); + p->drawLine(x,y,x,((float) y+(3*sizeMult))); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(3*sizeMult))); + p->drawLine (((float) x+(3*sizeMult)),y,((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); break; case 5: - p->drawLine(x+3,y,x,y); - p->lineTo(x,y+3); - p->lineTo(x+3,y+3); - p->lineTo(x+3,y+6); - p->lineTo(x,y+6); + p->drawLine(((float) x+(3*sizeMult)),y,x,y); + p->lineTo(x,((float) y+(3*sizeMult))); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(3*sizeMult))); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); + p->lineTo(x,((float) y+(6*sizeMult))); break; case 6: - p->drawRect(x,y+3,4,4); - p->drawLine(x,y+3,x,y); - p->lineTo(x+3,y); + p->drawRect(x,((float) y+(3*sizeMult)),((float) 4*sizeMult),((float) 4*sizeMult)); + p->drawLine(x,((float) y+(3*sizeMult)),x,y); + p->lineTo(((float) x+(3*sizeMult)),y); break; case 7: - p->drawLine(x,y,x+3,y); - p->lineTo(x+3,y+6); + p->drawLine(x,y,((float) x+(3*sizeMult)),y); + p->lineTo(((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); break; case 8: - p->drawRect(x,y,4,7); - p->drawLine(x,y+3,x+3,y+3); + p->drawRect(x,y,((float) 4*sizeMult),((float) 7*sizeMult)); + p->drawLine(x,((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(3*sizeMult))); break; case 9: - p->drawRect(x,y,4,4); - p->drawLine(x+3,y+3,x+3,y+6); - p->lineTo(x,y+6); + p->drawRect(x,y,((float) 4*sizeMult),((float) 4*sizeMult)); + p->drawLine(((float) x+(3*sizeMult)),((float) y+(3*sizeMult)),((float) x+(3*sizeMult)),((float) y+(6*sizeMult))); + p->lineTo(x,((float) y+(6*sizeMult))); break; } - } + } + p->setPen(oldPen); } diff --git a/src/knutdock.h b/src/knutdock.h index 15fa69c..7a798bd 100755 --- a/src/knutdock.h +++ b/src/knutdock.h @@ -1,7 +1,7 @@ /*************************************************************************** knutdock.h - description ------------------- - begin : Út zari 23 2003 + begin : �t zari 23 2003 copyright : (C) 2003 by Daniel Prynych email : Daniel.Prynych@alo.cz ***************************************************************************/ @@ -164,7 +164,7 @@ class KNutDock : public KSystemTray { signals: /**This signal is emited when end of application was selected in menu. * Tento signal je vyslan pokud bylo vybrano v menu ukonceni aplikace. - * + * * * @since 0.1 **/ @@ -173,7 +173,7 @@ class KNutDock : public KSystemTray { /** * Tento signal je vyslan pokud bylo vybrano v menu minimalizace aplikace. * Tento signal is emited when minimize application was selected in menu. - * + * * * @since 0.1 **/ @@ -372,7 +372,7 @@ class KNutDock : public KSystemTray { * * @since 0.2 **/ - void paintNumbers (int numbers, int x, int y, QPainter* p ); //x,y levy horni roh cisla 1 + void paintNumbers (int numbers, int x, int y, QPainter* p, float sizeMult ); //x,y levy horni roh cisla 1 /** * @internal @@ -385,7 +385,7 @@ class KNutDock : public KSystemTray { * * @since 0.1 **/ - void paintNumber (int x, int y, int number, QPainter *p); + void paintNumber (int x, int y, int number, QPainter *p, float sizeMult); /** * @internal @@ -410,7 +410,7 @@ class KNutDock : public KSystemTray { * * @since 0.1 **/ - void paintDash (int x, int y, QPainter *p); + void paintDash (int x, int y, QPainter *p, float sizeMult); /** @@ -481,6 +481,8 @@ class KNutDock : public KSystemTray { **/ void clearValues(void); + void resizeEvent ( QResizeEvent * ); + KNutUpsData* m_upsRecords; KNutVarData::SettingDataDef* m_settingData; // v teto strukture jsou ulozeny promene ktere nastavuji konfiguraci |