summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/datesensor.cpp
blob: 6adef6d687aefe12c15d1fd2ba9acd5ba7eb3148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/***************************************************************************
 *   Copyright (C) 2003 by Hans Karlsson                                   *
 *   [email protected]                                                      *
 *                                                                         *
 *   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 <tqapplication.h>
DateSensor::DateSensor( int interval ) : Sensor( interval )
{
	hidden = true;
}
DateSensor::~DateSensor()
{
}

void DateSensor::update()
{
    TQDateTime qdt  =  TQDateTime::currentDateTime();
    TQString format;
    SensorParams *sp;
    Meter *meter;

    TQObjectListIt 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(TQWidget *parent)
    : TQVBox( parent, 0, WType_TopLevel | WDestructiveClose |
             WStyle_Customize | WStyle_StaysOnTop | WStyle_NoBorder )
{
    setFrameStyle( TQFrame::PopupPanel | TQFrame::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(TQKeyEvent *e)
{
        TQVBox::keyReleaseEvent(e);
        if (e->key() == TQt::Key_Escape)
                close();
}

void DateSensor::toggleCalendar(TQMouseEvent *ev)
{
	TQObjectListIt it(*objList);
	while (it != 0)
	{
		SensorParams *sp = (SensorParams*)(*it);
		Meter *meter = sp->getMeter();
		TQString width = sp->getParam("CALWIDTH");
		TQString height = sp->getParam("CALHEIGHT");

		TQRect 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, TQT_SIGNAL(destroyed()), TQT_SLOT(slotCalendarDeleted()));
				TQPoint c = (TQPoint(ev->x(), ev->y()));

				int w = cal->sizeHint().width();
				int h = cal->sizeHint().height();

				// make calendar fully visible
				 TQRect deskR = TQApplication::desktop()->screenGeometry(TQApplication::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(TQMouseEvent *ev)
{
	switch (ev->button()) 
	{
		case TQt::LeftButton:
			toggleCalendar(ev);
			break;
		default:
			break;
	}
}


#include "datesensor.moc"