You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kmymoney/kmymoney2/widgets/kguiutils.cpp

179 lines
6.0 KiB

/***************************************************************************
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 TQDateEdit, TQSpinBox, etc., since these always return values
#include <tqcheckbox.h>
#include <tqlistbox.h>
#include <tqcombobox.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqwidget.h>
#include <tqhbox.h>
#include <tqspinbox.h>
// ----------------------------------------------------------------------------
// KDE Includes
// ----------------------------------------------------------------------------
// Project Includes
#include "kguiutils.h"
#include "../kmymoneyglobalsettings.h"
/**************************************************************************
* *
* The MandatoryFieldGroup code is courtesy of *
* Mark Summerfield in TQt Quarterly *
* http://doc.trolltech.com/qq/qq11-mandatoryfields.html *
* *
* Enhanced by Thomas Baumgart to support the lineedit field of a *
* a TQComboBox. *
* *
**************************************************************************/
void kMandatoryFieldGroup::add(TQWidget *widget)
{
if (!widgets.tqcontains(widget)) {
if (widget->inherits(TQCHECKBOX_OBJECT_NAME_STRING))
connect((TQCheckBox*)widget->qt_cast(TQCHECKBOX_OBJECT_NAME_STRING),
TQT_SIGNAL(clicked()),
this, TQT_SLOT(changed()));
else if (widget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING)) {
TQComboBox* combo = (TQComboBox*)widget->qt_cast(TQCOMBOBOX_OBJECT_NAME_STRING);
TQLineEdit* lineedit = combo->lineEdit();
if(lineedit) {
connect(lineedit, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(changed()));
} else {
connect(combo, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(changed()));
}
}
else if (widget->inherits(TQLINEEDIT_OBJECT_NAME_STRING))
connect((TQLineEdit*)widget->qt_cast(TQLINEEDIT_OBJECT_NAME_STRING),
TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT(changed()));
else if (widget->inherits(TQSPINBOX_OBJECT_NAME_STRING))
connect((TQSpinBox*)widget->qt_cast(TQSPINBOX_OBJECT_NAME_STRING),
TQT_SIGNAL(valueChanged(const TQString&)),
this, TQT_SLOT(changed()));
else if (widget->inherits(TQLISTBOX_OBJECT_NAME_STRING))
connect((TQListBox*)widget->qt_cast(TQLISTBOX_OBJECT_NAME_STRING),
TQT_SIGNAL(selectionChanged()),
this, TQT_SLOT(changed()));
else {
qWarning("MandatoryFieldGroup: unsupported class %s",
widget->className());
return;
}
widget->setPaletteBackgroundColor(KMyMoneyGlobalSettings::requiredFieldColor());
widgets.append(widget);
changed();
}
}
void kMandatoryFieldGroup::remove(TQWidget *widget)
{
widget->setPaletteBackgroundColor(widget->tqcolorGroup().background());
widgets.remove(widget);
changed();
}
void kMandatoryFieldGroup::setOkButton(TQPushButton *button)
{
if (okButton && okButton != button)
okButton->setEnabled(true);
okButton = button;
changed();
}
void kMandatoryFieldGroup::changed(void)
{
bool enable = true;
TQValueList<TQWidget *>::ConstIterator i;
for (i = widgets.begin(); i != widgets.end(); ++i) {
TQWidget *widget = *i;
// disabled widgets don't count
if(!(widget->isEnabled())) {
continue;
}
if (widget->inherits(TQCHECKBOX_OBJECT_NAME_STRING)) {
if (((TQCheckBox*)widget->qt_cast(TQCHECKBOX_OBJECT_NAME_STRING))->state() == TQButton::NoChange) {
enable = false;
break;
} else
continue;
}
if (widget->inherits(TQCOMBOBOX_OBJECT_NAME_STRING)) {
if (((TQComboBox*)widget->qt_cast(TQCOMBOBOX_OBJECT_NAME_STRING))->currentText().isEmpty()) {
enable = false;
break;
} else
continue;
}
if (widget->inherits(TQLINEEDIT_OBJECT_NAME_STRING)) {
if (((TQLineEdit*)widget->qt_cast(TQLINEEDIT_OBJECT_NAME_STRING))->text().isEmpty()) {
enable = false;
break;
} else
continue;
}
if (widget->inherits(TQLISTBOX_OBJECT_NAME_STRING)) {
if (((TQListBox*)widget->qt_cast(TQLISTBOX_OBJECT_NAME_STRING))->selectedItem() == 0) {
enable = false;
break;
} else
continue;
}
}
if (okButton)
okButton->setEnabled(enable);
m_enabled = enable;
emit stateChanged();
emit stateChanged(enable);
}
void kMandatoryFieldGroup::clear(void)
{
TQValueList<TQWidget *>::Iterator i;
for (i = widgets.begin(); i != widgets.end(); ++i)
(*i)->setPaletteBackgroundColor((*i)->tqcolorGroup().background());
widgets.clear();
if (okButton) {
okButton->setEnabled(true);
okButton = 0;
m_enabled = true;
}
}
#include "kguiutils.moc"