1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/***************************************************************************
kguiutils.cpp - description
-------------------
begin : Fri Jan 27 2006
copyright : (C) 2006 Tony Bloomfield
email : Tony Bloomfield <tonybloom@users.sourceforge.net>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// ----------------------------------------------------------------------------
// QT Includes
// No need for QDateEdit, QSpinBox, etc., since these always return values
#include <qcheckbox.h>
#include <qlistbox.h>
#include <qcombobox.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qwidget.h>
#include <qhbox.h>
#include <qspinbox.h>
// ----------------------------------------------------------------------------
// KDE Includes
// ----------------------------------------------------------------------------
// Project Includes
#include "kguiutils.h"
#include "../kmymoneyglobalsettings.h"
/**************************************************************************
* *
* The MandatoryFieldGroup code is courtesy of *
* Mark Summerfield in Qt Quarterly *
* http://doc.trolltech.com/qq/qq11-mandatoryfields.html *
* *
* Enhanced by Thomas Baumgart to support the lineedit field of a *
* a QComboBox. *
* *
**************************************************************************/
void kMandatoryFieldGroup::add(QWidget *widget)
{
if (!widgets.contains(widget)) {
if (widget->inherits("QCheckBox"))
connect((QCheckBox*)widget->qt_cast("QCheckBox"),
SIGNAL(clicked()),
this, SLOT(changed()));
else if (widget->inherits("QComboBox")) {
QComboBox* combo = (QComboBox*)widget->qt_cast("QComboBox");
QLineEdit* lineedit = combo->lineEdit();
if(lineedit) {
connect(lineedit, SIGNAL(textChanged(const QString&)), this, SLOT(changed()));
} else {
connect(combo, SIGNAL(highlighted(int)), this, SLOT(changed()));
}
}
else if (widget->inherits("QLineEdit"))
connect((QLineEdit*)widget->qt_cast("QLineEdit"),
SIGNAL(textChanged(const QString&)),
this, SLOT(changed()));
else if (widget->inherits("QSpinBox"))
connect((QSpinBox*)widget->qt_cast("QSpinBox"),
SIGNAL(valueChanged(const QString&)),
this, SLOT(changed()));
else if (widget->inherits("QListBox"))
connect((QListBox*)widget->qt_cast("QListBox"),
SIGNAL(selectionChanged()),
this, SLOT(changed()));
else {
qWarning("MandatoryFieldGroup: unsupported class %s",
widget->className());
return;
}
widget->setPaletteBackgroundColor(KMyMoneyGlobalSettings::requiredFieldColor());
widgets.append(widget);
changed();
}
}
void kMandatoryFieldGroup::remove(QWidget *widget)
{
widget->setPaletteBackgroundColor(widget->colorGroup().background());
widgets.remove(widget);
changed();
}
void kMandatoryFieldGroup::setOkButton(QPushButton *button)
{
if (okButton && okButton != button)
okButton->setEnabled(true);
okButton = button;
changed();
}
void kMandatoryFieldGroup::changed(void)
{
bool enable = true;
QValueList<QWidget *>::ConstIterator i;
for (i = widgets.begin(); i != widgets.end(); ++i) {
QWidget *widget = *i;
// disabled widgets don't count
if(!(widget->isEnabled())) {
continue;
}
if (widget->inherits("QCheckBox")) {
if (((QCheckBox*)widget->qt_cast("QCheckBox"))->state() == QButton::NoChange) {
enable = false;
break;
} else
continue;
}
if (widget->inherits("QComboBox")) {
if (((QComboBox*)widget->qt_cast("QComboBox"))->currentText().isEmpty()) {
enable = false;
break;
} else
continue;
}
if (widget->inherits("QLineEdit")) {
if (((QLineEdit*)widget->qt_cast("QLineEdit"))->text().isEmpty()) {
enable = false;
break;
} else
continue;
}
if (widget->inherits("QListBox")) {
if (((QListBox*)widget->qt_cast("QListBox"))->selectedItem() == 0) {
enable = false;
break;
} else
continue;
}
}
if (okButton)
okButton->setEnabled(enable);
m_enabled = enable;
emit stateChanged();
emit stateChanged(enable);
}
void kMandatoryFieldGroup::clear(void)
{
QValueList<QWidget *>::Iterator i;
for (i = widgets.begin(); i != widgets.end(); ++i)
(*i)->setPaletteBackgroundColor((*i)->colorGroup().background());
widgets.clear();
if (okButton) {
okButton->setEnabled(true);
okButton = 0;
m_enabled = true;
}
}
#include "kguiutils.moc"
|