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-2006 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 #include "kexidblineedit.h"
00023 #include <kexidb/queryschema.h>
00024 
00025 #include <kapplication.h>
00026 
00027 #include <qpainter.h>
00028 
00029 KexiDBTextEdit::KexiDBTextEdit(QWidget *parent, const char *name)
00030  : KTextEdit(parent, name)
00031  , KexiDBTextWidgetInterface()
00032  , KexiFormDataItemInterface()
00033  , m_menuExtender(this, this)
00034  , m_slotTextChanged_enabled(true)
00035 {
00036     connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00037 }
00038 
00039 KexiDBTextEdit::~KexiDBTextEdit()
00040 {
00041 }
00042 
00043 void KexiDBTextEdit::setInvalidState( const QString& displayText )
00044 {
00045     setReadOnly(true);
00047     if (focusPolicy() & TabFocus)
00048         setFocusPolicy(QWidget::ClickFocus);
00049     KTextEdit::setText(displayText);
00050 }
00051 
00052 void KexiDBTextEdit::setValueInternal(const QVariant& add, bool removeOld)
00053 {
00054     if (m_columnInfo && m_columnInfo->field->type()==KexiDB::Field::Boolean) {
00056         KTextEdit::setText( add.toBool() ? "1" : "0" );
00057     }
00058     else {
00059         if (removeOld)
00060             KTextEdit::setText( add.toString() );
00061         else
00062             KTextEdit::setText( m_origValue.toString() + add.toString() );
00063     }
00064 }
00065 
00066 QVariant KexiDBTextEdit::value()
00067 {
00068     return text();
00069 }
00070 
00071 void KexiDBTextEdit::slotTextChanged()
00072 {
00073     if (!m_slotTextChanged_enabled)
00074         return;
00075     signalValueChanged();
00076 }
00077 
00078 bool KexiDBTextEdit::valueIsNull()
00079 {
00080     return text().isNull();
00081 }
00082 
00083 bool KexiDBTextEdit::valueIsEmpty()
00084 {
00085     return text().isEmpty();
00086 }
00087 
00088 bool KexiDBTextEdit::isReadOnly() const
00089 {
00090     return KTextEdit::isReadOnly();
00091 }
00092 
00093 void KexiDBTextEdit::setReadOnly( bool readOnly )
00094 {
00095     KTextEdit::setReadOnly( readOnly );
00096     QPalette p = palette();
00097     QColor c(readOnly ? lighterGrayBackgroundColor(kapp->palette()) : p.color(QPalette::Normal, QColorGroup::Base));
00098     setPaper( c );
00099     p.setColor(QColorGroup::Base, c);
00100     p.setColor(QColorGroup::Background, c);
00101     setPalette( p );
00102 }
00103 
00104 void KexiDBTextEdit::setText( const QString & text, const QString & context )
00105 {
00106     KTextEdit::setText(text, context);
00107 }
00108 
00109 QWidget* KexiDBTextEdit::widget()
00110 {
00111     return this;
00112 }
00113 
00114 bool KexiDBTextEdit::cursorAtStart()
00115 {
00116     int para, index;
00117     getCursorPosition ( &para, &index );
00118     return para==0 && index==0;
00119 }
00120 
00121 bool KexiDBTextEdit::cursorAtEnd()
00122 {
00123     int para, index;
00124     getCursorPosition ( &para, &index );
00125     return (paragraphs()-1)==para && (paragraphLength(paragraphs()-1)-1)==index;
00126 }
00127 
00128 void KexiDBTextEdit::clear()
00129 {
00130     setText(QString::null, QString::null);
00131 }
00132 
00133 void KexiDBTextEdit::setColumnInfo(KexiDB::QueryColumnInfo* cinfo)
00134 {
00135     KexiFormDataItemInterface::setColumnInfo(cinfo);
00136     if (!cinfo)
00137         return;
00138     KexiDBTextWidgetInterface::setColumnInfo(m_columnInfo, this);
00139 }
00140 
00141 void KexiDBTextEdit::paintEvent ( QPaintEvent *pe )
00142 {
00143     KTextEdit::paintEvent( pe );
00144     QPainter p(this);
00145     KexiDBTextWidgetInterface::paint( this, &p, text().isEmpty(), alignment(), hasFocus() );
00146 }
00147 
00148 QPopupMenu * KexiDBTextEdit::createPopupMenu(const QPoint & pos)
00149 {
00150     QPopupMenu *contextMenu = KTextEdit::createPopupMenu(pos);
00151     m_menuExtender.createTitle(contextMenu);
00152     return contextMenu;
00153 }
00154 
00155 void KexiDBTextEdit::undo()
00156 {
00157     cancelEditor();
00158 }
00159 
00160 void KexiDBTextEdit::setDisplayDefaultValue(QWidget* widget, bool displayDefaultValue)
00161 {
00162     KexiFormDataItemInterface::setDisplayDefaultValue(widget, displayDefaultValue);
00163     // initialize display parameters for default / entered value
00164     KexiDisplayUtils::DisplayParameters * const params 
00165         = displayDefaultValue ? m_displayParametersForDefaultValue : m_displayParametersForEnteredValue;
00166     QPalette pal(palette());
00167     pal.setColor(QPalette::Active, QColorGroup::Text, params->textColor);
00168     setPalette(pal);
00169     setFont(params->font);
00171 /*  m_slotTextChanged_enabled = false;
00172         //for rich text...
00173         const QString origText( text() );
00174         KTextEdit::setText(QString::null);
00175         setCurrentFont(params->font);
00176         setColor(params->textColor);
00177         KTextEdit::setText(origText);
00178     m_slotTextChanged_enabled = true;*/
00179 }
00180 
00181 void KexiDBTextEdit::moveCursorToEnd()
00182 {
00183     KTextEdit::setCursorPosition(paragraphs()-1, paragraphLength( paragraphs()-1 ));
00184 }
00185 
00186 void KexiDBTextEdit::moveCursorToStart()
00187 {
00188     KTextEdit::setCursorPosition(0 /*para*/, 0 /*index*/);
00189 }
00190 
00191 void KexiDBTextEdit::selectAll()
00192 {
00193     KTextEdit::selectAll();
00194 }
00195 
00196 #include "kexidbtextedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys