summaryrefslogtreecommitdiffstats
path: root/kmymoney2/widgets/kmymoneylineedit.h
blob: 99aa1f307bbc9fb51a95a44a61b1248b91d7596b (plain)
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
/***************************************************************************
                          kmymoneylineedit.h  -  description
                             -------------------
    begin                : Wed May 9 2001
    copyright            : (C) 2001 by Michael Edwardes
                               2006 by Thomas Baumgart
    email                : mte@users.sourceforge.net
                           Javier Campos Morales <javi_c@ctv.es>
                           Felix Rodriguez <frodriguez@mail.wesleyan.edu>
                           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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KMYMONEYLINEEDIT_H
#define KMYMONEYLINEEDIT_H

// ----------------------------------------------------------------------------
// QT Includes

// ----------------------------------------------------------------------------
// KDE Includes

#include <klineedit.h>

// ----------------------------------------------------------------------------
// Project Includes

/**
  * This class represents a special verson of a KLineEdit object that
  * supports the display of a hint if the display area is empty. It also
  * overrides the comma key on the numeric keypad with the currently
  * selected monetaryDecimalSymbol if selected during creation of the object.
  *
  * @author Michael Edwardes
  * @author Thomas Baumgart
  */
class kMyMoneyLineEdit : public KLineEdit
{
  TQ_OBJECT
  
public:
  /**
    * @param w pointer to parent
    * @param name pointer to name of object
    * @param forceMonetaryDecimalSymbol if @a true, the numeric keypad comma key will have a fixed
    *            value and does not follow the keyboard layout (default: @p false)
    * @param alignment Controls the alignment of the text. Default is TQt::AlignLeft | TQt::AlignVCenter.
    *                  See TQt::AlignmentFlags for other possible values.
    */
  kMyMoneyLineEdit(TQWidget *w = 0, const char* name = 0, bool forceMonetaryDecimalSymbol = false, int alignment = (AlignLeft | AlignVCenter));
  ~kMyMoneyLineEdit();

  /**
    * This method is used to set the value of the widget back to
    * the one passed using loadText().
    */
  void resetText(void);

  /**
   * This method is used to turn on/off the hint display
   */
  void setHint(const TQString& hint) { m_hint = hint; };


public slots:
  void loadText(const TQString& text);

signals:
  /**
    * This signal is emitted when the focus leaves the object and the text
    * has been changed. The new text is passed as @a str.
    */
  void lineChanged(const TQString& str);

protected:
  void focusOutEvent(TQFocusEvent *ev);

  /** reimplemented to support the hint display */
  void drawContents( TQPainter *);

  /**
    * Overridden so that the period key on the numeric keypad always sends
    * out the currently selected monetary decimal symbol instead of the
    * key defined by the keymap.
    *
    * Example: If you have set the keymap (keyboard layout) as English, then
    * the numeric keypad will send a period but if you have set the keymap to
    * be German, the same key will send a comma.
    *
    * @param ev pointer to current TQKeyEvent
    */
  void keyPressEvent(TQKeyEvent* ev);

  /**
    * Overridden so that the period key on the numeric keypad always sends
    * out the currently selected monetary decimal symbol instead of the
    * key defined by the keymap.
    *
    * Example: If you have set the keymap (keyboard layout) as English, then
    * the numeric keypad will send a period but if you have set the keymap to
    * be German, the same key will send a comma.
    *
    * @param ev pointer to current TQKeyEvent
    */
  void keyReleaseEvent(TQKeyEvent* ev);

private:
  /**
    * This member keeps the initial value. It is used during
    * resetText() to set the widgets text back to this initial value
    * and as comparison during focusOutEvent() to emit the lineChanged
    * signal if the current text is different.
    */
  TQString m_text;

  /**
    * This member tells what to display as hint as long as the field is empty
    */
  TQString m_hint;

  /**
    * This member keeps the status if overriding the numeric keypad comma key
    * is requested or not.
    */
  bool m_forceMonetaryDecimalSymbol;
};

#endif