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

superkaramba

date.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Hans Karlsson                                   *
00003  *   karlsson.h@home.se                                                      *
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 
00011 #include "date.h"
00012 
00013 #include <QApplication>
00014 #include <QDesktopWidget>
00015 #include <QVBoxLayout>
00016 
00017 DateSensor::DateSensor(int interval) : Sensor(interval)
00018 {
00019     hidden = true;
00020 }
00021 DateSensor::~DateSensor()
00022 {}
00023 
00024 void DateSensor::update()
00025 {
00026     QDateTime qdt  =  QDateTime::currentDateTime();
00027     QString format;
00028     SensorParams *sp;
00029     Meter *meter;
00030 
00031     QObject *obj;
00032     foreach(obj, *objList) {
00033         sp = (SensorParams*)(obj);
00034         meter = sp->getMeter();
00035         format = sp->getParam("FORMAT");
00036 
00037         if (format.length() == 0) {
00038             format = "hh:mm";
00039         }
00040         meter->setValue(qdt.toString(format));
00041     }
00042 }
00043 
00044 void DateSensor::slotCalendarDeleted()
00045 {
00046     hidden = true;
00047     cal = 0L;
00048 }
00049 
00050 
00051 DatePicker::DatePicker(QWidget *parent)
00052         : QWidget(parent, Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint)
00053 {
00054     setAttribute(Qt::WA_DeleteOnClose);
00055 
00056     picker = new KDatePicker();
00057     picker->setCloseButton(true);
00058 
00059     QVBoxLayout *layout = new QVBoxLayout;
00060     layout->addWidget(picker);
00061     setLayout(layout);
00062 
00063     /* name and icon for kicker's taskbar */
00064     //setCaption(i18n("Calendar"));
00065     //setIcon(SmallIcon("date"));
00066 }
00067 
00068 void DatePicker::keyReleaseEvent(QKeyEvent *e)
00069 {
00070     QWidget::keyReleaseEvent(e);
00071     if (e->key() == Qt::Key_Escape)
00072         close();
00073 }
00074 
00075 void DateSensor::toggleCalendar(QMouseEvent *ev)
00076 {
00077     QObject *obj;
00078     foreach(obj, *objList) {
00079         SensorParams *sp = (SensorParams*)(obj);
00080         Meter *meter = sp->getMeter();
00081         QString width = sp->getParam("CALWIDTH");
00082         QString height = sp->getParam("CALHEIGHT");
00083 
00084         QRect rect(meter->getX(), meter->getY(), width.toInt(), height.toInt());
00085         if (rect.contains(ev->x(), ev->y())) {
00086             if (hidden) {
00087                 hidden = false;
00088                 cal = new DatePicker(0);
00089 
00090                 connect(cal, SIGNAL(destroyed()), SLOT(slotCalendarDeleted()));
00091                 QPoint c = (QPoint(ev->x(), ev->y()));
00092 
00093                 int w = cal->sizeHint().width();
00094                 int h = cal->sizeHint().height();
00095 
00096                 // make calendar fully visible
00097                 QRect deskR = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(c));
00098 
00099 
00100                 if (c.y() + h > deskR.bottom()) c.setY(deskR.bottom() - h - 1);
00101                 if (c.x() + w > deskR.right()) c.setX(deskR.right() - w - 1);
00102                 cal->move(c);
00103                 cal->show();
00104 
00105             } else {
00106                 cal->close();
00107             }
00108         }
00109     }
00110 }
00111 
00112 void DateSensor::mousePressEvent(QMouseEvent *ev)
00113 {
00114     switch (ev->button()) {
00115     case Qt::LeftButton:
00116         toggleCalendar(ev);
00117         break;
00118     default:
00119         break;
00120     }
00121 }
00122 
00123 
00124 #include "date.moc"

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils 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