QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTextInput.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_TEXT_INPUT_H
7#define QSK_TEXT_INPUT_H
8
9#include "QskControl.h"
10#include "QskTextOptions.h"
11
12class QValidator;
13class QskFontRole;
14
15class QSK_EXPORT QskTextInput : public QskControl
16{
17 Q_OBJECT
18
19 Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged USER true)
20
21 Q_PROPERTY( QString description READ description
22 WRITE setDescription NOTIFY descriptionChanged )
23
24 Q_PROPERTY( QskFontRole fontRole READ fontRole
25 WRITE setFontRole RESET resetFontRole NOTIFY fontRoleChanged )
26
27 Q_PROPERTY( QFont font READ font )
28
29 Q_PROPERTY( Qt::Alignment alignment READ alignment
30 WRITE setAlignment RESET resetAlignment NOTIFY alignmentChanged )
31
32 Q_PROPERTY( QskTextOptions::WrapMode wrapMode READ wrapMode
33 WRITE setWrapMode NOTIFY wrapModeChanged )
34
35 Q_PROPERTY( ActivationModes activationModes READ activationModes
36 WRITE setActivationModes NOTIFY activationModesChanged )
37
38 Q_PROPERTY( bool editing READ isEditing
39 WRITE setEditing NOTIFY editingChanged )
40
41 Q_PROPERTY( EchoMode echoMode READ echoMode
42 WRITE setEchoMode NOTIFY echoModeChanged )
43
44 Q_PROPERTY( QString passwordCharacter READ passwordCharacter
45 WRITE setPasswordCharacter RESET resetPasswordCharacter
46 NOTIFY passwordCharacterChanged )
47
48 Q_PROPERTY( int passwordMaskDelay READ passwordMaskDelay
49 WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay
50 NOTIFY passwordMaskDelayChanged )
51
52 Q_PROPERTY( bool panel READ hasPanel
53 WRITE setPanel NOTIFY panelChanged )
54
55 using Inherited = QskControl;
56
57 public:
58 QSK_SUBCONTROLS( Panel, Text, PanelSelected, TextSelected )
59 QSK_STATES( ReadOnly, Editing )
60
61 enum ActivationMode
62 {
63 NoActivation,
64
65 ActivationOnFocus = 1 << 0,
66 ActivationOnMouse = 1 << 1,
67 ActivationOnKey = 1 << 2,
68
69 ActivationOnInput = ActivationOnMouse | ActivationOnKey,
70 ActivationOnAll = ActivationOnFocus | ActivationOnMouse | ActivationOnKey
71 };
72
73 Q_ENUM( ActivationMode )
74 Q_DECLARE_FLAGS( ActivationModes, ActivationMode )
75
76 enum EchoMode
77 {
78 Normal,
79 NoEcho,
80 Password,
81 PasswordEchoOnEdit
82 };
83
84 Q_ENUM( EchoMode )
85
86 QskTextInput( QQuickItem* parent = nullptr );
87 QskTextInput( const QString& text, QQuickItem* parent = nullptr );
88
89 ~QskTextInput() override;
90
91 void setupFrom( const QQuickItem* );
92
93 QString text() const;
94
95 void setDescription( const QString& );
96 QString description() const;
97
98 void setPanel( bool );
99 bool hasPanel() const;
100
101 void setFontRole( const QskFontRole& role );
102 void resetFontRole();
103 QskFontRole fontRole() const;
104
105 void setAlignment( Qt::Alignment );
106 void resetAlignment();
107 Qt::Alignment alignment() const;
108
109 void setWrapMode( QskTextOptions::WrapMode );
110 QskTextOptions::WrapMode wrapMode() const;
111
112 void setActivationModes( ActivationModes );
113 ActivationModes activationModes() const;
114
115 bool isEditing() const;
116
117 QFont font() const;
118
119 bool isReadOnly() const;
120 void setReadOnly( bool );
121
122 int cursorPosition() const;
123 void setCursorPosition( int );
124
125 int maxLength() const;
126 void setMaxLength( int );
127
128 QValidator* validator() const;
129 void setValidator( QValidator* );
130
131 QString inputMask() const;
132 void setInputMask( const QString& );
133
134 EchoMode echoMode() const;
135 void setEchoMode( EchoMode );
136
137 QString passwordCharacter() const;
138 void setPasswordCharacter( const QString& );
139 void resetPasswordCharacter();
140
141 int passwordMaskDelay() const;
142 void setPasswordMaskDelay( int );
143 void resetPasswordMaskDelay();
144
145 QString displayText() const;
146 QString preeditText() const;
147
148 bool overwriteMode() const;
149 void setOverwriteMode( bool );
150
151 bool hasAcceptableInput() const;
152 bool fixup();
153
154 QVariant inputMethodQuery( Qt::InputMethodQuery ) const override;
155 QVariant inputMethodQuery( Qt::InputMethodQuery, const QVariant& argument ) const;
156
157 bool canUndo() const;
158 bool canRedo() const;
159
160 Qt::InputMethodHints inputMethodHints() const;
161 void setInputMethodHints( Qt::InputMethodHints );
162
163 void ensureVisible( int position );
164
165 public Q_SLOTS:
166 void setText( const QString& );
167 void setEditing( bool );
168
169 Q_SIGNALS:
170 void editingChanged( bool );
171
172 void activationModesChanged();
173 void readOnlyChanged( bool );
174 void panelChanged( bool );
175
176 void textChanged( const QString& );
177 void displayTextChanged( const QString& );
178
179 void textEdited( const QString& );
180 void descriptionChanged( const QString& );
181
182 void fontRoleChanged();
183 void alignmentChanged();
184 void wrapModeChanged( QskTextOptions::WrapMode );
185
186 void overwriteModeChanged( bool );
187 void maximumLengthChanged( int );
188
189 void echoModeChanged( EchoMode );
190 void passwordMaskDelayChanged();
191 void passwordCharacterChanged();
192
193 void validatorChanged();
194 void inputMaskChanged( const QString& );
195
196 protected:
197 bool event( QEvent* ) override;
198
199 void inputMethodEvent( QInputMethodEvent* ) override;
200
201 void focusInEvent( QFocusEvent* ) override;
202 void focusOutEvent( QFocusEvent* ) override;
203
204 void mousePressEvent( QMouseEvent* ) override;
205 void mouseMoveEvent( QMouseEvent* ) override;
206 void mouseReleaseEvent( QMouseEvent* ) override;
207 void mouseDoubleClickEvent( QMouseEvent* ) override;
208
209 void keyPressEvent( QKeyEvent* ) override;
210 void keyReleaseEvent( QKeyEvent* ) override;
211
212 QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
213
214 void updateLayout() override;
215 void updateNode( QSGNode* ) override;
216
217 private:
218 class PrivateData;
219 std::unique_ptr< PrivateData > m_data;
220};
221
222Q_DECLARE_OPERATORS_FOR_FLAGS( QskTextInput::ActivationModes )
223Q_DECLARE_METATYPE( QskTextInput::ActivationModes )
224
225#endif
Base class of all controls.
Definition QskControl.h:23
virtual void updateNode(QSGNode *)