• 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
knotestray.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013, 2014 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 "knotestray.h"
19 
20 #include <KIconLoader>
21 #include <KGlobalSettings>
22 #include <KLocalizedString>
23 #include <KColorScheme>
24 
25 #include <QPainter>
26 #include <QWidget>
27 
28 KNotesTray::KNotesTray(QWidget *parent)
29  : KStatusNotifierItem(parent)
30 {
31  setToolTipTitle( i18n( "KNotes: Sticky notes for KDE" ) );
32  setToolTipIconByName( QLatin1String("knotes") );
33  setStatus( KStatusNotifierItem::Active );
34  setCategory( KStatusNotifierItem::ApplicationStatus );
35  setStandardActionsEnabled(false);
36  mIcon = KIcon( QLatin1String("knotes") );
37 }
38 
39 KNotesTray::~KNotesTray()
40 {
41 }
42 
43 void KNotesTray::updateNumberOfNotes(int value)
44 {
45  const int overlaySize = KIconLoader::SizeSmallMedium;
46 
47  const QString countString = QString::number( value );
48  QFont countFont = KGlobalSettings::generalFont();
49  countFont.setBold(true);
50 
51  // decrease the size of the font for the number of unread messages if the
52  // number doesn't fit into the available space
53  float countFontSize = countFont.pointSizeF();
54  QFontMetrics qfm( countFont );
55  const int width = qfm.width( countString );
56  if ( width > (overlaySize - 2) ) {
57  countFontSize *= float( overlaySize - 2 ) / float( width );
58  countFont.setPointSizeF( countFontSize );
59  }
60 
61  // Paint the number in a pixmap
62  QPixmap overlayPixmap( overlaySize, overlaySize );
63  overlayPixmap.fill( Qt::transparent );
64 
65  QPainter p( &overlayPixmap );
66  p.setFont( countFont );
67  KColorScheme scheme( QPalette::Active, KColorScheme::View );
68 
69  p.setBrush( Qt::NoBrush );
70  p.setPen( scheme.foreground( KColorScheme::LinkText ).color() );
71  p.setOpacity( 1.0 );
72  p.drawText( overlayPixmap.rect(),Qt::AlignCenter, countString );
73  p.end();
74 
75  QPixmap iconPixmap = mIcon.pixmap(overlaySize, overlaySize);
76 
77  QPainter pp(&iconPixmap);
78  pp.drawPixmap(0, 0, overlayPixmap);
79  pp.end();
80 
81  setIconByPixmap( iconPixmap );
82 }
83 
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
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)
KNotesTray::KNotesTray
KNotesTray(QWidget *parent=0)
Definition: knotestray.cpp:28
QLatin1String
knotestray.h
KStatusNotifierItem
QPixmap::rect
QRect rect() const
KNotesTray::updateNumberOfNotes
void updateNumberOfNotes(int value)
Definition: knotestray.cpp:43
KNotesTray::~KNotesTray
~KNotesTray()
Definition: knotestray.cpp:39
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