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

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
  • apps
knotesakonaditray.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "knotesakonaditray.h"
19 #include <Akonadi/ChangeRecorder>
20 #include "knotesglobalconfig.h"
21 
22 #include <KIconLoader>
23 #include <KGlobalSettings>
24 #include <KLocalizedString>
25 #include <KColorScheme>
26 
27 #include <QPainter>
28 #include <QWidget>
29 
30 KNotesAkonadiTray::KNotesAkonadiTray(QWidget *parent)
31  : KStatusNotifierItem(parent)
32 {
33  setToolTipTitle( i18n( "KNotes: Sticky notes for KDE" ) );
34  setToolTipIconByName( QLatin1String("knotes") );
35  setStatus( KStatusNotifierItem::Active );
36  setCategory( KStatusNotifierItem::ApplicationStatus );
37  setStandardActionsEnabled(false);
38  mIcon = KIcon( QLatin1String("knotes") );
39  //Initialize
40  updateNumberOfNotes(0);
41  connect( KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(slotGeneralPaletteChanged()));
42 }
43 
44 KNotesAkonadiTray::~KNotesAkonadiTray()
45 {
46 }
47 
48 void KNotesAkonadiTray::slotGeneralPaletteChanged()
49 {
50  const KColorScheme scheme( QPalette::Active, KColorScheme::View );
51  mTextColor = scheme.foreground( KColorScheme::LinkText ).color();
52 }
53 
54 void KNotesAkonadiTray::updateNumberOfNotes(int number)
55 {
56  if (KNotesGlobalConfig::self()->systemTrayShowNotes() && number != 0) {
57  const int overlaySize = KIconLoader::SizeSmallMedium;
58 
59  const QString countString = QString::number( number );
60  QFont countFont = KGlobalSettings::generalFont();
61  countFont.setBold(true);
62 
63  // decrease the size of the font for the number of unread messages if the
64  // number doesn't fit into the available space
65  float countFontSize = countFont.pointSizeF();
66  QFontMetrics qfm( countFont );
67  const int width = qfm.width( countString );
68  if ( width > (overlaySize - 2) ) {
69  countFontSize *= float( overlaySize - 2 ) / float( width );
70  countFont.setPointSizeF( countFontSize );
71  }
72 
73  // Paint the number in a pixmap
74  QPixmap overlayPixmap( overlaySize, overlaySize );
75  overlayPixmap.fill( Qt::transparent );
76 
77  QPainter p( &overlayPixmap );
78  p.setFont( countFont );
79  if (!mTextColor.isValid()) {
80  slotGeneralPaletteChanged();
81  }
82 
83  p.setBrush( Qt::NoBrush );
84  p.setPen(mTextColor);
85  p.setOpacity( 1.0 );
86  p.drawText( overlayPixmap.rect(),Qt::AlignCenter, countString );
87  p.end();
88 
89  QPixmap iconPixmap = mIcon.pixmap(overlaySize, overlaySize);
90 
91  QPainter pp(&iconPixmap);
92  pp.drawPixmap(0, 0, overlayPixmap);
93  pp.end();
94 
95  setIconByPixmap( iconPixmap );
96  } else {
97  setIconByPixmap(mIcon);
98  }
99 }
100 
QPainter::setOpacity
void setOpacity(qreal opacity)
QWidget
QPainter::end
bool end()
QPixmap::fill
void fill(const QColor &color)
QFont::pointSizeF
qreal pointSizeF() const
QFont
QFontMetrics
QFont::setBold
void setBold(bool enable)
QPainter::setFont
void setFont(const QFont &font)
QString::number
QString number(int n, int base)
QPainter::setPen
void setPen(const QColor &color)
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
knotesakonaditray.h
QPainter::setBrush
void setBrush(const QBrush &brush)
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QString
QPixmap
QFontMetrics::width
int width(const QString &text, int len) const
QFont::setPointSizeF
void setPointSizeF(qreal pointSize)
QLatin1String
KNotesAkonadiTray::~KNotesAkonadiTray
~KNotesAkonadiTray()
Definition: knotesakonaditray.cpp:44
KNotesAkonadiTray::KNotesAkonadiTray
KNotesAkonadiTray(QWidget *parent=0)
Definition: knotesakonaditray.cpp:30
KStatusNotifierItem
QPixmap::rect
QRect rect() const
KNotesAkonadiTray::updateNumberOfNotes
void updateNumberOfNotes(int number)
Definition: knotesakonaditray.cpp:54
QColor::isValid
bool isValid() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • 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
  • pimprint

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