summaryrefslogtreecommitdiffstats
path: root/kmymoney2/widgets/kmymoneycategory.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
commitdadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (patch)
tree99e72842fe687baea16376a147619b6048d7e441 /kmymoney2/widgets/kmymoneycategory.cpp
downloadkmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.tar.gz
kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.zip
Added kmymoney
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmymoney2/widgets/kmymoneycategory.cpp')
-rw-r--r--kmymoney2/widgets/kmymoneycategory.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/kmymoney2/widgets/kmymoneycategory.cpp b/kmymoney2/widgets/kmymoneycategory.cpp
new file mode 100644
index 0000000..e14a5a5
--- /dev/null
+++ b/kmymoney2/widgets/kmymoneycategory.cpp
@@ -0,0 +1,203 @@
+/***************************************************************************
+ kmymoneycategory.cpp - description
+ -------------------
+ begin : Mon Jul 10 2006
+ copyright : (C) 2006 by Thomas Baumgart
+ email : Thomas Baumgart <ipwizard@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
+
+#include <qrect.h>
+#include <qpainter.h>
+#include <qpalette.h>
+#include <qlayout.h>
+#include <qtimer.h>
+
+// ----------------------------------------------------------------------------
+// KDE Includes
+
+#include <klocale.h>
+#include <kpushbutton.h>
+#include <kdebug.h>
+#include <kiconloader.h>
+#include <kguiitem.h>
+
+// ----------------------------------------------------------------------------
+// Project Includes
+
+#include "kmymoneycategory.h"
+#include <kmymoney/mymoneyfile.h>
+#include "kmymoneyaccountcompletion.h"
+
+class KMyMoneyCategory::Private
+{
+public:
+ Private() :
+ splitButton(0),
+ frame(0),
+ recursive(false) {}
+
+ KPushButton* splitButton;
+ QFrame* frame;
+ bool recursive;
+};
+
+KMyMoneyCategory::KMyMoneyCategory(QWidget* parent, const char * name, bool splitButton) :
+ KMyMoneyCombo(true, parent, name),
+ d(new Private)
+{
+ if(splitButton) {
+ d->frame = new QFrame(0);
+ d->frame->setFocusProxy(this);
+ QHBoxLayout* layout = new QHBoxLayout(d->frame);
+ // make sure not to use our own overridden version of reparent() here
+ KMyMoneyCombo::reparent(d->frame, getWFlags() & ~WType_Mask, QPoint(0, 0), true);
+ if(parent)
+ d->frame->reparent(parent, QPoint(0, 0), true);
+
+ // create button
+ KGuiItem splitButtonItem("",
+ QIconSet(KGlobal::iconLoader()->loadIcon("split_transaction", KIcon::Small,
+ KIcon::SizeSmall)), "", "");
+ d->splitButton = new KPushButton(splitButtonItem, d->frame, "splitButton");
+
+ layout->addWidget(this, 5);
+ layout->addWidget(d->splitButton);
+ }
+
+ m_completion = new kMyMoneyAccountCompletion(this, 0);
+ connect(m_completion, SIGNAL(itemSelected(const QString&)), this, SLOT(slotItemSelected(const QString&)));
+ connect(this, SIGNAL(textChanged(const QString&)), m_completion, SLOT(slotMakeCompletion(const QString&)));
+}
+
+KMyMoneyCategory::~KMyMoneyCategory()
+{
+ // make sure to wipe out the frame, button and layout
+ if(d->frame && !d->frame->parentWidget())
+ d->frame->deleteLater();
+
+ delete d;
+}
+
+KPushButton* KMyMoneyCategory::splitButton(void) const
+{
+ return d->splitButton;
+}
+
+void KMyMoneyCategory::setPalette(const QPalette& palette)
+{
+ if(d->frame)
+ d->frame->setPalette(palette);
+ KMyMoneyCombo::setPalette(palette);
+}
+
+void KMyMoneyCategory::reparent(QWidget *parent, WFlags w, const QPoint& pos, bool showIt)
+{
+ if(d->frame)
+ d->frame->reparent(parent, w, pos, showIt);
+ else
+ KMyMoneyCombo::reparent(parent, w, pos, showIt);
+}
+
+kMyMoneyAccountSelector* KMyMoneyCategory::selector(void) const
+{
+ return dynamic_cast<kMyMoneyAccountSelector*>(KMyMoneyCombo::selector());
+}
+
+void KMyMoneyCategory::setCurrentTextById(const QString& id)
+{
+ if(!id.isEmpty())
+ setCurrentText(MyMoneyFile::instance()->accountToCategory(id));
+ else
+ setCurrentText();
+ setSuppressObjectCreation(false);
+}
+
+void KMyMoneyCategory::slotItemSelected(const QString& id)
+{
+ setCurrentTextById(id);
+
+ m_completion->hide();
+
+ if(m_id != id) {
+ m_id = id;
+ emit itemSelected(id);
+ }
+}
+
+void KMyMoneyCategory::focusOutEvent(QFocusEvent *ev)
+{
+ if(isSplitTransaction()) {
+ KComboBox::focusOutEvent(ev);
+ } else {
+ KMyMoneyCombo::focusOutEvent(ev);
+ }
+}
+
+void KMyMoneyCategory::focusInEvent(QFocusEvent *ev)
+{
+ KMyMoneyCombo::focusInEvent(ev);
+
+ // make sure, we get a clean state before we automagically move the focus to
+ // some other widget (like for 'split transaction'). We do this by delaying
+ // the emission of the focusIn signal until the next run of the event loop.
+ QTimer::singleShot(0, this, SIGNAL(focusIn()));
+}
+
+void KMyMoneyCategory::setSplitTransaction(void)
+{
+ setCurrentText(i18n("Split transaction (category replacement)", "Split transaction"));
+ setSuppressObjectCreation(true);
+}
+
+bool KMyMoneyCategory::isSplitTransaction(void) const
+{
+ return currentText() == i18n("Split transaction (category replacement)", "Split transaction");
+}
+
+void KMyMoneyCategory::setEnabled(bool enable)
+{
+ if(d->recursive || !d->frame) {
+ KMyMoneyCombo::setEnabled(enable);
+
+ } else if(d->frame) {
+ d->recursive = true;
+ d->frame->setEnabled(enable);
+ d->recursive = false;
+ }
+}
+
+void KMyMoneyCategory::setDisabled(bool disable)
+{
+ setEnabled(!disable);
+}
+
+KMyMoneySecurity::KMyMoneySecurity(QWidget* parent, const char * name) :
+ KMyMoneyCategory(parent, name, false)
+{
+}
+
+KMyMoneySecurity::~KMyMoneySecurity()
+{
+}
+
+void KMyMoneySecurity::setCurrentTextById(const QString& id)
+{
+ if(!id.isEmpty())
+ KMyMoneyCategory::setCurrentText(MyMoneyFile::instance()->account(id).name());
+ else
+ KMyMoneyCategory::setCurrentText();
+}
+
+#include "kmymoneycategory.moc"