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=true
; Support multiple keyboard layout
multiple_keyboard_layout=true
[editor]
; Auto indent as previous line
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;
}
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();

View File

@ -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);

View File

@ -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 {

View File

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

View File

@ -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 &section, 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