• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

calendar.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net>           *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00018  ***************************************************************************/
00019 
00020 #include <QGraphicsLayout>
00021 #include <QPainter>
00022 
00023 #include <KDebug>
00024 #include <KIcon>
00025 
00026 #include <Plasma/Svg>
00027 #include <Plasma/Theme>
00028 
00029 #include "calendar.h"
00030 
00031 
00032 CalendarTest::CalendarTest(QObject *parent, const QVariantList &args)
00033     : Plasma::PopupApplet(parent, args),
00034     m_calendarDialog(0),
00035     m_theme(0)
00036 {
00037     setAspectRatioMode(Plasma::IgnoreAspectRatio);
00038 }
00039 
00040 void CalendarTest::init()
00041 {
00042     setPopupIcon("view-pim-calendar");
00043 }
00044 
00045 QGraphicsWidget *CalendarTest::graphicsWidget()
00046 {
00047     if (!m_calendarDialog) {
00048         m_calendarDialog = new Plasma::Calendar(this);
00049         m_calendarDialog->setPreferredSize(220, 250);
00050     }
00051 
00052     return m_calendarDialog;
00053 }
00054 
00055 CalendarTest::~CalendarTest()
00056 {
00057 
00058 }
00059 
00060 void CalendarTest::constraintsEvent(Plasma::Constraints constraints)
00061 {
00062     if (!m_calendarDialog) {
00063         graphicsWidget();
00064     }
00065 
00066     if ((constraints|Plasma::FormFactorConstraint || constraints|Plasma::SizeConstraint) && 
00067         layout()->itemAt(0) != m_calendarDialog) {
00068         paintIcon();
00069     }
00070 }
00071 
00072 void CalendarTest::paintIcon()
00073 {
00074     //TODO: connect to a dataengine to repaint this thing on date change
00075     const int iconSize = qMin(size().width(), size().height());
00076 
00077     if (iconSize <= 0) {
00078         return;
00079     }
00080 
00081     QPixmap icon(iconSize, iconSize);
00082 
00083     if (!m_theme) {
00084         m_theme = new Plasma::Svg(this);
00085         m_theme->setImagePath("calendar/mini-calendar");
00086         m_theme->setContainsMultipleImages(true);
00087     }
00088 
00089     icon.fill(Qt::transparent);
00090     QPainter p(&icon);
00091 
00092     m_theme->paint(&p, icon.rect(), "mini-calendar");
00093 
00094     QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
00095     p.setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
00096     font.setPixelSize(icon.size().height() / 2);
00097     p.setFont(font);
00098     p.drawText(icon.rect().adjusted(0, icon.size().height()/4, 0, 0), Qt::AlignCenter, QString::number(QDate::currentDate().day()));
00099     m_theme->resize();
00100     p.end();
00101     setPopupIcon(icon);
00102 }
00103 
00104 void CalendarTest::configAccepted()
00105 {
00106     update();
00107 }
00108 
00109 #include "calendar.moc"

Applets

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

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal