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

Merge pull request !73 from zhangyuanyuan1/nile0511panelIface
This commit is contained in:
赵世旭 2024-05-20 03:30:12 +00:00 committed by Gitee
commit e17ed15f8e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 110 additions and 68 deletions

View File

@ -20,8 +20,12 @@
#include "vpnpage.h" #include "vpnpage.h"
#include <QDebug> #include <QDebug>
#include <QScrollBar> #include <QScrollBar>
#include <QScreen>
#include "windowmanager/windowmanager.h" #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) VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
{ {
@ -29,6 +33,7 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
m_connectResourse = new KyConnectResourse(this); m_connectResourse = new KyConnectResourse(this);
m_vpnConnectOperation = new KyVpnConnectOperation(this); m_vpnConnectOperation = new KyVpnConnectOperation(this);
initPanelGSettings();
initUI(); initUI();
initVpnArea(); initVpnArea();
installEventFilter(this); installEventFilter(this);
@ -588,6 +593,33 @@ bool VpnPage::eventFilter(QObject *watched, QEvent *event)
return QWidget::eventFilter(watched, 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) void VpnPage::deleteVpn(const QString &connUuid)
{ {
qDebug() << "[VpnPage] deleteVpn" << connUuid; qDebug() << "[VpnPage] deleteVpn" << connUuid;
@ -649,50 +681,33 @@ void VpnPage::resetWindowPosition()
#define PANEL_LEFT 2 #define PANEL_LEFT 2
#define PANEL_RIGHT 3 #define PANEL_RIGHT 3
//#define PANEL_BOTTOM 4 //#define PANEL_BOTTOM 4
if (!m_positionInterface) {
m_positionInterface = new QDBusInterface("org.ukui.panel", QRect availableGeo = QGuiApplication::screenAt(QCursor::pos())->geometry();
"/panel/position", int x, y;
"org.ukui.panel", switch(m_panelPosition){
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: case PANEL_TOP:
//任务栏位于上方 //任务栏位于上方
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
position_list.at(1).toInt() + MARGIN, y = availableGeo.y() + m_panelSize + MARGIN;
this->width(), this->height());
break; break;
//任务栏位于左边 //任务栏位于左边
case PANEL_LEFT: case PANEL_LEFT:
rect = QRect(position_list.at(0).toInt() + MARGIN, x = availableGeo.x() + m_panelSize + MARGIN;
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
this->width(), this->height());
break; break;
//任务栏位于右边 //任务栏位于右边
case PANEL_RIGHT: case PANEL_RIGHT:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, x = availableGeo.x() + availableGeo.width() - m_panelSize - this->width() - MARGIN;
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
this->width(), this->height());
break; break;
//任务栏位于下方 //任务栏位于下方
default: default:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, y = availableGeo.y() + availableGeo.height() - m_panelSize - this->height() - MARGIN;
this->width(), this->height());
break; break;
} }
kdk::WindowManager::setGeometry(this->windowHandle(), rect); kdk::WindowManager::setGeometry(this->windowHandle(), QRect(x, y, this->width(), this->height()));
qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; qDebug() << " Position of ukui-panel is " << m_panelPosition << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__;
} }
void VpnPage::resetListWidgetWidth() void VpnPage::resetListWidgetWidth()

View File

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

View File

@ -41,6 +41,9 @@
#define LOADING_TRAYICON_TIMER_MS 60 #define LOADING_TRAYICON_TIMER_MS 60
#define THEME_SCHAME "org.ukui.style" #define THEME_SCHAME "org.ukui.style"
#define COLOR_THEME "styleName" #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 v10Sp1 = "V10SP1";
const QString intel = "V10SP1-edu"; const QString intel = "V10SP1-edu";
@ -164,6 +167,7 @@ void MainWindow::firstlyStart()
initWindowProperties(); initWindowProperties();
initTransparency(); initTransparency();
registerTrayIcon(); registerTrayIcon();
initPanelGSettings();
initUI(); initUI();
initDbusConnnect(); initDbusConnnect();
initWindowTheme(); initWindowTheme();
@ -325,6 +329,36 @@ void MainWindow::paintWithTrans()
m_centralWidget->tabBar()->setPalette(tabPal); 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 * @brief MainWindow::initUI
*/ */
@ -503,50 +537,32 @@ void MainWindow::resetWindowPosition()
#define PANEL_LEFT 2 #define PANEL_LEFT 2
#define PANEL_RIGHT 3 #define PANEL_RIGHT 3
//#define PANEL_BOTTOM 4 //#define PANEL_BOTTOM 4
if (!m_positionInterface) { QRect availableGeo = QGuiApplication::screenAt(QCursor::pos())->geometry();
m_positionInterface = new QDBusInterface("org.ukui.panel", int x, y;
"/panel/position", switch(m_panelPosition){
"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:
//任务栏位于上方 //任务栏位于上方
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, case PANEL_TOP:
position_list.at(1).toInt() + MARGIN, x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
this->width(), this->height()); y = availableGeo.y() + m_panelSize + MARGIN;
break; break;
//任务栏位于左边 //任务栏位于左边
case PANEL_LEFT: case PANEL_LEFT:
rect = QRect(position_list.at(0).toInt() + MARGIN, x = availableGeo.x() + m_panelSize + MARGIN;
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
this->width(), this->height());
break; break;
//任务栏位于右边 //任务栏位于右边
case PANEL_RIGHT: case PANEL_RIGHT:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, x = availableGeo.x() + availableGeo.width() - m_panelSize - this->width() - MARGIN;
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, y = availableGeo.y() + availableGeo.height() - this->height() - MARGIN;
this->width(), this->height());
break; break;
//任务栏位于下方 //任务栏位于下方
default: default:
rect = QRect(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN, x = availableGeo.x() + availableGeo.width() - this->width() - MARGIN;
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, y = availableGeo.y() + availableGeo.height() - m_panelSize - this->height() - MARGIN;
this->width(), this->height());
break; break;
} }
kdk::WindowManager::setGeometry(this->windowHandle(), rect); kdk::WindowManager::setGeometry(this->windowHandle(), QRect(x, y, this->width(), this->height()));
qDebug() << " Position of ukui-panel is " << position << "; Position of mainwindow is " << this->geometry() << "." << Q_FUNC_INFO << __LINE__; 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 initWindowProperties();
void initTransparency(); void initTransparency();
void paintWithTrans(); void paintWithTrans();
void initPanelGSettings();
void initUI(); void initUI();
void initDbusConnnect(); void initDbusConnnect();
void registerTrayIcon(); void registerTrayIcon();
@ -194,9 +195,15 @@ private:
//监听主题的Gsettings //监听主题的Gsettings
QGSettings * m_styleGsettings = nullptr; QGSettings * m_styleGsettings = nullptr;
//获取任务栏位置和大小
QGSettings *m_panelGSettings = nullptr;
int m_panelPosition;
int m_panelSize;
//获取和重置窗口位置 //获取和重置窗口位置
void resetWindowPosition(); void resetWindowPosition();
QDBusInterface * m_positionInterface = nullptr; //QDBusInterface * m_positionInterface = nullptr;
//托盘图标,托盘图标右键菜单 //托盘图标,托盘图标右键菜单
QSystemTrayIcon * m_trayIcon = nullptr; QSystemTrayIcon * m_trayIcon = nullptr;