• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

clockapplet.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007-2008 by Riccardo Iaconelli <riccardo@kde.org>      *
00003  *   Copyright (C) 2007-2008 by Sebastian Kuegler <sebas@kde.org>          *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
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     //QString timeString = KGlobal::locale()->formatTime(d->time, d->showSeconds);
00071     //TODO port to TOOLTIP manager
00072     /*Plasma::ToolTipData tipData;
00073 
00074     tipData.mainText = "";//d->time.toString(timeString);
00075     tipData.subText = "";//d->date.toString();
00076     //tipData.image = d->toolTipIcon;
00077 
00078     setToolTip(tipData);*/
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"

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal