1
/***************************************************************************
2
* Copyright 2008 by Davide Bettio <davide.bettio@kdemail.net> *
3
* Copyright 2009 by John Layt <john@layt.net> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
19
***************************************************************************/
23
#include <QGraphicsLayout>
28
#include <KSystemTimeZones>
29
#include <KConfigDialog>
30
#include <KConfigGroup>
33
#include <Plasma/Theme>
35
CalendarApplet::CalendarApplet(QObject *parent, const QVariantList &args)
36
: Plasma::PopupApplet(parent, args),
40
setAspectRatioMode(Plasma::IgnoreAspectRatio);
41
setCacheMode(DeviceCoordinateCache);
44
CalendarApplet::~CalendarApplet()
48
void CalendarApplet::init()
50
setPopupIcon("view-pim-calendar");
51
m_calendarWidget = new Plasma::Calendar(this);
52
if (m_calendarWidget->isDisplayingDateDetails()) {
53
m_calendarWidget->setPreferredSize(440, 250);
55
m_calendarWidget->setPreferredSize(220, 250);
59
setFocusPolicy(Qt::StrongFocus);
62
void CalendarApplet::focusInEvent(QFocusEvent* event)
65
m_calendarWidget->setFlag(QGraphicsItem::ItemIsFocusable);
66
m_calendarWidget->setFocus();
69
void CalendarApplet::configChanged()
71
m_calendarWidget->applyConfiguration(config());
74
QGraphicsWidget *CalendarApplet::graphicsWidget()
76
return m_calendarWidget;
79
void CalendarApplet::constraintsEvent(Plasma::Constraints constraints)
81
if ((constraints|Plasma::FormFactorConstraint || constraints|Plasma::SizeConstraint) &&
82
layout()->itemAt(0) != m_calendarWidget) {
87
void CalendarApplet::paintIcon()
89
const int iconSize = qMin(size().width(), size().height());
95
QPixmap icon(iconSize, iconSize);
98
m_theme = new Plasma::Svg(this);
99
m_theme->setImagePath("calendar/mini-calendar");
100
m_theme->setContainsMultipleImages(true);
103
icon.fill(Qt::transparent);
106
m_theme->paint(&p, icon.rect(), "mini-calendar");
108
QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
109
p.setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::ButtonTextColor));
110
font.setPixelSize(icon.size().height() / 2);
112
p.drawText(icon.rect().adjusted(0, icon.size().height()/4, 0, 0), Qt::AlignCenter,
113
QString::number(m_calendarWidget->calendar()->day(m_calendarWidget->date())));
119
void CalendarApplet::configAccepted()
121
m_calendarWidget->configAccepted(config());
125
void CalendarApplet::updateDate()
127
QDateTime now = QDateTime::currentDateTime();
128
int updateIn = (24 * 60 * 60) - (now.toTime_t() + KSystemTimeZones::local().currentOffset()) % (24 * 60 * 60);
129
QTimer::singleShot(updateIn * 1000, this, SLOT(updateDate()));
133
void CalendarApplet::createConfigurationInterface(KConfigDialog *parent)
135
m_calendarWidget->createConfigurationInterface(parent);
136
parent->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
137
connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
138
connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
141
#include "calendar.moc"