From 052a08cfa032c8bf93f61e8b74bd407f7eff39b4 Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Sun, 16 Feb 2025 10:19:48 -0300 Subject: [PATCH] refactor: setup and use a single base scheme --- src/Gui/QSint/actionpanel/actiongroup.cpp | 40 ++- src/Gui/QSint/actionpanel/actionlabel.cpp | 1 + .../QSint/actionpanel/actionpanelscheme.cpp | 51 ++-- src/Gui/QSint/actionpanel/freecadscheme.cpp | 237 ------------------ src/Gui/QSint/actionpanel/taskgroup_p.cpp | 14 -- src/Gui/QSint/actionpanel/taskheader_p.cpp | 16 +- src/Gui/TaskView/TaskView.cpp | 2 +- 7 files changed, 37 insertions(+), 324 deletions(-) delete mode 100644 src/Gui/QSint/actionpanel/freecadscheme.cpp diff --git a/src/Gui/QSint/actionpanel/actiongroup.cpp b/src/Gui/QSint/actionpanel/actiongroup.cpp index e85e29c308..9f90350619 100644 --- a/src/Gui/QSint/actionpanel/actiongroup.cpp +++ b/src/Gui/QSint/actionpanel/actiongroup.cpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include namespace QSint { @@ -44,6 +42,7 @@ ActionGroup::~ActionGroup() = default; void ActionGroup::init(bool hasHeader) { m_foldStep = 0; + myScheme = ActionPanelScheme::defaultScheme(); auto *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); @@ -59,7 +58,6 @@ void ActionGroup::init(bool hasHeader) myDummy->hide(); connect(myHeader.get(), &TaskHeader::activated, this, &ActionGroup::showHide); - } QBoxLayout* ActionGroup::groupLayout() @@ -96,22 +94,24 @@ void ActionGroup::showHide() if (myGroup->isVisible()) { + m_foldPixmap = myGroup->transparentRender(); m_tempHeight = m_fullHeight = myGroup->height(); - m_foldDelta = m_fullHeight / 20; // foldsteps - m_foldStep = 20; + m_foldDelta = m_fullHeight / myScheme->groupFoldSteps; + m_foldStep = myScheme->groupFoldSteps; m_foldDirection = -1; myGroup->hide(); myDummy->setFixedSize(myGroup->size()); - QTimer::singleShot(15, this, &ActionGroup::processHide); + + QTimer::singleShot(myScheme->groupFoldDelay, this, &ActionGroup::processHide); } else { - m_foldStep = 20; + m_foldStep = myScheme->groupFoldSteps; m_foldDirection = 1; m_tempHeight = 0; - QTimer::singleShot(15, this, &ActionGroup::processShow); + QTimer::singleShot(myScheme->groupFoldDelay, this, &ActionGroup::processShow); } myDummy->show(); } @@ -131,7 +131,7 @@ void ActionGroup::processHide() myDummy->setFixedHeight(m_tempHeight); setFixedHeight(myDummy->height() + myHeader->height()); - QTimer::singleShot(15, this, &ActionGroup::processHide); + QTimer::singleShot(myScheme->groupFoldDelay, this, &ActionGroup::processHide); } void ActionGroup::processShow() @@ -152,7 +152,7 @@ void ActionGroup::processShow() myDummy->setFixedHeight(m_tempHeight); setFixedHeight(myDummy->height() + myHeader->height()); - QTimer::singleShot(15, this, &ActionGroup::processShow); + QTimer::singleShot(myScheme->groupFoldDelay, this, &ActionGroup::processShow); } void ActionGroup::paintEvent(QPaintEvent *event) @@ -160,31 +160,25 @@ void ActionGroup::paintEvent(QPaintEvent *event) Q_UNUSED(event); QPainter p(this); - int foldsteps = 20; - bool groupFoldThaw = true; // Change opacity gradually - FoldEffect groupFoldEffect = NoFolding; - - if (m_foldPixmap.isNull()) return; - if (myDummy->isVisible()) { - if (groupFoldThaw) + if (myScheme->groupFoldThaw) { double opacity = (m_foldDirection < 0) - ? static_cast(m_foldStep) / foldsteps - : static_cast(foldsteps - m_foldStep) / foldsteps; + ? static_cast(m_foldStep) / myScheme->groupFoldSteps + : static_cast(myScheme->groupFoldSteps - m_foldStep) / myScheme->groupFoldSteps; p.setOpacity(opacity); } - switch (groupFoldEffect) + switch (myScheme->groupFoldEffect) { - case ShrunkFolding: + case ActionPanelScheme::ShrunkFolding: p.drawPixmap(myDummy->pos(), m_foldPixmap.scaled(myDummy->size())); break; - case SlideFolding: + case ActionPanelScheme::SlideFolding: p.drawPixmap(myDummy->pos(), m_foldPixmap, QRect(0, m_foldPixmap.height() - myDummy->height(), - m_foldPixmap.width(), myDummy->height())); + m_foldPixmap.width(), myDummy->width())); break; default: p.drawPixmap(myDummy->pos(), m_foldPixmap); diff --git a/src/Gui/QSint/actionpanel/actionlabel.cpp b/src/Gui/QSint/actionpanel/actionlabel.cpp index 1a2f18229e..3a548e0403 100644 --- a/src/Gui/QSint/actionpanel/actionlabel.cpp +++ b/src/Gui/QSint/actionpanel/actionlabel.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace QSint { diff --git a/src/Gui/QSint/actionpanel/actionpanelscheme.cpp b/src/Gui/QSint/actionpanel/actionpanelscheme.cpp index 9e3e6e8bd5..6eecbbb9af 100644 --- a/src/Gui/QSint/actionpanel/actionpanelscheme.cpp +++ b/src/Gui/QSint/actionpanel/actionpanelscheme.cpp @@ -21,10 +21,12 @@ const QString ActionPanelScheme::minimumStyle = QString::fromLatin1( "border: none;" "font-weight: bold;" "text-align: center;" + "background: none;" "}" "QSint--ActionGroup QToolButton[class='action'] {" "border: none;" + "background: none;" "}" "QSint--ActionGroup QToolButton[class='action']:hover {" @@ -64,54 +66,33 @@ QString ActionPanelScheme::systemStyle(const QPalette& p) } // Draws fold/unfold icons based on the palette -QPixmap ActionPanelScheme::drawFoldIcon(const QPalette& palette, bool fold, bool hover) const +QPixmap ActionPanelScheme::drawFoldIcon(const QPalette& palette, bool fold, bool /*hover*/) const { - QSize bSize = headerButtonSize; - QImage img(bSize.width(), bSize.height(), QImage::Format_ARGB32_Premultiplied); - img.fill(Qt::transparent); + QStyle::StandardPixmap iconType = fold ? QStyle::SP_ArrowUp : QStyle::SP_ArrowDown; + QIcon icon = qApp->style()->standardIcon(iconType); + + QSize iconSize = headerButtonSize; + QPixmap pixmap = icon.pixmap(iconSize); + QImage img = pixmap.toImage(); + img = img.convertToFormat(QImage::Format_ARGB32); QPainter painter(&img); - painter.setRenderHint(QPainter::Antialiasing); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(img.rect(), palette.color(QPalette::HighlightedText)); + painter.end(); - qreal penWidth = bSize.width() / 14.0; - qreal lef_X = 0.25 * bSize.width(); - qreal mid_X = 0.50 * bSize.width(); - qreal rig_X = 0.75 * bSize.width(); - qreal bot_Y = 0.40 * bSize.height(); - qreal top_Y = 0.64 * bSize.height(); - - if (hover) { - penWidth *= 1.8; - } - - painter.setBrush(Qt::NoBrush); - painter.setPen(QPen(palette.color(QPalette::HighlightedText), penWidth)); - - QPolygon chevron; - if (fold) { - // Upward chevron - chevron << QPoint(lef_X, top_Y) - << QPoint(mid_X, bot_Y) - << QPoint(rig_X, top_Y); - } else { - // Downward chevron - chevron << QPoint(lef_X, bot_Y) - << QPoint(mid_X, top_Y) - << QPoint(rig_X, bot_Y); - } - - painter.drawPolyline(chevron); return QPixmap::fromImage(img); } ActionPanelScheme::ActionPanelScheme() { - headerSize = 28; + QFontMetrics fm(QApplication::font()); + headerSize = fm.height() + 10; headerAnimation = true; QPalette p = QApplication::palette(); - headerButtonSize = QSize(17, 17); + headerButtonSize = QSize(16, 16); headerButtonFold = drawFoldIcon(p, true, false); headerButtonFoldOver = drawFoldIcon(p, true, true); headerButtonUnfold = drawFoldIcon(p, false, false); diff --git a/src/Gui/QSint/actionpanel/freecadscheme.cpp b/src/Gui/QSint/actionpanel/freecadscheme.cpp deleted file mode 100644 index 3802ea6234..0000000000 --- a/src/Gui/QSint/actionpanel/freecadscheme.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2015 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#include "freecadscheme.h" - -#include -#include -#include -#include -#include - -namespace QSint -{ - -const QString SystemPanelScheme::minimumStyle = QString::fromLatin1( - "QSint--ActionGroup QToolButton[class='header'] {" - "text-align: left;" - "background-color: transparent;" - "border: 1px solid transparent;" - "font-weight: bold;" - "}" - - "QSint--ActionGroup QToolButton[class='action'] {" - "background-color: transparent;" - "border: 1px solid transparent;" - "text-align: left;" - "}" - - "QSint--ActionGroup QToolButton[class='action']:hover {" - "text-decoration: underline;" - "}" -); - -FreeCADPanelScheme::FreeCADPanelScheme() - : ActionPanelScheme() -{ - ActionPanelScheme* panelStyle = SystemPanelScheme::defaultScheme(); - - actionStyle = panelStyle->actionStyle; - builtinScheme = actionStyle; - - headerSize = panelStyle->headerSize; - headerAnimation = panelStyle->headerAnimation; - headerButtonFold = panelStyle->headerButtonFold; - headerButtonFoldOver = panelStyle->headerButtonFoldOver; - headerButtonUnfold = panelStyle->headerButtonUnfold; - headerButtonUnfoldOver = panelStyle->headerButtonUnfoldOver; - headerButtonSize = panelStyle->headerButtonSize; - - groupFoldSteps = panelStyle->groupFoldSteps; - groupFoldDelay = panelStyle->groupFoldDelay; - groupFoldEffect = panelStyle->groupFoldEffect; - groupFoldThaw = panelStyle->groupFoldThaw; - - builtinFold = headerButtonFold; - builtinFoldOver = headerButtonFoldOver; - builtinUnfold = headerButtonUnfold; - builtinUnfoldOver = headerButtonUnfoldOver; -} - -void FreeCADPanelScheme::clearActionStyle() -{ - headerButtonFold = QPixmap(); - headerButtonFoldOver = QPixmap(); - headerButtonUnfold = QPixmap(); - headerButtonUnfoldOver = QPixmap(); - - actionStyle = SystemPanelScheme::minimumStyle; -} - -void FreeCADPanelScheme::restoreActionStyle() -{ - headerButtonFold = builtinFold; - headerButtonFoldOver = builtinFoldOver; - headerButtonUnfold = builtinUnfold; - headerButtonUnfoldOver = builtinUnfoldOver; - - actionStyle = builtinScheme; -} - -SystemPanelScheme::SystemPanelScheme() -{ - headerSize = 25; - headerAnimation = true; - - QPalette p = QApplication::palette(); - - headerButtonFold = drawFoldIcon(p, true, false); - headerButtonFoldOver = drawFoldIcon(p, true, true); - headerButtonUnfold = drawFoldIcon(p, false, false); - headerButtonUnfoldOver = drawFoldIcon(p, false, true); - headerButtonSize = QSize(17, 17); - - groupFoldSteps = 20; - groupFoldDelay = 15; - groupFoldEffect = NoFolding; - groupFoldThaw = true; - - actionStyle = systemStyle(p); -} - -// Draws fold/unfold icons based on the palette -QPixmap SystemPanelScheme::drawFoldIcon(const QPalette& palette, bool fold, bool hover) const -{ - QSize bSize = headerButtonSize; - QImage img(bSize.width(), bSize.height(), QImage::Format_ARGB32_Premultiplied); - img.fill(Qt::transparent); - - QPainter painter(&img); - painter.setRenderHint(QPainter::Antialiasing); - - qreal penWidth = bSize.width() / 14.0; - qreal lef_X = 0.25 * bSize.width(); - qreal mid_X = 0.50 * bSize.width(); - qreal rig_X = 0.75 * bSize.width(); - qreal bot_Y = 0.40 * bSize.height(); - qreal top_Y = 0.64 * bSize.height(); - - if (hover) { - penWidth *= 1.8; - } - - painter.setBrush(Qt::NoBrush); - painter.setPen(QPen(palette.color(QPalette::HighlightedText), penWidth)); - - QPolygon chevron; - if (fold) { - // Upward chevron - chevron << QPoint(lef_X, top_Y) - << QPoint(mid_X, bot_Y) - << QPoint(rig_X, top_Y); - } else { - // Downward chevron - chevron << QPoint(lef_X, bot_Y) - << QPoint(mid_X, top_Y) - << QPoint(rig_X, bot_Y); - } - - painter.drawPolyline(chevron); - return QPixmap::fromImage(img); -} - -QString SystemPanelScheme::systemStyle(const QPalette& p) const -{ - QHash replacements; - replacements.insert(QStringLiteral("headerBackground"), - p.color(QPalette::Highlight).name()); - replacements.insert(QStringLiteral("headerLabelText"), - p.color(QPalette::HighlightedText).name()); - replacements.insert(QStringLiteral("headerLabelTextOver"), - p.color(QPalette::BrightText).name()); - replacements.insert(QStringLiteral("groupBorder"), - p.color(QPalette::Mid).name()); - replacements.insert(QStringLiteral("disabledActionText"), - p.color(QPalette::Disabled, QPalette::Text).name()); - replacements.insert(QStringLiteral("actionSelectedBg"), - p.color(QPalette::Active, QPalette::Light).name()); - replacements.insert(QStringLiteral("actionSelectedText"), - p.color(QPalette::Active, QPalette::ButtonText).name()); - replacements.insert(QStringLiteral("actionSelectedBorder"), - p.color(QPalette::Active, QPalette::Highlight).name()); - replacements.insert(QStringLiteral("panelBackground"), - p.color(QPalette::Window).name()); - replacements.insert(QStringLiteral("groupBackground"), - p.color(QPalette::Button).name()); - - QString style = minimumStyle; - - style += QStringLiteral( - "QFrame[class='panel'] {" - "background-color: {panelBackground};" - "}" - - "QSint--ActionGroup QFrame[class='header'] {" - "border: 1px solid {headerBackground};" - "background-color: {headerBackground};" - "}" - - "QSint--ActionGroup QToolButton[class='header'] {" - "color: {headerLabelText};" - "}" - - "QSint--ActionGroup QToolButton[class='header']:hover {" - "color: {headerLabelTextOver};" - "}" - - "QSint--ActionGroup QFrame[class='content'] {" - "border: 1px solid {groupBorder};" - "background-color: {groupBackground};" - "}" - - "QSint--ActionGroup QFrame[class='content'][header='true'] {" - "border-top: none;" - "}" - - "QSint--ActionGroup QToolButton[class='action']:!enabled {" - "color: {disabledActionText};" - "}" - - "QSint--ActionGroup QToolButton[class='action']:focus {" - "color: {actionSelectedText};" - "border: 1px dotted {actionSelectedBorder};" - "}" - - "QSint--ActionGroup QToolButton[class='action']:on {" - "background-color: {actionSelectedBg};" - "color: {actionSelectedText};" - "}" - ); - - for (auto it = replacements.begin(); it != replacements.end(); ++it) { - style.replace("{" + it.key() + "}", it.value()); - } - - return style; -} - -} // namespace QSint diff --git a/src/Gui/QSint/actionpanel/taskgroup_p.cpp b/src/Gui/QSint/actionpanel/taskgroup_p.cpp index e1cecdd4b7..b5ec621d87 100644 --- a/src/Gui/QSint/actionpanel/taskgroup_p.cpp +++ b/src/Gui/QSint/actionpanel/taskgroup_p.cpp @@ -35,8 +35,6 @@ bool TaskGroup::addActionLabel(ActionLabel *label, bool addToLayout, bool addStr if (!label) return false; - label->setStyleSheet(""); - return addWidget(label, addToLayout, addStretch); } @@ -74,18 +72,6 @@ QPixmap TaskGroup::transparentRender() return pm; } -void TaskGroup::paintEvent ( QPaintEvent * event ) -{ -// QPainter p(this); - -// p.setBrush(myScheme->groupBackground); - -// p.setPen(myScheme->groupBorder); -// p.drawRect(rect().adjusted(0,-(int)myHasHeader,-1,-1)); - - BaseClass::paintEvent(event); -} - void TaskGroup::keyPressEvent ( QKeyEvent * event ) { switch (event->key()) diff --git a/src/Gui/QSint/actionpanel/taskheader_p.cpp b/src/Gui/QSint/actionpanel/taskheader_p.cpp index 387b796d3f..36ddc8bd00 100644 --- a/src/Gui/QSint/actionpanel/taskheader_p.cpp +++ b/src/Gui/QSint/actionpanel/taskheader_p.cpp @@ -19,7 +19,6 @@ namespace QSint { - TaskHeader::TaskHeader(const QIcon &icon, const QString &title, bool expandable, QWidget *parent) : BaseClass(parent), myExpandable(expandable), @@ -27,6 +26,7 @@ TaskHeader::TaskHeader(const QIcon &icon, const QString &title, bool expandable, m_buttonOver(false), m_fold(true), m_opacity(0.1), + myButton(nullptr) { setProperty("class", "header"); @@ -40,7 +40,7 @@ TaskHeader::TaskHeader(const QIcon &icon, const QString &title, bool expandable, connect(myTitle, &ActionLabel::clicked, this, &TaskHeader::fold); QHBoxLayout *hbl = new QHBoxLayout(); - hbl->setContentsMargins(2, 2, 2, 2); + hbl->setContentsMargins(4, 2, 8, 2); setLayout(hbl); hbl->addWidget(myTitle); @@ -48,7 +48,6 @@ TaskHeader::TaskHeader(const QIcon &icon, const QString &title, bool expandable, setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); setScheme(ActionPanelScheme::defaultScheme()); - //myTitle->setSchemePointer(&myLabelScheme); setExpandable(myExpandable); } @@ -110,16 +109,10 @@ void TaskHeader::setScheme(ActionPanelScheme *scheme) { if (scheme) { myScheme = scheme; - //myLabelScheme = &(scheme->headerLabelScheme); - setStyleSheet(myScheme->actionStyle); - if (myExpandable) { - //setCursor(myLabelScheme->cursorOver ? Qt::PointingHandCursor : cursor()); changeIcons(); } - setFixedHeight(scheme->headerSize); - update(); } } @@ -131,11 +124,6 @@ void TaskHeader::paintEvent ( QPaintEvent * event ) if (myScheme->headerAnimation) p.setOpacity(m_opacity+0.7); -// p.setPen(m_over ? myScheme->headerBorderOver : myScheme->headerBorder); -// p.setBrush(m_over ? myScheme->headerBackgroundOver : myScheme->headerBackground); - -// myScheme->headerCorners.draw(&p, rect()); - BaseClass::paintEvent(event); } diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index 2bcb7deca4..77b3af097c 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -185,7 +185,7 @@ void TaskBox::hideGroupBox() } else { m_tempHeight = m_fullHeight = myGroup->height(); - m_foldDelta = m_fullHeight / 20; // foldsteps + m_foldDelta = m_fullHeight / myScheme->groupFoldSteps; } m_foldStep = 0.0;