Applets
calendar.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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"