• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

ktimetracker

  • sources
  • kde-4.12
  • kdepim
  • ktimetracker
tray.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 by Scott Monachello <smonach@cox.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the
16  * Free Software Foundation, Inc.
17  * 51 Franklin Street, Fifth Floor
18  * Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 /*
23  * TrayIcon.
24  *
25  * This implements the functionality of the little icon in the kpanel
26  * tray. Among which are tool tips and the running clock animated icon
27  */
28 
29 #include "tray.h"
30 
31 #include <QPixmap>
32 #include <QString>
33 #include <QTimer>
34 #include <QToolTip>
35 #include <QMenu>
36 
37 #include <KAction>
38 #include <KGlobalSettings>
39 #include <KLocale>
40 #include <KMenu>
41 #include <KDebug>
42 #include "mainwindow.h"
43 #include "task.h"
44 #include "timetrackerwidget.h"
45 
46 QVector<QPixmap*> *TrayIcon::icons = 0;
47 
48 TrayIcon::TrayIcon(MainWindow* parent)
49  : KStatusNotifierItem(parent)
50 {
51  setObjectName( "Ktimetracker Tray" );
52  // the timer that updates the "running" icon in the tray
53  _taskActiveTimer = new QTimer(this);
54  connect( _taskActiveTimer, SIGNAL(timeout()), this,
55  SLOT(advanceClock()) );
56 
57  if (icons == 0)
58  {
59  icons = new QVector<QPixmap*>(8);
60  for (int i=0; i<8; ++i)
61  {
62  QPixmap *icon = new QPixmap();
63  QString name;
64  name.sprintf("active-icon-%d.xpm",i);
65  *icon = UserIcon(name);
66  icons->insert(i,icon);
67  }
68  }
69  TimetrackerWidget *timetrackerWidget = static_cast< TimetrackerWidget * >( parent->centralWidget() );
70  if ( timetrackerWidget )
71  {
72  KAction *action = timetrackerWidget->action( "configure_ktimetracker" );
73  if ( action ) contextMenu()->addAction( action );
74  action = timetrackerWidget->action( "stopAll" );
75  if ( action ) contextMenu()->addAction( action );
76  }
77  resetClock();
78  initToolTip();
79 }
80 
81 TrayIcon::TrayIcon(ktimetrackerpart *)
82  : KStatusNotifierItem( 0 )
83 {
84  setObjectName( "Ktimetracker Tray" );
85  // it is not convenient if every kpart gets an icon in the systray.
86  _taskActiveTimer = 0;
87 }
88 
89 TrayIcon::TrayIcon()
90  : KStatusNotifierItem( 0 )
91 // will display nothing at all
92 {
93  setObjectName( "Ktimetracker Tray" );
94  _taskActiveTimer = 0;
95 }
96 
97 TrayIcon::~TrayIcon()
98 {
99 }
100 
101 void TrayIcon::startClock()
102 {
103  kDebug(5970) << "Entering function";
104  if ( _taskActiveTimer )
105  {
106  _taskActiveTimer->start(1000);
107  setIconByPixmap( *(*icons)[_activeIcon] );
108  }
109  kDebug(5970) << "Leaving function";
110 }
111 
112 void TrayIcon::stopClock()
113 {
114  kDebug(5970) << "Entering function";
115  if ( _taskActiveTimer )
116  {
117  _taskActiveTimer->stop();
118  }
119  kDebug(5970) << "Leaving function";
120 }
121 
122 void TrayIcon::advanceClock()
123 {
124  _activeIcon = (_activeIcon+1) % 8;
125  setIconByPixmap( *(*icons)[_activeIcon]);
126 }
127 
128 void TrayIcon::resetClock()
129 {
130  _activeIcon = 0;
131  setIconByPixmap( *(*icons)[_activeIcon]);
132 }
133 
134 void TrayIcon::initToolTip()
135 {
136  updateToolTip(QList<Task*> ());
137 }
138 
139 void TrayIcon::updateToolTip(QList<Task*> activeTasks)
140 {
141  if ( activeTasks.isEmpty() )
142  {
143  this->setToolTip( "ktimetracker", "ktimetracker", i18n("No active tasks") );
144  return;
145  }
146 
147  QFontMetrics fm( QToolTip::font() );
148  const QString continued = i18n( ", ..." );
149  const int buffer = fm.boundingRect( continued ).width();
150  const int desktopWidth = KGlobalSettings::desktopGeometry(associatedWidget()).width();
151  const int maxWidth = desktopWidth - buffer;
152 
153  QString qTip;
154  QString s;
155 
156  // Build the tool tip with all of the names of the active tasks.
157  // If at any time the width of the tool tip is larger than the desktop,
158  // stop building it.
159 
160  for ( int i = 0; i < activeTasks.count(); ++i )
161  {
162  Task* task = activeTasks.at( i );
163  if ( i > 0 )
164  s += i18n( ", " ) + task->name();
165  else
166  s += task->name();
167  int width = fm.boundingRect( s ).width();
168  if ( width > maxWidth )
169  {
170  qTip += continued;
171  break;
172  }
173  qTip = s;
174  }
175  this->setToolTip( "ktimetracker", "ktimetracker", qTip );
176 }
177 
178 #include "tray.moc"
timetrackerwidget.h
TrayIcon::stopClock
void stopClock()
Definition: tray.cpp:112
TimetrackerWidget
Definition: timetrackerwidget.h:36
TrayIcon::advanceClock
void advanceClock()
Definition: tray.cpp:122
TrayIcon::initToolTip
void initToolTip()
Definition: tray.cpp:134
Task::name
QString name() const
returns the name of this task.
Definition: task.cpp:680
TrayIcon::startClock
void startClock()
Definition: tray.cpp:101
TrayIcon::resetClock
void resetClock()
Definition: tray.cpp:128
TrayIcon::updateToolTip
void updateToolTip(QList< Task * > activeTasks)
Definition: tray.cpp:139
mainwindow.h
tray.h
task.h
name
const char * name
Definition: toolicons.h:159
KStatusNotifierItem
ktimetrackerpart
This is a "Part".
Definition: ktimetrackerpart.h:41
TimetrackerWidget::action
KAction * action(const QString &name) const
returns a generated action by name.
Definition: timetrackerwidget.cpp:338
Task
A class representing a task.
Definition: task.h:54
MainWindow
Main window to tie the application together.
Definition: mainwindow.h:43
TrayIcon::~TrayIcon
~TrayIcon()
Definition: tray.cpp:97
TrayIcon::TrayIcon
TrayIcon()
Definition: tray.cpp:89
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktimetracker

Skip menu "ktimetracker"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal