kexidbcheckbox.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "kexidbcheckbox.h"
22
23#include <kexiutils/utils.h>
24#include <kexidb/queryschema.h>
25
26KexiDBCheckBox::KexiDBCheckBox(const TQString &text, TQWidget *parent, const char *name)
27 : TQCheckBox(text, parent, name), KexiFormDataItemInterface()
28 , m_invalidState(false)
29 , m_tristateChanged(false)
30 , m_tristate(TristateDefault)
31{
32 setFocusPolicy(TQWidget::StrongFocus);
33 updateTristate();
34 connect(this, TQ_SIGNAL(stateChanged(int)), this, TQ_SLOT(slotStateChanged(int)));
35}
36
37KexiDBCheckBox::~KexiDBCheckBox()
38{
39}
40
41void KexiDBCheckBox::setInvalidState( const TQString& displayText )
42{
43 setEnabled(false);
44 setState(NoChange);
45 m_invalidState = true;
47 if (focusPolicy() & TQWidget::TabFocus)
48 setFocusPolicy(TQWidget::ClickFocus);
49 setText(displayText);
50}
51
52void
53KexiDBCheckBox::setEnabled(bool enabled)
54{
55 if(enabled && m_invalidState)
56 return;
57 TQCheckBox::setEnabled(enabled);
58}
59
60void
62{
63 setEnabled(!readOnly);
64}
65
66void KexiDBCheckBox::setValueInternal(const TQVariant &add, bool removeOld)
67{
68 Q_UNUSED(add);
69 Q_UNUSED(removeOld);
71 setState( m_origValue.isNull() ? NoChange : (m_origValue.toBool() ? On : Off) );
72 else
73 setState( m_origValue.toBool() ? On : Off );
74}
75
76TQVariant
78{
79 if (state()==NoChange)
80 return TQVariant();
81 return TQVariant(state()==On);
82}
83
84void KexiDBCheckBox::slotStateChanged(int )
85{
87}
88
90{
91 return state() == NoChange;
92}
93
95{
96 return false;
97}
98
100{
101 return !isEnabled();
102}
103
104TQWidget*
106{
107 return this;
108}
109
111{
112 return false;
113}
114
116{
117 return false;
118}
119
121{
122 setState(NoChange);
123}
124
125void KexiDBCheckBox::setTristate(KexiDBCheckBox::Tristate tristate)
126{
127 m_tristateChanged = true;
128 m_tristate = tristate;
130}
131
132KexiDBCheckBox::Tristate KexiDBCheckBox::isTristate() const
133{
134 return m_tristate;
135}
136
138{
139 if (m_tristate == TristateDefault)
140 return !dataSource().isEmpty();
141
142 return m_tristate == TristateOn;
143}
144
146{
147 if (m_tristate == TristateDefault) {
149 TQCheckBox::setTristate( !dataSource().isEmpty() );
150 }
151 else {
152 TQCheckBox::setTristate( m_tristate == TristateOn );
153 }
154}
155
156void KexiDBCheckBox::setDataSource(const TQString &ds)
157{
160}
161
162void KexiDBCheckBox::setDisplayDefaultValue(TQWidget *widget, bool displayDefaultValue)
163{
165 // initialize display parameters for default / entered value
168// setFont(params->font);
169 TQPalette pal(palette());
170// pal.setColor(TQPalette::Active, TQColorGroup::Text, params->textColor);
171 pal.setColor(TQPalette::Active, TQColorGroup::Foreground, params->textColor);
172 setPalette(pal);
173}
174
175#include "kexidbcheckbox.moc"
bool isTristateInternal() const
virtual bool cursorAtStart()
virtual void setInvalidState(const TQString &displayText)
virtual bool isReadOnly() const
virtual TQVariant value()
virtual TQWidget * widget()
void updateTristate()
Updates tristate in TQCheckBox itself according to m_tristate.
virtual void setValueInternal(const TQVariant &add, bool removeOld)
virtual void setReadOnly(bool readOnly)
This implementation just disables read only widget.
virtual void setDisplayDefaultValue(TQWidget *widget, bool displayDefaultValue)
virtual bool valueIsEmpty()
virtual bool cursorAtEnd()
virtual bool valueIsNull()
virtual void clear()
clears item's data, so the data will contain NULL data
Stores set of display parameters used in utility functions.
An interface for declaring form widgets to be data-aware.
virtual void setDisplayDefaultValue(TQWidget *widget, bool displayDefaultValue)
KexiDisplayUtils::DisplayParameters * m_displayParametersForEnteredValue
used in setDisplayDefaultValue()
void setDataSource(const TQString &ds)
Sets the name of the data source for this widget.
KexiDisplayUtils::DisplayParameters * m_displayParametersForDefaultValue
used in setDisplayDefaultValue()
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100