1 /***************************************************************************
2 * Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net> *
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. *
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. *
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>
27 #include <Plasma/Theme>
32 CalendarTest::CalendarTest(QObject
*parent
, const QVariantList
&args
)
33 : Plasma::PopupApplet(parent
, args
),
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
) {
66 if ((constraints
|Plasma::FormFactorConstraint
|| constraints
|Plasma::SizeConstraint
) &&
67 layout()->itemAt(0) != m_calendarDialog
) {
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());
81 QPixmap
icon(iconSize
, iconSize
);
84 m_theme
= new Plasma::Svg(this);
85 m_theme
->setImagePath("calendar/mini-calendar");
86 m_theme
->setContainsMultipleImages(true);
89 icon
.fill(Qt::transparent
);
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);
98 p
.drawText(icon
.rect().adjusted(0, icon
.size().height()/4, 0, 0), Qt::AlignCenter
, QString::number(QDate::currentDate().day()));
104 void CalendarTest::configAccepted()
109 #include "calendar.moc"