fix: 同步替换任务栏弹窗位置重置接口

This commit is contained in:
zhangyuanyuan1 2024-05-11 10:49:59 +08:00
parent ae8be60b63
commit 57939b27a1
4 changed files with 110 additions and 68 deletions

View File

@ -20,8 +20,12 @@
#include "vpnpage.h"
#include <QDebug>
#include <QScrollBar>
#include <QScreen>
#include "windowmanager/windowmanager.h"
#define PANEL_SETTINGS "org.ukui.panel.settings"
#define PANEL_SIZE_KEY "panelsize"
#define PANEL_POSITION_KEY "panelposition"
VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
{
@ -29,6 +33,7 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
m_connectResourse = new KyConnectResourse(this);
m_vpnConnectOperation = new KyVpnConnectOperation(this);
initPanelGSettings();
initUI();
initVpnArea();
installEventFilter(this);
@ -588,6 +593,33 @@ bool VpnPage::eventFilter(QObject *watched, QEvent *event)
return QWidget::eventFilter(watched, event);
}
void VpnPage::initPanelGSettings()
{
const QByteArray id(PANEL_SETTINGS);
if (QGSettings::isSchemaInstalled(id)) {
if (m_panelGSettings == nullptr) {
m_panelGSettings = new QGSettings(id, QByteArray(), this);
}
if (m_panelGSettings->keys().contains(PANEL_POSITION_KEY)) {
m_panelPosition = m_panelGSettings->get(PANEL_POSITION_KEY).toInt();
}
if (m_panelGSettings->keys().contains(PANEL_SIZE_KEY)) {
m_panelSize = m_panelGSettings->get(PANEL_SIZE_KEY).toInt();
}
connect(m_panelGSettings, &QGSettings::changed, this, [&] (const QString &key) {
if (key == PANEL_POSITION_KEY) {
m_panelPosition = m_panelGSettings->get(PANEL_POSITION_KEY).toInt();
}
if (key == PANEL_SIZE_KEY) {
m_panelSize = m_panelGSettings->get(PANEL_SIZE_KEY).toInt();
}
if (this->isVisible()) {
resetWindowPosition();
}
});
}
}
void VpnPage::deleteVpn(const QString &connUuid)
{
qDebug() << "[VpnPage] deleteVpn" << connUuid;
@ -649,50 +681,33 @@ void VpnPage::resetWindowPosition()
#define PANEL_LEFT 2
#define PANEL_RIGHT 3
//#define PANEL_BOTTOM 4
if (!m_positionInterface) {
m_positionInterface = new QDBusInterface("org.ukui.panel",
"/panel/position",
"org.ukui.panel",
QDBusConnection::sessionBus());
}
QRect rect;
QDBusReply<QVariantList> reply = m_positionInterface->call("GetPrimaryScreenGeometry");
//reply获取的参数共5个分别是 主屏可用区域的起点x坐标主屏可用区域的起点y坐标主屏可用区域的宽度主屏可用区域高度任务栏位置
if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) {
qCritical() << QDBusConnection::sessionBus().lastError().message();
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height()));
return;
}
QVariantList position_list = reply.value();
int position = position_list.at(4).toInt();
switch(position){
QRect availableGeo = QGuiApplication::screenAt(QCursor::pos())->geometry();
int x, y;
switch(m_panelPosition){
case PANEL_TOP:
//任务栏位于上方
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + MARGIN,
this->width(), this->height());
x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
y = availableGeo.y() + m_panelSize + MARGIN;
break;
//任务栏位于左边
case PANEL_LEFT:
rect = QRect(position_list.at(0).toInt() + MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
x = availableGeo.x() + m_panelSize + MARGIN;
y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
break;
//任务栏位于右边
case PANEL_RIGHT:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
x = availableGeo.x() + availableGeo.width() - m_panelSize - this->width() - MARGIN;
y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
break;
//任务栏位于下方
default:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
y = availableGeo.y() + availableGeo.height() - m_panelSize - this->height() - MARGIN;
break;
}
kdk::WindowManager::setGeometry(this->windowHandle(), rect);
qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(x, y, this->width(), this->height()));
qDebug() << " Position of ukui-panel is " << m_panelPosition << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
}
void VpnPage::resetListWidgetWidth()

View File

@ -66,6 +66,7 @@ protected:
bool eventFilter(QObject *watched, QEvent *event);
private:
void initPanelGSettings();
void initUI();
void initVpnArea();
void resetPageHeight();
@ -126,8 +127,11 @@ private:
QMap<QString, QListWidgetItem *> m_vpnItemMap;
QMap<QString, QListWidgetItem *> m_activeItemMap;
QDBusInterface * m_positionInterface = nullptr;
//获取任务栏位置和大小
QGSettings *m_panelGSettings = nullptr;
int m_panelPosition;
int m_panelSize;
public Q_SLOTS:

View File

@ -41,6 +41,9 @@
#define LOADING_TRAYICON_TIMER_MS 60
#define THEME_SCHAME "org.ukui.style"
#define COLOR_THEME "styleName"
#define PANEL_SETTINGS "org.ukui.panel.settings"
#define PANEL_SIZE_KEY "panelsize"
#define PANEL_POSITION_KEY "panelposition"
const QString v10Sp1 = "V10SP1";
const QString intel = "V10SP1-edu";
@ -164,6 +167,7 @@ void MainWindow::firstlyStart()
initWindowProperties();
initTransparency();
registerTrayIcon();
initPanelGSettings();
initUI();
initDbusConnnect();
initWindowTheme();
@ -325,6 +329,36 @@ void MainWindow::paintWithTrans()
m_centralWidget->tabBar()->setPalette(tabPal);
}
/**
* @brief MainWindow::initPanelGSettings
*/
void MainWindow::initPanelGSettings()
{
const QByteArray id(PANEL_SETTINGS);
if (QGSettings::isSchemaInstalled(id)) {
if (m_panelGSettings == nullptr) {
m_panelGSettings = new QGSettings(id, QByteArray(), this);
}
if (m_panelGSettings->keys().contains(PANEL_POSITION_KEY)) {
m_panelPosition = m_panelGSettings->get(PANEL_POSITION_KEY).toInt();
}
if (m_panelGSettings->keys().contains(PANEL_SIZE_KEY)) {
m_panelSize = m_panelGSettings->get(PANEL_SIZE_KEY).toInt();
}
connect(m_panelGSettings, &QGSettings::changed, this, [&] (const QString &key) {
if (key == PANEL_POSITION_KEY) {
m_panelPosition = m_panelGSettings->get(PANEL_POSITION_KEY).toInt();
}
if (key == PANEL_SIZE_KEY) {
m_panelSize = m_panelGSettings->get(PANEL_SIZE_KEY).toInt();
}
if (this->isVisible()) {
resetWindowPosition();
}
});
}
}
/**
* @brief MainWindow::initUI
*/
@ -503,50 +537,32 @@ void MainWindow::resetWindowPosition()
#define PANEL_LEFT 2
#define PANEL_RIGHT 3
//#define PANEL_BOTTOM 4
if (!m_positionInterface) {
m_positionInterface = new QDBusInterface("org.ukui.panel",
"/panel/position",
"org.ukui.panel",
QDBusConnection::sessionBus());
}
QRect rect;
QDBusReply<QVariantList> reply = m_positionInterface->call("GetPrimaryScreenGeometry");
//reply获取的参数共5个分别是 主屏可用区域的起点x坐标主屏可用区域的起点y坐标主屏可用区域的宽度主屏可用区域高度任务栏位置
if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) {
qCritical() << QDBusConnection::sessionBus().lastError().message();
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(0, 0, this->width(), this->height()));
return;
}
QVariantList position_list = reply.value();
int position = position_list.at(4).toInt();
switch(position){
case PANEL_TOP:
QRect availableGeo = QGuiApplication::screenAt(QCursor::pos())->geometry();
int x, y;
switch(m_panelPosition){
//任务栏位于上方
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + MARGIN,
this->width(), this->height());
case PANEL_TOP:
x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
y = availableGeo.y() + m_panelSize + MARGIN;
break;
//任务栏位于左边
case PANEL_LEFT:
rect = QRect(position_list.at(0).toInt() + MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
x = availableGeo.x() + m_panelSize + MARGIN;
y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
break;
//任务栏位于右边
case PANEL_RIGHT:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
x = availableGeo.x() + availableGeo.width() - m_panelSize - this->width() - MARGIN;
y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
break;
//任务栏位于下方
default:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
y = availableGeo.y() + availableGeo.height() - m_panelSize - this->height() - MARGIN;
break;
}
kdk::WindowManager::setGeometry(this->windowHandle(), rect);
qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
kdk::WindowManager::setGeometry(this->windowHandle(), QRect(x, y, this->width(), this->height()));
qDebug() << " Position of ukui-panel is " << m_panelPosition << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
}
/**

View File

@ -160,6 +160,7 @@ private:
void initWindowProperties();
void initTransparency();
void paintWithTrans();
void initPanelGSettings();
void initUI();
void initDbusConnnect();
void registerTrayIcon();
@ -194,9 +195,15 @@ private:
//监听主题的Gsettings
QGSettings * m_styleGsettings = nullptr;
//获取任务栏位置和大小
QGSettings *m_panelGSettings = nullptr;
int m_panelPosition;
int m_panelSize;
//获取和重置窗口位置
void resetWindowPosition();
QDBusInterface * m_positionInterface = nullptr;
//QDBusInterface * m_positionInterface = nullptr;
//托盘图标,托盘图标右键菜单
QSystemTrayIcon * m_trayIcon = nullptr;