Captain: fix captain mode in diffrent keyboard layout

This commit is contained in:
Le Tan 2018-09-02 14:04:21 +08:00
parent af912619a0
commit ffa413fa26
6 changed files with 29 additions and 4 deletions

View File

@ -249,6 +249,9 @@ max_num_of_tag_labels=3
; Smart live preview ; Smart live preview
smart_live_preview=true smart_live_preview=true
; Support multiple keyboard layout
multiple_keyboard_layout=true
[editor] [editor]
; Auto indent as previous line ; Auto indent as previous line
auto_indent=true auto_indent=true

View File

@ -592,10 +592,11 @@ bool VUtils::realEqual(qreal p_a, qreal p_b)
return std::abs(p_a - p_b) < 1e-8; return std::abs(p_a - p_b) < 1e-8;
} }
QChar VUtils::keyToChar(int p_key) QChar VUtils::keyToChar(int p_key, bool p_smallCase)
{ {
if (p_key >= Qt::Key_A && p_key <= Qt::Key_Z) { QString key = QKeySequence(p_key).toString();
return QChar('a' + p_key - Qt::Key_A); if (key.size() == 1) {
return p_smallCase ? key[0].toLower() : key[0];
} }
return QChar(); return QChar();

View File

@ -171,7 +171,9 @@ public:
static bool isImageURLText(const QString &p_url); static bool isImageURLText(const QString &p_url);
static qreal calculateScaleFactor(); static qreal calculateScaleFactor();
static bool realEqual(qreal p_a, qreal p_b); static bool realEqual(qreal p_a, qreal p_b);
static QChar keyToChar(int p_key);
static QChar keyToChar(int p_key, bool p_smallCase = true);
static QString getLocale(); static QString getLocale();
static void sleepWait(int p_milliseconds); static void sleepWait(int p_milliseconds);

View File

@ -95,6 +95,12 @@ void VCaptain::keyPressEvent(QKeyEvent *p_event)
return; return;
} }
if (g_config->getMultipleKeyboardLayout()) {
qDebug() << "Captain mode" << key << p_event->nativeScanCode() << p_event->nativeVirtualKey();
key = p_event->nativeVirtualKey();
}
// Use virtual key here for different layout.
if (handleKeyPress(key, modifiers)) { if (handleKeyPress(key, modifiers)) {
p_event->accept(); p_event->accept();
} else { } else {

View File

@ -314,6 +314,9 @@ void VConfigManager::initialize()
m_smartLivePreview = getConfigFromSettings("global", m_smartLivePreview = getConfigFromSettings("global",
"smart_live_preview").toBool(); "smart_live_preview").toBool();
m_multipleKeyboardLayout = getConfigFromSettings("global",
"multiple_keyboard_layout").toBool();
initEditorConfigs(); initEditorConfigs();
} }

View File

@ -549,6 +549,8 @@ public:
bool getSmartLivePreview() const; bool getSmartLivePreview() const;
bool getMultipleKeyboardLayout() const;
private: private:
// Look up a config from user and default settings. // Look up a config from user and default settings.
QVariant getConfigFromSettings(const QString &section, const QString &key) const; QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@ -989,6 +991,9 @@ private:
// Smart live preview. // Smart live preview.
bool m_smartLivePreview; bool m_smartLivePreview;
// Support multiple keyboard layout.
bool m_multipleKeyboardLayout;
// The name of the config file in each directory. // The name of the config file in each directory.
static const QString c_dirConfigFile; static const QString c_dirConfigFile;
@ -2549,4 +2554,9 @@ inline bool VConfigManager::getSmartLivePreview() const
{ {
return m_smartLivePreview; return m_smartLivePreview;
} }
inline bool VConfigManager::getMultipleKeyboardLayout() const
{
return m_multipleKeyboardLayout;
}
#endif // VCONFIGMANAGER_H #endif // VCONFIGMANAGER_H