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

akregator

  • sources
  • kde-4.12
  • kdepim
  • akregator
  • src
trayicon.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "trayicon.h"
26 #include "akregatorconfig.h"
27 
28 #include <kapplication.h>
29 #include <kwindowsystem.h>
30 #include <kdebug.h>
31 #include <klocale.h>
32 #include <kglobalsettings.h>
33 #include <kmenu.h>
34 #include <kicon.h>
35 #include <kiconloader.h>
36 #include <KColorScheme>
37 
38 #include <QPainter>
39 #include <QBitmap>
40 #include <QDesktopWidget>
41 
42 
43 namespace Akregator {
44 
45 TrayIcon* TrayIcon::m_instance = 0;
46 
47 TrayIcon* TrayIcon::getInstance()
48 {
49  return m_instance;
50 }
51 
52 void TrayIcon::setInstance(TrayIcon* trayIcon)
53 {
54  m_instance = trayIcon;
55 }
56 
57 
58 TrayIcon::TrayIcon(QObject* parent)
59  : KStatusNotifierItem(parent), m_unread(0)
60 {
61  setToolTipTitle( i18n("Akregator") );
62  setToolTipIconByName( i18n("Akregator") );
63  setIconByName( QLatin1String("akregator") );
64  m_defaultIcon = KIcon( QLatin1String("akregator") );
65 }
66 
67 
68 TrayIcon::~TrayIcon()
69 {}
70 
71 void TrayIcon::slotSetUnread(int unread)
72 {
73  m_unread = unread;
74 
75  this->setToolTip( m_defaultIcon.name(), i18n("Akregator"), unread == 0 ? i18n("There are no unread articles") : i18np( "1 unread article", "%1 unread articles", unread ) );
76  setStatus( unread > 0 ? KStatusNotifierItem::Active : KStatusNotifierItem::Passive );
77 
78  if (unread <= 0 || !Settings::enableTrayIconUnreadArticleCount())
79  {
80  setIconByName( m_defaultIcon.name() );
81  }
82  else
83  {
84  // adapted from KMSystemTray::updateCount()
85  int oldWidth = KIconLoader::SizeSmallMedium;
86 
87  QString countStr = QString::number( unread );
88  QFont f = KGlobalSettings::generalFont();
89  f.setBold(true);
90 
91  float pointSize = f.pointSizeF();
92  QFontMetrics fm(f);
93  int w = fm.width(countStr);
94  if( w > (oldWidth - 2) )
95  {
96  pointSize *= float(oldWidth - 2) / float(w);
97  f.setPointSizeF(pointSize);
98  }
99 
100  // overlay
101  QPixmap overlayImg( oldWidth, oldWidth );
102  overlayImg.fill( Qt::transparent );
103 
104  QPainter p(&overlayImg);
105  p.setFont(f);
106  KColorScheme scheme(QPalette::Active, KColorScheme::View);
107 
108  fm = QFontMetrics(f);
109  QRect boundingRect = fm.tightBoundingRect(countStr);
110  boundingRect.adjust(0, 0, 0, 2);
111  boundingRect.setHeight(qMin(boundingRect.height(), oldWidth));
112  boundingRect.moveTo((oldWidth - boundingRect.width()) / 2,
113  ((oldWidth - boundingRect.height()) / 2) - 1);
114  p.setOpacity(0.7);
115  p.setBrush(scheme.background(KColorScheme::LinkBackground));
116  p.setPen(scheme.background(KColorScheme::LinkBackground).color());
117  p.drawRoundedRect(boundingRect, 2.0, 2.0);
118 
119  p.setBrush(Qt::NoBrush);
120  p.setPen(scheme.foreground(KColorScheme::LinkText).color());
121  p.setOpacity(1.0);
122  p.drawText(overlayImg.rect(), Qt::AlignCenter, countStr);
123  p.end();
124 
125  QPixmap iconPixmap = m_defaultIcon.pixmap( oldWidth, oldWidth );
126 
127  QPainter pp( &iconPixmap );
128  pp.drawPixmap( 0, 0, overlayImg );
129  pp.end();
130 
131  setIconByPixmap( iconPixmap );
132  }
133 }
134 
135 void TrayIcon::viewButtonClicked()
136 {
137  QWidget* p = static_cast<QWidget*>(parent());
138  KWindowSystem::activateWindow(p->winId());
139 }
140 
141 void TrayIcon::settingsChanged()
142 {
143  slotSetUnread(m_unread);
144 }
145 
146 } // namespace Akregator
147 
148 #include "trayicon.moc"
Akregator::TrayIcon
Definition: trayicon.h:39
Akregator::Settings::enableTrayIconUnreadArticleCount
static bool enableTrayIconUnreadArticleCount()
Get Display an unread article count in the tray icon.
Definition: akregatorconfig.h:619
QWidget
QObject
Akregator::TrayIcon::slotSetUnread
void slotSetUnread(int unread)
Definition: trayicon.cpp:71
akregatorconfig.h
Akregator::TrayIcon::setInstance
static void setInstance(TrayIcon *trayIcon)
Definition: trayicon.cpp:52
Akregator::TrayIcon::~TrayIcon
~TrayIcon()
Definition: trayicon.cpp:68
trayicon.h
Akregator::TrayIcon::settingsChanged
void settingsChanged()
Definition: trayicon.cpp:141
Akregator::TrayIcon::getInstance
static TrayIcon * getInstance()
Definition: trayicon.cpp:47
Akregator::TrayIcon::viewButtonClicked
void viewButtonClicked()
Definition: trayicon.cpp:135
Akregator::TrayIcon::TrayIcon
TrayIcon(QObject *parent=0)
Definition: trayicon.cpp:58
KStatusNotifierItem
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

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

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