2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
2018-02-06 14:55:35 +01:00
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
2017-07-21 18:21:34 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QSK_INPUT_PANEL_H
|
|
|
|
#define QSK_INPUT_PANEL_H
|
|
|
|
|
|
|
|
#include "QskControl.h"
|
2018-03-14 17:30:37 +01:00
|
|
|
#include "QskPushButton.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#include <QRectF>
|
|
|
|
|
2018-03-14 17:30:37 +01:00
|
|
|
class QskInputCompositionModel;
|
|
|
|
class QskInputPanel;
|
|
|
|
|
2018-03-14 17:30:41 +01:00
|
|
|
class QskKeyButton : public QskPushButton // ### rename to QskInputButton or so?
|
2018-03-14 17:30:37 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
using Inherited = QskPushButton;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QSK_SUBCONTROLS( Panel, Text, TextCancelButton )
|
|
|
|
QskKeyButton( int keyIndex, QskInputPanel* inputPanel, QQuickItem* parent = nullptr );
|
|
|
|
|
|
|
|
virtual QskAspect::Subcontrol effectiveSubcontrol( QskAspect::Subcontrol subControl ) const override;
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void updateText();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool isCancelButton() const;
|
|
|
|
|
|
|
|
const int m_keyIndex;
|
|
|
|
QskInputPanel* m_inputPanel;
|
|
|
|
};
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
class QSK_EXPORT QskInputPanel : public QskControl
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY( QRectF keyboardRect READ keyboardRect NOTIFY keyboardRectChanged )
|
|
|
|
|
|
|
|
Q_PROPERTY( QString displayLanguageName READ displayLanguageName
|
2018-03-14 17:30:35 +01:00
|
|
|
NOTIFY displayLanguageNameChanged )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
using Inherited = QskControl;
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct KeyData
|
|
|
|
{
|
|
|
|
Qt::Key key = Qt::Key( 0 );
|
2018-03-14 17:30:37 +01:00
|
|
|
bool isSuggestionKey = false;
|
2017-07-21 18:21:34 +02:00
|
|
|
QRectF rect;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Action
|
|
|
|
{
|
|
|
|
Compose = 0x10,
|
|
|
|
SelectGroup = 0x11,
|
|
|
|
SelectCandidate = 0x12,
|
|
|
|
};
|
|
|
|
Q_ENUM( Action )
|
|
|
|
|
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
CurrentMode = -1,
|
|
|
|
LowercaseMode,
|
|
|
|
UppercaseMode,
|
|
|
|
SpecialCharacterMode,
|
|
|
|
ModeCount
|
|
|
|
};
|
|
|
|
Q_ENUM( Mode )
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
RowCount = 5,
|
|
|
|
KeyCount = 12
|
|
|
|
};
|
|
|
|
|
|
|
|
using KeyRow = Qt::Key[KeyCount];
|
|
|
|
using KeyDataRow = KeyData[KeyCount];
|
|
|
|
using KeyDataSet = KeyDataRow[RowCount];
|
|
|
|
|
|
|
|
QskInputPanel( QQuickItem* parent = nullptr );
|
2018-03-14 17:30:41 +01:00
|
|
|
virtual ~QskInputPanel() override;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
void updateLocale( const QLocale& locale );
|
|
|
|
|
|
|
|
void setMode( QskInputPanel::Mode index );
|
|
|
|
Mode mode() const;
|
|
|
|
|
|
|
|
const KeyDataSet& keyData( QskInputPanel::Mode = CurrentMode ) const;
|
|
|
|
|
|
|
|
QString textForKey( Qt::Key ) const;
|
|
|
|
QString displayLanguageName() const;
|
|
|
|
|
|
|
|
QRectF keyboardRect() const;
|
|
|
|
|
2018-03-14 17:30:37 +01:00
|
|
|
// takes ownership:
|
|
|
|
void registerCompositionModelForLocale( const QLocale& locale,
|
|
|
|
QskInputCompositionModel* model );
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
void setPreeditGroups( const QVector< Qt::Key >& );
|
|
|
|
void setPreeditCandidates( const QVector< Qt::Key >& );
|
|
|
|
bool advanceFocus( bool = true );
|
|
|
|
bool activateFocusKey();
|
|
|
|
bool deactivateFocusKey();
|
|
|
|
void clearFocusKey();
|
|
|
|
|
2018-03-14 17:30:37 +01:00
|
|
|
void handleKey( int keyIndex );
|
|
|
|
KeyData& keyDataAt( int ) const;
|
|
|
|
QString currentTextForKeyIndex( int keyIndex ) const;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
protected:
|
|
|
|
virtual void geometryChanged( const QRectF&, const QRectF& ) override;
|
|
|
|
virtual void timerEvent( QTimerEvent* ) override;
|
2018-03-14 17:30:37 +01:00
|
|
|
virtual bool eventFilter( QObject* object, QEvent* event ) override;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
private:
|
2018-03-14 17:30:37 +01:00
|
|
|
void createUI();
|
|
|
|
void updateUI(); // e.g. called when updating Pinyin suggestions
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
void compose( Qt::Key );
|
|
|
|
void selectGroup( int );
|
|
|
|
void selectCandidate( int );
|
|
|
|
void setCandidateOffset( int );
|
|
|
|
|
|
|
|
void updateKeyData();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void keyboardRectChanged();
|
|
|
|
void displayLanguageNameChanged();
|
2018-03-14 17:30:37 +01:00
|
|
|
void inputMethodRegistered( const QLocale& locale, QskInputCompositionModel* model );
|
|
|
|
void inputMethodEventReceived( QInputMethodEvent* inputMethodEvent );
|
|
|
|
void keyEventReceived( QKeyEvent* keyEvent );
|
|
|
|
void modeChanged( QskInputPanel::Mode mode );
|
|
|
|
void cancelPressed();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
class PrivateData;
|
|
|
|
std::unique_ptr< PrivateData > m_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_TYPEINFO( QskInputPanel::KeyData, Q_PRIMITIVE_TYPE );
|
|
|
|
|
|
|
|
#endif
|