14 #include <tqptrlist.h>
17 #include <tqtooltip.h>
19 #include <tdeaction.h>
20 #include <tdeglobal.h>
21 #include <tdeglobalsettings.h>
22 #include <kiconloader.h>
23 #include <tdelocale.h>
24 #include <tdepopupmenu.h>
25 #include <ksystemtray.h>
27 #include "mainwindow.h"
31 TQPtrVector<TQPixmap> *KarmTray::icons = 0;
34 : KSystemTray(parent,
"Karm Tray")
37 _taskActiveTimer =
new TQTimer(
this);
38 connect( _taskActiveTimer, TQ_SIGNAL( timeout() ),
this,
39 TQ_SLOT( advanceClock()) );
42 icons =
new TQPtrVector<TQPixmap>(8);
43 for (
int i=0; i<8; i++) {
44 TQPixmap *icon =
new TQPixmap();
46 name.sprintf(
"active-icon-%d.xpm",i);
47 *icon = UserIcon(name);
48 icons->insert(i,icon);
52 parent->actionPreferences->plug( contextMenu() );
53 parent->actionStopAll->plug( contextMenu() );
74 KarmTray::KarmTray(
karmPart * parent)
75 : KSystemTray( 0 ,
"Karm Tray")
94 void KarmTray::startClock()
96 if ( _taskActiveTimer )
98 _taskActiveTimer->start(1000);
99 setPixmap( *(*icons)[_activeIcon] );
104 void KarmTray::stopClock()
106 if ( _taskActiveTimer )
108 _taskActiveTimer->stop();
113 void KarmTray::advanceClock()
115 _activeIcon = (_activeIcon+1) % 8;
116 setPixmap( *(*icons)[_activeIcon]);
119 void KarmTray::resetClock()
122 setPixmap( *(*icons)[_activeIcon]);
126 void KarmTray::initToolTip()
128 updateToolTip(TQPtrList<Task> ());
131 void KarmTray::updateToolTip(TQPtrList<Task> activeTasks)
133 if ( activeTasks.isEmpty() ) {
134 TQToolTip::add(
this, i18n(
"No active tasks") );
138 TQFontMetrics fm( TQToolTip::font() );
139 const TQString continued = i18n(
", ..." );
140 const int buffer = fm.boundingRect( continued ).width();
141 const int desktopWidth = TDEGlobalSettings::desktopGeometry(
this).width();
142 const int maxWidth = desktopWidth - buffer;
150 TQPtrListIterator<Task> item( activeTasks );
151 for (
int i = 0; item.current(); ++item, ++i ) {
152 Task* task = item.current();
154 s += i18n(
", " ) + task->
name();
157 int width = fm.boundingRect( s ).width();
158 if ( width > maxWidth ) {
165 TQToolTip::add(
this, qTip );
Main window to tie the application together.
A class representing a task.
TQString name() const
returns the name of this task.