summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/datesensor.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /superkaramba/src/datesensor.cpp
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'superkaramba/src/datesensor.cpp')
-rw-r--r--superkaramba/src/datesensor.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/superkaramba/src/datesensor.cpp b/superkaramba/src/datesensor.cpp
new file mode 100644
index 0000000..186f552
--- /dev/null
+++ b/superkaramba/src/datesensor.cpp
@@ -0,0 +1,129 @@
+/***************************************************************************
+ * Copyright (C) 2003 by Hans Karlsson *
+ * karlsson.h@home.se *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "datesensor.h"
+
+#include <qapplication.h>
+DateSensor::DateSensor( int interval ) : Sensor( interval )
+{
+ hidden = true;
+}
+DateSensor::~DateSensor()
+{
+}
+
+void DateSensor::update()
+{
+ QDateTime qdt = QDateTime::currentDateTime();
+ QString format;
+ SensorParams *sp;
+ Meter *meter;
+
+ QObjectListIt it( *objList );
+ while (it != 0)
+ {
+ sp = (SensorParams*)(*it);
+ meter = sp->getMeter();
+ format = sp->getParam("FORMAT");
+
+ if (format.length() == 0 )
+ {
+ format = "hh:mm";
+ }
+ meter->setValue(qdt.toString(format));
+ ++it;
+ }
+}
+
+void DateSensor::slotCalendarDeleted()
+{
+ hidden = true;
+ cal = 0L;
+}
+
+
+DatePicker::DatePicker(QWidget *parent)
+ : QVBox( parent, 0, WType_TopLevel | WDestructiveClose |
+ WStyle_Customize | WStyle_StaysOnTop | WStyle_NoBorder )
+{
+ setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
+ //KWin::setOnAllDesktops( handle(), true );
+ picker = new KDatePicker(this);
+ picker->setCloseButton(true);
+
+ /* name and icon for kicker's taskbar */
+ //setCaption(i18n("Calendar"));
+ //setIcon(SmallIcon("date"));
+}
+
+void DatePicker::keyReleaseEvent(QKeyEvent *e)
+{
+ QVBox::keyReleaseEvent(e);
+ if (e->key() == Qt::Key_Escape)
+ close();
+}
+
+void DateSensor::toggleCalendar(QMouseEvent *ev)
+{
+ QObjectListIt it(*objList);
+ while (it != 0)
+ {
+ SensorParams *sp = (SensorParams*)(*it);
+ Meter *meter = sp->getMeter();
+ QString width = sp->getParam("CALWIDTH");
+ QString height = sp->getParam("CALHEIGHT");
+
+ QRect rect(meter->getX(),meter->getY(),width.toInt(), height.toInt());
+ if (rect.contains( ev->x(), ev->y() ))
+ {
+ if (hidden)
+ {
+ hidden = false;
+ cal = new DatePicker(0);
+
+ connect(cal, SIGNAL(destroyed()), SLOT(slotCalendarDeleted()));
+ QPoint c = (QPoint(ev->x(), ev->y()));
+
+ int w = cal->sizeHint().width();
+ int h = cal->sizeHint().height();
+
+ // make calendar fully visible
+ QRect deskR = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(c));
+
+
+ if (c.y()+h > deskR.bottom()) c.setY(deskR.bottom()-h-1);
+ if (c.x()+w > deskR.right()) c.setX(deskR.right()-w-1);
+ cal->move(c);
+ cal->show();
+
+ }
+ else
+ {
+ cal->close();
+ }
+ }
+
+ ++it;
+ }
+}
+
+void DateSensor::mousePressEvent(QMouseEvent *ev)
+{
+ switch (ev->button())
+ {
+ case QMouseEvent::LeftButton:
+ toggleCalendar(ev);
+ break;
+ default:
+ break;
+ }
+}
+
+
+#include "datesensor.moc"