kiran-session-guard/0008-fix-styleditemdelegate-updateEditorGeometry-to-updat.patch
2024-01-18 11:52:48 +08:00

119 lines
4.3 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 66d11ae4717a846e06a7fc85354993ba2e90ce0e Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinsec.com.cn>
Date: Thu, 26 Oct 2023 14:40:23 +0800
Subject: [PATCH 08/10] fix(styleditemdelegate): updateEditorGeometry to update
the wrong size of ItemWidgets in QStyledItemDelegate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 使用自定义的代理避免QStyledItemDelegate中错误的使用updateEditorGeometry更新ItemWidget大小
Closes #16513
---
.../widgets/styled-item-delegate.cpp | 33 +++++++++++++++++++
.../widgets/styled-item-delegate.h | 28 ++++++++++++++++
src/lightdm-greeter/widgets/user-list.cpp | 2 ++
3 files changed, 63 insertions(+)
create mode 100644 src/lightdm-greeter/widgets/styled-item-delegate.cpp
create mode 100644 src/lightdm-greeter/widgets/styled-item-delegate.h
diff --git a/src/lightdm-greeter/widgets/styled-item-delegate.cpp b/src/lightdm-greeter/widgets/styled-item-delegate.cpp
new file mode 100644
index 0000000..a5323ce
--- /dev/null
+++ b/src/lightdm-greeter/widgets/styled-item-delegate.cpp
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2020 ~ 2023 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
+#include "styled-item-delegate.h"
+
+StyledItemDelegate::StyledItemDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+StyledItemDelegate::~StyledItemDelegate()
+{
+}
+
+/**
+ * 避免某些时候QListWidget更新item大小时调用QStyledItemDelegate相关接口错误的更新Editor大小
+*/
+void StyledItemDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ editor->setGeometry(option.rect);
+}
\ No newline at end of file
diff --git a/src/lightdm-greeter/widgets/styled-item-delegate.h b/src/lightdm-greeter/widgets/styled-item-delegate.h
new file mode 100644
index 0000000..e229306
--- /dev/null
+++ b/src/lightdm-greeter/widgets/styled-item-delegate.h
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2020 ~ 2023 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
+#pragma once
+
+#include <QStyledItemDelegate>
+
+class StyledItemDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ StyledItemDelegate(QObject* parent = nullptr);
+ ~StyledItemDelegate();
+
+ void updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+};
\ No newline at end of file
diff --git a/src/lightdm-greeter/widgets/user-list.cpp b/src/lightdm-greeter/widgets/user-list.cpp
index b83efdf..e59fa8b 100644
--- a/src/lightdm-greeter/widgets/user-list.cpp
+++ b/src/lightdm-greeter/widgets/user-list.cpp
@@ -24,6 +24,7 @@
#include "ui_user-list.h"
#include "user-info.h"
#include "user-item.h"
+#include "styled-item-delegate.h"
using namespace QLightDM;
@@ -126,6 +127,7 @@ int UserList::userCount()
void UserList::initUI()
{
setAttribute(Qt::WA_Hover, true);
+ ui->userList->setItemDelegate(new StyledItemDelegate(this));
ui->userList->setFocusPolicy(Qt::ClickFocus);
ui->userList->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->userList->setSelectionMode(QAbstractItemView::SingleSelection);
--
2.27.0