1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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 <tqkeycode.h>
// #include <tqlayout.h>
#include <tqpixmap.h>
#include <tqptrlist.h>
#include <tqstring.h>
#include <tqtimer.h>
#include <tqtooltip.h>
#include <tdeaction.h> // actionPreferences()
#include <tdeglobal.h>
#include <tdeglobalsettings.h>
#include <kiconloader.h> // UserIcon
#include <tdelocale.h> // i18n
#include <tdepopupmenu.h> // plug()
#include <ksystemtray.h>
#include "mainwindow.h"
#include "task.h"
#include "tray.h"
TQPtrVector<TQPixmap> *KarmTray::icons = 0;
KarmTray::KarmTray(MainWindow* parent)
: KSystemTray(parent, "Karm Tray")
{
// the timer that updates the "running" icon in the tray
_taskActiveTimer = new TQTimer(this);
connect( _taskActiveTimer, TQT_SIGNAL( timeout() ), this,
TQT_SLOT( advanceClock()) );
if (icons == 0) {
icons = new TQPtrVector<TQPixmap>(8);
for (int i=0; i<8; i++) {
TQPixmap *icon = new TQPixmap();
TQString 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 TQPopupMenu();
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(TQString 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(TQPtrList<Task> ());
}
void KarmTray::updateToolTip(TQPtrList<Task> activeTasks)
{
if ( activeTasks.isEmpty() ) {
TQToolTip::add( this, i18n("No active tasks") );
return;
}
TQFontMetrics fm( TQToolTip::font() );
const TQString continued = i18n( ", ..." );
const int buffer = fm.boundingRect( continued ).width();
const int desktopWidth = TDEGlobalSettings::desktopGeometry(this).width();
const int maxWidth = desktopWidth - buffer;
TQString qTip;
TQString 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.
TQPtrListIterator<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;
}
TQToolTip::add( this, qTip );
}
#include "tray.moc"
|