kexi

kexidbtextwidgetinterface.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexidbtextwidgetinterface.h"
21#include "kexiformdataiteminterface.h"
22#include <kexidb/queryschema.h>
23#include <kexiutils/utils.h>
24#include <tqframe.h>
25#include <tqpainter.h>
26
27KexiDBTextWidgetInterface::KexiDBTextWidgetInterface()
28 : m_autonumberDisplayParameters(0)
29{
30}
31
32KexiDBTextWidgetInterface::~KexiDBTextWidgetInterface()
33{
35}
36
45
46void KexiDBTextWidgetInterface::paint( TQFrame *w, TQPainter* p, bool textIsEmpty, int alignment, bool hasFocus )
47{
48 KexiFormDataItemInterface *dataItemIface = dynamic_cast<KexiFormDataItemInterface*>(w);
49 KexiDB::QueryColumnInfo *columnInfo = dataItemIface ? dataItemIface->columnInfo() : 0;
50 if (columnInfo && columnInfo->field && dataItemIface->cursorAtNewRow() && textIsEmpty) {
51 const int margin = w->lineWidth() + w->midLineWidth();
52 if (columnInfo->field->isAutoIncrement() && m_autonumberDisplayParameters) {
53 if (w->hasFocus()) {
54 p->setPen(
56 m_autonumberDisplayParameters->textColor, w->palette().active().base(), 1, 3));
57 }
59 2 + margin + w->margin(), margin, w->width() - margin*2 -2-2,
60 w->height() - margin*2 -2, alignment, hasFocus);
61 }
62 }
63}
64
65void KexiDBTextWidgetInterface::event( TQEvent * e, TQWidget *w, bool textIsEmpty )
66{
67 if (e->type()==TQEvent::FocusIn || e->type()==TQEvent::FocusOut) {
68 if (m_autonumberDisplayParameters && textIsEmpty)
69 w->repaint();
70 }
71}
void setColumnInfo(KexiDB::QueryColumnInfo *cinfo, TQWidget *w)
Called from KexiFormDataItemInterface::setColumnInfo(KexiDB::QueryColumnInfo* cinfo) implementation.
void event(TQEvent *e, TQWidget *w, bool textIsEmpty)
Called from event( TQEvent * e ) method of the data aware widget.
void paint(TQFrame *w, TQPainter *p, bool textIsEmpty, int alignment, bool hasFocus)
Called from paintEvent( TQPaintEvent *pe ) method of the data aware widget.
KexiDisplayUtils::DisplayParameters * m_autonumberDisplayParameters
parameters for displaying autonumber sign
bool isAutoIncrement() const
Definition field.h:231
Helper class that assigns additional information for the column in a query.
Definition queryschema.h:49
Stores set of display parameters used in utility functions.
static void paintAutonumberSign(const DisplayParameters &par, TQPainter *painter, int x, int y, int width, int height, int align, bool overrideColor=false)
Paints autonumber sign using par parameters.
static void initDisplayForAutonumberSign(DisplayParameters &par, TQWidget *widget)
Initializes display parameters for autonumber sign.
An interface for declaring form widgets to be data-aware.
virtual KexiDB::QueryColumnInfo * columnInfo() const
KEXIUTILS_EXPORT TQColor blendedColors(const TQColor &c1, const TQColor &c2, int factor1=1, int factor2=1)