feat(panel/ukcc-plugin)任务栏增加相关配置,可实现配置托盘仅在主屏显示或在所有显示器都显示功能

This commit is contained in:
amingamingaming 2024-09-03 10:17:11 +08:00 committed by iaom
parent 5338cd0f89
commit 0e956e7d40
9 changed files with 123 additions and 4 deletions

View File

@ -32,6 +32,7 @@ RemoteConfig::RemoteConfig(QObject *parent) : RemoteConfigSource(parent)
, m_panelLock(false)
, m_taskBarIconsShowedOn(GeneralConfigDefine::TaskBarIconsShowedOn::PanelWhereWindowIsOpen)
, m_showPanelOnAllScreens(true)
, m_showSystemTrayOnAllPanels(true)
{
qRegisterMetaType<GeneralConfigDefine::MergeIcons>("GeneralConfigDefine::MergeIcons");
qRegisterMetaType<GeneralConfigDefine::PanelLocation>("GeneralConfigDefine::PanelLocation");
@ -66,6 +67,7 @@ RemoteConfig::RemoteConfig(QObject *parent) : RemoteConfigSource(parent)
m_panelAutoHide = m_mainViewConfig->getValue(QStringLiteral("panelAutoHide")).toBool();
m_panelLock = m_mainViewConfig->getValue(QStringLiteral("lockPanel")).toBool();
m_panelWidgets = m_mainViewConfig->getValue(QStringLiteral("widgets")).toStringList();
m_showSystemTrayOnAllPanels = m_mainViewConfig->getValue(QStringLiteral("showSystemTrayOnAllPanels")).toBool();
connect(m_mainViewConfig, &UkuiQuick::Config::configChanged, this, &RemoteConfig::onPanelViewConfigChanged);
}
}
@ -193,6 +195,12 @@ void RemoteConfig::onPanelViewConfigChanged(const QString &key)
} else if (key == "position") {
updatePanelLocation();
Q_EMIT panelLocationChanged(m_panelLocation);
} else if (key == "showSystemTrayOnAllPanels") {
bool value = m_mainViewConfig->getValue(QStringLiteral("showSystemTrayOnAllPanels")).toBool();
if(value != m_showSystemTrayOnAllPanels) {
m_showSystemTrayOnAllPanels = value;
Q_EMIT showSystemTrayOnAllPanelsChanged(m_showSystemTrayOnAllPanels);
}
}
}
@ -300,3 +308,14 @@ void RemoteConfig::setShowPanelOnAllScreens(bool showPanelOnAllScreens)
Q_EMIT showPanelOnAllScreensChanged(m_showPanelOnAllScreens);
}
}
void RemoteConfig::setShowSystemTrayOnAllPanels(bool showSystemTrayOnAllPanels)
{
if (showSystemTrayOnAllPanels != m_showSystemTrayOnAllPanels) {
m_showSystemTrayOnAllPanels = showSystemTrayOnAllPanels;
if(m_mainViewConfig) {
m_mainViewConfig->setValue(QStringLiteral("showSystemTrayOnAllPanels"), showSystemTrayOnAllPanels);
}
Q_EMIT showSystemTrayOnAllPanelsChanged(m_showSystemTrayOnAllPanels);
}
}

View File

@ -44,6 +44,7 @@ public:
QStringList trayIconsInhibited() const override {return m_trayIconsInhibited; }
GeneralConfigDefine::TaskBarIconsShowedOn taskBarIconsShowedOn() const override { return m_taskBarIconsShowedOn; };
bool showPanelOnAllScreens() const override { return m_showPanelOnAllScreens; }
bool showSystemTrayOnAllPanels() const override { return m_showSystemTrayOnAllPanels; }
void setMergeIcons(GeneralConfigDefine::MergeIcons mergeIcons) override;
void setPanelLocation(GeneralConfigDefine::PanelLocation panelLocation) override;
@ -54,6 +55,7 @@ public:
void setTrayIconsInhibited(QStringList trayIconsInhibited) override;
void setTaskBarIconsShowedOn(GeneralConfigDefine::TaskBarIconsShowedOn taskBarIconsShowedOn) override;
void setShowPanelOnAllScreens(bool showPanelOnAllScreens) override;
void setShowSystemTrayOnAllPanels(bool showSystemTrayOnAllPanels) override;
public Q_SLOTS:
void disableWidget(const QString &id, bool disable) override;
@ -76,6 +78,7 @@ private:
GeneralConfigDefine::TaskBarIconsShowedOn m_taskBarIconsShowedOn;
bool m_showPanelOnAllScreens;
bool m_showSystemTrayOnAllPanels;
UkuiQuick::Config *m_panelConfig = nullptr;
UkuiQuick::Config *m_mainViewConfig = nullptr;

View File

@ -31,6 +31,7 @@ class RemoteConfig
PROP(QStringList trayIconsInhibited READWRITE);
PROP(GeneralConfigDefine::TaskBarIconsShowedOn taskBarIconsShowedOn READWRITE);
PROP(bool showPanelOnAllScreens READWRITE);
PROP(bool showSystemTrayOnAllPanels READWRITE);
SLOT(disableWidget(const QString &id, bool disable))
};

View File

@ -42,12 +42,14 @@ void Shell::start()
Screen *primary = m_screenManager->primaryScreen();
auto panel = new Panel(primary, "panel0");
connect(m_screenManager, &ScreensManager::primaryScreenChanged, panel, &Panel::primaryScreenChanged);
m_panels.insert(primary, panel);
//如果设置为在所有屏幕上显示任务栏再创建副屏的任务栏,否则不创建
if(m_showPanelOnAllScreens) {
for(Screen * screen : m_screenManager->screens()) {
if(screen != primary) {
panel = new Panel(screen, QString("panel%1").arg(m_panels.size()));
connect(m_screenManager, &ScreensManager::primaryScreenChanged, panel, &Panel::primaryScreenChanged);
m_panels.insert(screen, panel);
}
}
@ -62,6 +64,7 @@ void Shell::start()
}
if(!m_panels.contains(screen)) {
panel = new Panel(screen, QString("panel%1").arg(m_panels.size()));
connect(m_screenManager, &ScreensManager::primaryScreenChanged, panel, &Panel::primaryScreenChanged);
m_panels.insert(screen, panel);
}
});
@ -154,6 +157,7 @@ bool Shell::event(QEvent* e)
for(Screen * screen : m_screenManager->screens()) {
if(!m_panels.contains(screen)) {
auto panel = new Panel(screen, QString("panel%1").arg(m_panels.size()));
connect(m_screenManager, &ScreensManager::primaryScreenChanged, panel, &Panel::primaryScreenChanged);
m_panels.insert(screen, panel);
}
}

View File

@ -63,6 +63,9 @@ Panel::Panel(Screen *screen, const QString &id, QWindow *parent)
loadWidgetsConfig();
loadActions();
setShowSystemTrayStatus();
loadMainViewItem();
// 加载任务栏设置
initPanelConfig();
@ -100,7 +103,7 @@ void Panel::initIsland()
UkuiQuick::WidgetContainer::widgetLoader().addWidgetSearchPath(QStringLiteral(":/ukui-panel"));
// TODO: 配置错误检查
if (!loadMainView(defaultViewId)) {
if (!loadMainViewWithoutItem(defaultViewId)) {
// 全部使用默认配置
auto metadata = UkuiQuick::WidgetMetadata(QStringLiteral(":/ukui-panel/org.ukui.panel"));
auto cont = new UkuiQuick::WidgetContainer(metadata, this);
@ -164,6 +167,15 @@ void Panel::initPanelConfig()
setAutoHide(config->getValue(key).toBool());
} else if (key == QStringLiteral("lockPanel")) {
setLockPanel(config->getValue(key).toBool());
} else if (key == QStringLiteral("showSystemTrayOnAllPanels")) {
//根据托盘是否显示在任务栏上面的值更新托盘的启用状态
if(config->getValue(key).toBool()) {
mainView()->addWidget(QStringLiteral("org.ukui.systemTray"), m_systemTrayInstance);
} else {
if(m_screen->internal() != qApp->primaryScreen()) {
mainView()->removeWidget(QStringLiteral("org.ukui.systemTray"));
}
}
}
});
}
@ -336,6 +348,9 @@ void Panel::loadWidgetsConfig()
wData.insert(QStringLiteral("instanceId"), instanceId);
containerConfig->addChild(QStringLiteral("widgets"), wData);
if(widget == QStringLiteral("org.ukui.systemTray")) {
m_systemTrayInstance = instanceId;
}
mainView()->addWidget(widget, instanceId);
}
@ -921,4 +936,40 @@ void Panel::activeHideTimer(bool active)
}
}
void Panel::primaryScreenChanged(Screen *screen)
{
if(m_screen == screen) {
mainView()->addWidget(QStringLiteral("org.ukui.systemTray"), m_systemTrayInstance);
} else {
if(mainView()->config()->getValue("showSystemTrayOnAllPanels").toBool()) {
mainView()->addWidget(QStringLiteral("org.ukui.systemTray"), m_systemTrayInstance);
} else {
mainView()->removeWidget(QStringLiteral("org.ukui.systemTray"));
}
}
}
void Panel::setShowSystemTrayStatus()
{
//读取托盘是否始终显示在任务栏上
auto value = mainView()->config()->getValue(QStringLiteral("showSystemTrayOnAllPanels"));
if (!value.isValid()) {
value = true;
mainView()->config()->setValue(QStringLiteral("showSystemTrayOnAllPanels"), value);
}
//获取系统托盘的instanceid
if(m_systemTrayInstance == -1) {
auto widgetsList = mainView()->config()->children(QStringLiteral("widgets"));
for (const auto widgetConfig : widgetsList) {
if(widgetConfig->getValue(QStringLiteral("id")).toString() == QStringLiteral("org.ukui.systemTray")) {
m_systemTrayInstance = widgetConfig->getValue(QStringLiteral("instanceId")).toInt();
break;
}
}
}
if(m_screen->internal() != qApp->primaryScreen() && !value.toBool()) {
mainView()->removeWidget(QStringLiteral("org.ukui.systemTray"));
}
}
} // UkuiPanel

View File

@ -50,7 +50,13 @@ public:
Q_INVOKABLE void customPanelSize(int distance);
Q_INVOKABLE void changeCursor(const QString &type);
Q_INVOKABLE void changePanelPos(UkuiQuick::Types::Pos pos);
public Q_SLOTS:
/**
* @brief primaryScreenChanged
* @param screen
* @return
*/
void primaryScreenChanged(Screen *screen);
Q_SIGNALS:
void lockPanelChanged();
void enableCustomSizeChanged();
@ -74,7 +80,6 @@ private Q_SLOTS:
void widgetActionTriggered(const QAction *);
void disableWidget(const QString &id, bool disable);
void onContainerActiveChanged();
private:
void initConfig();
void initPanelConfig();
@ -91,7 +96,8 @@ private:
void updateLockPanelAction();
void updateMask();
void initIsland();
//初始化系统托盘是否显示
void setShowSystemTrayStatus();
private:
int m_panelSize {48};
GeneralConfigDefine::PanelSizePolicy m_sizePolicy {GeneralConfigDefine::Small};
@ -114,6 +120,7 @@ private:
bool m_containsMouse = false;
int m_panelMaxSize = 92;
int m_panelMinSize = 48;
int m_systemTrayInstance = -1;
};
} // UkuiPanel

View File

@ -219,6 +219,22 @@ void PanelUkccPlugin::initUI()
m_vLayout1->addWidget(m_showPanelOnAllScreensFrame);
m_vLayout1->addWidget(setLine(m_frame1));
//show system tray on all panel
m_showSystemTrayOnAllPanelsFrame = new QFrame(m_frame1);
m_showSystemTrayOnAllPanelsFrame->setFixedHeight(56);
m_showSystemTrayOnAllPanelsLayout = new QHBoxLayout(m_showSystemTrayOnAllPanelsFrame);
m_showSystemTrayOnAllPanelsLayout->setContentsMargins(16, 0, 16, 0);
m_showSystemTrayOnAllPanelsLabel = new QLabel(m_showSystemTrayOnAllPanelsFrame);
m_showSystemTrayOnAllPanelsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_showSystemTrayOnAllPanelsLabel->setText(tr("Show system tray area on all panels "));
m_showSystemTrayOnAllPanels = new kdk::KSwitchButton(m_showSystemTrayOnAllPanelsFrame);
m_showSystemTrayOnAllPanels->setFixedSize(48,24);
m_showSystemTrayOnAllPanels->setEnabled(false);
m_showSystemTrayOnAllPanelsLayout->addWidget(m_showSystemTrayOnAllPanelsLabel);
m_showSystemTrayOnAllPanelsLayout->addWidget(m_showSystemTrayOnAllPanels);
m_vLayout1->addWidget(m_showSystemTrayOnAllPanelsFrame);
m_vLayout1->addWidget(setLine(m_frame1));
//taskmanager icons showed on
m_iconsShowedOnFrame = new QFrame(m_frame1);
m_iconsShowedOnFrame->setFixedHeight(56);
@ -388,6 +404,11 @@ void PanelUkccPlugin::initData()
}, Qt::UniqueConnection);
m_showPanelOnAllScreens->setEnabled(true);
m_showSystemTrayOnAllPanels->setChecked(m_configReplica->showSystemTrayOnAllPanels());
connect(m_showSystemTrayOnAllPanels, &kdk::KSwitchButton::stateChanged, m_configReplica, &RemoteConfigReplica::setShowSystemTrayOnAllPanels);
connect(m_configReplica, &RemoteConfigReplica::showSystemTrayOnAllPanelsChanged, m_showSystemTrayOnAllPanels, &kdk::KSwitchButton::setChecked, Qt::UniqueConnection);
m_showSystemTrayOnAllPanels->setEnabled(true);
m_showTaskView->setChecked(!m_configReplica->disabledWidgets().contains(QStringLiteral("org.ukui.panel.taskView")));
connect(m_configReplica, &RemoteConfigReplica::disabledWidgetsChanged, m_showTaskView, [this] (const QStringList& list) {
m_showTaskView->setChecked(!list.contains(QStringLiteral("org.ukui.panel.taskView")));
@ -449,6 +470,9 @@ void PanelUkccPlugin::sourceStateChanged(QRemoteObjectReplica::State state, QRem
m_showPanelOnAllScreens->disconnect(m_configReplica);
m_showPanelOnAllScreens->disconnect(this);
m_showPanelOnAllScreens->setEnabled(false);
m_showSystemTrayOnAllPanels->disconnect(m_configReplica);
m_showSystemTrayOnAllPanels->disconnect(this);
m_showSystemTrayOnAllPanels->setEnabled(false);
for(const QString &id : m_systemTrayIconId) {
auto button = m_frame3->findChild<SwitchButton *>(id, Qt::FindDirectChildrenOnly);
if(button) {

View File

@ -100,6 +100,12 @@ private:
QLabel *m_showPanelOnAllScreensLabel = nullptr;
kdk::KSwitchButton *m_showPanelOnAllScreens = nullptr;
//show system tray on all panel
QFrame *m_showSystemTrayOnAllPanelsFrame = nullptr;
QHBoxLayout *m_showSystemTrayOnAllPanelsLayout = nullptr;
QLabel *m_showSystemTrayOnAllPanelsLabel = nullptr;
kdk::KSwitchButton *m_showSystemTrayOnAllPanels = nullptr;
//icons showed on witch panel
QFrame *m_iconsShowedOnFrame = nullptr;
QHBoxLayout *m_iconsShowedOnLayout = nullptr;

View File

@ -120,6 +120,10 @@
<translation></translation>
<extra-contents_path>/Panel/Show panel on all screens</extra-contents_path>
</message>
<message>
<source>Show system tray area on all panels </source>
<translation></translation>
</message>
</context>
<context>
<name>SwitchButton</name>