kexi

kexidbtextwidgetinterface.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexidbtextwidgetinterface.h"
00021 #include "kexiformdataiteminterface.h"
00022 #include <kexidb/queryschema.h>
00023 #include <kexiutils/utils.h>
00024 #include <qframe.h>
00025 #include <qpainter.h>
00026 
00027 void KexiDBTextWidgetInterface::setColumnInfo(KexiDB::QueryColumnInfo* cinfo, QWidget *w)
00028 {
00029     if (cinfo->field->isAutoIncrement()) {
00030         if (!m_autonumberDisplayParameters)
00031             m_autonumberDisplayParameters = new KexiDisplayUtils::DisplayParameters();
00032         KexiDisplayUtils::initDisplayForAutonumberSign(*m_autonumberDisplayParameters, w);
00033     }
00034 }
00035 
00036 void KexiDBTextWidgetInterface::paintEvent( QFrame *w, bool textIsEmpty, int alignment, bool hasFocus  )
00037 {
00038     KexiFormDataItemInterface *dataItemIface = dynamic_cast<KexiFormDataItemInterface*>(w);
00039     if (dataItemIface && dataItemIface->columnInfo() && dataItemIface->columnInfo()->field->isAutoIncrement()
00040         && m_autonumberDisplayParameters && dataItemIface->cursorAtNewRow() && textIsEmpty)
00041     {
00042         QPainter p(w);
00043         if (w->hasFocus()) {
00044             p.setPen(KexiUtils::blendedColors(m_autonumberDisplayParameters->textColor, w->palette().active().base(), 1, 3));
00045         }
00046         const int m = w->lineWidth()+w->midLineWidth();
00047         KexiDisplayUtils::drawAutonumberSign(*m_autonumberDisplayParameters, &p,
00048             2+m+w->margin(), m, w->width()-m*2 -2-2, w->height()-m*2 -2, alignment, hasFocus);
00049     }
00050 }
00051 
00052 void KexiDBTextWidgetInterface::event( QEvent * e, QWidget *w, bool textIsEmpty )
00053 {
00054     if (e->type()==QEvent::FocusIn || e->type()==QEvent::FocusOut) {
00055         if (m_autonumberDisplayParameters && textIsEmpty)
00056             w->repaint();
00057     }
00058 }
KDE Home | KDE Accessibility Home | Description of Access Keys