add more spacing
[personal-kdebase.git] / workspace / plasma / applets / calendar / calendar.cpp
blob98438cf0e8856ba7cb737cf88210f6ba1a9e343a
1 /***************************************************************************
2 * Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net> *
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 ***************************************************************************/
20 #include <QGraphicsLayout>
21 #include <QPainter>
23 #include <KDebug>
24 #include <KIcon>
26 #include <Plasma/Svg>
27 #include <Plasma/Theme>
29 #include "calendar.h"
32 CalendarTest::CalendarTest(QObject *parent, const QVariantList &args)
33 : Plasma::PopupApplet(parent, args),
34 m_calendarDialog(0),
35 m_theme(0)
37 setAspectRatioMode(Plasma::IgnoreAspectRatio);
40 void CalendarTest::init()
42 setPopupIcon("view-pim-calendar");
45 QGraphicsWidget *CalendarTest::graphicsWidget()
47 if (!m_calendarDialog) {
48 m_calendarDialog = new Plasma::Calendar(this);
49 m_calendarDialog->setPreferredSize(220, 250);
52 return m_calendarDialog;
55 CalendarTest::~CalendarTest()
60 void CalendarTest::constraintsEvent(Plasma::Constraints constraints)
62 if (!m_calendarDialog) {
63 graphicsWidget();
66 if ((constraints|Plasma::FormFactorConstraint || constraints|Plasma::SizeConstraint) &&
67 layout()->itemAt(0) != m_calendarDialog) {
68 paintIcon();
72 void CalendarTest::paintIcon()
74 //TODO: connect to a dataengine to repaint this thing on date change
75 const int iconSize = qMin(size().width(), size().height());
77 if (iconSize <= 0) {
78 return;
81 QPixmap icon(iconSize, iconSize);
83 if (!m_theme) {
84 m_theme = new Plasma::Svg(this);
85 m_theme->setImagePath("calendar/mini-calendar");
86 m_theme->setContainsMultipleImages(true);
89 icon.fill(Qt::transparent);
90 QPainter p(&icon);
92 m_theme->paint(&p, icon.rect(), "mini-calendar");
94 QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
95 p.setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
96 font.setPixelSize(icon.size().height() / 2);
97 p.setFont(font);
98 p.drawText(icon.rect().adjusted(0, icon.size().height()/4, 0, 0), Qt::AlignCenter, QString::number(QDate::currentDate().day()));
99 m_theme->resize();
100 p.end();
101 setPopupIcon(icon);
104 void CalendarTest::configAccepted()
106 update();
109 #include "calendar.moc"