6#include "QskInputPanelBox.h"
7#include "QskInputPredictionBar.h"
8#include "QskLinearBox.h"
9#include "QskTextInput.h"
10#include "QskTextLabel.h"
11#include "QskVirtualKeyboard.h"
21 TextInputProxy(
QskInputPanelBox* panelBox, QQuickItem* parentItem =
nullptr )
23 , m_panelBox( panelBox )
25 setObjectName( QStringLiteral(
"InputBoxProxy" ) );
27 setFocusPolicy( Qt::NoFocus );
35 if ( subControl == QskTextInput::Panel )
36 return m_panelBox->effectiveSubcontrol( QskInputPanelBox::ProxyPanel );
38 if ( subControl == QskTextInput::Text )
39 return m_panelBox->effectiveSubcontrol( QskInputPanelBox::ProxyText );
44 void focusInEvent( QFocusEvent* )
override
48 void focusOutEvent( QFocusEvent* )
override
61class QskInputPanelBox::PrivateData
64 QPointer< QQuickItem > inputItem;
68 TextInputProxy* inputProxy;
72 QskInputPanelBox::PanelHints panelHints = QskInputPanelBox::InputProxy;
75QskInputPanelBox::QskInputPanelBox( QQuickItem* parent )
77 , m_data( new PrivateData() )
79 setAutoLayoutChildren(
true );
82 m_data->prompt->setVisible(
false );
84 m_data->inputProxy =
new TextInputProxy(
this,
nullptr );
85 m_data->inputProxy->setVisible(
86 m_data->panelHints & QskInputPanelBox::InputProxy );
89 m_data->predictionBar->setVisible(
90 m_data->panelHints & QskInputPanelBox::Prediction );
95 layout->setDefaultAlignment( Qt::AlignLeft | Qt::AlignHCenter );
96 layout->setSpacing( 0 );
98 layout->addItem( m_data->prompt );
99 layout->addItem( m_data->inputProxy );
100 layout->addStretch( 10 );
101 layout->addItem( m_data->predictionBar );
102 layout->addItem( m_data->keyboard );
104 m_data->layout = layout;
106 connect( m_data->predictionBar, &QskInputPredictionBar::predictiveTextSelected,
107 this, &QskInputPanelBox::predictiveTextSelected );
109 connect( m_data->keyboard, &QskVirtualKeyboard::keySelected,
110 this, &QskInputPanelBox::keySelected );
113QskInputPanelBox::~QskInputPanelBox()
117void QskInputPanelBox::setPanelHint( PanelHint hint,
bool on )
120 setPanelHints( m_data->panelHints | hint );
122 setPanelHints( m_data->panelHints & ~hint );
125void QskInputPanelBox::setPanelHints( PanelHints hints )
127 if ( hints == m_data->panelHints )
130 m_data->panelHints = hints;
132 m_data->inputProxy->setVisible( hints & QskInputPanelBox::InputProxy );
133 m_data->predictionBar->setVisible( hints & QskInputPanelBox::Prediction );
135 const bool showPrompt = ( hints & QskInputPanelBox::InputProxy ) &&
136 !m_data->prompt->text().isEmpty();
138 m_data->prompt->setVisible( showPrompt );
140 Q_EMIT panelHintsChanged();
143QskInputPanelBox::PanelHints QskInputPanelBox::panelHints()
const
145 return m_data->panelHints;
148void QskInputPanelBox::attachInputItem( QQuickItem* item )
150 if ( item == m_data->inputItem )
153 m_data->inputItem = item;
157 if ( m_data->panelHints & QskInputPanelBox::InputProxy )
159 m_data->inputProxy->setupFrom( item );
160 m_data->inputProxy->setEditing(
true );
165QQuickItem* QskInputPanelBox::attachedInputItem()
const
167 return m_data->inputItem;
170QQuickItem* QskInputPanelBox::inputProxy()
const
172 if ( m_data->panelHints & QskInputPanelBox::InputProxy )
173 return m_data->inputProxy;
181 if ( subControl == QskBox::Panel )
182 return QskInputPanelBox::Panel;
186 if ( subControl == QskInputPanelBox::ProxyPanel )
187 return QskTextInput::Panel;
189 if ( subControl == QskInputPanelBox::ProxyText )
190 return QskTextInput::Text;
196QString QskInputPanelBox::inputPrompt()
const
198 return m_data->prompt->text();
201void QskInputPanelBox::setInputPrompt(
const QString& text )
203 auto prompt = m_data->prompt;
205 if ( text != prompt->text() )
207 prompt->setText( text );
209 if ( m_data->panelHints & QskInputPanelBox::InputProxy )
210 prompt->setVisible( !text.isEmpty() );
212 Q_EMIT inputPromptChanged( text );
216void QskInputPanelBox::setPrediction(
const QStringList& prediction )
218 m_data->predictionBar->setPrediction( prediction );
223 if( m_data->keyboard )
225 m_data->keyboard->deleteLater();
228 m_data->keyboard = keyboard;
229 m_data->layout->addItem( m_data->keyboard );
231 connect( m_data->keyboard, &QskVirtualKeyboard::keySelected,
232 this, &QskInputPanelBox::keySelected );
235void QskInputPanelBox::keyPressEvent( QKeyEvent* event )
239 switch ( event->key() )
244 keyCode =
event->key();
250 const auto text =
event->text();
252 if ( !text.isEmpty() )
253 keyCode = text[ 0 ].unicode();
255 keyCode =
event->key();
259 if ( m_data->keyboard->hasKey( keyCode ) )
262 Q_EMIT keySelected( keyCode );
266#include "moc_QskInputPanelBox.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
void initSizePolicy(QskSizePolicy::Policy, QskSizePolicy::Policy)
Layout stringing items in rows and columns.