00001
00002
00003
00004
00005
00006
00007
00008
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
00057 picker = new KDatePicker(this);
00058 picker->setCloseButton(true);
00059
00060
00061
00062
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
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