21#include "kexiinputtableedit.h"
28#include <tqapplication.h>
29#include <tqclipboard.h>
35#include <tdeglobalsettings.h>
36#include <tdecompletionbox.h>
37#include <knumvalidator.h>
38#include <kexiutils/longlongvalidator.h>
39#include <kexidb/field.h>
40#include <kexidb/fieldvalidator.h>
43class MyLineEdit :
public KLineEdit
46 MyLineEdit(TQWidget *parent,
const char *name) : KLineEdit(parent,name)
49 virtual void drawFrame ( TQPainter * p ) {
50 p->setPen( TQPen( colorGroup().text() ) );
52 p->moveTo( r.topLeft() );
53 p->lineTo( r.topRight() );
54 p->lineTo( r.bottomRight() );
55 p->lineTo( r.bottomLeft() );
57 p->lineTo( r.topLeft() );
66 setName(
"KexiInputTableEdit");
73KexiInputTableEdit::~KexiInputTableEdit()
77void KexiInputTableEdit::init()
86 m_decsym = TDEGlobal::locale()->decimalSymbol();
87 if (m_decsym.isEmpty())
94 TQHBoxLayout *lyr =
new TQHBoxLayout(
this);
96 lyr->setAutoAdd(
true);
100 m_lineedit =
new MyLineEdit(
this,
"KexiInputTableEdit-KLineEdit");
107 m_calculatedCell =
false;
110 connect(m_cview->completionBox(), TQ_SIGNAL(activated(
const TQString &)),
111 this, TQ_SLOT(completed(
const TQString &)));
112 connect(m_cview->completionBox(), TQ_SIGNAL(highlighted(
const TQString &)),
113 this, TQ_SLOT(completed(
const TQString &)));
114 m_cview->completionBox()->setTabHandling(
true);
121 TQString text( m_textFormatter.
valueToText(removeOld ? TQVariant() : m_origValue, add.toString()) );
122 if (text.isEmpty()) {
123 if (m_origValue.toString().isEmpty()) {
134 m_cview->selectAll();
149TQString KexiInputTableEdit::valueToText(
KexiDB::Field* field,
const TQVariant& value,
const TQString& add)
156 text = TQString::number(
value.toDouble(),
'f',
159 if (
value.toDouble() == 0.0) {
160 text = add.isEmpty() ?
"0" : add;
164 TQStringList sl = TQStringList::split(
".", text);
165 if (text.isEmpty()) {
168 else if (sl.count()==2) {
170 const TQString sl1 = sl[1];
171 int pos = sl1.length()-1;
173 for (;pos>=0 && sl1[pos]==
'0';pos--)
178 text = sl[0] + m_decsym + sl1.left(pos);
191 text =
value.toString();
193 if (
value.toInt() == 0) {
201 if (setValidator && !m_lineedit->validator()) {
202 TQValidator *validator;
203 if (KexiDB::Field::BigInteger == field()->type()) {
205 validator = new KexiUtils::LongLongValidator(m_lineedit);
208 validator = new KIntValidator(m_lineedit);
210 m_lineedit->setValidator( validator );
222void KexiInputTableEdit::paintEvent ( TQPaintEvent * )
225 p.setPen( TQPen( colorGroup().text() ) );
226 p.drawRect( rect() );
230KexiInputTableEdit::setRestrictedCompletion()
233kdDebug() <<
"KexiInputTableEdit::setRestrictedCompletion()" << endl;
235 if(m_cview->text().isEmpty())
238 kdDebug() <<
"KexiInputTableEdit::setRestrictedCompletion(): something to do" << endl;
240 m_cview->useGlobalKeyBindings();
243 TQStringList::ConstIterator it, end( m_comp.constEnd() );
244 for( it = m_comp.constBegin(); it != end; ++it)
246 if((*it).startsWith(m_cview->text()))
249 m_cview->setCompletedItems(newC);
254KexiInputTableEdit::completed(
const TQString &s)
279 if (
field()->isFPNumericType()) {
283 txt = txt.replace(m_decsym,
".");
285 const double result = txt.toDouble(&ok);
286 return ok ? TQVariant(result) : TQVariant();
288 else if (
field()->isIntegerType()) {
292 if (
field()->isUnsigned()) {
293 const TQ_ULLONG result =
m_lineedit->text().toULongLong(&ok);
294 return ok ? TQVariant(result) : TQVariant();
297 const TQ_LLONG result =
m_lineedit->text().toLongLong(&ok);
298 return ok ? TQVariant(result) : TQVariant();
302 if (
field()->isUnsigned()) {
303 const uint result =
m_lineedit->text().toUInt(&ok);
304 return ok ? TQVariant(result) : TQVariant();
308 const int result =
m_lineedit->text().toInt(&ok);
309 return ok ? TQVariant(result) : TQVariant();
342 tqApp->clipboard()->setText( m_textFormatter.
valueToText(
value, TQString()) );
347 const bool alreadyVisible =
m_lineedit->isVisible();
349 if (actionName==
"edit_paste") {
350 if (!alreadyVisible) {
351 emit editRequested();
356 else if (actionName==
"edit_cut") {
358 if (!alreadyVisible) {
359 emit editRequested();
367 const TQFontMetrics& fm,
bool focused)
369 TQString text(
value.type()==TQVariant::String ?
value.toString()
371 TQRect internalRect(rect);
373 internalRect.setWidth(internalRect.width()-
rightMargin(focused)-2*3);
374 kexidbg << rect <<
" " << internalRect <<
" " << fm.width(text) << endl;
375 return fm.width(text) > internalRect.width();
395#include "kexiinputtableedit.moc"
A validator for KexiDB data types.
bool isFPNumericType() const
bool isIntegerType() const
bool isNumericType() const
int visibleDecimalPlaces() const
virtual bool valueChanged()
virtual TQVariant visibleValue()
Abstract class for a cell editor. Handles cell painting and displaying the editor widget.
virtual KexiDB::Field * field() const
Implemented for KexiDataItemInterface.
void setViewWidget(TQWidget *v)
KexiDB::Field * displayedField() const
int rightMargin(bool focused) const
void setField(KexiDB::Field *field)
Assigns field to the formatter. This affects its behaviour.
TQString valueToText(const TQVariant &value, const TQString &add) const