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

kapptemplate

  • sources
  • kde-4.12
  • kdesdk
  • kapptemplate
  • templates
  • C++
  • plasmoid
plasmoid/%{APPNAMELC}.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
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 *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18  ***************************************************************************/
19 
20 #include "%{APPNAMELC}.h"
21 #include <QPainter>
22 #include <QFontMetrics>
23 #include <QSizeF>
24 #include <KLocale>
25 
26 #include <plasma/svg.h>
27 #include <plasma/theme.h>
28 
29 %{APPNAME}::%{APPNAME}(QObject *parent, const QVariantList &args)
30  : Plasma::Applet(parent, args),
31  m_svg(this),
32  m_icon("document")
33 {
34  // this will get us the standard applet background, for free!
35  setBackgroundHints(DefaultBackground);
36  m_svg.setImagePath("widgets/background");
37  setHasConfigurationInterface(true);
38  resize(200, 200);
39 }
40 
41 
42 %{APPNAME}::~%{APPNAME}()
43 {
44  if (hasFailedToLaunch()) {
45  // Do some cleanup here
46  } else {
47  // Save settings
48  }
49 }
50 
51 void %{APPNAME}::init()
52 {
53  // A small demonstration of the setFailedToLaunch function
54  if (m_icon.isNull()) {
55  setFailedToLaunch(true, i18n("No world to say hello"));
56  }
57 }
58 
59 
60 void %{APPNAME}::paintInterface(QPainter *p,
61  const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
62 {
63  p->setRenderHint(QPainter::SmoothPixmapTransform);
64  p->setRenderHint(QPainter::Antialiasing);
65 
66  // Now we draw the applet, starting with our svg
67  m_svg.resize((int)contentsRect.width(), (int)contentsRect.height());
68  m_svg.paint(p, (int)contentsRect.left(), (int)contentsRect.top());
69 
70  // We place the icon and text on our background
71  p->drawPixmap(25, 40, m_icon.pixmap((int)contentsRect.width(),(int)contentsRect.width()-50));
72  p->save();
73  p->setPen(Qt::white);
74  p->setFont(QFont("Times", 15, QFont::Bold));
75  p->drawText(contentsRect,
76  Qt::AlignBottom | Qt::AlignHCenter,
77  i18n("Hello Plasmoid!"));
78  p->restore();
79 }
80 
81 #include "%{APPNAMELC}.moc"
m_svg
m_svg(this)
m_icon
m_icon("document")
Definition: plasmoid/%{APPNAMELC}.cpp:32
init
void init()
%{APPNAMELC}.h
APPNAME
main APPNAME
paintInterface
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapptemplate

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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