diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index 61a161bf..40f388b4 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -249,6 +249,9 @@ max_num_of_tag_labels=3 ; Smart live preview smart_live_preview=true +; Support multiple keyboard layout +multiple_keyboard_layout=true + [editor] ; Auto indent as previous line auto_indent=true diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 6d01b00a..dede68da 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -592,10 +592,11 @@ bool VUtils::realEqual(qreal p_a, qreal p_b) 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) { - return QChar('a' + p_key - Qt::Key_A); + QString key = QKeySequence(p_key).toString(); + if (key.size() == 1) { + return p_smallCase ? key[0].toLower() : key[0]; } return QChar(); diff --git a/src/utils/vutils.h b/src/utils/vutils.h index 27681a9a..107fd253 100644 --- a/src/utils/vutils.h +++ b/src/utils/vutils.h @@ -171,7 +171,9 @@ public: static bool isImageURLText(const QString &p_url); static qreal calculateScaleFactor(); 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 void sleepWait(int p_milliseconds); diff --git a/src/vcaptain.cpp b/src/vcaptain.cpp index cabe88b6..30e41999 100644 --- a/src/vcaptain.cpp +++ b/src/vcaptain.cpp @@ -95,6 +95,12 @@ void VCaptain::keyPressEvent(QKeyEvent *p_event) 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)) { p_event->accept(); } else { diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 0ab027b1..6821f686 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -314,6 +314,9 @@ void VConfigManager::initialize() m_smartLivePreview = getConfigFromSettings("global", "smart_live_preview").toBool(); + m_multipleKeyboardLayout = getConfigFromSettings("global", + "multiple_keyboard_layout").toBool(); + initEditorConfigs(); } diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 8ee6cae2..e650fa0f 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -549,6 +549,8 @@ public: bool getSmartLivePreview() const; + bool getMultipleKeyboardLayout() const; + private: // Look up a config from user and default settings. QVariant getConfigFromSettings(const QString §ion, const QString &key) const; @@ -989,6 +991,9 @@ private: // Smart live preview. bool m_smartLivePreview; + // Support multiple keyboard layout. + bool m_multipleKeyboardLayout; + // The name of the config file in each directory. static const QString c_dirConfigFile; @@ -2549,4 +2554,9 @@ inline bool VConfigManager::getSmartLivePreview() const { return m_smartLivePreview; } + +inline bool VConfigManager::getMultipleKeyboardLayout() const +{ + return m_multipleKeyboardLayout; +} #endif // VCONFIGMANAGER_H