Applets
clockapplet.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
00021 #include "clockapplet.h"
00022
00023 #include <math.h>
00024
00025 #include <QtGui/QPainter>
00026 #include <QtGui/QStyleOptionGraphicsItem>
00027 #include <QtGui/QSpinBox>
00028 #include <QtCore/QTimeLine>
00029 #include <QtGui/QGraphicsView>
00030 #include <QtGui/QGraphicsSceneMouseEvent>
00031 #include <QtCore/QDate>
00032
00033 #include <KColorScheme>
00034 #include <KDatePicker>
00035 #include <KDebug>
00036 #include <KDialog>
00037 #include <KGlobalSettings>
00038
00039 #include <plasma/dataengine.h>
00040 #include <plasma/dialog.h>
00041 #include <plasma/theme.h>
00042
00043 class ClockApplet::Private
00044 {
00045 public:
00046 Private()
00047 : calendar(0),
00048 timezone("Local")
00049 {}
00050
00051 Ui::calendar calendarUi;
00052 Plasma::Dialog *calendar;
00053 QString timezone;
00054 QPoint clicked;
00055 };
00056
00057 ClockApplet::ClockApplet(QObject *parent, const QVariantList &args)
00058 : Plasma::Applet(parent, args),
00059 d(new Private)
00060 {
00061 }
00062
00063 ClockApplet::~ClockApplet()
00064 {
00065 delete d->calendar;
00066 delete d;
00067 }
00068
00069 void ClockApplet::updateToolTipContent() {
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 }
00080
00081 void ClockApplet::mousePressEvent(QGraphicsSceneMouseEvent *event)
00082 {
00083 if (event->buttons() == Qt::LeftButton) {
00084 d->clicked = scenePos().toPoint();
00085 event->setAccepted(true);
00086 return;
00087 }
00088
00089 Applet::mousePressEvent(event);
00090 }
00091
00092 void ClockApplet::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
00093 {
00094 if ((d->clicked - scenePos().toPoint()).manhattanLength() <
00095 KGlobalSettings::dndEventDelay()) {
00096 showCalendar(event);
00097 }
00098 }
00099
00100 void ClockApplet::showCalendar(QGraphicsSceneMouseEvent *event)
00101 {
00102 Q_UNUSED(event);
00103
00104 if (d->calendar == 0) {
00105 d->calendar = new Plasma::Dialog();
00106 d->calendarUi.setupUi(d->calendar);
00107 d->calendar->setWindowFlags(Qt::Popup);
00108 d->calendar->adjustSize();
00109 }
00110
00111 if (d->calendar->isVisible()) {
00112 d->calendar->hide();
00113 } else {
00114 kDebug();
00115 Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone());
00116 d->calendarUi.kdatepicker->setDate(data["Date"].toDate());
00117 d->calendar->move(popupPosition(d->calendar->sizeHint()));
00118 d->calendar->show();
00119 }
00120 }
00121
00122 void ClockApplet::setCurrentTimezone(const QString &tz)
00123 {
00124 d->timezone = tz;
00125 }
00126
00127 QString ClockApplet::currentTimezone() const
00128 {
00129 return d->timezone;
00130 }
00131
00132 bool ClockApplet::isLocalTimezone() const
00133 {
00134 return d->timezone == localTimezone();
00135 }
00136
00137 QString ClockApplet::localTimezone()
00138 {
00139 return "Local";
00140 }
00141
00142 #include "clockapplet.moc"