mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat: 添加任务栏-键盘布局图标提供配置文件或接口
社区版桌面系统支持任务栏显示键盘布局插件,用户可以gsetting指令控制插件的显示、隐藏、置灰功能,其他版本桌面系统不显示键盘布局插件插件. Log: 社区版任务栏支持键盘布局插件功能 Task: https://pms.uniontech.com/zentao/task-view-80977.html Change-Id: I7abc680b2ef425644d9d43ee1c1f777d9e853c53
This commit is contained in:
parent
ea709fe3be
commit
03977ba903
1
debian/dde-dock.install
vendored
1
debian/dde-dock.install
vendored
@ -8,4 +8,5 @@ usr/lib/dde-dock/plugins/liboverlay-warning.so
|
||||
usr/lib/dde-dock/plugins/system-trays
|
||||
usr/lib/dde-dock/plugins/libmultitasking.so
|
||||
usr/lib/dde-dock/plugins/libshow-desktop.so
|
||||
usr/lib/dde-dock/plugins/libkeyboard-layout.so
|
||||
usr/share
|
||||
|
@ -26,6 +26,10 @@
|
||||
#include <QLibrary>
|
||||
#include <QGSettings>
|
||||
|
||||
#include <DSysInfo>
|
||||
|
||||
DCORE_USE_NAMESPACE
|
||||
|
||||
PluginLoader::PluginLoader(const QString &pluginDirPath, QObject *parent)
|
||||
: QThread(parent)
|
||||
, m_pluginDirPath(pluginDirPath)
|
||||
@ -56,6 +60,10 @@ void PluginLoader::run()
|
||||
if (!QLibrary::isLibrary(file))
|
||||
continue;
|
||||
|
||||
// 社区版需要加载键盘布局,其他不需要
|
||||
if (file.contains("libkeyboard-layout") && !DSysInfo::isCommunityEdition())
|
||||
continue;
|
||||
|
||||
// TODO: old dock plugins is uncompatible
|
||||
if (file.startsWith("libdde-dock-"))
|
||||
continue;
|
||||
|
@ -148,6 +148,22 @@
|
||||
</description>
|
||||
</key>
|
||||
</schema>
|
||||
<schema path="/com/deepin/dde/dock/module/keyboard/" id="com.deepin.dde.dock.module.keyboard" gettext-domain="DDE">
|
||||
<key type="b" name="enable">
|
||||
<default>true</default>
|
||||
<summary>Module Enable</summary>
|
||||
<description>
|
||||
Control Module Enable
|
||||
</description>
|
||||
</key>
|
||||
<key type="b" name="item-enable">
|
||||
<default>true</default>
|
||||
<summary>Menu Enable</summary>
|
||||
<description>
|
||||
disable item
|
||||
</description>
|
||||
</key>
|
||||
</schema>
|
||||
<schema path="/com/deepin/dde/dock/module/onboard/" id="com.deepin.dde.dock.module.onboard" gettext-domain="DDE">
|
||||
<key type="b" name="control">
|
||||
<default>false</default>
|
||||
|
@ -6,7 +6,7 @@ add_subdirectory("power")
|
||||
add_subdirectory("sound")
|
||||
add_subdirectory("tray")
|
||||
add_subdirectory("trash")
|
||||
#add_subdirectory("keyboard-layout")
|
||||
add_subdirectory("keyboard-layout")
|
||||
add_subdirectory("onboard")
|
||||
add_subdirectory("overlay-warning")
|
||||
add_subdirectory("show-desktop")
|
||||
|
@ -61,6 +61,17 @@ QString DBusAdaptors::layout() const
|
||||
return m_currentLayout;
|
||||
}
|
||||
|
||||
void DBusAdaptors::setLayout(const QString &str)
|
||||
{
|
||||
m_currentLayout = str;
|
||||
emit layoutChanged(str);
|
||||
}
|
||||
|
||||
Keyboard *DBusAdaptors::getCurrentKeyboard()
|
||||
{
|
||||
return m_keyboard;
|
||||
}
|
||||
|
||||
void DBusAdaptors::onClicked(int button, int x, int y)
|
||||
{
|
||||
// button value means(XCB_BUTTON_INDEX):
|
||||
|
@ -44,8 +44,11 @@ public:
|
||||
~DBusAdaptors();
|
||||
|
||||
public:
|
||||
Q_PROPERTY(QString layout READ layout NOTIFY layoutChanged)
|
||||
Q_PROPERTY(QString layout READ layout WRITE setLayout NOTIFY layoutChanged)
|
||||
QString layout() const;
|
||||
void setLayout(const QString &str);
|
||||
|
||||
Keyboard *getCurrentKeyboard();
|
||||
|
||||
public slots:
|
||||
void onClicked(int button, int x, int y);
|
||||
|
@ -18,10 +18,14 @@
|
||||
*/
|
||||
|
||||
#include "keyboardplugin.h"
|
||||
#include "utils.h"
|
||||
|
||||
KeyboardPlugin::KeyboardPlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_gsettings(Utils::ModuleSettingsPtr(pluginName(), QByteArray(), this))
|
||||
{
|
||||
if (m_gsettings)
|
||||
connect(m_gsettings, &QGSettings::changed, this, &KeyboardPlugin::onGSettingsChanged);
|
||||
}
|
||||
|
||||
KeyboardPlugin::~KeyboardPlugin()
|
||||
@ -91,3 +95,15 @@ void KeyboardPlugin::setSortKey(const QString &itemKey, const int order)
|
||||
|
||||
m_proxyInter->saveValue(this, key, order);
|
||||
}
|
||||
|
||||
void KeyboardPlugin::onGSettingsChanged(const QString &key)
|
||||
{
|
||||
Q_UNUSED(key);
|
||||
|
||||
// 键盘布局插件处显示的内容就是QLabel中的内容,有文字了就显示,没有文字就不显示了
|
||||
if (m_gsettings && m_gsettings->keys().contains("enable")) {
|
||||
const bool enable = m_gsettings->get("enable").toBool();
|
||||
QString layoutStr = m_dbusAdaptors->getCurrentKeyboard()->currentLayout().split(';').first();
|
||||
m_dbusAdaptors->setLayout(enable ? layoutStr : "");
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "dbusadaptors.h"
|
||||
|
||||
class QGSettings;
|
||||
|
||||
class KeyboardPlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -43,8 +45,12 @@ public:
|
||||
int itemSortKey(const QString &itemKey) override;
|
||||
void setSortKey(const QString &itemKey, const int order) override;
|
||||
|
||||
private slots:
|
||||
void onGSettingsChanged(const QString &key);
|
||||
|
||||
private:
|
||||
DBusAdaptors *m_dbusAdaptors = nullptr;
|
||||
const QGSettings *m_gsettings;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -20,8 +20,8 @@
|
||||
*/
|
||||
|
||||
#include "indicatortraywidget.h"
|
||||
#include "util/utils.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
#include <QBoxLayout>
|
||||
|
||||
@ -31,6 +31,8 @@
|
||||
IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget *parent, Qt::WindowFlags f)
|
||||
: AbstractTrayWidget(parent, f)
|
||||
, m_indicatorName(indicatorName)
|
||||
, m_gsettings(Utils::ModuleSettingsPtr("keyboard", QByteArray(), this))
|
||||
, m_enableClick(true)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
@ -38,9 +40,9 @@ IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget *
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
m_label = new QLabel(this);
|
||||
|
||||
QPalette p = palette();
|
||||
QPalette p = m_label->palette();
|
||||
p.setColor(QPalette::Foreground, Qt::white);
|
||||
p.setColor(QPalette::Background, Qt::red);
|
||||
p.setColor(QPalette::Background, Qt::transparent);
|
||||
m_label->setPalette(p);
|
||||
|
||||
m_label->setAttribute(Qt::WA_TranslucentBackground);
|
||||
@ -56,6 +58,14 @@ IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget *
|
||||
interface,
|
||||
this,
|
||||
QDBusConnection::ExportScriptableSlots);
|
||||
|
||||
if (m_gsettings) {
|
||||
// 显示键盘布局时更新label的状态
|
||||
if (m_gsettings->keys().contains("itemEnable"))
|
||||
enableLabel(m_gsettings->get("itemEnable").toBool());
|
||||
|
||||
connect(m_gsettings, &QGSettings::changed, this, &IndicatorTrayWidget::onGSettingsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
IndicatorTrayWidget::~IndicatorTrayWidget()
|
||||
@ -74,7 +84,32 @@ void IndicatorTrayWidget::updateIcon()
|
||||
|
||||
void IndicatorTrayWidget::sendClick(uint8_t buttonIndex, int x, int y)
|
||||
{
|
||||
Q_EMIT clicked(buttonIndex, x, y);
|
||||
if (m_enableClick)
|
||||
Q_EMIT clicked(buttonIndex, x, y);
|
||||
}
|
||||
|
||||
void IndicatorTrayWidget::enableLabel(bool enable)
|
||||
{
|
||||
QPalette p = m_label->palette();
|
||||
if (!enable) {
|
||||
m_enableClick = false;
|
||||
p.setColor(QPalette::Disabled, QPalette::Foreground, Qt::lightGray);
|
||||
p.setColor(QPalette::Disabled, QPalette::Background, Qt::transparent);
|
||||
m_label->setEnabled(enable);
|
||||
} else {
|
||||
m_enableClick = true;
|
||||
p.setColor(QPalette::Normal, QPalette::BrightText, Qt::white);
|
||||
p.setColor(QPalette::Normal, QPalette::Background, Qt::transparent);
|
||||
m_label->setEnabled(enable);
|
||||
}
|
||||
|
||||
m_label->setPalette(p);
|
||||
m_label->update();
|
||||
}
|
||||
|
||||
void IndicatorTrayWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
return QWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void IndicatorTrayWidget::setPixmapData(const QByteArray &data)
|
||||
@ -89,3 +124,13 @@ void IndicatorTrayWidget::setText(const QString &text)
|
||||
m_label->setText(text);
|
||||
}
|
||||
|
||||
void IndicatorTrayWidget::onGSettingsChanged(const QString &key)
|
||||
{
|
||||
Q_UNUSED(key);
|
||||
|
||||
if (m_gsettings && m_gsettings->keys().contains("itemEnable")) {
|
||||
const bool itemEnable = m_gsettings->get("itemEnable").toBool();
|
||||
enableLabel(itemEnable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
#include "abstracttraywidget.h"
|
||||
|
||||
class QGSettings;
|
||||
|
||||
class IndicatorTrayWidget: public AbstractTrayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -36,13 +38,20 @@ public:
|
||||
QString itemKeyForConfig() override;
|
||||
void updateIcon() override;
|
||||
void sendClick(uint8_t, int, int) override;
|
||||
void enableLabel(bool enable);
|
||||
static QString toIndicatorKey(const QString &indicatorName) { return QString("indicator:%1").arg(indicatorName); }
|
||||
static bool isIndicatorKey(const QString &itemKey) { return itemKey.startsWith("indicator:"); }
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void setPixmapData(const QByteArray &data);
|
||||
Q_SCRIPTABLE void setText(const QString &text);
|
||||
|
||||
private slots:
|
||||
void onGSettingsChanged(const QString &key);
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked(uint8_t, int, int);
|
||||
|
||||
@ -50,5 +59,7 @@ private:
|
||||
QLabel *m_label;
|
||||
|
||||
QString m_indicatorName;
|
||||
const QGSettings *m_gsettings;
|
||||
bool m_enableClick; // 置灰时设置为false,不触发click信号
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user