kexi

kexidbtextedit.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this program; see the file COPYING.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kexidbtextedit.h"
00022 
00023 #include <kexidb/queryschema.h>
00024 
00025 KexiDBTextEdit::KexiDBTextEdit(QWidget *parent, const char *name)
00026  : KTextEdit(parent, name)
00027  , KexiDBTextWidgetInterface()
00028  , KexiFormDataItemInterface()
00029 {
00030     connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00031 }
00032 
00033 KexiDBTextEdit::~KexiDBTextEdit()
00034 {
00035 }
00036 
00037 void KexiDBTextEdit::setInvalidState( const QString& displayText )
00038 {
00039     setReadOnly(true);
00041     if (focusPolicy() & TabFocus)
00042         setFocusPolicy(QWidget::ClickFocus);
00043     setText(displayText);
00044 }
00045 
00046 void KexiDBTextEdit::setValueInternal(const QVariant& add, bool removeOld)
00047 {
00048     if (m_columnInfo && m_columnInfo->field->type()==KexiDB::Field::Boolean) {
00050         setText( add.toBool() ? "1" : "0" );
00051     }
00052     else {
00053         if (removeOld)
00054             setText( add.toString() );
00055         else
00056             setText( m_origValue.toString() + add.toString() );
00057     }
00058 }
00059 
00060 QVariant KexiDBTextEdit::value()
00061 {
00062     return text();
00063 }
00064 
00065 void KexiDBTextEdit::slotTextChanged()
00066 {
00067     signalValueChanged();
00068 }
00069 
00070 bool KexiDBTextEdit::valueIsNull()
00071 {
00072     return text().isNull();
00073 }
00074 
00075 bool KexiDBTextEdit::valueIsEmpty()
00076 {
00077     return text().isEmpty();
00078 }
00079 
00080 bool KexiDBTextEdit::isReadOnly() const
00081 {
00082     return KTextEdit::isReadOnly();
00083 }
00084 
00085 QWidget* KexiDBTextEdit::widget()
00086 {
00087     return this;
00088 }
00089 
00090 bool KexiDBTextEdit::cursorAtStart()
00091 {
00092     int para, index;
00093     getCursorPosition ( &para, &index );
00094     return para==0 && index==0;
00095 }
00096 
00097 bool KexiDBTextEdit::cursorAtEnd()
00098 {
00099     int para, index;
00100     getCursorPosition ( &para, &index );
00101     return (paragraphs()-1)==para && (paragraphLength(paragraphs()-1)-1)==index;
00102 }
00103 
00104 void KexiDBTextEdit::clear()
00105 {
00106     setText(QString::null);
00107 }
00108 
00109 void KexiDBTextEdit::setColumnInfo(KexiDB::QueryColumnInfo* cinfo)
00110 {
00111     KexiFormDataItemInterface::setColumnInfo(cinfo);
00112     if (!cinfo)
00113         return;
00114     KexiDBTextWidgetInterface::setColumnInfo(m_columnInfo, this);
00115 }
00116 
00117 void KexiDBTextEdit::paintEvent ( QPaintEvent *pe )
00118 {
00119     KTextEdit::paintEvent( pe );
00120     KexiDBTextWidgetInterface::paintEvent( this, text().isEmpty(), alignment(), hasFocus() );
00121 }
00122 
00123 #include "kexidbtextedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys