summaryrefslogtreecommitdiffstats
path: root/karm/tray.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /karm/tray.cpp
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'karm/tray.cpp')
-rw-r--r--karm/tray.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/karm/tray.cpp b/karm/tray.cpp
new file mode 100644
index 000000000..228d807d8
--- /dev/null
+++ b/karm/tray.cpp
@@ -0,0 +1,168 @@
+/*
+* KTray.
+*
+* This implements the functionality of the little icon in the kpanel
+* tray. Among which are tool tips and the running clock animated icon
+*
+* Distributed under the GPL.
+*/
+
+
+// #include <qkeycode.h>
+// #include <qlayout.h>
+#include <qpixmap.h>
+#include <qptrlist.h>
+#include <qstring.h>
+#include <qtimer.h>
+#include <qtooltip.h>
+
+#include <kaction.h> // actionPreferences()
+#include <kglobal.h>
+#include <kglobalsettings.h>
+#include <kiconloader.h> // UserIcon
+#include <klocale.h> // i18n
+#include <kpopupmenu.h> // plug()
+#include <ksystemtray.h>
+
+#include "mainwindow.h"
+#include "task.h"
+#include "tray.h"
+
+QPtrVector<QPixmap> *KarmTray::icons = 0;
+
+KarmTray::KarmTray(MainWindow* parent)
+ : KSystemTray(parent, "Karm Tray")
+{
+ // the timer that updates the "running" icon in the tray
+ _taskActiveTimer = new QTimer(this);
+ connect( _taskActiveTimer, SIGNAL( timeout() ), this,
+ SLOT( advanceClock()) );
+
+ if (icons == 0) {
+ icons = new QPtrVector<QPixmap>(8);
+ for (int i=0; i<8; i++) {
+ QPixmap *icon = new QPixmap();
+ QString name;
+ name.sprintf("active-icon-%d.xpm",i);
+ *icon = UserIcon(name);
+ icons->insert(i,icon);
+ }
+ }
+
+ parent->actionPreferences->plug( contextMenu() );
+ parent->actionStopAll->plug( contextMenu() );
+
+ resetClock();
+ initToolTip();
+
+ // start of a kind of menu for the tray
+ // this are experiments/tests
+ /*
+ for (int i=0; i<30; i++)
+ _tray->insertTitle(i 18n("bla ").arg(i));
+ for (int i=0; i<30; i++)
+ _tray->insertTitle2(i 18n("bli ").arg(i));
+ */
+ // experimenting with menus for the tray
+ /*
+ trayPopupMenu = contextMenu();
+ trayPopupMenu2 = new QPopupMenu();
+ trayPopupMenu->insertItem(i18n("Submenu"), *trayPopupMenu2);
+ */
+}
+
+KarmTray::KarmTray(karmPart * parent)
+ : KSystemTray( 0 , "Karm Tray")
+{
+// it is not convenient if every kpart gets an icon in the systray.
+ _taskActiveTimer = 0;
+}
+
+KarmTray::~KarmTray()
+{
+}
+
+
+// experiment
+/*
+void KarmTray::insertTitle(QString title)
+{
+ trayPopupMenu->insertTitle(title);
+}
+*/
+
+void KarmTray::startClock()
+{
+ if ( _taskActiveTimer )
+ {
+ _taskActiveTimer->start(1000);
+ setPixmap( *(*icons)[_activeIcon] );
+ show();
+ }
+}
+
+void KarmTray::stopClock()
+{
+ if ( _taskActiveTimer )
+ {
+ _taskActiveTimer->stop();
+ show();
+ }
+}
+
+void KarmTray::advanceClock()
+{
+ _activeIcon = (_activeIcon+1) % 8;
+ setPixmap( *(*icons)[_activeIcon]);
+}
+
+void KarmTray::resetClock()
+{
+ _activeIcon = 0;
+ setPixmap( *(*icons)[_activeIcon]);
+ show();
+}
+
+void KarmTray::initToolTip()
+{
+ updateToolTip(QPtrList<Task> ());
+}
+
+void KarmTray::updateToolTip(QPtrList<Task> activeTasks)
+{
+ if ( activeTasks.isEmpty() ) {
+ QToolTip::add( this, i18n("No active tasks") );
+ return;
+ }
+
+ QFontMetrics fm( QToolTip::font() );
+ const QString continued = i18n( ", ..." );
+ const int buffer = fm.boundingRect( continued ).width();
+ const int desktopWidth = KGlobalSettings::desktopGeometry(this).width();
+ const int maxWidth = desktopWidth - buffer;
+
+ QString qTip;
+ QString s;
+
+ // Build the tool tip with all of the names of the active tasks.
+ // If at any time the width of the tool tip is larger than the desktop,
+ // stop building it.
+ QPtrListIterator<Task> item( activeTasks );
+ for ( int i = 0; item.current(); ++item, ++i ) {
+ Task* task = item.current();
+ if ( i > 0 )
+ s += i18n( ", " ) + task->name();
+ else
+ s += task->name();
+ int width = fm.boundingRect( s ).width();
+ if ( width > maxWidth ) {
+ qTip += continued;
+ break;
+ }
+ qTip = s;
+ }
+
+ QToolTip::add( this, qTip );
+}
+
+#include "tray.moc"