File indexing completed on 2024-05-12 05:07:58

0001 /*
0002     SPDX-FileCopyrightText: 2001 Felix Rodriguez <frodriguez@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002 Michael Edwardes <mte@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2006-2011 Thomas Baumgart <tbaumgart@kde.org>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KMYMONEYLINEEDIT_H
0009 #define KMYMONEYLINEEDIT_H
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 // ----------------------------------------------------------------------------
0015 // KDE Includes
0016 
0017 #include <KLineEdit>
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "kmm_base_widgets_export.h"
0023 
0024 /**
0025   * This class represents a special version of a KLineEdit object that
0026   * supports the display of a hint if the display area is empty. It also
0027   * overrides the comma key on the numeric keypad with the currently
0028   * selected monetaryDecimalSymbol if selected during creation of the object.
0029   *
0030   * @author Michael Edwardes
0031   * @author Thomas Baumgart
0032   */
0033 class QFocusEvent;
0034 class QKeyEvent;
0035 class KMM_BASE_WIDGETS_EXPORT KMyMoneyLineEdit : public KLineEdit
0036 {
0037     Q_OBJECT
0038 public:
0039     /**
0040       * @param w pointer to parent
0041       * @param forceMonetaryDecimalSymbol if @a true, the numeric keypad comma key will have a fixed
0042       *            value and does not follow the keyboard layout (default: @p false)
0043       * @param alignment Controls the alignment of the text. Default is Qt::AlignLeft | Qt::AlignVCenter.
0044       *                  See Qt::AlignmentFlags for other possible values.
0045       */
0046     explicit KMyMoneyLineEdit(QWidget *w = 0, bool forceMonetaryDecimalSymbol = false, Qt::Alignment alignment = (Qt::AlignLeft | Qt::AlignVCenter));
0047     ~KMyMoneyLineEdit();
0048 
0049     /**
0050       * This method is used to set the value of the widget back to
0051       * the one passed using loadText().
0052       */
0053     void resetText();
0054 
0055     /**
0056       * Do not select the text upon the next focus in event if
0057       * @p skipIt is set to @p true. When object is constructed,
0058       * the default is @p false.
0059       */
0060     void skipSelectAll(bool skipIt);
0061 
0062 public Q_SLOTS:
0063     void loadText(const QString& text);
0064 
0065 Q_SIGNALS:
0066     /**
0067       * This signal is emitted when the focus leaves the object and the text
0068       * has been changed. The new text is passed as @a str.
0069       */
0070     void lineChanged(const QString& str);
0071 
0072 protected:
0073     void focusOutEvent(QFocusEvent *ev) override;
0074     void focusInEvent(QFocusEvent *ev) override;
0075 
0076     /**
0077       * Overridden so that the period key on the numeric keypad always sends
0078       * out the currently selected monetary decimal symbol instead of the
0079       * key defined by the keymap.
0080       *
0081       * Example: If you have set the keymap (keyboard layout) as English, then
0082       * the numeric keypad will send a period but if you have set the keymap to
0083       * be German, the same key will send a comma.
0084       *
0085       * @param ev pointer to current QKeyEvent
0086       */
0087     void keyPressEvent(QKeyEvent* ev) override;
0088 
0089     /**
0090       * Overridden so that the period key on the numeric keypad always sends
0091       * out the currently selected monetary decimal symbol instead of the
0092       * key defined by the keymap.
0093       *
0094       * Example: If you have set the keymap (keyboard layout) as English, then
0095       * the numeric keypad will send a period but if you have set the keymap to
0096       * be German, the same key will send a comma.
0097       *
0098       * @param ev pointer to current QKeyEvent
0099       */
0100     void keyReleaseEvent(QKeyEvent* ev) override;
0101 
0102 private:
0103     /// \internal d-pointer class.
0104     class Private;
0105     /// \internal d-pointer instance.
0106     Private* const d;
0107 };
0108 
0109 #endif