kexi

kexidatetimetableedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Lucijan Busch <lucijan@gmx.at>
3 Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
4 Copyright (C) 2003-2004,2006 Jaroslaw Staniek <js@iidea.pl>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "kexidatetimetableedit.h"
23
24#include <tqapplication.h>
25#include <tqpainter.h>
26#include <tqvariant.h>
27#include <tqrect.h>
28#include <tqpalette.h>
29#include <tqcolor.h>
30#include <tqfontmetrics.h>
31#include <tqdatetime.h>
32#include <tqcursor.h>
33#include <tqpoint.h>
34#include <tqlayout.h>
35#include <tqtoolbutton.h>
36#include <tqdatetimeedit.h>
37#include <tqclipboard.h>
38
39#include <kdebug.h>
40#include <tdelocale.h>
41#include <tdeglobal.h>
42#include <kdatepicker.h>
43#include <kdatetbl.h>
44#include <klineedit.h>
45#include <tdepopupmenu.h>
46#include <kdatewidget.h>
47
48#include <kexiutils/utils.h>
49
51 : KexiInputTableEdit(column, parent)
52{
53 setName("KexiDateTimeTableEdit");
54
56
57 m_lineedit->setInputMask(
58 dateTimeInputMask( m_dateFormatter, m_timeFormatter ) );
59}
60
61KexiDateTimeTableEdit::~KexiDateTimeTableEdit()
62{
63}
64
66{
67 if (value.isValid() && value.toDateTime().isValid())
68 m_lineedit->setText(
69 m_dateFormatter.dateToString( value.toDateTime().date() ) + " " +
70 m_timeFormatter.timeToString( value.toDateTime().time() ) );
71 else
72 m_lineedit->setText( TQString() );
73}
74
75void KexiDateTimeTableEdit::setValueInternal(const TQVariant& add_, bool removeOld)
76{
77 if (removeOld) {
78 //new time entering... just fill the line edit
80 TQString add(add_.toString());
81 m_lineedit->setText(add);
82 m_lineedit->setCursorPosition(add.length());
83 return;
84 }
85 setValueInInternalEditor( m_origValue );
86 m_lineedit->setCursorPosition(0); //ok?
87}
88
89void KexiDateTimeTableEdit::setupContents( TQPainter *p, bool focused, const TQVariant& val,
90 TQString &txt, int &align, int &x, int &y_offset, int &w, int &h )
91{
92 Q_UNUSED(p);
93 Q_UNUSED(focused);
94 Q_UNUSED(x);
95 Q_UNUSED(w);
96 Q_UNUSED(h);
97#ifdef TQ_WS_WIN
98 y_offset = -1;
99#else
100 y_offset = 0;
101#endif
102 if (val.toDateTime().isValid())
103 txt = m_dateFormatter.dateToString(val.toDateTime().date()) + " "
104 + m_timeFormatter.timeToString(val.toDateTime().time());
105 align |= AlignLeft;
106}
107
109{
110 if (textIsEmpty())
111 return true;
112 return !stringToDateTime(m_dateFormatter, m_timeFormatter, m_lineedit->text()).isValid();
113}
114
116{
117 return valueIsNull();//js OK? TODO (nonsense?)
118}
119
121{
122 if (textIsEmpty())
123 return TQVariant();
124 return stringToDateTime(m_dateFormatter, m_timeFormatter, m_lineedit->text());
125}
126
128{
129 return dateTimeIsValid( m_dateFormatter, m_timeFormatter, m_lineedit->text() );
130}
131
132bool KexiDateTimeTableEdit::textIsEmpty() const
133{
134 return dateTimeIsEmpty( m_dateFormatter, m_timeFormatter, m_lineedit->text() );
135}
136
137void KexiDateTimeTableEdit::handleCopyAction(const TQVariant& value, const TQVariant& visibleValue)
138{
139 Q_UNUSED(visibleValue);
140 if (!value.isNull() && value.toDateTime().isValid())
141 tqApp->clipboard()->setText( m_dateFormatter.dateToString(value.toDateTime().date()) + " "
142 + m_timeFormatter.timeToString(value.toDateTime().time()) );
143 else
144 tqApp->clipboard()->setText( TQString() );
145}
146
147void KexiDateTimeTableEdit::handleAction(const TQString& actionName)
148{
149 const bool alreadyVisible = m_lineedit->isVisible();
150
151 if (actionName=="edit_paste") {
152 const TQVariant newValue( stringToDateTime(m_dateFormatter, m_timeFormatter, tqApp->clipboard()->text()) );
153 if (!alreadyVisible) { //paste as the entire text if the cell was not in edit mode
154 emit editRequested();
155 m_lineedit->clear();
156 }
157 setValueInInternalEditor( newValue );
158 }
159 else
161}
162
163KEXI_CELLEDITOR_FACTORY_ITEM_IMPL(KexiDateTimeEditorFactoryItem, KexiDateTimeTableEdit)
164
165#include "kexidatetimetableedit.moc"
virtual TQVariant visibleValue()
Editor class for Date/Time type. It is a replacement TQDateTimeEdit due to usability problems: people...
virtual void setValueInternal(const TQVariant &add, bool removeOld)
initializes this editor with add value
KexiDateTimeTableEdit(KexiTableViewColumn &column, TQWidget *parent=0)
KexiDateFormatter m_dateFormatter
Used to format and convert date values.
virtual void setupContents(TQPainter *p, bool focused, const TQVariant &val, TQString &txt, int &align, int &x, int &y_offset, int &w, int &h)
virtual void handleAction(const TQString &actionName)
KexiTimeFormatter m_timeFormatter
Used to format and convert time values.
void setValueInInternalEditor(const TQVariant &value)
helper
virtual void handleCopyAction(const TQVariant &value, const TQVariant &visibleValue)
KLineEdit * m_lineedit
orig. Line Edit's text after conversion - for easy comparing
virtual void handleAction(const TQString &actionName)
KexiTableViewColumn * column() const