From dadc34655c3ab961b0b0b94a10eaaba710f0b5e8 Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 4 Jul 2011 22:38:03 +0000 Subject: Added kmymoney git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmymoney2/widgets/kguiutils.cpp | 178 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 kmymoney2/widgets/kguiutils.cpp (limited to 'kmymoney2/widgets/kguiutils.cpp') diff --git a/kmymoney2/widgets/kguiutils.cpp b/kmymoney2/widgets/kguiutils.cpp new file mode 100644 index 0000000..c6157f9 --- /dev/null +++ b/kmymoney2/widgets/kguiutils.cpp @@ -0,0 +1,178 @@ +/*************************************************************************** + kguiutils.cpp - description + ------------------- + begin : Fri Jan 27 2006 + copyright : (C) 2006 Tony Bloomfield + email : Tony Bloomfield +***************************************************************************/ + +/*************************************************************************** + * * + * 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 +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// 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::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::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" + -- cgit v1.2.1