File indexing completed on 2024-04-21 05:51:35
0001 /* 0002 * SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-only 0005 **/ 0006 0007 #ifndef characterswidget 0008 #define characterswidget 0009 0010 #include <QDialog> 0011 0012 #include "kmultiformlistbox.h" 0013 #include "kmultiformlistboxfactory.h" 0014 #include "regexpwidget.h" 0015 0016 class CharacterEdits; 0017 class TextRangeRegExp; 0018 class CharSelector; 0019 class QCheckBox; 0020 0021 /** 0022 RegExp widget for charcter ranges. 0023 @internal 0024 */ 0025 class CharactersWidget : public RegExpWidget 0026 { 0027 public: 0028 CharactersWidget(RegExpEditorWindow *editorWindow, QWidget *parent); 0029 CharactersWidget(TextRangeRegExp *regexp, RegExpEditorWindow *editorWindow, QWidget *parent); 0030 ~CharactersWidget() override; 0031 QSize sizeHint() const override; 0032 RegExp *regExp() const override; 0033 RegExpType type() const override 0034 { 0035 return CHARSET; 0036 } 0037 0038 RegExpWidget *findWidgetToEdit(QPointF globalPos) override; 0039 int edit() override; 0040 0041 protected: 0042 void paintEvent(QPaintEvent *event) override; 0043 QString text() const; 0044 QString title() const; 0045 0046 private: 0047 TextRangeRegExp *_regexp = nullptr; 0048 static CharacterEdits *_configWindow; 0049 0050 mutable QSize _textSize; 0051 mutable QSize _contentSize; 0052 }; 0053 0054 /** 0055 @internal 0056 */ 0057 class SingleEntry : public KMultiFormListBoxEntry 0058 { 0059 public: 0060 explicit SingleEntry(QWidget *parent); 0061 QString text() const; 0062 void setText(const QString &text); 0063 bool isEmpty() const; 0064 0065 private: 0066 CharSelector *_selector = nullptr; 0067 }; 0068 0069 /** 0070 @internal 0071 */ 0072 class RangeEntry : public KMultiFormListBoxEntry 0073 { 0074 public: 0075 explicit RangeEntry(QWidget *parent); 0076 QString fromText() const; 0077 QString toText() const; 0078 void setFrom(const QString &text); 0079 void setTo(const QString &text); 0080 bool isEmpty() const; 0081 0082 private: 0083 CharSelector *_from = nullptr; 0084 CharSelector *_to = nullptr; 0085 }; 0086 0087 /** 0088 @internal 0089 */ 0090 class SingleFactory : public KMultiFormListBoxFactory 0091 { 0092 public: 0093 KMultiFormListBoxEntry *create(QWidget *parent) override 0094 { 0095 return new SingleEntry(parent); 0096 } 0097 0098 QWidget *separator(QWidget *) override 0099 { 0100 return nullptr; 0101 } 0102 }; 0103 0104 /** 0105 @internal 0106 */ 0107 class RangeFactory : public KMultiFormListBoxFactory 0108 { 0109 public: 0110 KMultiFormListBoxEntry *create(QWidget *parent) override 0111 { 0112 return new RangeEntry(parent); 0113 } 0114 0115 QWidget *separator(QWidget *) override 0116 { 0117 return nullptr; 0118 } 0119 }; 0120 0121 /** 0122 @internal 0123 */ 0124 class CharacterEdits : public QDialog 0125 { 0126 Q_OBJECT 0127 public: 0128 explicit CharacterEdits(QWidget *parent = nullptr); 0129 0130 public Q_SLOTS: 0131 void setRegexp(TextRangeRegExp *regexp); 0132 0133 protected Q_SLOTS: 0134 void slotOK(); 0135 0136 private: 0137 QCheckBox *negate = nullptr; 0138 QCheckBox *wordChar = nullptr; 0139 QCheckBox *_nonWordChar = nullptr; 0140 QCheckBox *digit = nullptr; 0141 QCheckBox *_nonDigit = nullptr; 0142 QCheckBox *space = nullptr; 0143 QCheckBox *_nonSpace = nullptr; 0144 KMultiFormListBox *_single = nullptr; 0145 KMultiFormListBox *_range = nullptr; 0146 0147 void addCharacter(const QString &txt); 0148 void addRange(const QString &from, const QString &to); 0149 TextRangeRegExp *_regexp = nullptr; 0150 }; 0151 0152 #endif // characterswidget