kexidbtimeedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "kexidbtimeedit.h"
22
23#include <tqtoolbutton.h>
24#include <tqlayout.h>
25#include <tqpainter.h>
26
27#include <tdepopupmenu.h>
28#include <kdatepicker.h>
29#include <kdatetbl.h>
30#include <kexiutils/utils.h>
31
32KexiDBTimeEdit::KexiDBTimeEdit(const TQTime &time, TQWidget *parent, const char *name)
33 : TQTimeEdit(time, parent, name), KexiFormDataItemInterface()
34{
35 m_invalidState = false;
36 setAutoAdvance(true);
37 m_cleared = false;
38
39#ifdef TQDateTimeEditor_HACK
40 m_dte_time = KexiUtils::findFirstChild<TQDateTimeEditor>(this, "TQDateTimeEditor");
41#else
42 m_dte_time = 0;
43#endif
44
45 connect(this, TQ_SIGNAL(valueChanged(const TQTime&)), this, TQ_SLOT(slotValueChanged(const TQTime&)));
46}
47
48KexiDBTimeEdit::~KexiDBTimeEdit()
49{
50}
51
52void KexiDBTimeEdit::setInvalidState( const TQString&)
53{
54 setEnabled(false);
55 setReadOnly(true);
56 m_invalidState = true;
58 if (focusPolicy() & TabFocus)
59 setFocusPolicy(TQWidget::ClickFocus);
60}
61
62void
63KexiDBTimeEdit::setEnabled(bool enabled)
64{
65 // prevent the user from reenabling the widget when it is in invalid state
66 if(enabled && m_invalidState)
67 return;
68 TQTimeEdit::setEnabled(enabled);
69}
70
71void KexiDBTimeEdit::setValueInternal(const TQVariant &add, bool removeOld)
72{
73 m_cleared = !m_origValue.isValid();
74
75 int setNumberOnFocus = -1;
76 TQTime t;
77 TQString addString(add.toString());
78 if (removeOld) {
79 if (!addString.isEmpty() && addString[0].latin1()>='0' && addString[0].latin1() <='9') {
80 setNumberOnFocus = addString[0].latin1()-'0';
81 t = TQTime(setNumberOnFocus, 0, 0);
82 }
83 }
84 else
85 t = m_origValue.toTime();
86
87 setTime(t);
88}
89
90TQVariant
92{
93 //TQDateTime - a hack needed because TQVariant(TQTime) has broken isNull()
94 return TQVariant(TQDateTime( m_cleared ? TQDate() : TQDate(0,1,2)/*nevermind*/, time()));
95}
96
98{
99 return !time().isValid() || time().isNull();
100}
101
103{
104 return m_cleared;
105}
106
108{
111 return m_readOnly;
112}
113
114void KexiDBTimeEdit::setReadOnly(bool set)
115{
116 m_readOnly = set;
117}
118
119TQWidget*
121{
122 return this;
123}
124
126{
127#ifdef TQDateTimeEditor_HACK
128 return m_dte_time && hasFocus() && m_dte_time->focusSection()==0;
129#else
130 return false;
131#endif
132}
133
135{
136#ifdef TQDateTimeEditor_HACK
137 return m_dte_time && hasFocus()
138 && m_dte_time->focusSection()==int(m_dte_time->sectionCount()-1);
139#else
140 return false;
141#endif
142}
143
145{
146 setTime(TQTime());
147 m_cleared = true;
148}
149
150void
151KexiDBTimeEdit::slotValueChanged(const TQTime&)
152{
153 m_cleared = false;
154}
155
156#include "kexidbtimeedit.moc"
virtual bool cursorAtStart()
virtual void setInvalidState(const TQString &displayText)
virtual bool valueIsNull()
virtual bool cursorAtEnd()
virtual bool valueIsEmpty()
virtual void setValueInternal(const TQVariant &add, bool removeOld)
virtual bool isReadOnly() const
virtual void clear()
clears item's data, so the data will contain NULL data
virtual TQVariant value()
virtual TQWidget * widget()
An interface for declaring form widgets to be data-aware.
type * findParent(TQObject *o, const char *className)