kexi

kexidbtextwidgetinterface.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005-2006 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 KexiDBTextWidgetInterface::KexiDBTextWidgetInterface()
00028  : m_autonumberDisplayParameters(0)
00029 {
00030 }
00031 
00032 KexiDBTextWidgetInterface::~KexiDBTextWidgetInterface()
00033 {
00034     delete m_autonumberDisplayParameters;
00035 }
00036 
00037 void KexiDBTextWidgetInterface::setColumnInfo(KexiDB::QueryColumnInfo* cinfo, QWidget *w)
00038 {
00039     if (cinfo->field->isAutoIncrement()) {
00040         if (!m_autonumberDisplayParameters)
00041             m_autonumberDisplayParameters = new KexiDisplayUtils::DisplayParameters();
00042         KexiDisplayUtils::initDisplayForAutonumberSign(*m_autonumberDisplayParameters, w);
00043     }
00044 }
00045 
00046 void KexiDBTextWidgetInterface::paint( QFrame *w, QPainter* p, bool textIsEmpty, int alignment, bool hasFocus )
00047 {
00048     KexiFormDataItemInterface *dataItemIface = dynamic_cast<KexiFormDataItemInterface*>(w);
00049     KexiDB::QueryColumnInfo *columnInfo = dataItemIface ? dataItemIface->columnInfo() : 0;
00050     if (columnInfo && columnInfo->field && dataItemIface->cursorAtNewRow() && textIsEmpty) {
00051         const int margin = w->lineWidth() + w->midLineWidth();
00052         if (columnInfo->field->isAutoIncrement() && m_autonumberDisplayParameters) {
00053             if (w->hasFocus()) {
00054                 p->setPen(
00055                     KexiUtils::blendedColors(
00056                         m_autonumberDisplayParameters->textColor, w->palette().active().base(), 1, 3));
00057             }
00058             KexiDisplayUtils::paintAutonumberSign(*m_autonumberDisplayParameters, p,
00059                 2 + margin + w->margin(), margin, w->width() - margin*2 -2-2, 
00060                 w->height() - margin*2 -2, alignment, hasFocus);
00061         }
00062     }
00063 }
00064 
00065 void KexiDBTextWidgetInterface::event( QEvent * e, QWidget *w, bool textIsEmpty )
00066 {
00067     if (e->type()==QEvent::FocusIn || e->type()==QEvent::FocusOut) {
00068         if (m_autonumberDisplayParameters && textIsEmpty)
00069             w->repaint();
00070     }
00071 }
KDE Home | KDE Accessibility Home | Description of Access Keys