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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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 <tqrect.h>
#include <tqpainter.h>
#include <tqpalette.h>
#include <tqlayout.h>
#include <tqtimer.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;
TQFrame* frame;
bool recursive;
};
KMyMoneyCategory::KMyMoneyCategory(TQWidget* parent, const char * name, bool splitButton) :
KMyMoneyCombo(true, parent, name),
d(new Private)
{
if(splitButton) {
d->frame = new TQFrame(0);
d->frame->setFocusProxy(this);
TQHBoxLayout* layout = new TQHBoxLayout(d->frame);
// make sure not to use our own overridden version of reparent() here
KMyMoneyCombo::reparent(d->frame, getWFlags() & ~WType_Mask, TQPoint(0, 0), true);
if(parent)
d->frame->reparent(parent, TQPoint(0, 0), true);
// create button
KGuiItem splitButtonItem("",
TQIconSet(TDEGlobal::iconLoader()->loadIcon("split_transaction", TDEIcon::Small,
TDEIcon::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, TQT_SIGNAL(itemSelected(const TQString&)), this, TQT_SLOT(slotItemSelected(const TQString&)));
connect(this, TQT_SIGNAL(textChanged(const TQString&)), m_completion, TQT_SLOT(slotMakeCompletion(const TQString&)));
}
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 TQPalette& palette)
{
if(d->frame)
d->frame->setPalette(palette);
KMyMoneyCombo::setPalette(palette);
}
void KMyMoneyCategory::reparent(TQWidget *parent, WFlags w, const TQPoint& 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 TQString& id)
{
if(!id.isEmpty())
setCurrentText(MyMoneyFile::instance()->accountToCategory(id));
else
setCurrentText();
setSuppressObjectCreation(false);
}
void KMyMoneyCategory::slotItemSelected(const TQString& id)
{
setCurrentTextById(id);
m_completion->hide();
if(m_id != id) {
m_id = id;
emit itemSelected(id);
}
}
void KMyMoneyCategory::focusOutEvent(TQFocusEvent *ev)
{
if(isSplitTransaction()) {
KComboBox::focusOutEvent(ev);
} else {
KMyMoneyCombo::focusOutEvent(ev);
}
}
void KMyMoneyCategory::focusInEvent(TQFocusEvent *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.
TQTimer::singleShot(0, this, TQT_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(TQWidget* parent, const char * name) :
KMyMoneyCategory(parent, name, false)
{
}
KMyMoneySecurity::~KMyMoneySecurity()
{
}
void KMyMoneySecurity::setCurrentTextById(const TQString& id)
{
if(!id.isEmpty())
KMyMoneyCategory::setCurrentText(MyMoneyFile::instance()->account(id).name());
else
KMyMoneyCategory::setCurrentText();
}
#include "kmymoneycategory.moc"
|