From 8b29f13e09e2ed34541d63656d03da00d33dce38 Mon Sep 17 00:00:00 2001 From: liuxinhao 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 #include #include +#include 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(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 children(viewport->findChildren()); + 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(widget)) - { - auto scrollArea = qobject_cast(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(widget)); + if (QAbstractItemView *itemView = qobject_cast(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; -- Gitee From d3cb409336c622b078b3c03ef6266775b5717346 Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Mon, 8 Aug 2022 17:02:11 +0800 Subject: [PATCH 2/2] refactor(log): update log output when creating theme and style plug-ins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新创建主题和风格插件时的日志输出 --- platformtheme/kiran-theme-plugin.cpp | 2 +- style/src/kiran-style-plugin.cpp | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/platformtheme/kiran-theme-plugin.cpp b/platformtheme/kiran-theme-plugin.cpp index 20c0198..961b7b3 100644 --- a/platformtheme/kiran-theme-plugin.cpp +++ b/platformtheme/kiran-theme-plugin.cpp @@ -23,7 +23,7 @@ QPlatformTheme* KiranThemePlugin::create(const QString& key, const QStringList& if(keySet.contains(key)) { - qDebug(kiranPlatformTheme) << "create kiran style for" << QCoreApplication::applicationName(); + qDebug(kiranPlatformTheme) << "create kiran platformtheme for" << QCoreApplication::applicationName(); return new KiranTheme(paramList); } diff --git a/style/src/kiran-style-plugin.cpp b/style/src/kiran-style-plugin.cpp index ee5f33e..aefbabc 100644 --- a/style/src/kiran-style-plugin.cpp +++ b/style/src/kiran-style-plugin.cpp @@ -26,18 +26,20 @@ KiranStylePlugin::KiranStylePlugin(QObject *parent) : QStylePlugin(parent) QStyle *KiranStylePlugin::create(const QString & key) { - QStringList disableApps = KiranIntegrationSettings::instance()->getDisableKiranStyleApps(); - QString processName = qAppName(); - if( disableApps.contains(processName) ) - { - return QStyleFactory::create("fusion"); - } - - qDebug("create style:%s",key.toStdString().c_str()); if( key.compare("kiran",Qt::CaseInsensitive) == 0 ) { - return new Style(); + QStringList disableApps = KiranIntegrationSettings::instance()->getDisableKiranStyleApps(); + QString processName = qAppName(); + if( disableApps.contains(processName) ) + { + qDebug("%s in black list,create fusion style for it.",processName.toStdString().c_str()); + return QStyleFactory::create("fusion"); + } + else + { + qDebug("create style:%s",key.toStdString().c_str()); + return new Style(); + } } - return nullptr; } -- Gitee