qskinny/src/controls/QskTextInput.h

218 lines
5.7 KiB
C
Raw Normal View History

/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_TEXT_INPUT_H
#define QSK_TEXT_INPUT_H
#include "QskControl.h"
class QValidator;
class QSK_EXPORT QskTextInput : public QskControl
{
Q_OBJECT
Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged )
Q_PROPERTY( QString description READ description
WRITE setDescription NOTIFY descriptionChanged )
Q_PROPERTY( int fontRole READ fontRole
WRITE setFontRole RESET resetFontRole NOTIFY fontRoleChanged )
2020-07-15 16:17:50 +02:00
Q_PROPERTY( QFont font READ font )
Q_PROPERTY( Qt::Alignment alignment READ alignment
WRITE setAlignment NOTIFY alignmentChanged )
2018-04-13 16:32:48 +02:00
Q_PROPERTY( ActivationModes activationModes READ activationModes
WRITE setActivationModes NOTIFY activationModesChanged )
Q_PROPERTY( bool editing READ isEditing
WRITE setEditing NOTIFY editingChanged )
2018-06-02 17:10:41 +02: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 09:18:50 +02:00
Q_PROPERTY( bool panel READ hasPanel
2021-04-21 09:28:57 +02:00
WRITE setPanel NOTIFY panelChanged )
2021-04-21 09:18:50 +02:00
using Inherited = QskControl;
2018-08-03 08:15:28 +02:00
public:
2018-04-18 10:46:11 +02:00
QSK_SUBCONTROLS( Panel, Text, PanelSelected, TextSelected )
2018-04-13 16:32:48 +02:00
QSK_STATES( ReadOnly, Editing )
enum ActivationMode
{
NoActivation,
ActivationOnFocus = 1 << 0,
2018-04-13 16:32:48 +02:00
ActivationOnMouse = 1 << 1,
2018-04-18 10:46:11 +02:00
ActivationOnKey = 1 << 2,
ActivationOnInput = ActivationOnMouse | ActivationOnKey,
ActivationOnAll = ActivationOnFocus | ActivationOnMouse | ActivationOnKey
2018-04-13 16:32:48 +02:00
};
Q_ENUM( ActivationMode )
Q_DECLARE_FLAGS( ActivationModes, ActivationMode )
enum EchoMode
{
Normal,
NoEcho,
Password,
PasswordEchoOnEdit
};
2018-08-03 08:15:28 +02:00
Q_ENUM( EchoMode )
QskTextInput( QQuickItem* parent = nullptr );
QskTextInput( const QString& text, QQuickItem* parent = nullptr );
2018-07-31 17:32:25 +02:00
~QskTextInput() override;
2018-06-02 17:10:41 +02:00
void setupFrom( const QQuickItem* );
QString text() const;
void setDescription( const QString& );
QString description() const;
2021-04-21 09:18:50 +02:00
void setPanel( bool );
bool hasPanel() const;
void setFontRole( int role );
void resetFontRole();
int fontRole() const;
void setAlignment( Qt::Alignment );
void resetAlignment();
Qt::Alignment alignment() const;
2018-04-13 16:32:48 +02:00
void setActivationModes( ActivationModes );
ActivationModes activationModes() const;
bool isEditing() const;
QFont font() const;
bool isReadOnly() const;
2018-08-03 08:15:28 +02: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 17:32:25 +02:00
QVariant inputMethodQuery( Qt::InputMethodQuery ) const override;
2018-08-03 08:15:28 +02:00
QVariant inputMethodQuery( Qt::InputMethodQuery, QVariant argument ) const;
bool canUndo() const;
bool canRedo() const;
Qt::InputMethodHints inputMethodHints() const;
void setInputMethodHints( Qt::InputMethodHints );
2018-04-09 10:05:59 +02:00
void ensureVisible( int position );
2018-08-03 08:15:28 +02:00
public Q_SLOTS:
void setText( const QString& );
2018-04-13 16:32:48 +02:00
void setEditing( bool );
2018-08-03 08:15:28 +02:00
Q_SIGNALS:
2018-04-13 16:32:48 +02:00
void editingChanged( bool );
void activationModesChanged();
void readOnlyChanged( bool );
2021-04-21 09:18:50 +02:00
void panelChanged( bool );
2018-04-13 16:32:48 +02:00
void textChanged( const QString& );
void displayTextChanged( const QString& );
2018-06-11 11:34:12 +02:00
void textEdited( const QString& );
void descriptionChanged( const QString& );
void textOptionsChanged();
void fontRoleChanged();
void alignmentChanged();
void overwriteModeChanged( bool );
void maximumLengthChanged( int );
void echoModeChanged( EchoMode );
void passwordMaskDelayChanged();
void passwordCharacterChanged();
void validatorChanged();
void inputMaskChanged( const QString& );
2018-08-03 08:15:28 +02:00
protected:
2018-07-31 17:32:25 +02:00
bool event( QEvent* ) override;
2018-07-31 17:32:25 +02:00
void inputMethodEvent( QInputMethodEvent* ) override;
2018-07-31 17:32:25 +02:00
void focusInEvent( QFocusEvent* ) override;
void focusOutEvent( QFocusEvent* ) override;
2018-04-03 20:15:20 +02:00
2018-07-31 17:32:25 +02:00
void mousePressEvent( QMouseEvent* ) override;
void mouseMoveEvent( QMouseEvent* ) override;
void mouseReleaseEvent( QMouseEvent* ) override;
void mouseDoubleClickEvent( QMouseEvent* ) override;
2018-07-31 17:32:25 +02:00
void keyPressEvent( QKeyEvent* ) override;
void keyReleaseEvent( QKeyEvent* ) override;
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
2019-09-05 15:16:33 +02:00
void updateLayout() override;
2018-08-03 08:15:28 +02:00
void updateNode( QSGNode* ) override;
2018-08-03 08:15:28 +02:00
private:
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
2018-04-13 16:32:48 +02:00
Q_DECLARE_OPERATORS_FOR_FLAGS( QskTextInput::ActivationModes )
Q_DECLARE_METATYPE( QskTextInput::ActivationModes )
#endif