File indexing completed on 2024-05-12 16:44:04

0001 /*
0002     SPDX-FileCopyrightText: 2013-2014 Christian Dávid <christian-david@web.de>
0003     SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KMYMONEYTEXTEDITHIGHLIGHTER_H
0008 #define KMYMONEYTEXTEDITHIGHLIGHTER_H
0009 
0010 #include <KTextEdit>
0011 #include "kmm_widgets_export.h"
0012 
0013 /**
0014  * @brief KTextEdit with restricted character set and length
0015  *
0016  * Used to set constraints on input. It allows to set readOnly property by
0017  * slots as well (not possible with KTextEdit).
0018  */
0019 class KMyMoneyTextEditPrivate;
0020 class KMM_WIDGETS_EXPORT KMyMoneyTextEdit : public KTextEdit
0021 {
0022     Q_OBJECT
0023     Q_DISABLE_COPY(KMyMoneyTextEdit)
0024 
0025     /**
0026      * @brief Maximal number of characters allowed
0027      */
0028     Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
0029 
0030     /**
0031      * @brief Maximal number of characters allowed per line
0032      */
0033     Q_PROPERTY(int maxLineLength READ maxLineLength WRITE setMaxLineLength)
0034 
0035     /**
0036      * @brief Maximal number of lines
0037      */
0038     Q_PROPERTY(int maxLines READ maxLines WRITE setMaxLines)
0039 
0040     /**
0041      * @brief List of all allowed chars
0042      */
0043     Q_PROPERTY(QString allowedChars READ allowedChars WRITE setAllowedChars)
0044 
0045     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
0046 
0047 public:
0048     explicit KMyMoneyTextEdit(QWidget* parent = nullptr);
0049     ~KMyMoneyTextEdit();
0050 
0051     int maxLength() const;
0052     int maxLineLength() const;
0053     int maxLines() const;
0054     QString allowedChars() const;
0055     bool isValid() const;
0056 
0057 public Q_SLOTS:
0058     void setMaxLength(const int& maxLength);
0059     void setMaxLineLength(const int& maxLineLength);
0060     void setMaxLines(const int& maxLines);
0061     void setAllowedChars(const QString& allowedChars);
0062 
0063     /** @brief Slot to set this text edit read only */
0064     void setReadOnly(bool) override;
0065 
0066 protected:
0067     virtual void keyReleaseEvent(QKeyEvent* e) override;
0068     virtual void keyPressEvent(QKeyEvent* e) override;
0069 
0070 private:
0071     KMyMoneyTextEditPrivate * const d_ptr;
0072     Q_DECLARE_PRIVATE(KMyMoneyTextEdit)
0073 };
0074 
0075 #endif // KMYMONEYTEXTEDITHIGHLIGHTER_H