From 7b2e63c7e526aee50a57665774f6bfe20f967257 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 4 Apr 2018 20:19:47 +0200 Subject: [PATCH] dead inputcontext related code removed --- inputcontext/QskHunspellCompositionModel.cpp | 7 -- inputcontext/QskHunspellCompositionModel.h | 1 - inputcontext/QskInputCompositionModel.cpp | 38 ------- inputcontext/QskInputCompositionModel.h | 10 -- inputcontext/QskInputContext.cpp | 113 +++++++++++++------ inputcontext/QskInputContext.h | 3 +- inputcontext/QskPinyinCompositionModel.cpp | 20 +--- inputcontext/QskPinyinCompositionModel.h | 5 - playground/inputpanel/main.cpp | 26 ++--- src/common/QskModule.cpp | 2 +- src/controls/QskSetup.cpp | 7 +- src/controls/QskSetup.h | 10 +- src/controls/QskVirtualKeyboard.cpp | 52 +-------- src/controls/QskVirtualKeyboard.h | 4 +- 14 files changed, 102 insertions(+), 196 deletions(-) diff --git a/inputcontext/QskHunspellCompositionModel.cpp b/inputcontext/QskHunspellCompositionModel.cpp index 9ab2e4f9..dfba993a 100644 --- a/inputcontext/QskHunspellCompositionModel.cpp +++ b/inputcontext/QskHunspellCompositionModel.cpp @@ -93,13 +93,6 @@ QString QskHunspellCompositionModel::polishPreedit( const QString& preedit ) return preedit; } -bool QskHunspellCompositionModel::isComposable( const QStringRef& preedit ) const -{ - // ### What is this function even supposed do? - Q_UNUSED( preedit ); - return false; -} - bool QskHunspellCompositionModel::hasIntermediate() const { return true; diff --git a/inputcontext/QskHunspellCompositionModel.h b/inputcontext/QskHunspellCompositionModel.h index e45266c4..5904f85e 100644 --- a/inputcontext/QskHunspellCompositionModel.h +++ b/inputcontext/QskHunspellCompositionModel.h @@ -25,7 +25,6 @@ public: protected: virtual bool hasIntermediate() const override; virtual QString polishPreedit( const QString& ) override; - virtual bool isComposable( const QStringRef& ) const override; private: class PrivateData; diff --git a/inputcontext/QskInputCompositionModel.cpp b/inputcontext/QskInputCompositionModel.cpp index f3ef1328..f174ce4c 100644 --- a/inputcontext/QskInputCompositionModel.cpp +++ b/inputcontext/QskInputCompositionModel.cpp @@ -42,8 +42,6 @@ public: QString preedit; QTextCharFormat preeditFormat; QList< QInputMethodEvent::Attribute > preeditAttributes; - - int groupIndex = 0; }; QskInputCompositionModel::QskInputCompositionModel( QskInputContext* context ): @@ -272,40 +270,4 @@ bool QskInputCompositionModel::hasIntermediate() const return false; } -bool QskInputCompositionModel::isComposable( const QStringRef& preedit ) const -{ - Q_UNUSED( preedit ); - return false; -} - -int QskInputCompositionModel::groupIndex() const -{ - return m_data->groupIndex; -} - -void QskInputCompositionModel::setGroupIndex( int groupIndex ) -{ - if ( groupIndex == m_data->groupIndex ) - return; - - m_data->groupIndex = groupIndex; - const QString displayText = polishPreedit( m_data->preedit ); - m_data->preeditAttributes.first().length = displayText.length(); - - QInputMethodEvent event( displayText, m_data->preeditAttributes ); - sendCompositionEvent( &event ); -} - -QVector< Qt::Key > QskInputCompositionModel::groups() const -{ - return QVector< Qt::Key >(); -} - -bool QskInputCompositionModel::nextGroupIndex( int& index, bool forward ) const -{ - Q_UNUSED( index ); - Q_UNUSED( forward ); - return false; -} - #include "moc_QskInputCompositionModel.cpp" diff --git a/inputcontext/QskInputCompositionModel.h b/inputcontext/QskInputCompositionModel.h index 99e01626..4b154071 100644 --- a/inputcontext/QskInputCompositionModel.h +++ b/inputcontext/QskInputCompositionModel.h @@ -17,8 +17,6 @@ class QskInputCompositionModel : public QObject { Q_OBJECT - Q_PROPERTY( QVector< Qt::Key > groups READ groups NOTIFY groupsChanged ) - public: QskInputCompositionModel( QskInputContext* context ); virtual ~QskInputCompositionModel(); @@ -35,22 +33,14 @@ public: virtual int candidateCount() const; virtual QString candidate( int ) const; - int groupIndex() const; - void setGroupIndex( int groupIndex ); - virtual bool nextGroupIndex( int&, bool = true ) const; - - virtual QVector< Qt::Key > groups() const; - protected: // Used for text composition virtual bool hasIntermediate() const; virtual QString polishPreedit( const QString& preedit ); - virtual bool isComposable( const QStringRef& preedit ) const; QskInputContext* context() const; Q_SIGNALS: - void groupsChanged( const QVector< Qt::Key >& ); void candidatesChanged(); private: diff --git a/inputcontext/QskInputContext.cpp b/inputcontext/QskInputContext.cpp index 617ad3d9..a911544c 100644 --- a/inputcontext/QskInputContext.cpp +++ b/inputcontext/QskInputContext.cpp @@ -4,24 +4,63 @@ *****************************************************************************/ #include "QskInputContext.h" +#include "QskVirtualKeyboard.h" #include "QskInputCompositionModel.h" #include "QskPinyinCompositionModel.h" -#include #include #include +#include #include #include #include #include +void qskSetLocale( QQuickItem* inputPanel, const QLocale& locale ) +{ + if ( auto control = qobject_cast< QskControl* >( inputPanel ) ) + { + control->setLocale( locale ); + } + else + { + const auto mo = inputPanel->metaObject(); + + const auto property = mo->property( mo->indexOfProperty( "locale" ) ); + if ( property.isWritable() ) + property.write( inputPanel, locale ); + } +} + +QLocale qskLocale( const QQuickItem* inputPanel ) +{ + if ( inputPanel == nullptr ) + return QLocale(); + + if ( auto control = qobject_cast< const QskControl* >( inputPanel ) ) + return control->locale(); + + return inputPanel->property( "locale" ).toLocale(); +} + +QskVirtualKeyboard* qskVirtualKeyboard( QQuickItem* inputPanel ) +{ + // we should not depend on QskVirtualKeyboard TODO ... + + if ( inputPanel ) + return inputPanel->findChild< QskVirtualKeyboard* >(); + + return nullptr; +} + class QskInputContext::PrivateData { public: QPointer< QQuickItem > inputItem; - QPointer< QskVirtualKeyboard > inputPanel; + QPointer< QQuickItem > inputPanel; + QskInputCompositionModel* compositionModel; QHash< QLocale, QskInputCompositionModel* > compositionModels; }; @@ -119,23 +158,17 @@ void QskInputContext::update( Qt::InputMethodQueries queries ) auto oldModel = compositionModel(); if( m_data->inputPanel ) - m_data->inputPanel->setLocale( locale ); + qskSetLocale( m_data->inputPanel, locale ); auto newModel = compositionModel(); if( oldModel != newModel ) { - if( m_data->inputPanel ) - { - m_data->inputPanel->setCandidateBarVisible( newModel->supportsSuggestions() ); - m_data->inputPanel->disconnect( oldModel ); + connect( newModel, &QskInputCompositionModel::candidatesChanged, + this, &QskInputContext::handleCandidatesChanged ); - connect( newModel, &QskInputCompositionModel::groupsChanged, - m_data->inputPanel.data(), &QskVirtualKeyboard::setPreeditGroups ); - - connect( newModel, &QskInputCompositionModel::candidatesChanged, - this, &QskInputContext::handleCandidatesChanged ); - } + if ( auto keyboard = qskVirtualKeyboard( m_data->inputPanel ) ) + keyboard->setCandidateBarVisible( newModel->supportsSuggestions() ); } } @@ -160,7 +193,7 @@ QRectF QskInputContext::keyboardRect() const if ( m_data->inputPanel && QskDialog::instance()->policy() != QskDialog::TopLevelWindow ) { - return m_data->inputPanel->geometry(); + return qskItemGeometry( m_data->inputPanel ); } return Inherited::keyboardRect(); @@ -226,7 +259,7 @@ bool QskInputContext::isInputPanelVisible() const QLocale QskInputContext::locale() const { - return m_data->inputPanel ? m_data->inputPanel->locale() : QLocale(); + return qskLocale( m_data->inputPanel ); } Qt::LayoutDirection QskInputContext::inputDirection() const @@ -308,7 +341,7 @@ QskInputCompositionModel* QskInputContext::compositionModel() const return m_data->compositionModels.value( locale(), m_data->compositionModel ); } -void QskInputContext::invokeAction( QInputMethod::Action action, int cursorPosition ) +void QskInputContext::invokeAction( QInputMethod::Action action, int value ) { auto model = compositionModel(); @@ -316,20 +349,15 @@ void QskInputContext::invokeAction( QInputMethod::Action action, int cursorPosit { case QskVirtualKeyboard::Compose: { - model->composeKey( static_cast< Qt::Key >( cursorPosition ) ); - break; - } - case QskVirtualKeyboard::SelectGroup: - { - model->setGroupIndex( cursorPosition ); + model->composeKey( static_cast< Qt::Key >( value ) ); break; } case QskVirtualKeyboard::SelectCandidate: { - model->commitCandidate( cursorPosition ); + model->commitCandidate( value ); - if ( m_data->inputPanel ) - m_data->inputPanel->setPreeditCandidates( QVector< QString >() ); + if ( auto keyboard = qskVirtualKeyboard( m_data->inputPanel ) ) + keyboard->setPreeditCandidates( QVector< QString >() ); break; } @@ -355,10 +383,11 @@ void QskInputContext::handleCandidatesChanged() for( int i = 0; i < count; i++ ) candidates += model->candidate( i ); - m_data->inputPanel->setPreeditCandidates( candidates ); + if ( auto keyboard = qskVirtualKeyboard( m_data->inputPanel ) ) + keyboard->setPreeditCandidates( candidates ); } -void QskInputContext::setInputPanel( QskVirtualKeyboard* inputPanel ) +void QskInputContext::setInputPanel( QQuickItem* inputPanel ) { if ( m_data->inputPanel == inputPanel ) return; @@ -377,22 +406,34 @@ void QskInputContext::setInputPanel( QskVirtualKeyboard* inputPanel ) if ( inputPanel ) { - connect( inputPanel, &QskVirtualKeyboard::visibleChanged, + // maybe using a QQuickItemChangeListener instead +#if 1 + connect( inputPanel, &QQuickItem::visibleChanged, this, &QPlatformInputContext::emitInputPanelVisibleChanged ); - connect( inputPanel, &QskVirtualKeyboard::keyboardRectChanged, + connect( inputPanel, &QQuickItem::xChanged, this, &QPlatformInputContext::emitKeyboardRectChanged ); - connect( inputPanel, &QskVirtualKeyboard::localeChanged, - this, &QPlatformInputContext::emitLocaleChanged ); + connect( inputPanel, &QQuickItem::yChanged, + this, &QPlatformInputContext::emitKeyboardRectChanged ); + + connect( inputPanel, &QQuickItem::widthChanged, + this, &QPlatformInputContext::emitKeyboardRectChanged ); + + connect( inputPanel, &QQuickItem::heightChanged, + this, &QPlatformInputContext::emitKeyboardRectChanged ); +#endif + + if ( auto control = qobject_cast< QskControl* >( inputPanel ) ) + { + connect( control, &QskControl::localeChanged, + this, &QPlatformInputContext::emitLocaleChanged ); + } if ( model ) { - inputPanel->setCandidateBarVisible( - model->supportsSuggestions() ); - - connect( model, &QskInputCompositionModel::groupsChanged, - inputPanel, &QskVirtualKeyboard::setPreeditGroups ); + if ( auto keyboard = qskVirtualKeyboard( inputPanel ) ) + keyboard->setCandidateBarVisible( model->supportsSuggestions() ); } } } diff --git a/inputcontext/QskInputContext.h b/inputcontext/QskInputContext.h index 928d1055..79458d70 100644 --- a/inputcontext/QskInputContext.h +++ b/inputcontext/QskInputContext.h @@ -9,7 +9,6 @@ #include #include -class QskVirtualKeyboard; class QskInputCompositionModel; class QQuickItem; class QInputMethodQueryEvent; @@ -56,7 +55,7 @@ public: private Q_SLOTS: void handleCandidatesChanged(); - void setInputPanel( QskVirtualKeyboard* ); + void setInputPanel( QQuickItem* ); private: void setInputItem( QQuickItem* ); diff --git a/inputcontext/QskPinyinCompositionModel.cpp b/inputcontext/QskPinyinCompositionModel.cpp index 30a66a36..f0e87658 100644 --- a/inputcontext/QskPinyinCompositionModel.cpp +++ b/inputcontext/QskPinyinCompositionModel.cpp @@ -8,15 +8,13 @@ #include "pinyinime.h" -#include -#include #include +#include class QskPinyinCompositionModel::PrivateData { public: QStringList candidates; - QVector< Qt::Key > groups; }; QskPinyinCompositionModel::QskPinyinCompositionModel( QskInputContext* context ): @@ -59,11 +57,6 @@ QString QskPinyinCompositionModel::candidate( int index ) const return QString(); } -QVector< Qt::Key > QskPinyinCompositionModel::groups() const -{ - return m_data->groups; -} - bool QskPinyinCompositionModel::hasIntermediate() const { return m_data->candidates.count() > 0; @@ -114,14 +107,3 @@ QString QskPinyinCompositionModel::polishPreedit( const QString& preedit ) return preedit; } - -bool QskPinyinCompositionModel::isComposable( const QStringRef& preedit ) const -{ - Q_UNUSED( preedit ); - return false; // ### implement -} - -void QskPinyinCompositionModel::handleGroupIndexChanged() -{ - // ### implement -} diff --git a/inputcontext/QskPinyinCompositionModel.h b/inputcontext/QskPinyinCompositionModel.h index 4821a0ee..168f2059 100644 --- a/inputcontext/QskPinyinCompositionModel.h +++ b/inputcontext/QskPinyinCompositionModel.h @@ -21,17 +21,12 @@ public: virtual int candidateCount() const override; virtual QString candidate( int ) const override; - virtual QVector< Qt::Key > groups() const override; - protected: // Used for text composition virtual bool hasIntermediate() const override; virtual QString polishPreedit( const QString& preedit ) override; - virtual bool isComposable( const QStringRef& preedit ) const override; private: - void handleGroupIndexChanged(); - class PrivateData; std::unique_ptr< PrivateData > m_data; }; diff --git a/playground/inputpanel/main.cpp b/playground/inputpanel/main.cpp index 90408fbe..a681daff 100644 --- a/playground/inputpanel/main.cpp +++ b/playground/inputpanel/main.cpp @@ -90,17 +90,6 @@ public: setPreferredWidth( columnWidth( 0 ) + 20 ); setScrollableSize( QSizeF( columnWidth( 0 ), rowCount() * rowHeight() ) ); - - // TODO: - // 1) changing the keyboard layouts does not yet work - // 2) QskInputPanel does not work properly in the threaded environment -#if 1 - connect( this, &QskListView::selectedRowChanged, - this, [ this ] { qskSetup->inputPanel()->setLocale( m_values[selectedRow()].second ); } ); -#else - connect( this, &QskListView::selectedRowChanged, - this, [ this ] { QLocale::setDefault( m_values[selectedRow()].second ); } ); -#endif } virtual int rowCount() const override final @@ -146,6 +135,14 @@ public: return m_values[row].first; } + QLocale localeAt( int row ) const + { + if ( row >= 0 && row < m_values.size() ) + return m_values[row].second; + + return QLocale(); + } + private: inline void append( QLocale locale, const QString& name ) { @@ -179,8 +176,11 @@ int main( int argc, char* argv[] ) box->setSpacing( 10 ); box->setMargins( 20 ); - (void) new LocaleListView( box ); - (void) new InputBox( box ); + auto listView = new LocaleListView( box ); + auto inputBox = new InputBox( box ); + + QObject::connect( listView, &QskListView::selectedRowChanged, + inputBox, [ = ]( int row ) { inputBox->setLocale( listView->localeAt( row ) ); } ); QskWindow window; window.setColor( "PapayaWhip" ); diff --git a/src/common/QskModule.cpp b/src/common/QskModule.cpp index 1a3b0b85..27a0ca2e 100644 --- a/src/common/QskModule.cpp +++ b/src/common/QskModule.cpp @@ -159,7 +159,7 @@ public: Q_PROPERTY( QStringList skinList READ skinList NOTIFY skinListChanged ) - Q_PRIVATE_PROPERTY( setup(), QskVirtualKeyboard* inputPanel READ inputPanel + Q_PRIVATE_PROPERTY( setup(), QQuickItem* inputPanel READ inputPanel WRITE setInputPanel NOTIFY inputPanelChanged ) Q_PRIVATE_PROPERTY( setup(), QskSetupFlagsProvider controlFlags diff --git a/src/controls/QskSetup.cpp b/src/controls/QskSetup.cpp index bb0bcb0f..40a67e63 100644 --- a/src/controls/QskSetup.cpp +++ b/src/controls/QskSetup.cpp @@ -8,7 +8,6 @@ #include "QskSkinManager.h" #include "QskGraphicProviderMap.h" #include "QskControl.h" -#include "QskVirtualKeyboard.h" #include "QskWindow.h" #include "QskObjectTree.h" @@ -127,7 +126,7 @@ public: QskGraphicProviderMap graphicProviders; - QPointer< QskVirtualKeyboard > inputPanel; + QPointer< QQuickItem > inputPanel; QskSetup::Flags controlFlags; }; @@ -262,7 +261,7 @@ QskGraphicProvider* QskSetup::graphicProvider( const QString& providerId ) const return m_data->graphicProviders.provider( providerId ); } -void QskSetup::setInputPanel( QskVirtualKeyboard* inputPanel ) +void QskSetup::setInputPanel( QQuickItem* inputPanel ) { if ( m_data->inputPanel == inputPanel ) return; @@ -271,7 +270,7 @@ void QskSetup::setInputPanel( QskVirtualKeyboard* inputPanel ) Q_EMIT inputPanelChanged( m_data->inputPanel ); } -QskVirtualKeyboard* QskSetup::inputPanel() +QQuickItem* QskSetup::inputPanel() { return m_data->inputPanel; } diff --git a/src/controls/QskSetup.h b/src/controls/QskSetup.h index 7edba676..2092ae9f 100644 --- a/src/controls/QskSetup.h +++ b/src/controls/QskSetup.h @@ -11,10 +11,8 @@ #include #include -class QskVirtualKeyboard; class QskSkin; -class QskSkinlet; -class QskControl; +class QQuickItem; class QskGraphicProvider; class QLocale; @@ -60,8 +58,8 @@ public: QskSkin* skin(); - void setInputPanel( QskVirtualKeyboard* ); - QskVirtualKeyboard* inputPanel(); + void setInputPanel( QQuickItem* ); + QQuickItem* inputPanel(); void addGraphicProvider( const QString& providerId, QskGraphicProvider* ); QskGraphicProvider* graphicProvider( const QString& providerId ) const; @@ -76,7 +74,7 @@ public: Q_SIGNALS: void skinChanged( QskSkin* ); - void inputPanelChanged( QskVirtualKeyboard* ); + void inputPanelChanged( QQuickItem* ); void controlFlagsChanged(); private: diff --git a/src/controls/QskVirtualKeyboard.cpp b/src/controls/QskVirtualKeyboard.cpp index 97366dfd..6ab579e6 100644 --- a/src/controls/QskVirtualKeyboard.cpp +++ b/src/controls/QskVirtualKeyboard.cpp @@ -271,9 +271,6 @@ public: qint16 selectedGroup; qint32 candidateOffset; - QLocale locale; - - QVector< Qt::Key > groups; QVector< QString > candidates; KeyTable keyTable[ ModeCount ]; @@ -506,25 +503,6 @@ QString QskVirtualKeyboard::displayLanguageName() const return QLocale::languageToString( locale.language() ); } -void QskVirtualKeyboard::setPreeditGroups( const QVector< Qt::Key >& groups ) -{ - auto& topRow = m_data->keyTable[ LowercaseMode ].data[ 0 ]; - - for( const auto& group : groups ) - { - auto& keyData = topRow[ &group - groups.data() ]; - keyData.key = group; - } - - m_data->groups = groups; - selectGroup( -1 ); - - if( m_data->mode == LowercaseMode ) - { - update(); - } -} - void QskVirtualKeyboard::setPreeditCandidates( const QVector< QString >& candidates ) { if( m_data->candidates == candidates ) @@ -540,7 +518,6 @@ void QskVirtualKeyboard::setCandidateOffset( int candidateOffset ) { m_data->candidateOffset = candidateOffset; - const auto groupCount = m_data->groups.length(); const auto candidateCount = m_data->candidates.length(); const auto count = std::min( candidateCount, QskVirtualKeyboardCandidateButton::maxCandidates() ); const bool continueLeft = m_data->candidateOffset > 0; @@ -554,7 +531,7 @@ void QskVirtualKeyboard::setCandidateOffset( int candidateOffset ) { button->setIndexAndText( i, textForKey( Qt::Key_ApplicationLeft ) ); } - else if( continueRight && ( i == KeyCount - groupCount - 1 ) ) + else if( continueRight && ( i == KeyCount - 1 ) ) { button->setIndexAndText( i, textForKey( Qt::Key_ApplicationRight ) ); } @@ -727,33 +704,6 @@ void QskVirtualKeyboard::compose( int key ) static_cast< QInputMethod::Action >( Compose ), key ); } -void QskVirtualKeyboard::selectGroup( int index ) -{ - auto& topRow = m_data->keyTable[ m_data->mode ].data[ 0 ]; - - if( m_data->selectedGroup >= 0 ) - { - auto group = static_cast< int >( m_data->selectedGroup ); - topRow[ group ].key &= ~KeyLocked; - } - - if( m_data->selectedGroup == index ) - { - index = -1; // clear selection - } - - m_data->selectedGroup = index; - QGuiApplication::inputMethod()->invokeAction( - static_cast< QInputMethod::Action >( SelectGroup ), m_data->selectedGroup + 1 ); - - if( m_data->selectedGroup < 0 ) - { - return; - } - - topRow[ m_data->selectedGroup ].key |= KeyLocked; -} - void QskVirtualKeyboard::selectCandidate( int index ) { QGuiApplication::inputMethod()->invokeAction( diff --git a/src/controls/QskVirtualKeyboard.h b/src/controls/QskVirtualKeyboard.h index c31cad27..a0a97ee4 100644 --- a/src/controls/QskVirtualKeyboard.h +++ b/src/controls/QskVirtualKeyboard.h @@ -84,8 +84,7 @@ public: enum Action { Compose = 0x10, - SelectGroup = 0x11, - SelectCandidate = 0x12, + SelectCandidate = 0x11, }; Q_ENUM( Action ) @@ -133,7 +132,6 @@ public: void setCandidateBarVisible( bool visible ); public Q_SLOTS: - void setPreeditGroups( const QVector< Qt::Key >& ); void setPreeditCandidates( const QVector< QString >& ); protected: