[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: [PATCH] Tray icon patches
From: Ivor Hewitt <ivor () ivor ! org>
Date: 2005-09-20 19:48:53
Message-ID: 200509202048.53267.ivor () ivor ! org
[Download RAW message or body]
Hi,
Two patches attached for tray icon drawing logic, to take advantage of the
tray icon shrinking.
The behaviour/appearance should be exactly the same as existing if there is no
global tray size setting.
An example of a shrunk tray running on a 1024x768 screen:-
http://img129.imageshack.us/img129/4306/dinkytray5gi.png
Cheers,
--
Ivor Hewitt.
["tray_cpuload.diff" (text/x-diff)]
Index: statdock.cpp
===================================================================
--- statdock.cpp (revision 454662)
+++ statdock.cpp (working copy)
@@ -16,6 +16,7 @@
#include <qpainter.h>
#include <kglobalsettings.h>
+#include <kconfig.h>
const int StatDock::fillLines = 0;
const int StatDock::fillBars = 1;
@@ -29,7 +30,7 @@
const QColor StatDock::colorLowerInactive(125, 125, 125);
const QColor StatDock::colorBlack(0, 0, 0);
-#define DOCK_SIZE 24
+#define DOCK_SIZE (m_iconSize+2)
#define DOCK_SCALE 4.34783 // Approx. 100/23.
#define SOFT_STEP 3
@@ -37,9 +38,18 @@
StatPopup *parent, const char *name) :
KSystemTray(parent,name),
label(useLabel),
- bufUpper(new int[DOCK_SIZE]),
- bufLower(new int[DOCK_SIZE]),
- pos(0) {
+ pos(0),
+ m_iconSize( 22 )
+{
+ //This setting gets here from the kdeglobals config
+ KConfig* config = KGlobal::config();
+ if (config->hasGroup("System Tray"))
+ config->setGroup("System Tray");
+ m_iconSize=config->readNumEntry("systrayIconWidth", 22);
+
+ 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;
@@ -47,7 +57,7 @@
// Initialise the display.
parent->initDock(this, contextMenu(), whichDock);
setBackgroundColor(colorBlack);
- resize(24, 24);
+ resize(DOCK_SIZE, DOCK_SIZE);
show();
}
@@ -147,16 +157,18 @@
// Start by drawing the grid.
if(grid) {
+ int space = DOCK_SIZE/4;
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=space; i<DOCK_SIZE; i+=space )
+ {
+ p.drawLine(0, i, DOCK_SIZE, 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)
@@ -191,20 +203,20 @@
// 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);
@@ -216,19 +228,19 @@
// 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]);
}
Index: statdock.h
===================================================================
--- statdock.h (revision 454662)
+++ statdock.h (working copy)
@@ -150,6 +150,7 @@
/**< The index in our arrays of the most recent reading. */
+ int m_iconSize;
/**
* Temporaries.
*/
["tray_kwifi.diff" (text/x-diff)]
Index: kwifimanager.h
===================================================================
--- kwifimanager.h (revision 457265)
+++ kwifimanager.h (working copy)
@@ -137,6 +137,7 @@
bool showStatsNoise;
bool m_startDocked;
bool m_shuttingDown;
+ int m_iconSize;
};
#endif /* KWIFIMANAGER_H */
Index: kwifimanager.cpp
===================================================================
--- kwifimanager.cpp (revision 457265)
+++ kwifimanager.cpp (working copy)
@@ -65,7 +65,7 @@
bool useAlternateStrengthCalc;
KWiFiManagerApp::KWiFiManagerApp (QWidget *, const char *name):
-DCOPObject("dcop_interface"), KMainWindow (0, name), device(0), \
m_shuttingDown(false) +DCOPObject("dcop_interface"), KMainWindow (0, name), \
device(0), m_shuttingDown(false), m_iconSize( 22 ) {
statistik = 0;
disablePower = 0;
@@ -81,10 +81,22 @@
// substitute the following line with a different interface if required
device = new Interface_wireless_wirelessextensions (ignoreInterfaces);
+ //This setting gets here from the kdeglobals config
+ KConfig* config = kapp->config();
+ if (config->hasGroup("System Tray"))
+ config->setGroup("System Tray");
+ m_iconSize=config->readNumEntry("systrayIconWidth", 22);
+
/* initView updates the main widget, system tray icon and the ASUS led if \
applicable
it needs to called before initActions() because that uses some icons that get
initialized by initView() */
+ config->setGroup("System Tray");
+ m_iconSize=config->readNumEntry("systrayIconWidth", 22);
+ /* initView updates the main widget, system tray icon and the ASUS led if \
applicable + it needs to called before initActions() because that uses some icons \
that get + initialized by initView() */
+
initView ();
initActions ();
@@ -189,12 +201,6 @@
}
void
-KWiFiManagerApp::slotChangeTrayIcon ()
-{
- QPixmap* ICON;
- int sig, noi, str;
- double freq = 0.;
- bool validdata = device->get_current_quality (sig, noi, str);
if ( settingsUseAlternateCalc->isChecked() ) str = sig - noi;
int mode;
QLabel sstrength2( i18n("N/A"), 0, 0 );
@@ -202,6 +208,12 @@
if (!device->get_device_freq (freq))
{
ICON = strength->NOT_CON_OFFLINE_ADHOC;
+ int mode;
+ QLabel sstrength2( i18n("N/A"), 0, 0 );
+
+ if (!device->get_device_freq (freq))
+ {
+ ICON = strength->NOT_CON_OFFLINE_ADHOC;
if (led->state == true)
led->Off ();
}
@@ -255,44 +267,54 @@
}
else if (((str == 0) && (mode == 2)) || (!validdata))
{
- sstrength2.setText( QString::fromLatin1("0") );
- ICON = strength->OOR_DOWN;
- if (led->state == true)
- led->Off ();
- }
- else
{
ICON = strength->NOT_CON_OFFLINE_ADHOC;
if (led->state == true)
led->Off ();
}
- if (showStrength) {
- QPixmap temp (30, 30);
+ if (showStrength) {
+ QPixmap temp (m_iconSize+8, m_iconSize+8);
QPainter bla (&temp);
- bla.fillRect (0, 0, 30, 30, backgroundBrush ());
- bla.drawPixmap ( 1, 4, *ICON );
+ bla.fillRect (0, 0, m_iconSize+8, m_iconSize+8, backgroundBrush ());
+ bla.drawPixmap ( QRect( 1, 4, m_iconSize+2, m_iconSize+2 ), *ICON );
- static QFont labelfont ( "Helvetica", 10 );
-
- labelfont.setStyleHint( QFont::SansSerif );
- labelfont.setStretch( QFont::Condensed );
- labelfont.setBold( true );
- sstrength2.setFont( labelfont );
- sstrength2.setFixedSize( sstrength2.sizeHint() );
- QPixmap labeltemp = QPixmap::grabWidget( &sstrength2 );
- labeltemp.setMask( labeltemp.createHeuristicMask() );
- bla.drawPixmap (0, 0, labeltemp );
- temp.setMask (temp.createHeuristicMask() );
- trayicon->setPixmap ( temp );
- this->setIcon( temp );
- } else {
- trayicon->setPixmap ( *ICON );
- this->setIcon ( *ICON );
- }
+ static QFont labelfont ( "Helvetica", 10 );
+
+ labelfont.setStyleHint( QFont::SansSerif );
+ labelfont.setStretch( QFont::Condensed );
+ labelfont.setBold( true );
+ sstrength2.setFont( labelfont );
+ sstrength2.setFixedSize( sstrength2.sizeHint() );
+ QPixmap labeltemp = QPixmap::grabWidget( &sstrength2 );
+ labeltemp.setMask( labeltemp.createHeuristicMask() );
+ bla.drawPixmap (0, 0, labeltemp );
+ temp.setMask (temp.createHeuristicMask() );
+ trayicon->setPixmap ( temp );
+ this->setIcon ( temp );
+ } else {
+ QPixmap temp (m_iconSize+8, m_iconSize+8);
+ QPainter bla (&temp);
+ bla.fillRect (0, 0, m_iconSize+8, m_iconSize+8, backgroundBrush ());
+ bla.drawPixmap ( QRect( 1, 4, m_iconSize+2, m_iconSize+2 ), *ICON );
+ trayicon->setPixmap ( temp );
+ this->setIcon ( temp );
+ }
+
QToolTip::add( trayicon, "SSID: "+device->get_essid() );
}
+ QPixmap temp (m_iconSize+8, m_iconSize+8);
+ QPainter bla (&temp);
+ bla.fillRect (0, 0, m_iconSize+8, m_iconSize+8, backgroundBrush ());
+ bla.drawPixmap ( QRect( 1, 4, m_iconSize+2, m_iconSize+2 ), *ICON );
+ trayicon->setPixmap ( temp );
+ this->setIcon ( temp );
+ }
+
+ QToolTip::add( trayicon, "SSID: "+device->get_essid() );
+}
+
void
KWiFiManagerApp::initActions ()
{
@@ -303,17 +325,6 @@
SLOT (slotDisableRadio ()), actionCollection (), "disable_radio");
fileDisableRadio->setChecked( false );
- settingsUseAlternateCalc =
- new KToggleAction (i18n ("&Use Alternate Strength Calculation"), 0, this,
- SLOT (slotToggleStrengthCalc ()), actionCollection (), \
"use_alt_calculation");
-
- settingsUseAlternateCalc->setChecked( \
config->readBoolEntry("useAlternateStrengthCalculation") );
- slotToggleStrengthCalc(); //set to value saved by KConfig
-
- settingsShowStatsNoise =
- new KToggleAction (i18n ("Show &Noise Graph in Statistics Window"), 0, this,
- SLOT (slotShowStatsNoise ()), actionCollection (), "show_stats_noise");
-
settingsShowStatsNoise->setChecked( config->readBoolEntry("showStatsNoise") );
slotShowStatsNoise(); //set to value saved by KConfig
@@ -325,6 +336,17 @@
KStdAction::quit (this, SLOT (slotFileQuit ()), actionCollection ());
new KAction (i18n ("Configuration &Editor..."), 0, this,
+ settingsShowStatsNoise->setChecked( config->readBoolEntry("showStatsNoise") );
+ slotShowStatsNoise(); //set to value saved by KConfig
+
+ settingsShowStrengthNumber = new KToggleAction (i18n ("&Show Strength Number in \
System Tray"), 0, this, + SLOT (slotToggleShowStrengthNumber \
()), actionCollection (), "show_strength_number_in_tray"); + \
settingsShowStrengthNumber->setChecked( \
config->readBoolEntry("showStrengthNumberInTray") ); + slotToggleShowStrengthNumber \
(); //set to value saved by KConfig +
+ KStdAction::quit (this, SLOT (slotFileQuit ()), actionCollection ());
+
+ new KAction (i18n ("Configuration &Editor..."), 0, this,
SLOT (slotStartConfigEditor ()), actionCollection (), \
"configuration_editor"); new KAction (i18n ("Connection &Statistics"), 0, this,
SLOT (slotStartStatViewer ()), actionCollection (), \
"connection_statistics"); @@ -384,12 +406,12 @@
connect (device, SIGNAL (speedChanged ()), speedmeter, SLOT (repaint ()));
connect (device, SIGNAL (modeChanged ()), pictogram, SLOT (repaint ()));
connect (device, SIGNAL (essidChanged (QString)), this, SLOT (slotLogESSID \
(QString)));
- connect (device, SIGNAL (essidChanged (QString)), location, SLOT (repaint ()));
- connect (device, SIGNAL (statusChanged ()), location, SLOT (repaint ()));
- connect (device, SIGNAL (txPowerChanged ()), this, SLOT (slotTXPowerChanged ()));
- connect (device, SIGNAL (txPowerChanged ()), pictogram, SLOT (repaint ()));
- connect (device, SIGNAL (txPowerChanged ()), strength, SLOT (repaint ()));
- connect (scan, SIGNAL (clicked()), this, SLOT (slotNetworkScan()));
+ KConfig* config = kapp->config();
+ config->setGroup("General");
+ config->writeEntry( "showStrengthNumberInTray", \
settingsShowStrengthNumber->isChecked() ); + if \
(settingsShowStrengthNumber->isChecked()) { showStrength = true; } + else { \
showStrength = false; } + slotChangeTrayIcon ();
}
void
@@ -398,7 +420,7 @@
KConfig* config = kapp->config();
config->setGroup("General");
config->writeEntry( "showStrengthNumberInTray", \
settingsShowStrengthNumber->isChecked() );
- if (settingsShowStrengthNumber->isChecked()) { showStrength = true; }
+ if (settingsShowStrengthNumber->isChecked()) { showStrength = true; }
else { showStrength = false; }
slotChangeTrayIcon ();
}
@@ -590,17 +612,6 @@
bool
KWiFiManagerApp::queryExit()
-{
- // Save settings if auto-save is enabled, and settings have changed
- if ( settingsDirty() && autoSaveSettings() )
- saveAutoSaveSettings();
- return true;
-}
-
-// List of network interfaces used by all running kwifimanager applications
-QStringList usedInterfacesList()
-{
- // Register with DCOP
DCOPClient *client = kapp->dcopClient();
client->registerAs( "kwifimanager" );
client->setDefaultObject( "dcop_interface" );
@@ -615,6 +626,17 @@
continue;
DCOPRef ask( clientId, "dcop_interface" );
+
+ // shamelessly stolen from kdelibs/kio/booksmarks/kbookmarkimporter_crash.cc
+ QStringList ignoreInterfaces;
+ QCStringList apps = client->registeredApplications();
+ for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it )
+ {
+ QCString &clientId = *it;
+ if ( qstrncmp(clientId, "kwifimanager", 12) != 0 )
+ continue;
+
+ DCOPRef ask( clientId, "dcop_interface" );
DCOPReply reply = ask.call( "interface()" );
QString interface;
if ( reply.isValid() ) {
=
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscrib=
e <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic