QskTextInput improved
This commit is contained in:
parent
5d9f22a757
commit
3f8616c084
@ -146,6 +146,11 @@ void QskInputCompositionModel::composeKey( int key )
|
||||
|
||||
return;
|
||||
}
|
||||
case Qt::Key_Escape:
|
||||
{
|
||||
sendKeyEvents( Qt::Key_Escape );
|
||||
return;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if ( !spaceLeft )
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
auto* textInput2 = new QskTextInput( this );
|
||||
textInput2->setText( "Press and edit Me." );
|
||||
textInput2->setSizePolicy( Qt::Horizontal, QskSizePolicy::Preferred );
|
||||
textInput2->setActivationModes( QskTextInput::ActivationOnAll );
|
||||
|
||||
auto* textInput3 = new QskTextInput( this );
|
||||
textInput3->setReadOnly( true );
|
||||
|
@ -202,6 +202,8 @@ void QskMaterialSkin::initTextInputHints()
|
||||
const ColorPalette& pal = m_data->palette;
|
||||
|
||||
setColor( Q::Text, pal.textColor );
|
||||
setColor( Q::PanelSelected, pal.accentColor );
|
||||
setColor( Q::TextSelected, pal.contrastColor );
|
||||
|
||||
setMargins( Q::Panel | Padding, 5 );
|
||||
setBoxShape( Q::Panel, 4 );
|
||||
|
@ -308,6 +308,8 @@ void QskSquiekSkin::initTextInputHints()
|
||||
static_cast<int>( Qt::AlignLeft | Qt::AlignTop ) );
|
||||
|
||||
setColor( Q::Text, pal.themeForeground );
|
||||
setColor( Q::PanelSelected, pal.highlighted );
|
||||
setColor( Q::TextSelected, pal.highlightedText );
|
||||
|
||||
setMargins( Q::Panel | Padding, 5 );
|
||||
setBoxBorderMetrics( Q::Panel, 2 );
|
||||
|
@ -21,6 +21,8 @@ QSK_QT_PRIVATE_END
|
||||
|
||||
QSK_SUBCONTROL( QskTextInput, Panel )
|
||||
QSK_SUBCONTROL( QskTextInput, Text )
|
||||
QSK_SUBCONTROL( QskTextInput, PanelSelected )
|
||||
QSK_SUBCONTROL( QskTextInput, TextSelected )
|
||||
|
||||
QSK_STATE( QskTextInput, ReadOnly, QskAspect::FirstSystemState << 1 )
|
||||
QSK_STATE( QskTextInput, Editing, QskAspect::FirstSystemState << 2 )
|
||||
@ -70,6 +72,8 @@ namespace
|
||||
{
|
||||
class TextInput final : public QQuickTextInput
|
||||
{
|
||||
using Inherited = QQuickTextInput;
|
||||
|
||||
public:
|
||||
TextInput( QskTextInput* );
|
||||
|
||||
@ -94,13 +98,19 @@ namespace
|
||||
return isAcceptable;
|
||||
}
|
||||
|
||||
inline bool handleEvent( QEvent* event ) { return this->event( event ); }
|
||||
void updateColors();
|
||||
void updateMetrics();
|
||||
|
||||
inline bool handleEvent( QEvent* event )
|
||||
{
|
||||
return this->event( event );
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void geometryChanged(
|
||||
const QRectF& newGeometry, const QRectF& oldGeometry ) override
|
||||
{
|
||||
QQuickTextInput::geometryChanged( newGeometry, oldGeometry );
|
||||
Inherited::geometryChanged( newGeometry, oldGeometry );
|
||||
updateClip();
|
||||
}
|
||||
|
||||
@ -109,6 +119,13 @@ namespace
|
||||
setClip( ( contentWidth() > width() ) ||
|
||||
( contentHeight() > height() ) );
|
||||
}
|
||||
|
||||
virtual QSGNode* updatePaintNode(
|
||||
QSGNode *oldNode, UpdatePaintNodeData* data ) override
|
||||
{
|
||||
updateColors();
|
||||
return Inherited::updatePaintNode( oldNode, data );
|
||||
}
|
||||
};
|
||||
|
||||
TextInput::TextInput( QskTextInput* textInput ):
|
||||
@ -134,6 +151,7 @@ namespace
|
||||
return;
|
||||
|
||||
setCursorVisible( on );
|
||||
d->setBlinkingCursorEnabled( on );
|
||||
|
||||
if ( !on )
|
||||
{
|
||||
@ -151,6 +169,55 @@ namespace
|
||||
polish();
|
||||
update();
|
||||
}
|
||||
|
||||
void TextInput::updateMetrics()
|
||||
{
|
||||
auto input = static_cast< const QskTextInput* >( parentItem() );
|
||||
|
||||
setAlignment( input->alignment() );
|
||||
setFont( input->font() );
|
||||
}
|
||||
|
||||
void TextInput::updateColors()
|
||||
{
|
||||
auto input = static_cast< const QskTextInput* >( parentItem() );
|
||||
auto d = QQuickTextInputPrivate::get( this );
|
||||
|
||||
bool isDirty = false;
|
||||
|
||||
QColor color;
|
||||
|
||||
color = input->color( QskTextInput::Text );
|
||||
if ( d->color != color )
|
||||
{
|
||||
d->color = color;
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
if ( d->hasSelectedText() )
|
||||
{
|
||||
color = input->color( QskTextInput::PanelSelected );
|
||||
if ( d->selectionColor != color )
|
||||
{
|
||||
d->selectionColor = color;
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
color = input->color( QskTextInput::TextSelected );
|
||||
if ( d->selectedTextColor != color )
|
||||
{
|
||||
d->selectedTextColor = color;
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isDirty )
|
||||
{
|
||||
d->textLayoutDirty = true;
|
||||
d->updateType = QQuickTextInputPrivate::UpdatePaintNode;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class QskTextInput::PrivateData
|
||||
@ -216,20 +283,32 @@ void QskTextInput::keyPressEvent( QKeyEvent* event )
|
||||
{
|
||||
if ( isEditing() )
|
||||
{
|
||||
if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return )
|
||||
switch( event->key() )
|
||||
{
|
||||
if ( m_data->textInput->fixup() )
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
{
|
||||
auto inputMethod = QGuiApplication::inputMethod();
|
||||
inputMethod->commit();
|
||||
|
||||
if ( !( inputMethodHints() & Qt::ImhMultiLine) )
|
||||
setEditing( false );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data->textInput->handleEvent( event );
|
||||
if ( m_data->textInput->fixup() )
|
||||
{
|
||||
QGuiApplication::inputMethod()->commit();
|
||||
|
||||
if ( !( inputMethodHints() & Qt::ImhMultiLine) )
|
||||
setEditing( false );
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if 1
|
||||
case Qt::Key_Escape:
|
||||
{
|
||||
QGuiApplication::inputMethod()->hide();
|
||||
setEditing( false );
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
m_data->textInput->handleEvent( event );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@ -285,6 +364,19 @@ void QskTextInput::inputMethodEvent( QInputMethodEvent* event )
|
||||
|
||||
void QskTextInput::focusInEvent( QFocusEvent* event )
|
||||
{
|
||||
if ( m_data->activationModes & ActivationOnFocus )
|
||||
{
|
||||
switch( event->reason() )
|
||||
{
|
||||
case Qt::ActiveWindowFocusReason:
|
||||
case Qt::PopupFocusReason:
|
||||
break;
|
||||
|
||||
default:
|
||||
setEditing( true );
|
||||
}
|
||||
}
|
||||
|
||||
Inherited::focusInEvent( event );
|
||||
}
|
||||
|
||||
@ -315,8 +407,12 @@ QSizeF QskTextInput::contentsSizeHint() const
|
||||
{
|
||||
using namespace QskAspect;
|
||||
|
||||
const qreal w = m_data->textInput->implicitWidth();
|
||||
const qreal h = m_data->textInput->implicitHeight();
|
||||
auto input = m_data->textInput;
|
||||
|
||||
input->updateMetrics();
|
||||
|
||||
const qreal w = input->implicitWidth();
|
||||
const qreal h = input->implicitHeight();
|
||||
|
||||
const QSizeF minSize( metric( Panel | MinimumWidth ),
|
||||
metric( Panel | MinimumHeight ) );
|
||||
@ -328,12 +424,16 @@ void QskTextInput::updateLayout()
|
||||
{
|
||||
auto input = m_data->textInput;
|
||||
|
||||
input->setAlignment( alignment() );
|
||||
input->setFont( font() );
|
||||
|
||||
input->updateMetrics();
|
||||
qskSetItemGeometry( input, subControlRect( Text ) );
|
||||
}
|
||||
|
||||
void QskTextInput::updateNode( QSGNode* node )
|
||||
{
|
||||
m_data->textInput->updateColors();
|
||||
Inherited::updateNode( node );
|
||||
}
|
||||
|
||||
QString QskTextInput::text() const
|
||||
{
|
||||
return m_data->textInput->text();
|
||||
|
@ -31,7 +31,7 @@ class QSK_EXPORT QskTextInput : public QskControl
|
||||
using Inherited = QskControl;
|
||||
|
||||
public:
|
||||
QSK_SUBCONTROLS( Panel, Text )
|
||||
QSK_SUBCONTROLS( Panel, Text, PanelSelected, TextSelected )
|
||||
QSK_STATES( ReadOnly, Editing )
|
||||
|
||||
enum ActivationMode
|
||||
@ -40,7 +40,10 @@ public:
|
||||
|
||||
ActivationOnFocus = 1 << 0 ,
|
||||
ActivationOnMouse = 1 << 1,
|
||||
ActivationOnKey = 1 << 2
|
||||
ActivationOnKey = 1 << 2,
|
||||
|
||||
ActivationOnInput = ActivationOnMouse | ActivationOnKey,
|
||||
ActivationOnAll = ActivationOnFocus | ActivationOnMouse | ActivationOnKey
|
||||
};
|
||||
|
||||
Q_ENUM( ActivationMode )
|
||||
@ -156,6 +159,7 @@ protected:
|
||||
virtual void keyReleaseEvent( QKeyEvent* ) override;
|
||||
|
||||
virtual void updateLayout() override;
|
||||
virtual void updateNode( QSGNode*) override;
|
||||
|
||||
private:
|
||||
class PrivateData;
|
||||
|
Loading…
x
Reference in New Issue
Block a user