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
|
/***************************************************************************
kselecttransactionsdlg.cpp
-------------------
begin : Wed May 16 2007
copyright : (C) 2007 by Thomas Baumgart
email : 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
// ----------------------------------------------------------------------------
// KDE Includes
#include <kpushbutton.h>
#include <kstdguiitem.h>
#include <kapplication.h>
#include <kactivelabel.h>
#include <klocale.h>
// ----------------------------------------------------------------------------
// Project Includes
#include <kmymoney/mymoneyfile.h>
#include <kmymoney/mymoneytransaction.h>
#include <kmymoney/kmymoneyglobalsettings.h>
#include "kmergetransactionsdlg.h"
KSelectTransactionsDlg::KSelectTransactionsDlg(const MyMoneyAccount& _account, QWidget* parent, const char* name) :
KSelectTransactionsDlgDecl(parent, name),
m_account(_account)
{
// setup descriptive texts
setCaption(i18n("Select Transaction"));
m_description->setText(i18n("Select a transaction and press the OK button or use Cancel to select none."));
// clear current register contents
m_register->clear();
// no selection possible
m_register->setSelectionMode(QTable::Single);
// setup header font
QFont font = KMyMoneyGlobalSettings::listHeaderFont();
QFontMetrics fm( font );
int height = fm.lineSpacing()+6;
m_register->horizontalHeader()->setMinimumHeight(height);
m_register->horizontalHeader()->setMaximumHeight(height);
m_register->horizontalHeader()->setFont(font);
// setup cell font
font = KMyMoneyGlobalSettings::listCellFont();
m_register->setFont(font);
// ... setup the register columns ...
m_register->setupRegister(m_account);
// setup buttons
m_helpButton->setGuiItem(KStdGuiItem::help());
buttonOk->setGuiItem(KStdGuiItem::ok());
buttonCancel->setGuiItem(KStdGuiItem::cancel());
// default is to need at least one transaction selected
buttonOk->setDisabled(true);
// catch some events from the register
m_register->installEventFilter(this);
connect(m_register, SIGNAL(selectionChanged(const KMyMoneyRegister::SelectedTransactions&)), this, SLOT(slotEnableOk(const KMyMoneyRegister::SelectedTransactions&)));
connect(m_register, SIGNAL(editTransaction()), this, SLOT(accept()));
connect(m_helpButton, SIGNAL(clicked()), this, SLOT(slotHelp()));
}
void KSelectTransactionsDlg::slotEnableOk(const KMyMoneyRegister::SelectedTransactions& list)
{
buttonOk->setEnabled(list.count() != 0);
}
void KSelectTransactionsDlg::addTransaction(const MyMoneyTransaction& t)
{
QValueList<MyMoneySplit>::const_iterator it_s;
for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s) {
if((*it_s).accountId() == m_account.id()) {
KMyMoneyRegister::Transaction* tr = KMyMoneyRegister::Register::transactionFactory(m_register, t, (*it_s), 0);
// force full detail display
tr->setNumRowsRegister(tr->numRowsRegister(true));
break;
}
}
}
int KSelectTransactionsDlg::exec(void)
{
m_register->updateRegister(true);
m_register->updateContents();
m_register->setFocus();
return KSelectTransactionsDlgDecl::exec();
}
void KSelectTransactionsDlg::slotHelp(void)
{
// kapp->invokeHelp("details.ledgers.match");
}
void KSelectTransactionsDlg::show(void)
{
KSelectTransactionsDlgDecl::show();
m_register->resize(KMyMoneyRegister::DetailColumn);
}
void KSelectTransactionsDlg::resizeEvent(QResizeEvent* ev)
{
// don't forget the resizer
KSelectTransactionsDlgDecl::resizeEvent(ev);
// resize the register
m_register->resize(KMyMoneyRegister::DetailColumn);
}
MyMoneyTransaction KSelectTransactionsDlg::transaction(void) const
{
MyMoneyTransaction t;
QValueList<KMyMoneyRegister::RegisterItem*> list;
list = m_register->selectedItems();
if(list.count()) {
KMyMoneyRegister::Transaction* _t = dynamic_cast<KMyMoneyRegister::Transaction*>(list[0]);
if(_t)
t = _t->transaction();
}
return t;
}
bool KSelectTransactionsDlg::eventFilter(QObject* o, QEvent* e)
{
bool rc = false;
QKeyEvent* k;
if(o == m_register) {
switch(e->type()) {
case QEvent::KeyPress:
k = dynamic_cast<QKeyEvent*>(e);
if((k->state() & Qt::KeyButtonMask) == 0) {
switch(k->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
if(buttonOk->isEnabled()) {
accept();
rc = true;
}
// tricky fall through here
default:
break;
}
}
// tricky fall through here
default:
break;
}
}
return rc;
}
#include "kselecttransactionsdlg.moc"
// vim:cin:si:ai:et:ts=2:sw=2:
|