File indexing completed on 2024-04-14 14:20:24

0001 /*
0002  * Definition of KRestrictedLine
0003  *
0004  * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public
0017  * License along with this library; if not, write to the Free
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019  *
0020  */
0021 
0022 #ifndef KRESTRICTEDLINE_H
0023 #define KRESTRICTEDLINE_H
0024 
0025 #include <klineedit.h>
0026 #include <kdelibs4support_export.h>
0027 
0028 class KRestrictedLinePrivate;
0029 /**
0030  * @short A line editor for restricted character sets.
0031  *
0032  * The KRestrictedLine widget is a variant of QLineEdit which
0033  * accepts only a restricted set of characters as input.
0034  * All other characters will be discarded and the signal invalidChar()
0035  * will be emitted for each of them.
0036  *
0037  * Valid characters can be passed as a QString to the constructor
0038  * or set afterwards via setValidChars().
0039  * The default key bindings of QLineEdit are still in effect.
0040  *
0041  * This is almost like setting a QRegExpValidator on a KLineEdit;
0042  * the difference is that with KRestrictedLine it can all be done in Qt designer.
0043  *
0044  * \image html krestrictedline.png "KDE Restricted Line Edit allowing all characters but 'o'"
0045  *
0046  * @author Michael Wiedmann <mw@miwie.in-berlin.de>
0047  *
0048  * @deprecated from KF 5.0. Use QLineEdit instead, with a QValidator
0049  */
0050 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KRestrictedLine : public KLineEdit
0051 {
0052     Q_OBJECT
0053     Q_PROPERTY(QString validChars READ validChars WRITE setValidChars)
0054 
0055 public:
0056 
0057     /**
0058      * Constructor
0059      *  @param parent   pointer to the parent widget
0060      */
0061     KDELIBS4SUPPORT_DEPRECATED explicit KRestrictedLine(QWidget *parent = nullptr);
0062 
0063     /**
0064      * Destructs the restricted line editor.
0065      */
0066     ~KRestrictedLine() override;
0067 
0068     /**
0069      * All characters in the string valid are treated as
0070      * acceptable characters.
0071      */
0072     void setValidChars(const QString &valid);
0073     /**
0074      * @return the string of acceptable characters.
0075      */
0076     QString validChars() const;
0077 
0078 Q_SIGNALS:
0079 
0080     /**
0081      * Emitted when an invalid character was typed.
0082      */
0083     void  invalidChar(int);
0084 
0085 protected:
0086     void keyPressEvent(QKeyEvent *e) override;
0087     void inputMethodEvent(QInputMethodEvent *e) override;
0088 
0089 private:
0090     KRestrictedLinePrivate *const d;
0091 };
0092 
0093 #endif // KRESTRICTEDLINE_H