1
/* This file is part of the KDE project
2
Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
3
Copyright (C) 2004-2006 Jarosław Staniek <staniek@kde.org>
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.
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.
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.
21
#include "kexidbcheckbox.h"
22
#include <kexiutils/utils.h>
24
#include <KDbQuerySchema>
26
KexiDBCheckBox::KexiDBCheckBox(const QString &text, QWidget *parent)
27
: QCheckBox(text, parent), KexiFormDataItemInterface()
28
, m_invalidState(false)
29
, m_tristateChanged(false)
30
, m_tristate(TristateDefault)
32
setFocusPolicy(Qt::StrongFocus);
33
setMinimumHeight(sizeHint().height());
34
setMinimumWidth(minimumHeight());
36
connect(this, SIGNAL(stateChanged(int)), this, SLOT(slotStateChanged(int)));
39
KexiDBCheckBox::~KexiDBCheckBox()
43
void KexiDBCheckBox::setInvalidState(const QString& displayText)
46
setCheckState(Qt::PartiallyChecked);
47
m_invalidState = true;
48
//! @todo move this to KexiDataItemInterface::setInvalidStateInternal() ?
49
if (focusPolicy() & Qt::TabFocus)
50
setFocusPolicy(Qt::ClickFocus);
55
KexiDBCheckBox::setEnabled(bool enabled)
57
if (enabled && m_invalidState)
59
QCheckBox::setEnabled(enabled);
62
void KexiDBCheckBox::setReadOnly(bool readOnly)
64
setEnabled(!readOnly);
67
void KexiDBCheckBox::setValueInternal(const QVariant &add, bool removeOld)
71
if (isTristateInternal())
72
setCheckState(KexiDataItemInterface::originalValue().isNull()
73
? Qt::PartiallyChecked : (KexiDataItemInterface::originalValue().toBool() ? Qt::Checked : Qt::Unchecked));
75
setCheckState(KexiDataItemInterface::originalValue().toBool() ? Qt::Checked : Qt::Unchecked);
78
QVariant KexiDBCheckBox::value()
80
if (checkState() == Qt::PartiallyChecked)
82
return checkState() == Qt::Checked;
85
void KexiDBCheckBox::slotStateChanged(int)
90
bool KexiDBCheckBox::valueIsNull()
92
return checkState() == Qt::PartiallyChecked;
95
bool KexiDBCheckBox::valueIsEmpty()
100
bool KexiDBCheckBox::isReadOnly() const
106
KexiDBCheckBox::widget()
111
bool KexiDBCheckBox::cursorAtStart()
113
return false; //! \todo ?
116
bool KexiDBCheckBox::cursorAtEnd()
118
return false; //! \todo ?
121
void KexiDBCheckBox::clear()
123
setCheckState(Qt::PartiallyChecked);
126
void KexiDBCheckBox::setTristate(KexiDBCheckBox::Tristate tristate)
128
m_tristateChanged = true;
129
m_tristate = tristate;
133
KexiDBCheckBox::Tristate KexiDBCheckBox::isTristate() const
138
bool KexiDBCheckBox::isTristateInternal() const
140
if (m_tristate == TristateDefault)
141
return !dataSource().isEmpty();
143
return m_tristate == TristateOn;
146
void KexiDBCheckBox::updateTristate()
148
if (m_tristate == TristateDefault) {
149
//! @todo the data source may be defined as NOT NULL... thus disallowing NULL state
150
QCheckBox::setTristate(!dataSource().isEmpty());
152
QCheckBox::setTristate(m_tristate == TristateOn);
156
void KexiDBCheckBox::setDataSource(const QString &ds)
158
KexiFormDataItemInterface::setDataSource(ds);
162
void KexiDBCheckBox::setDisplayDefaultValue(QWidget *widget, bool displayDefaultValue)
164
KexiFormDataItemInterface::setDisplayDefaultValue(widget, displayDefaultValue);
165
// initialize display parameters for default / entered value
166
KexiDisplayUtils::DisplayParameters * const params
167
= displayDefaultValue ? m_displayParametersForDefaultValue : m_displayParametersForEnteredValue;
168
QPalette pal(palette());
169
pal.setColor(QPalette::Active, QPalette::Foreground, params->textColor);
173
void KexiDBCheckBox::paintEvent(QPaintEvent* e)
178
QPalette pal(palette());
179
pal.setBrush(QPalette::WindowText, Qt::transparent);
182
QCheckBox::paintEvent(e);