From 5c512d6ff872c40edb60cb8f2b1d3fa5c097aeef Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Tue, 28 Jan 2025 08:57:38 -0300 Subject: [PATCH] refactor: qsint style should be minimum plus mods --- src/Gui/QSint/actionpanel/freecadscheme.cpp | 50 +++++------------ src/Gui/QSint/actionpanel/freecadscheme.h | 62 +++++++++++++++++---- 2 files changed, 67 insertions(+), 45 deletions(-) diff --git a/src/Gui/QSint/actionpanel/freecadscheme.cpp b/src/Gui/QSint/actionpanel/freecadscheme.cpp index fde8250da5..3802ea6234 100644 --- a/src/Gui/QSint/actionpanel/freecadscheme.cpp +++ b/src/Gui/QSint/actionpanel/freecadscheme.cpp @@ -28,12 +28,10 @@ #include #include - namespace QSint { -const char* MinimumActionPanelFreeCAD = - +const QString SystemPanelScheme::minimumStyle = QString::fromLatin1( "QSint--ActionGroup QToolButton[class='header'] {" "text-align: left;" "background-color: transparent;" @@ -50,16 +48,15 @@ const char* MinimumActionPanelFreeCAD = "QSint--ActionGroup QToolButton[class='action']:hover {" "text-decoration: underline;" "}" - ; +); -FreeCADPanelScheme::FreeCADPanelScheme() : ActionPanelScheme() +FreeCADPanelScheme::FreeCADPanelScheme() + : ActionPanelScheme() { ActionPanelScheme* panelStyle = SystemPanelScheme::defaultScheme(); actionStyle = panelStyle->actionStyle; - builtinScheme = actionStyle; - minimumStyle = QString(MinimumActionPanelFreeCAD); headerSize = panelStyle->headerSize; headerAnimation = panelStyle->headerAnimation; @@ -74,7 +71,6 @@ FreeCADPanelScheme::FreeCADPanelScheme() : ActionPanelScheme() groupFoldEffect = panelStyle->groupFoldEffect; groupFoldThaw = panelStyle->groupFoldThaw; - builtinFold = headerButtonFold; builtinFoldOver = headerButtonFoldOver; builtinUnfold = headerButtonUnfold; @@ -88,7 +84,7 @@ void FreeCADPanelScheme::clearActionStyle() headerButtonUnfold = QPixmap(); headerButtonUnfoldOver = QPixmap(); - actionStyle = minimumStyle; + actionStyle = SystemPanelScheme::minimumStyle; } void FreeCADPanelScheme::restoreActionStyle() @@ -101,8 +97,6 @@ void FreeCADPanelScheme::restoreActionStyle() actionStyle = builtinScheme; } -// ----------------------------------------------------- - SystemPanelScheme::SystemPanelScheme() { headerSize = 25; @@ -114,16 +108,17 @@ SystemPanelScheme::SystemPanelScheme() headerButtonFoldOver = drawFoldIcon(p, true, true); headerButtonUnfold = drawFoldIcon(p, false, false); headerButtonUnfoldOver = drawFoldIcon(p, false, true); - headerButtonSize = QSize(17,17); + headerButtonSize = QSize(17, 17); groupFoldSteps = 20; groupFoldDelay = 15; groupFoldEffect = NoFolding; groupFoldThaw = true; - actionStyle = systemStyle(QApplication::palette()); + 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; @@ -131,7 +126,6 @@ QPixmap SystemPanelScheme::drawFoldIcon(const QPalette& palette, bool fold, bool img.fill(Qt::transparent); QPainter painter(&img); - painter.setRenderHint(QPainter::Antialiasing); qreal penWidth = bSize.width() / 14.0; @@ -150,23 +144,21 @@ QPixmap SystemPanelScheme::drawFoldIcon(const QPalette& palette, bool fold, bool QPolygon chevron; if (fold) { - // Upward + // Upward chevron chevron << QPoint(lef_X, top_Y) << QPoint(mid_X, bot_Y) << QPoint(rig_X, top_Y); } else { - // Downward + // Downward chevron chevron << QPoint(lef_X, bot_Y) << QPoint(mid_X, top_Y) << QPoint(rig_X, bot_Y); } painter.drawPolyline(chevron); - painter.end(); return QPixmap::fromImage(img); } - QString SystemPanelScheme::systemStyle(const QPalette& p) const { QHash replacements; @@ -191,22 +183,20 @@ QString SystemPanelScheme::systemStyle(const QPalette& p) const replacements.insert(QStringLiteral("groupBackground"), p.color(QPalette::Button).name()); - QString style = QStringLiteral( + QString style = minimumStyle; + + style += QStringLiteral( "QFrame[class='panel'] {" "background-color: {panelBackground};" "}" "QSint--ActionGroup QFrame[class='header'] {" - "border: 1px solid transparent;" + "border: 1px solid {headerBackground};" "background-color: {headerBackground};" "}" "QSint--ActionGroup QToolButton[class='header'] {" - "text-align: left;" "color: {headerLabelText};" - "background-color: transparent;" - "border: 1px solid transparent;" - "font-weight: bold;" "}" "QSint--ActionGroup QToolButton[class='header']:hover {" @@ -222,20 +212,10 @@ QString SystemPanelScheme::systemStyle(const QPalette& p) const "border-top: none;" "}" - "QSint--ActionGroup QToolButton[class='action'] {" - "background-color: transparent;" - "border: 1px solid transparent;" - "text-align: left;" - "}" - "QSint--ActionGroup QToolButton[class='action']:!enabled {" "color: {disabledActionText};" "}" - "QSint--ActionGroup QToolButton[class='action']:hover {" - "text-decoration: underline;" - "}" - "QSint--ActionGroup QToolButton[class='action']:focus {" "color: {actionSelectedText};" "border: 1px dotted {actionSelectedBorder};" @@ -254,4 +234,4 @@ QString SystemPanelScheme::systemStyle(const QPalette& p) const return style; } -} +} // namespace QSint diff --git a/src/Gui/QSint/actionpanel/freecadscheme.h b/src/Gui/QSint/actionpanel/freecadscheme.h index 4cbeca0ba6..61d737e930 100644 --- a/src/Gui/QSint/actionpanel/freecadscheme.h +++ b/src/Gui/QSint/actionpanel/freecadscheme.h @@ -20,56 +20,98 @@ * * ***************************************************************************/ - #ifndef FREECADTASKPANELSCHEME_H #define FREECADTASKPANELSCHEME_H #include "actionpanelscheme.h" +#include +#include +#include namespace QSint { - +/** + * @class FreeCADPanelScheme + * @brief A specialized panel scheme for FreeCAD task panels. + */ class QSINT_EXPORT FreeCADPanelScheme : public ActionPanelScheme { public: explicit FreeCADPanelScheme(); + /** + * @brief Provides the default scheme for FreeCAD panels. + * @return A pointer to the default FreeCADPanelScheme instance. + */ static ActionPanelScheme* defaultScheme() { static FreeCADPanelScheme scheme; return &scheme; } + /** + * @brief Clears the custom action style, resetting to a minimal style. + */ void clearActionStyle(); + + /** + * @brief Restores the original action style. + */ void restoreActionStyle(); private: - QString builtinScheme; - QString minimumStyle; - QPixmap builtinFold; - QPixmap builtinFoldOver; - QPixmap builtinUnfold; - QPixmap builtinUnfoldOver; + QString builtinScheme; ///< Backup of the original scheme style. + QPixmap builtinFold; ///< Backup of the default fold icon. + QPixmap builtinFoldOver; ///< Backup of the default hover fold icon. + QPixmap builtinUnfold; ///< Backup of the default unfold icon. + QPixmap builtinUnfoldOver; ///< Backup of the default hover unfold icon. }; +/** + * @class SystemPanelScheme + * @brief A system-wide default panel scheme for action panels. + */ class QSINT_EXPORT SystemPanelScheme : public ActionPanelScheme { public: explicit SystemPanelScheme(); + /** + * @brief Provides the default system panel scheme. + * @return A pointer to the default SystemPanelScheme instance. + */ static ActionPanelScheme* defaultScheme() { static SystemPanelScheme scheme; return &scheme; } + /** + * @brief The minimal style definition shared across schemes. + */ + static const QString minimumStyle; + private: + /** + * @brief Draws a fold/unfold icon based on the palette. + * @param p The palette to use for coloring the icon. + * @param fold True for fold icon, false for unfold icon. + * @param hover True for hover effect, false otherwise. + * @return A QPixmap representing the icon. + */ QPixmap drawFoldIcon(const QPalette& p, bool fold, bool hover) const; + + /** + * @brief Generates a custom system style based on the palette. + * @param p The palette to use for generating the style. + * @return A QString containing the generated style. + */ QString systemStyle(const QPalette& p) const; }; -} +} // namespace QSint + +#endif // FREECADTASKPANELSCHEME_H -#endif // IISFREECADTASKPANELSCHEME_H