qskinny/src/controls/QskTextInput.h

269 lines
7.3 KiB
C
Raw Normal View History

/******************************************************************************
2024-01-17 13:31:45 +00:00
* QSkinny - Copyright (C) The authors
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#ifndef QSK_TEXT_INPUT_H
#define QSK_TEXT_INPUT_H
#include "QskControl.h"
#include "QskGraphic.h"
2024-10-28 08:26:22 +00:00
#include "QskTextOptions.h"
class QValidator;
2024-02-19 14:51:55 +00:00
class QskFontRole;
class QSK_EXPORT QskTextInput : public QskControl
{
Q_OBJECT
Q_PROPERTY( QString inputText READ inputText WRITE setInputText NOTIFY inputTextChanged USER true )
Q_PROPERTY( QString labelText READ labelText WRITE setLabelText NOTIFY labelTextChanged )
Q_PROPERTY( QString hintText READ hintText
WRITE setHintText NOTIFY hintTextChanged )
Q_PROPERTY( QString supportingText READ supportingText
WRITE setSupportingText NOTIFY supportingTextChanged )
2024-02-19 14:51:55 +00:00
Q_PROPERTY( QskFontRole fontRole READ fontRole
WRITE setFontRole RESET resetFontRole NOTIFY fontRoleChanged )
Q_PROPERTY( QFont font READ font CONSTANT )
2020-07-15 14:17:50 +00:00
Q_PROPERTY( Qt::Alignment alignment READ alignment
2024-10-28 08:26:22 +00:00
WRITE setAlignment RESET resetAlignment NOTIFY alignmentChanged )
Q_PROPERTY( QskTextOptions::WrapMode wrapMode READ wrapMode
WRITE setWrapMode NOTIFY wrapModeChanged )
2018-04-13 14:32:48 +00:00
Q_PROPERTY( ActivationModes activationModes READ activationModes
WRITE setActivationModes NOTIFY activationModesChanged )
Q_PROPERTY( bool editing READ isEditing
WRITE setEditing NOTIFY editingChanged )
2018-06-02 15:10:41 +00:00
Q_PROPERTY( EchoMode echoMode READ echoMode
WRITE setEchoMode NOTIFY echoModeChanged )
Q_PROPERTY( QString passwordCharacter READ passwordCharacter
WRITE setPasswordCharacter RESET resetPasswordCharacter
NOTIFY passwordCharacterChanged )
Q_PROPERTY( int passwordMaskDelay READ passwordMaskDelay
WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay
NOTIFY passwordMaskDelayChanged )
2021-04-21 07:18:50 +00:00
Q_PROPERTY( bool panel READ hasPanel
2021-04-21 07:28:57 +00:00
WRITE setPanel NOTIFY panelChanged )
2021-04-21 07:18:50 +00:00
2024-10-07 12:46:55 +00:00
Q_PROPERTY( Emphasis emphasis READ emphasis
WRITE setEmphasis NOTIFY emphasisChanged )
using Inherited = QskControl;
2018-08-03 06:15:28 +00:00
public:
QSK_SUBCONTROLS( Panel, LeadingIcon, LabelText, InputText,
TrailingIconRipple, TrailingIcon, HintText, SupportingText,
CharacterCount )
QSK_STATES( ReadOnly, Editing, Selected, Error, TextPopulated )
2018-04-13 14:32:48 +00:00
2024-10-07 12:46:55 +00:00
enum Emphasis
{
LowEmphasis = -1,
NoEmphasis = 0,
};
Q_ENUM( Emphasis )
2018-04-13 14:32:48 +00:00
enum ActivationMode
{
NoActivation,
ActivationOnFocus = 1 << 0,
2018-04-13 14:32:48 +00:00
ActivationOnMouse = 1 << 1,
2018-04-18 08:46:11 +00:00
ActivationOnKey = 1 << 2,
ActivationOnInput = ActivationOnMouse | ActivationOnKey,
ActivationOnAll = ActivationOnFocus | ActivationOnMouse | ActivationOnKey
2018-04-13 14:32:48 +00:00
};
Q_ENUM( ActivationMode )
Q_DECLARE_FLAGS( ActivationModes, ActivationMode )
enum EchoMode
{
Normal,
NoEcho,
Password,
PasswordEchoOnEdit
};
2018-08-03 06:15:28 +00:00
Q_ENUM( EchoMode )
QskTextInput( QQuickItem* parent = nullptr );
QskTextInput( const QString&, QQuickItem* parent = nullptr ); // ### do we need this constructor?
2018-07-31 15:32:25 +00:00
~QskTextInput() override;
2018-06-02 15:10:41 +00:00
void setupFrom( const QQuickItem* );
2024-10-07 12:46:55 +00:00
void setEmphasis( Emphasis );
Emphasis emphasis() const;
QString inputText() const;
QString labelText() const;
QskGraphic leadingIcon() const;
void setLeadingIcon( const QskGraphic& );
void setHintText( const QString& );
QString hintText() const;
void setSupportingText( const QString& );
QString supportingText() const;
2021-04-21 07:18:50 +00:00
void setPanel( bool );
bool hasPanel() const;
2024-02-19 14:51:55 +00:00
void setFontRole( const QskFontRole& role );
void resetFontRole();
2024-02-19 14:51:55 +00:00
QskFontRole fontRole() const;
void setAlignment( Qt::Alignment );
void resetAlignment();
Qt::Alignment alignment() const;
2024-10-28 08:26:22 +00:00
void setWrapMode( QskTextOptions::WrapMode );
QskTextOptions::WrapMode wrapMode() const;
2018-04-13 14:32:48 +00:00
void setActivationModes( ActivationModes );
ActivationModes activationModes() const;
bool isEditing() const;
QFont font() const;
bool isReadOnly() const;
2018-08-03 06:15:28 +00:00
void setReadOnly( bool );
int cursorPosition() const;
void setCursorPosition( int );
int maxLength() const;
void setMaxLength( int );
QValidator* validator() const;
void setValidator( QValidator* );
QString inputMask() const;
void setInputMask( const QString& );
EchoMode echoMode() const;
void setEchoMode( EchoMode );
QString passwordCharacter() const;
void setPasswordCharacter( const QString& );
void resetPasswordCharacter();
int passwordMaskDelay() const;
void setPasswordMaskDelay( int );
void resetPasswordMaskDelay();
QString displayText() const;
QString preeditText() const;
bool overwriteMode() const;
void setOverwriteMode( bool );
bool hasAcceptableInput() const;
bool fixup();
2018-07-31 15:32:25 +00:00
QVariant inputMethodQuery( Qt::InputMethodQuery ) const override;
2022-03-24 07:10:29 +00:00
QVariant inputMethodQuery( Qt::InputMethodQuery, const QVariant& argument ) const;
bool canUndo() const;
bool canRedo() const;
Qt::InputMethodHints inputMethodHints() const;
void setInputMethodHints( Qt::InputMethodHints );
2018-04-09 08:05:59 +00:00
void ensureVisible( int position );
2024-10-07 12:46:55 +00:00
QskAspect::Variation effectiveVariation() const override;
2018-08-03 06:15:28 +00:00
public Q_SLOTS:
void setInputText( const QString& );
void setLabelText( const QString& );
2018-04-13 14:32:48 +00:00
void setEditing( bool );
2018-08-03 06:15:28 +00:00
Q_SIGNALS:
2024-10-07 12:46:55 +00:00
void emphasisChanged( Emphasis );
2018-04-13 14:32:48 +00:00
void editingChanged( bool );
void activationModesChanged();
void readOnlyChanged( bool );
2021-04-21 07:18:50 +00:00
void panelChanged( bool );
2018-04-13 14:32:48 +00:00
void inputTextChanged( const QString& );
void labelTextChanged( const QString& );
void displayTextChanged( const QString& );
2018-06-11 09:34:12 +00:00
void textEdited( const QString& );
void hintTextChanged( const QString& );
void supportingTextChanged( const QString& );
void fontRoleChanged();
void alignmentChanged();
2024-10-28 08:26:22 +00:00
void wrapModeChanged( QskTextOptions::WrapMode );
void overwriteModeChanged( bool );
void maximumLengthChanged( int );
void echoModeChanged( EchoMode );
void passwordMaskDelayChanged();
void passwordCharacterChanged();
void validatorChanged();
void inputMaskChanged( const QString& );
2018-08-03 06:15:28 +00:00
protected:
2018-07-31 15:32:25 +00:00
bool event( QEvent* ) override;
2018-07-31 15:32:25 +00:00
void inputMethodEvent( QInputMethodEvent* ) override;
2018-07-31 15:32:25 +00:00
void focusInEvent( QFocusEvent* ) override;
void focusOutEvent( QFocusEvent* ) override;
2018-04-03 18:15:20 +00:00
void hoverEnterEvent( QHoverEvent* ) override;
void hoverMoveEvent( QHoverEvent* ) override;
void hoverLeaveEvent( QHoverEvent* ) override;
2018-07-31 15:32:25 +00:00
void mousePressEvent( QMouseEvent* ) override;
void mouseMoveEvent( QMouseEvent* ) override;
void mouseReleaseEvent( QMouseEvent* ) override;
void mouseDoubleClickEvent( QMouseEvent* ) override;
2018-07-31 15:32:25 +00:00
void keyPressEvent( QKeyEvent* ) override;
void keyReleaseEvent( QKeyEvent* ) override;
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
2019-09-05 13:16:33 +00:00
void updateLayout() override;
2018-08-03 06:15:28 +00:00
void updateNode( QSGNode* ) override;
2018-08-03 06:15:28 +00:00
private:
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
2018-04-13 14:32:48 +00:00
Q_DECLARE_OPERATORS_FOR_FLAGS( QskTextInput::ActivationModes )
Q_DECLARE_METATYPE( QskTextInput::ActivationModes )
#endif