2018-04-06 17:30:24 +02:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "QskInputPanel.h"
|
2018-04-10 16:51:35 +02:00
|
|
|
|
#include "QskVirtualKeyboard.h"
|
|
|
|
|
#include "QskInputSuggestionBar.h"
|
|
|
|
|
#include "QskLinearBox.h"
|
2018-04-06 17:30:24 +02:00
|
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QLocale>
|
2018-04-11 08:58:14 +02:00
|
|
|
|
#include <QGuiApplication>
|
2018-04-10 16:51:35 +02:00
|
|
|
|
|
2018-04-06 17:30:24 +02:00
|
|
|
|
QString qskNativeLocaleString( const QLocale& locale )
|
|
|
|
|
{
|
|
|
|
|
switch( locale.language() )
|
|
|
|
|
{
|
|
|
|
|
case QLocale::Bulgarian:
|
|
|
|
|
return QStringLiteral( "български език" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Czech:
|
|
|
|
|
return QStringLiteral( "Čeština" );
|
|
|
|
|
|
|
|
|
|
case QLocale::German:
|
|
|
|
|
return QStringLiteral( "Deutsch" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Danish:
|
|
|
|
|
return QStringLiteral( "Dansk" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Greek:
|
|
|
|
|
return QStringLiteral( "Eλληνικά" );
|
|
|
|
|
|
|
|
|
|
case QLocale::English:
|
|
|
|
|
{
|
|
|
|
|
switch( locale.country() )
|
|
|
|
|
{
|
|
|
|
|
case QLocale::Canada:
|
|
|
|
|
case QLocale::UnitedStates:
|
|
|
|
|
case QLocale::UnitedStatesMinorOutlyingIslands:
|
|
|
|
|
case QLocale::UnitedStatesVirginIslands:
|
|
|
|
|
return QStringLiteral( "English (US)" );
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return QStringLiteral( "English (UK)" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case QLocale::Spanish:
|
|
|
|
|
return QStringLiteral( "Español" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Finnish:
|
|
|
|
|
return QStringLiteral( "Suomi" );
|
|
|
|
|
|
|
|
|
|
case QLocale::French:
|
|
|
|
|
return QStringLiteral( "Français" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Hungarian:
|
|
|
|
|
return QStringLiteral( "Magyar" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Italian:
|
|
|
|
|
return QStringLiteral( "Italiano" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Japanese:
|
|
|
|
|
return QStringLiteral( "日本語" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Latvian:
|
|
|
|
|
return QStringLiteral( "Latviešu" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Lithuanian:
|
|
|
|
|
return QStringLiteral( "Lietuvių" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Dutch:
|
|
|
|
|
return QStringLiteral( "Nederlands" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Portuguese:
|
|
|
|
|
return QStringLiteral( "Português" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Romanian:
|
|
|
|
|
return QStringLiteral( "Română" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Russia:
|
|
|
|
|
return QStringLiteral( "Русский" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Slovenian:
|
|
|
|
|
return QStringLiteral( "Slovenščina" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Slovak:
|
|
|
|
|
return QStringLiteral( "Slovenčina" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Turkish:
|
|
|
|
|
return QStringLiteral( "Türkçe" );
|
|
|
|
|
|
|
|
|
|
case QLocale::Chinese:
|
|
|
|
|
return QStringLiteral( "中文" );
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return QLocale::languageToString( locale.language() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 16:51:35 +02:00
|
|
|
|
class QskInputPanel::PrivateData
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-04-12 12:03:51 +02:00
|
|
|
|
QskLinearBox* layout;
|
2018-04-10 16:51:35 +02:00
|
|
|
|
QskInputSuggestionBar* suggestionBar;
|
|
|
|
|
QskVirtualKeyboard* keyboard;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QskInputPanel::QskInputPanel( QQuickItem* parent ):
|
|
|
|
|
QskControl( parent ),
|
|
|
|
|
m_data( new PrivateData() )
|
|
|
|
|
{
|
|
|
|
|
setAutoLayoutChildren( true );
|
2018-04-12 12:03:51 +02:00
|
|
|
|
initSizePolicy( QskSizePolicy::Expanding, QskSizePolicy::Constrained );
|
2018-04-10 16:51:35 +02:00
|
|
|
|
|
2018-04-12 12:03:51 +02:00
|
|
|
|
m_data->layout = new QskLinearBox( Qt::Vertical, this );
|
2018-04-10 16:51:35 +02:00
|
|
|
|
|
2018-04-12 12:03:51 +02:00
|
|
|
|
m_data->suggestionBar = new QskInputSuggestionBar( m_data->layout );
|
2018-04-10 16:51:35 +02:00
|
|
|
|
m_data->suggestionBar->setVisible( false );
|
|
|
|
|
|
|
|
|
|
connect( m_data->suggestionBar, &QskInputSuggestionBar::suggested,
|
|
|
|
|
this, &QskInputPanel::commitCandidate );
|
|
|
|
|
|
2018-04-12 12:03:51 +02:00
|
|
|
|
m_data->keyboard = new QskVirtualKeyboard( m_data->layout );
|
2018-04-10 16:51:35 +02:00
|
|
|
|
|
|
|
|
|
connect( m_data->keyboard, &QskVirtualKeyboard::keySelected,
|
|
|
|
|
this, &QskInputPanel::commitKey );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QskInputPanel::~QskInputPanel()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 12:03:51 +02:00
|
|
|
|
qreal QskInputPanel::heightForWidth( qreal width ) const
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
This code looks like as it could be generalized
|
|
|
|
|
and moved to QskLinearBox. TODO ...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const auto margins = this->margins();
|
|
|
|
|
|
|
|
|
|
width -= margins.left() + margins.right();
|
|
|
|
|
|
|
|
|
|
qreal height = m_data->keyboard->heightForWidth( width );
|
|
|
|
|
|
|
|
|
|
if ( m_data->suggestionBar->isVisible() )
|
|
|
|
|
{
|
|
|
|
|
height += m_data->layout->spacing();
|
|
|
|
|
height += m_data->suggestionBar->sizeHint().height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
height += margins.top() + margins.bottom();
|
|
|
|
|
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qreal QskInputPanel::widthForHeight( qreal height ) const
|
|
|
|
|
{
|
|
|
|
|
const auto margins = this->margins();
|
|
|
|
|
|
|
|
|
|
height -= margins.top() + margins.bottom();
|
|
|
|
|
|
|
|
|
|
if ( m_data->suggestionBar->isVisible() )
|
|
|
|
|
{
|
|
|
|
|
height -= m_data->layout->spacing();
|
|
|
|
|
height -= m_data->suggestionBar->sizeHint().height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qreal width = m_data->keyboard->widthForHeight( height );
|
|
|
|
|
width += margins.left() + margins.right();
|
|
|
|
|
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-10 16:51:35 +02:00
|
|
|
|
bool QskInputPanel::isCandidatesEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return m_data->suggestionBar->isVisible();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector< QString > QskInputPanel::candidates() const
|
|
|
|
|
{
|
|
|
|
|
return m_data->suggestionBar->candidates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QskInputPanel::setCandidatesEnabled( bool on )
|
|
|
|
|
{
|
|
|
|
|
m_data->suggestionBar->setVisible( on );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QskInputPanel::setCandidates( const QVector< QString >& candidates )
|
|
|
|
|
{
|
|
|
|
|
m_data->suggestionBar->setCandidates( candidates );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QskInputPanel::commitCandidate( int index )
|
|
|
|
|
{
|
|
|
|
|
m_data->suggestionBar->setCandidates( QVector< QString >() );
|
|
|
|
|
|
|
|
|
|
QGuiApplication::inputMethod()->invokeAction(
|
|
|
|
|
static_cast< QInputMethod::Action >( SelectCandidate ), index );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QskInputPanel::commitKey( Qt::Key key )
|
|
|
|
|
{
|
|
|
|
|
QGuiApplication::inputMethod()->invokeAction(
|
|
|
|
|
static_cast< QInputMethod::Action >( Compose ), key );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "moc_QskInputPanel.cpp"
|