From 7b743193e9baf70403f29d90cf7f0cd280adba67 Mon Sep 17 00:00:00 2001 From: yuanxing Date: Thu, 13 Jul 2023 10:42:11 +0800 Subject: [PATCH 2/2] fix(keybord):add modifier lock tip with option MODIFIER_LOCK_TIPS_VISIBLE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加编译选项MODIFIER_LOCK_TIPS_VISIBLE来显示修饰键锁定提示 Fix #9379 --- plugins/keyboard/CMakeLists.txt | 7 ++ ....kylinsec.Kiran.SessionDaemon.Keyboard.xml | 29 ++++++ .../src/pages/general/general-page.cpp | 98 ++++++++++++++++--- .../keyboard/src/pages/general/general-page.h | 7 +- .../src/pages/general/general-page.ui | 87 +++++++++++++++- .../kiran-cpanel-keyboard.zh_CN.ts | 38 ++++--- 6 files changed, 233 insertions(+), 33 deletions(-) diff --git a/plugins/keyboard/CMakeLists.txt b/plugins/keyboard/CMakeLists.txt index f00f095..1d14652 100644 --- a/plugins/keyboard/CMakeLists.txt +++ b/plugins/keyboard/CMakeLists.txt @@ -1,5 +1,7 @@ set(TARGET_NAME kiran-cpanel-keyboard) +option(MODIFIER_LOCK_TIPS_VISIBLE "Is modifire lock tips visible" OFF) + file(GLOB TS_FILES "translation/*.ts") qt5_create_translation(KEYBOARD_QM ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES}) @@ -36,6 +38,11 @@ target_link_libraries(${TARGET_NAME} ${KLOG_LIBRARIES} ${KIRAN_STYLE_LIBRARIES}) +if (MODIFIER_LOCK_TIPS_VISIBLE) + add_definitions(-DMODIFIER_LOCK_TIPS) +endif () + + install(TARGETS ${TARGET_NAME} DESTINATION ${PLUGIN_LIBS_INSTALL_DIR}/) diff --git a/plugins/keyboard/data/com.kylinsec.Kiran.SessionDaemon.Keyboard.xml b/plugins/keyboard/data/com.kylinsec.Kiran.SessionDaemon.Keyboard.xml index 4c7c1a9..9f535fa 100644 --- a/plugins/keyboard/data/com.kylinsec.Kiran.SessionDaemon.Keyboard.xml +++ b/plugins/keyboard/data/com.kylinsec.Kiran.SessionDaemon.Keyboard.xml @@ -48,6 +48,35 @@ clear layout option. + + + enable option. + + Switch CapsLock Tips option. + + + + + enable option. + + Switch NumLock tips option. + + + + + Whether capslock and numlock is enabled. + + + + + Whether capslock tips is enabled. + + + + + Whether numlock tips is enabled. + + Whether repeat to trigger KeyPress and KeyRelease event when key is pressed. diff --git a/plugins/keyboard/src/pages/general/general-page.cpp b/plugins/keyboard/src/pages/general/general-page.cpp index 39608a9..dceb93f 100644 --- a/plugins/keyboard/src/pages/general/general-page.cpp +++ b/plugins/keyboard/src/pages/general/general-page.cpp @@ -12,19 +12,22 @@ * Author: yuanxing */ -#include "ui_general-page.h" #include "general-page.h" #include "keyboard_backEnd_proxy.h" +#include "ui_general-page.h" #include +#include #include #include -#include GeneralPage::GeneralPage(QWidget *parent) : QWidget(parent), - ui(new Ui::GeneralPage), - m_keyboardInterface(new KeyboardBackEndProxy(KEYBOARD_DBUS_NAME,KEYBOARD_OBJECT_PATH,QDBusConnection::sessionBus(),this)) + ui(new Ui::GeneralPage), + m_keyboardInterface(new KeyboardBackEndProxy(KEYBOARD_DBUS_NAME, KEYBOARD_OBJECT_PATH, QDBusConnection::sessionBus(), this)), + m_modifierLockEnabled(false), + m_capslockTipsEnabled(false), + m_numlockTipsEnabled(false) { ui->setupUi(this); @@ -46,17 +49,62 @@ void GeneralPage::init() m_timer = new QTimer(this); m_timer->setInterval(100); m_timer->setSingleShot(true); - connect(m_timer, &QTimer::timeout,this,&GeneralPage::handleSaverTimerTimeOut); + connect(m_timer, &QTimer::timeout, this, &GeneralPage::handleSaverTimerTimeOut); ui->lineEdit_key->setPlaceholderText(tr("Enter characters to test the settings")); +#ifdef MODIFIER_LOCK_TIPS + // 修饰键提示开关 + m_modifierLockEnabled = m_keyboardInterface->modifier_lock_enabled(); + connect(m_keyboardInterface, &KeyboardBackEndProxy::modifier_lock_enabledChanged, [this](bool enabled) { + KLOG_DEBUG() << "keyboard general setting modifier lock enable changed:" << enabled; + m_modifierLockEnabled = enabled; + ui->widget_modifier_lock->setVisible(enabled); + ui->switch_capsLock_tip->setChecked(m_keyboardInterface->capslock_tips_enabled()); + ui->switch_numLock_tip->setChecked(m_keyboardInterface->numlock_tips_enabled()); + }); + + if (m_modifierLockEnabled) + { + //大小写锁定提示 + m_capslockTipsEnabled = m_keyboardInterface->capslock_tips_enabled(); + ui->switch_capsLock_tip->setChecked(m_capslockTipsEnabled); + + connect(ui->switch_capsLock_tip, &KiranSwitchButton::toggled, + this, &GeneralPage::handleSwitchCapsLockTipToggled); + connect(m_keyboardInterface, &KeyboardBackEndProxy::capslock_tips_enabledChanged, [this](bool enabled) { + KLOG_DEBUG() << "keyboard general setting capslock tips enable changed:" << enabled; + m_capslockTipsEnabled = enabled; + ui->switch_capsLock_tip->setChecked(enabled); + }); + + //数字键盘锁定提示 + m_numlockTipsEnabled = m_keyboardInterface->numlock_tips_enabled(); + ui->switch_numLock_tip->setChecked(m_numlockTipsEnabled); + + connect(ui->switch_numLock_tip, &KiranSwitchButton::toggled, + this, &GeneralPage::handleSwitchNumLockTipsToggled); + connect(m_keyboardInterface, &KeyboardBackEndProxy::numlock_tips_enabledChanged, [this](bool enabled) { + KLOG_DEBUG() << "keyboard general setting numlock tips enable changed:" << enabled; + m_numlockTipsEnabled = enabled; + ui->switch_numLock_tip->setChecked(enabled); + }); + } + else + { + ui->widget_modifier_lock->hide(); + } +#else + ui->widget_modifier_lock->hide(); +#endif + // 重复键开关 m_repeateEnabled = m_keyboardInterface->repeat_enabled(); ui->switch_repeatKey->setChecked(m_repeateEnabled); handleSwitchRepeatKeyToggled(m_repeateEnabled); - connect(ui->switch_repeatKey,&KiranSwitchButton::toggled, - this,&GeneralPage::handleSwitchRepeatKeyToggled); - connect(m_keyboardInterface,&KeyboardBackEndProxy::repeat_enabledChanged,[this](bool enabled){ + connect(ui->switch_repeatKey, &KiranSwitchButton::toggled, + this, &GeneralPage::handleSwitchRepeatKeyToggled); + connect(m_keyboardInterface, &KeyboardBackEndProxy::repeat_enabledChanged, [this](bool enabled) { KLOG_DEBUG() << "keyboard general setting repeat enable changed:" << enabled; m_repeateEnabled = enabled; ui->switch_repeatKey->setChecked(enabled); @@ -65,30 +113,30 @@ void GeneralPage::init() // 重复键延时设置 m_delay = m_keyboardInterface->repeat_delay(); ui->hslider_delay->setValue(m_delay); - connect(ui->hslider_delay,&QSlider::valueChanged,[this](int value){ + connect(ui->hslider_delay, &QSlider::valueChanged, [this](int value) { m_timer->start(); }); - connect(m_keyboardInterface,&KeyboardBackEndProxy::repeat_delayChanged,[this](int delay){ - if( m_delay!=delay ) + connect(m_keyboardInterface, &KeyboardBackEndProxy::repeat_delayChanged, [this](int delay) { + if (m_delay != delay) { KLOG_DEBUG() << "keyboard general setting repeat delay changed:" << delay; - m_delay=delay; + m_delay = delay; ui->hslider_delay->setValue(m_delay); } }); - // 重复键间隔设置 m_interval = m_keyboardInterface->repeat_interval(); ui->hslider_interval->setValue(m_interval); - connect(ui->hslider_interval,&QSlider::valueChanged,[this](int value){ + connect(ui->hslider_interval, &QSlider::valueChanged, [this](int value) { m_timer->start(); }); - connect(m_keyboardInterface,&KeyboardBackEndProxy::repeat_intervalChanged,[this](int interval){ + connect(m_keyboardInterface, &KeyboardBackEndProxy::repeat_intervalChanged, [this](int interval) { if (m_interval != (ui->hslider_interval->maximum() - interval + 10)) { KLOG_DEBUG() << "keyboard general setting repeat interval changed:" << interval; - m_interval = ui->hslider_interval->maximum() - interval + 10;; + m_interval = ui->hslider_interval->maximum() - interval + 10; + ; ui->hslider_interval->setValue(m_interval); } }); @@ -127,3 +175,21 @@ void GeneralPage::handleSwitchRepeatKeyToggled(bool checked) m_keyboardInterface->setRepeat_enabled(checked); } } + +void GeneralPage::handleSwitchCapsLockTipToggled(bool checked) +{ + if (m_capslockTipsEnabled != checked) + { + m_capslockTipsEnabled = checked; + m_keyboardInterface->setCapslock_tips_enabled(checked); + } +} + +void GeneralPage::handleSwitchNumLockTipsToggled(bool checked) +{ + if (m_numlockTipsEnabled != checked) + { + m_numlockTipsEnabled = checked; + m_keyboardInterface->setNumlock_tips_enabled(checked); + } +} diff --git a/plugins/keyboard/src/pages/general/general-page.h b/plugins/keyboard/src/pages/general/general-page.h index e7cce52..985c6dd 100644 --- a/plugins/keyboard/src/pages/general/general-page.h +++ b/plugins/keyboard/src/pages/general/general-page.h @@ -38,14 +38,19 @@ private: private slots: void handleSaverTimerTimeOut(); void handleSwitchRepeatKeyToggled(bool checked); + void handleSwitchCapsLockTipToggled(bool checked); + void handleSwitchNumLockTipsToggled(bool checked); private: Ui::GeneralPage *ui; - KeyboardBackEndProxy* m_keyboardInterface; + KeyboardBackEndProxy *m_keyboardInterface; QTimer *m_timer = nullptr; bool m_repeateEnabled = false; qint32 m_delay; qint32 m_interval; + bool m_modifierLockEnabled; + bool m_capslockTipsEnabled; + bool m_numlockTipsEnabled; }; #endif // GENERALPAGE_H diff --git a/plugins/keyboard/src/pages/general/general-page.ui b/plugins/keyboard/src/pages/general/general-page.ui index e5e12aa..62337f4 100644 --- a/plugins/keyboard/src/pages/general/general-page.ui +++ b/plugins/keyboard/src/pages/general/general-page.ui @@ -6,8 +6,8 @@ 0 0 - 556 - 425 + 605 + 497 @@ -29,6 +29,89 @@ 40 + + + + + 16 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Capslock Tip + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + Numlock Tip + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + diff --git a/plugins/keyboard/translation/kiran-cpanel-keyboard.zh_CN.ts b/plugins/keyboard/translation/kiran-cpanel-keyboard.zh_CN.ts index 882cf4b..8eb7cbe 100644 --- a/plugins/keyboard/translation/kiran-cpanel-keyboard.zh_CN.ts +++ b/plugins/keyboard/translation/kiran-cpanel-keyboard.zh_CN.ts @@ -17,68 +17,78 @@ - + + Capslock Tip + 大写锁定提示 + + + + Numlock Tip + 数字键盘锁定提示 + + + Repeat Key 重复键 - + (Repeat a key while holding it down) (按住某一键时重复该键) - + SwitchRepeatKey - + Delay 延时 - + SliderRepeatDelay - + Short - + Long - + Interval 速度 - + SliderRepeatInterval - + Slow - + Fast - - + + Enter characters to test the settings 输入字符来测试设置 - + EditTestRepeatKey -- 2.27.0