152 lines
5.4 KiB
Diff
152 lines
5.4 KiB
Diff
From 8b29f13e09e2ed34541d63656d03da00d33dce38 Mon Sep 17 00:00:00 2001
|
|
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
|
Date: Mon, 8 Aug 2022 16:59:10 +0800
|
|
Subject: [PATCH 1/2] refactor(style): update painting effect of the scrolling
|
|
area
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
- 调整滚动区域绘制效果
|
|
---
|
|
style/src/draw-helper/draw-common-helper.cpp | 11 ++++-
|
|
style/src/render-helper.cpp | 6 +++
|
|
style/src/style.cpp | 46 +++++++++++++++-----
|
|
style/src/style.h | 2 +
|
|
4 files changed, 52 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/style/src/draw-helper/draw-common-helper.cpp b/style/src/draw-helper/draw-common-helper.cpp
|
|
index 650ec94..ed94654 100644
|
|
--- a/style/src/draw-helper/draw-common-helper.cpp
|
|
+++ b/style/src/draw-helper/draw-common-helper.cpp
|
|
@@ -25,6 +25,7 @@
|
|
#include <QRect>
|
|
#include <QStyle>
|
|
#include <QStyleOption>
|
|
+#include <QAbstractScrollArea>
|
|
|
|
namespace Kiran
|
|
{
|
|
@@ -39,7 +40,15 @@ bool drawPEFrame(const QStyle *style,
|
|
background = schemeLoader->getColor(widget,option,SchemeLoader::Frame_Background);
|
|
border = schemeLoader->getColor(widget,option,SchemeLoader::Frame_Border);
|
|
|
|
- RenderHelper::renderFrame(painter, option->rect, 1, 0, background,border );
|
|
+ if( qobject_cast<const QAbstractScrollArea*>(widget) )
|
|
+ {
|
|
+ RenderHelper::renderFrame(painter, option->rect, 1, 0, Qt::transparent,border );
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ RenderHelper::renderFrame(painter, option->rect, 1, 0, background,border );
|
|
+ }
|
|
+
|
|
return true;
|
|
}
|
|
|
|
diff --git a/style/src/render-helper.cpp b/style/src/render-helper.cpp
|
|
index b8117ff..60f66e3 100644
|
|
--- a/style/src/render-helper.cpp
|
|
+++ b/style/src/render-helper.cpp
|
|
@@ -53,7 +53,13 @@ bool RenderHelper::drawTreeBranches()
|
|
|
|
bool RenderHelper::isQtQuickControl(const QStyleOption *option, const QWidget *widget)
|
|
{
|
|
+#if QT_VERSION >= 0x050000
|
|
return (widget == nullptr) && option && option->styleObject && option->styleObject->inherits("QQuickItem");
|
|
+#else
|
|
+ Q_UNUSED(widget);
|
|
+ Q_UNUSED(option);
|
|
+ return false;
|
|
+#endif
|
|
}
|
|
|
|
bool RenderHelper::isVerticalTab(const QTabBar::Shape &shape)
|
|
diff --git a/style/src/style.cpp b/style/src/style.cpp
|
|
index 01ca5e8..a2c4f12 100644
|
|
--- a/style/src/style.cpp
|
|
+++ b/style/src/style.cpp
|
|
@@ -564,6 +564,38 @@ void Style::drawControl(QStyle::ControlElement element, const QStyleOption *opti
|
|
painter->restore();
|
|
}
|
|
|
|
+void Style::polishScrollArea(QAbstractScrollArea* scrollArea)
|
|
+{
|
|
+ if (!scrollArea)
|
|
+ return;
|
|
+
|
|
+ // enable mouse over effect in sunken scrollareas that support focus
|
|
+ if (scrollArea->frameShadow() == QFrame::Sunken && scrollArea->focusPolicy() & Qt::StrongFocus) {
|
|
+ scrollArea->setAttribute(Qt::WA_Hover);
|
|
+ }
|
|
+
|
|
+ // disable autofill background for flat (== NoFrame) scrollareas, with QPalette::Window as a background
|
|
+ // this fixes flat scrollareas placed in a tinted widget, such as groupboxes, tabwidgets or framed dock-widgets
|
|
+ if (!(scrollArea->frameShape() == QFrame::NoFrame || scrollArea->backgroundRole() == QPalette::Window)) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ // get viewport and check background role
|
|
+ QWidget *viewport(scrollArea->viewport());
|
|
+ if (!(viewport && viewport->backgroundRole() == QPalette::Window))
|
|
+ return;
|
|
+
|
|
+ // change viewport autoFill background.
|
|
+ // do the same for all children if the background role is QPalette::Window
|
|
+ viewport->setAutoFillBackground(false);
|
|
+ QList<QWidget *> children(viewport->findChildren<QWidget *>());
|
|
+ foreach (QWidget *child, children) {
|
|
+ if (child->parent() == viewport && child->backgroundRole() == QPalette::Window) {
|
|
+ child->setAutoFillBackground(false);
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
void Style::polish(QWidget *widget)
|
|
{
|
|
if (!widget)
|
|
@@ -588,18 +620,8 @@ void Style::polish(QWidget *widget)
|
|
widget->setAttribute(Qt::WA_Hover);
|
|
}
|
|
|
|
- if (qobject_cast<QAbstractScrollArea *>(widget))
|
|
- {
|
|
- auto scrollArea = qobject_cast<QAbstractScrollArea *>(widget);
|
|
- if (scrollArea->frameShadow() == QFrame::Sunken && scrollArea->focusPolicy() & Qt::StrongFocus)
|
|
- {
|
|
- scrollArea->setAttribute(Qt::WA_Hover);
|
|
- }
|
|
- // scrollArea->viewport()->setAutoFillBackground(false);
|
|
- // qInfo() << "viewport:" << scrollArea->viewport()->geometry();
|
|
- // qInfo() << "scroll area:" << scrollArea->geometry();
|
|
- }
|
|
-
|
|
+ polishScrollArea(qobject_cast<QAbstractScrollArea *>(widget));
|
|
+
|
|
if (QAbstractItemView *itemView = qobject_cast<QAbstractItemView *>(widget))
|
|
{
|
|
// enable mouse over effects in itemviews' viewport
|
|
diff --git a/style/src/style.h b/style/src/style.h
|
|
index aa454ea..7b3212c 100644
|
|
--- a/style/src/style.h
|
|
+++ b/style/src/style.h
|
|
@@ -27,6 +27,7 @@
|
|
#define ParentStyle QCommonStyle
|
|
#endif
|
|
|
|
+class QAbstractScrollArea;
|
|
class Style : public ParentStyle
|
|
{
|
|
public:
|
|
@@ -47,6 +48,7 @@ public:
|
|
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption* opt, const QWidget* widget) const override;
|
|
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption* option, const QWidget* widget) const override;
|
|
|
|
+ void polishScrollArea(QAbstractScrollArea* scrollArea);
|
|
void polish(QWidget* widget) override;
|
|
void polish(QApplication* app) override;
|
|
void polish(QPalette& pal) override;
|
|
--
|
|
2.33.0
|
|
|