22#include "kexidatetableedit.h"
24#include <tqapplication.h>
30#include <tqfontmetrics.h>
31#include <tqdatetime.h>
35#include <tqtoolbutton.h>
36#include <tqdatetimeedit.h>
37#include <tqclipboard.h>
42#include <kdatepicker.h>
45#include <tdepopupmenu.h>
46#include <kdatewidget.h>
48#include <kexiutils/utils.h>
52 : KexiInputTableEdit(
column, parent)
54 setName(
"KexiDateTableEdit");
61KexiDateTableEdit::~KexiDateTableEdit()
67 if (
value.isValid() &&
value.toDate().isValid())
78 TQString add(add_.toString());
88 TQString &txt,
int &align,
int &x,
int &y_offset,
int &w,
int &h )
100 if (val.toDate().isValid())
111 return dateValue().isNull();
119TQDate KexiDateTableEdit::dateValue()
const
139 if (!
value.isNull() &&
value.toDate().isValid())
142 tqApp->clipboard()->setText( TQString() );
147 const bool alreadyVisible =
m_lineedit->isVisible();
149 if (actionName==
"edit_paste") {
150 const TQVariant newValue(
m_formatter.stringToDate(tqApp->clipboard()->text()) );
151 if (!alreadyVisible) {
152 emit editRequested();
181void KexiDateTableEdit::moveToFirstSection()
185#ifdef TQDateTimeEditor_HACK
187 m_dte_date->setFocusSection(0);
189#ifdef TQ_WS_WIN //tmp
190 TQKeyEvent ke_left(TQEvent::KeyPress, TQt::Key_Left, 0, 0);
191 for (int i=0; i<8; i++)
192 TQApplication::sendEvent( m_dte_date_obj, &ke_left );
197bool KexiDateTableEdit::eventFilter( TQObject *o, TQEvent *e )
199 if (o==m_datePicker) {
200 kdDebug() << e->type() << endl;
203 m_datePickerPopupMenu->hide();
205 case TQEvent::KeyPress:
206 case TQEvent::KeyRelease: {
207 kdDebug() << "ok!" << endl;
208 TQKeyEvent *ke = (TQKeyEvent *)e;
209 if (ke->key()==Key_Enter || ke->key()==Key_Return) {
214 else if (ke->key()==Key_Escape) {
216 m_datePickerPopupMenu->hide();
217 kdDebug() << "reject" << endl;
220 else m_datePickerPopupMenu->setFocus();
227#ifdef TQ_WS_WIN //tmp
228 else if (e->type()==TQEvent::FocusIn && o->parent() && o->parent()->parent()==m_edit
229 && m_setNumberOnFocus >= 0 && m_dte_date_obj)
231 // there was a number character passed as 'add' parameter in init():
232 moveToFirstSection();
233 TQKeyEvent ke(TQEvent::KeyPress, int(TQt::Key_0)+m_setNumberOnFocus,
234 '0'+m_setNumberOnFocus, 0, TQString::number(m_setNumberOnFocus));
235 TQApplication::sendEvent( m_dte_date_obj, &ke );
236 m_setNumberOnFocus = -1;
239#ifdef TQDateTimeEditor_HACK
240 else if (e->type()==TQEvent::KeyPress && m_dte_date) {
241 TQKeyEvent *ke = static_cast<TQKeyEvent*>(e);
242 if ((ke->key()==TQt::Key_Right && !m_sentEvent && cursorAtEnd())
243 || (ke->key()==TQt::Key_Left && !m_sentEvent && cursorAtStart()))
245 //the editor should send this key event:
246 m_sentEvent = true; //avoid recursion
247 TQApplication::sendEvent( this, ke );
257void KexiDateTableEdit::acceptDate()
259 m_edit->setDate(m_datePicker->date());
260 m_datePickerPopupMenu->hide();
261 kdDebug() << "accept" << endl;
264bool KexiDateTableEdit::cursorAtStart()
266#ifdef TQDateTimeEditor_HACK
267 return m_dte_date && m_edit->hasFocus() && m_dte_date->focusSection()==0;
273bool KexiDateTableEdit::cursorAtEnd()
275#ifdef TQDateTimeEditor_HACK
276 return m_dte_date && m_edit->hasFocus()
277 && m_dte_date->focusSection()==int(m_dte_date->sectionCount()-1);
283void KexiDateTableEdit::clear()
285 m_edit->setDate(TQDate());
290#include "kexidatetableedit.moc"
virtual TQVariant visibleValue()
Editor class for Date type. It is a replacement TQDateEdit due to usability problems: people are accu...
virtual void setValueInternal(const TQVariant &add, bool removeOld)
initializes this editor with add value
KexiDateFormatter m_formatter
Used to format and convert date values.
virtual bool valueIsValid()
virtual TQVariant value()
virtual bool valueIsNull()
virtual void handleAction(const TQString &actionName)
void setValueInInternalEditor(const TQVariant &value)
helper
virtual void setupContents(TQPainter *p, bool focused, const TQVariant &val, TQString &txt, int &align, int &x, int &y_offset, int &w, int &h)
virtual bool valueIsEmpty()
virtual void handleCopyAction(const TQVariant &value, const TQVariant &visibleValue)
KexiDateTableEdit(KexiTableViewColumn &column, TQWidget *parent=0)
KexiTableViewColumn * column() const