Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

datesensor.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 #include "datesensor.h"
00011 
00012 #include <qapplication.h>
00013 DateSensor::DateSensor( int interval ) : Sensor( interval )
00014 {
00015         hidden = true;
00016 }
00017 DateSensor::~DateSensor()
00018 {
00019 }
00020 
00021 void DateSensor::update()
00022 {
00023     QDateTime qdt  =  QDateTime::currentDateTime();
00024     QString format;
00025     SensorParams *sp;
00026     Meter *meter;
00027 
00028     QObjectListIt it( *objList );
00029     while (it != 0)
00030     {
00031         sp = (SensorParams*)(*it);
00032         meter = sp->getMeter();
00033         format = sp->getParam("FORMAT");
00034 
00035         if (format.length() == 0 )
00036         {
00037            format = "hh:mm";
00038         }
00039         meter->setValue(qdt.toString(format));
00040         ++it;
00041     }
00042 }
00043 
00044 void DateSensor::slotCalendarDeleted()
00045 {
00046         hidden = true;
00047         cal = 0L;
00048 }
00049 
00050 
00051 DatePicker::DatePicker(QWidget *parent)
00052     : QVBox( parent, 0, WType_TopLevel | WDestructiveClose |
00053              WStyle_Customize | WStyle_StaysOnTop | WStyle_NoBorder )
00054 {
00055     setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
00056     //KWin::setOnAllDesktops( handle(), true );
00057     picker = new KDatePicker(this);
00058     picker->setCloseButton(true);
00059 
00060     /* name and icon for kicker's taskbar */
00061     //setCaption(i18n("Calendar"));
00062     //setIcon(SmallIcon("date"));
00063 }
00064 
00065 void DatePicker::keyReleaseEvent(QKeyEvent *e)
00066 {
00067         QVBox::keyReleaseEvent(e);
00068         if (e->key() == Qt::Key_Escape)
00069                 close();
00070 }
00071 
00072 void DateSensor::toggleCalendar(QMouseEvent *ev)
00073 {
00074         QObjectListIt it(*objList);
00075         while (it != 0)
00076         {
00077                 SensorParams *sp = (SensorParams*)(*it);
00078                 Meter *meter = sp->getMeter();
00079                 QString width = sp->getParam("CALWIDTH");
00080                 QString height = sp->getParam("CALHEIGHT");
00081 
00082                 QRect rect(meter->getX(),meter->getY(),width.toInt(), height.toInt());
00083                 if (rect.contains( ev->x(), ev->y() ))
00084                 {
00085                         if (hidden)
00086                         {
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                         }
00106                         else
00107                         {
00108                                 cal->close();
00109                         }
00110                 }
00111 
00112                 ++it;
00113         }
00114 }
00115 
00116 void DateSensor::mousePressEvent(QMouseEvent *ev)
00117 {
00118         switch (ev->button()) 
00119         {
00120                 case QMouseEvent::LeftButton:
00121                         toggleCalendar(ev);
00122                         break;
00123                 default:
00124                         break;
00125         }
00126 }
00127 

Generated on Mon May 16 13:59:20 2005 for karamba by  doxygen 1.3.9.1