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
|
/***************************************************************************
kmymoneylineedit.cpp - description
-------------------
begin : Wed May 9 2001
copyright : (C) 2001 by Michael Edwardes
email : mte@users.sourceforge.net
Javier Campos Morales <javi_c@ctv.es>
Felix Rodriguez <frodriguez@mail.wesleyan.edu>
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
// ----------------------------------------------------------------------------
// QT Includes
#include <tqrect.h>
#include <tqpainter.h>
#include <tqpalette.h>
// ----------------------------------------------------------------------------
// KDE Includes
#include <tdeglobal.h>
#include <tdelocale.h>
// ----------------------------------------------------------------------------
// Project Includes
#include "kmymoneylineedit.h"
kMyMoneyLineEdit::kMyMoneyLineEdit(TQWidget *w, const char* name, bool forceMonetaryDecimalSymbol, int alignment) :
KLineEdit(w, name),
m_forceMonetaryDecimalSymbol(forceMonetaryDecimalSymbol)
{
setAlignment(alignment);
}
kMyMoneyLineEdit::~kMyMoneyLineEdit()
{
}
void kMyMoneyLineEdit::resetText(void)
{
setText(m_text);
}
void kMyMoneyLineEdit::loadText(const TQString& text)
{
m_text = text;
setText(text);
}
void kMyMoneyLineEdit::focusOutEvent(TQFocusEvent *ev)
{
// if the current text is not in the list of
// possible completions, we have a new payee
// and signal that to the outside world.
if(text() != m_text) {
emit lineChanged(text());
}
KLineEdit::focusOutEvent(ev);
// force update of hint
if(text().isEmpty())
repaint();
}
void kMyMoneyLineEdit::keyReleaseEvent(TQKeyEvent* k)
{
if(m_forceMonetaryDecimalSymbol) {
if(k->state() & TQt::Keypad) {
if(k->key() == TQt::Key_Comma
|| k->key() == TQt::Key_Period) {
if(TDEGlobal::locale()->monetaryDecimalSymbol() == ",") {
TQKeyEvent newk(k->type(), TQt::Key_Comma, ',', k->state(), ",", k->isAutoRepeat(), k->count());
KLineEdit::keyReleaseEvent(&newk);
k->ignore();
return;
}
if(TDEGlobal::locale()->monetaryDecimalSymbol() == ".") {
TQKeyEvent newk(k->type(), TQt::Key_Comma, ',', k->state(), ".", k->isAutoRepeat(), k->count());
KLineEdit::keyReleaseEvent(&newk);
k->ignore();
return;
}
}
}
}
KLineEdit::keyReleaseEvent(k);
}
void kMyMoneyLineEdit::keyPressEvent(TQKeyEvent* k)
{
if(m_forceMonetaryDecimalSymbol) {
if(k->state() & TQt::Keypad) {
if(k->key() == TQt::Key_Comma
|| k->key() == TQt::Key_Period) {
if(TDEGlobal::locale()->monetaryDecimalSymbol() == ",") {
TQKeyEvent newk(k->type(), TQt::Key_Comma, ',', k->state(), ",", k->isAutoRepeat(), k->count());
KLineEdit::keyPressEvent(&newk);
k->ignore();
return;
}
if(TDEGlobal::locale()->monetaryDecimalSymbol() == ".") {
TQKeyEvent newk(k->type(), TQt::Key_Period, '.', k->state(), ".", k->isAutoRepeat(), k->count());
KLineEdit::keyPressEvent(&newk);
k->ignore();
return;
}
}
}
}
KLineEdit::keyPressEvent(k);
}
void kMyMoneyLineEdit::drawContents( TQPainter *p)
{
KLineEdit::drawContents(p);
if(text().isEmpty() && !m_hint.isEmpty() && !hasFocus()) {
const int innerMargin = 1;
// the following 5 lines are taken from TQLineEdit::drawContents()
TQRect cr = contentsRect();
TQFontMetrics fm = fontMetrics();
TQRect lineRect( cr.x() + innerMargin, cr.y() + (cr.height() - fm.height() + 1) / 2,
cr.width() - 2*innerMargin, fm.height() );
TQPoint topLeft = lineRect.topLeft() - TQPoint(0, -fm.ascent());
p->save();
TQFont f = p->font();
f.setItalic(true);
f.setWeight(TQFont::Light);
p->setFont(f);
p->setPen(palette().disabled().text());
p->drawText(topLeft, m_hint);
p->restore();
}
}
#include "kmymoneylineedit.moc"
|