refactor: reduce qsint schemes to 1

This commit is contained in:
Alfredo Monclus
2025-02-02 14:26:57 -03:00
parent 5c512d6ff8
commit ed1bfa20bf
10 changed files with 239 additions and 268 deletions

View File

@@ -437,7 +437,6 @@ set(Gui_RES_SRCS
Icons/resource.qrc
Language/translation.qrc
${FreeCAD_TR_QRC}
QSint/actionpanel/schemes.qrc
)
qt_add_resources(Gui_QRC_SRCS ${Gui_RES_SRCS})
@@ -854,8 +853,6 @@ SET(qsintActionPanel_SRCS
QSint/actionpanel/taskgroup_p.h
QSint/actionpanel/taskheader_p.cpp
QSint/actionpanel/taskheader_p.h
QSint/actionpanel/freecadscheme.cpp
QSint/actionpanel/freecadscheme.h
)
SOURCE_GROUP("Widget\\QSintActionPanel" FILES ${qsintActionPanel_SRCS})
set(qsint_MOC_HDRS

View File

@@ -8,122 +8,169 @@
#include "actionpanelscheme.h"
class StaticLibInitializer
{
public:
StaticLibInitializer()
{
Q_INIT_RESOURCE(schemes);
}
};
StaticLibInitializer staticLibInitializer;
namespace QSint
{
const char* ActionPanelDefaultStyle =
"QFrame[class='panel'] {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #99cccc, stop: 1 #EAF7FF);"
"}"
"QSint--ActionGroup QFrame[class='header'] {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F9FDFF, stop: 1 #EAF7FF);"
"border: 1px solid #00aa99;"
"border-bottom: 1px solid #99cccc;"
"border-top-left-radius: 3px;"
"border-top-right-radius: 3px;"
"}"
"QSint--ActionGroup QFrame[class='header']:hover {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #EAF7FF, stop: 1 #F9FDFF);"
"}"
const QString ActionPanelScheme::minimumStyle = QString::fromLatin1(
"QSint--ActionGroup QToolButton[class='header'] {"
"text-align: left;"
"font: 14px;"
"color: #006600;"
"background-color: transparent;"
"border: 1px solid transparent;"
"}"
"QSint--ActionGroup QToolButton[class='header']:hover {"
"color: #00cc00;"
"text-decoration: underline;"
"}"
"QSint--ActionGroup QFrame[class='content'] {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F9FDFF, stop: 1 #EAF7FF);"
"border: 1px solid #00aa99;"
"}"
"QSint--ActionGroup QFrame[class='content'][header='true'] {"
"border-top: none;"
"font-weight: bold;"
"}"
"QSint--ActionGroup QToolButton[class='action'] {"
"background-color: transparent;"
"border: 1px solid transparent;"
"color: #0033ff;"
"text-align: left;"
"font: 11px;"
"}"
"QSint--ActionGroup QToolButton[class='action']:!enabled {"
"color: #999999;"
"}"
"QSint--ActionGroup QToolButton[class='action']:hover {"
"color: #0099ff;"
"text-decoration: underline;"
"}"
);
"QSint--ActionGroup QToolButton[class='action']:focus {"
"border: 1px dotted black;"
"}"
QString ActionPanelScheme::systemStyle(const QPalette& p)
{
QString headerBackground = p.color(QPalette::Highlight).name();
QString headerLabelText = p.color(QPalette::HighlightedText).name();
QString headerLabelTextOver = p.color(QPalette::BrightText).name();
QString groupBorder = p.color(QPalette::Mid).name();
QString disabledActionText = p.color(QPalette::Disabled, QPalette::Text).name();
QString actionSelectedBg = p.color(QPalette::Active, QPalette::Light).name();
QString actionSelectedText = p.color(QPalette::Active, QPalette::ButtonText).name();
QString actionSelectedBorder = p.color(QPalette::Active, QPalette::Highlight).name();
QString panelBackground = p.color(QPalette::Window).name();
QString groupBackground = p.color(QPalette::Button).name();
"QSint--ActionGroup QToolButton[class='action']:on {"
"background-color: #ddeeff;"
"color: #006600;"
"}"
QHash<QString, QString> replacements;
replacements["headerBackground"] = headerBackground;
replacements["headerLabelText"] = headerLabelText;
replacements["headerLabelTextOver"] = headerLabelTextOver;
replacements["groupBorder"] = groupBorder;
replacements["disabledActionText"] = disabledActionText;
replacements["actionSelectedBg"] = actionSelectedBg;
replacements["actionSelectedText"] = actionSelectedText;
replacements["actionSelectedBorder"] = actionSelectedBorder;
replacements["panelBackground"] = panelBackground;
replacements["groupBackground"] = groupBackground;
// set a QGroupBox to avoid that the OS style is used, see
// https://github.com/FreeCAD/FreeCAD/issues/6102
// the px values are taken from Behave-dark.qss, except the padding
"QSint--ActionGroup QFrame[class='content'] QGroupBox {"
"border: 1px solid #bbbbbb;"
"border-radius: 3px;"
"margin-top: 10px;"
"padding: 2px;"
"}"
// since we set a custom frame we also need to set the title
"QSint--ActionGroup QFrame[class='content'] QGroupBox::title {"
"padding-left: 3px;"
"top: -6px;"
"left: 12px;"
"}"
;
QString style = QString::fromLatin1(
"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;
}
// Draws fold/unfold icons based on the palette
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);
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);
}
ActionPanelScheme::ActionPanelScheme()
{
headerSize = 28;
headerAnimation = true;
headerButtonFold = QPixmap(":/default/Fold.png");
headerButtonFoldOver = QPixmap(":/default/FoldOver.png");
headerButtonUnfold = QPixmap(":/default/Unfold.png");
headerButtonUnfoldOver = QPixmap(":/default/UnfoldOver.png");
headerButtonSize = QSize(18,18);
QPalette p = QApplication::palette();
groupFoldSteps = 20; groupFoldDelay = 15;
headerButtonSize = QSize(17, 17);
headerButtonFold = drawFoldIcon(p, true, false);
headerButtonFoldOver = drawFoldIcon(p, true, true);
headerButtonUnfold = drawFoldIcon(p, false, false);
headerButtonUnfoldOver = drawFoldIcon(p, false, true);
builtinFold = headerButtonFold;
builtinFoldOver = headerButtonFoldOver;
builtinUnfold = headerButtonUnfold;
builtinUnfoldOver = headerButtonUnfoldOver;
groupFoldSteps = 20;
groupFoldDelay = 15;
groupFoldEffect = NoFolding;
groupFoldThaw = true;
actionStyle = QString(ActionPanelDefaultStyle);
actionStyle = minimumStyle + systemStyle(p);
builtinScheme = actionStyle;
}
ActionPanelScheme* ActionPanelScheme::defaultScheme()
@@ -132,5 +179,24 @@ ActionPanelScheme* ActionPanelScheme::defaultScheme()
return &scheme;
}
void ActionPanelScheme::clearActionStyle()
{
headerButtonFold = QPixmap();
headerButtonFoldOver = QPixmap();
headerButtonUnfold = QPixmap();
headerButtonUnfoldOver = QPixmap();
actionStyle = minimumStyle;
}
void ActionPanelScheme::restoreActionStyle()
{
headerButtonFold = builtinFold;
headerButtonFoldOver = builtinFoldOver;
headerButtonUnfold = builtinUnfold;
headerButtonUnfoldOver = builtinUnfoldOver;
actionStyle = builtinScheme;
}
} // namespace QSint

View File

@@ -5,79 +5,112 @@
* *
***************************************************************************/
#ifndef TASKPANELSCHEME_H
#define TASKPANELSCHEME_H
#ifndef ACTIONPANELSCHEME_H
#define ACTIONPANELSCHEME_H
#include <QPixmap>
#include <QSize>
#include <QString>
#include "qsint_global.h"
#include <QApplication>
#include <QImage>
#include <QPainter>
#include <QPalette>
#include <QPixmap>
#include <QHash>
#include <QSize>
#include <QString>
namespace QSint
{
/**
\brief Class representing color scheme for ActionPanel and ActionGroup.
\since 0.2
\image html ActionPanel1.png Default ActionPanel scheme
*/
* #@brief Class representing color scheme for ActionPanel and ActionGroup.
*/
class QSINT_EXPORT ActionPanelScheme
{
public:
/** \enum TaskPanelFoldEffect
\brief Animation effect during expanding/collapsing of the ActionGroup's contents.
*/
enum TaskPanelFoldEffect
/**
* @brief Animation effect during expanding/collapsing of the ActionGroup's contents.
*/
enum FoldEffect
{
/// No folding effect
NoFolding,
/// Folding by scaling group's contents
ShrunkFolding,
/// Folding by sliding group's contents
SlideFolding
};
ActionPanelScheme();
ActionPanelScheme();
/** Returns a pointer to the default scheme object.
* Must be reimplemented in derived classes for custom schemes.
*/
static ActionPanelScheme* defaultScheme();
/** Returns a pointer to the default scheme object.
Must be reimplemented in the own schemes.
*/
static ActionPanelScheme* defaultScheme();
/// Height of the header in pixels.
int headerSize;
/// If set to \a true, moving mouse over the header results in changing its opacity slowly.
bool headerAnimation;
/// Height of the header in pixels.
int headerSize;
/// If set to \a true, moving mouse over the header results in changing its opacity slowly.
bool headerAnimation;
/// Image of folding button when the group is expanded.
QPixmap headerButtonFold;
/// Image of folding button when the group is expanded and mouse cursor is over the button.
QPixmap headerButtonFoldOver;
/// Image of folding button when the group is collapsed.
QPixmap headerButtonUnfold;
/// Image of folding button when the group is collapsed and mouse cursor is over the button.
QPixmap headerButtonUnfoldOver;
/// Image of folding button when the group is expanded.
QPixmap headerButtonFold;
/// Image of folding button when the group is expanded and mouse cursor is over the button.
QPixmap headerButtonFoldOver;
/// Image of folding button when the group is collapsed.
QPixmap headerButtonUnfold;
/// Image of folding button when the group is collapsed and mouse cursor is over the button.
QPixmap headerButtonUnfoldOver;
QSize headerButtonSize;
QSize headerButtonSize;
/// Number of steps made for expanding/collapsing animation (default 20).
int groupFoldSteps;
/// Delay in ms between steps made for expanding/collapsing animation (default 15).
int groupFoldDelay;
/// Sets folding effect during expanding/collapsing.
FoldEffect groupFoldEffect;
/// If set to \a true, changes group's opacity slowly during expanding/collapsing.
bool groupFoldThaw;
/// Number of steps made for expanding/collapsing animation (default 20).
int groupFoldSteps;
/// Delay in ms between steps made for expanding/collapsing animation (default 15).
int groupFoldDelay;
/// Sets folding effect during expanding/collapsing.
TaskPanelFoldEffect groupFoldEffect;
/// If set to \a true, changes group's opacity slowly during expanding/collapsing.
bool groupFoldThaw;
/// The CSS for the ActionPanel/ActionGroup elements.
QString actionStyle;
/// The CSS for the ActionPanel/ActionGroup elements.
QString actionStyle;
/**
* @brief Clears the custom action style, resetting to a minimal style.
*/
void clearActionStyle();
/**
* @brief Restores the original action style.
*/
void restoreActionStyle();
static const QString minimumStyle;
/**
* @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);
protected:
/**
* @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;
private:
// Store the built-in icons for restoration.
QPixmap builtinFold;
QPixmap builtinFoldOver;
QPixmap builtinUnfold;
QPixmap builtinUnfoldOver;
QString builtinScheme;
};
} // namespace QSint
}
#endif // TASKPANELSCHEME_H
#endif // ACTIONPANELSCHEME_H

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 747 B

View File

@@ -1,117 +0,0 @@
/***************************************************************************
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef FREECADTASKPANELSCHEME_H
#define FREECADTASKPANELSCHEME_H
#include "actionpanelscheme.h"
#include <QString>
#include <QPixmap>
#include <QPalette>
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; ///< 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

View File

@@ -1,8 +0,0 @@
<RCC>
<qresource prefix="/">
<file>default/Fold.png</file>
<file>default/FoldOver.png</file>
<file>default/Unfold.png</file>
<file>default/UnfoldOver.png</file>
</qresource>
</RCC>

View File

@@ -47,7 +47,7 @@
#include <Gui/QSint/actionpanel/taskgroup_p.h>
#include <Gui/QSint/actionpanel/taskheader_p.h>
#include <Gui/QSint/actionpanel/freecadscheme.h>
#include <Gui/QSint/actionpanel/actionpanelscheme.h>
using namespace Gui::TaskView;
@@ -279,7 +279,7 @@ TaskView::TaskView(QWidget *parent)
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(taskPanel->sizePolicy().hasHeightForWidth());
taskPanel->setSizePolicy(sizePolicy);
taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme());
taskPanel->setScheme(QSint::ActionPanelScheme::defaultScheme());
this->setWidget(taskPanel);
setWidgetResizable(true);
@@ -603,7 +603,7 @@ void TaskView::showDialog(TaskDialog *dlg)
taskPanel->addWidget(ActiveCtrl);
}
taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme());
taskPanel->setScheme(QSint::ActionPanelScheme::defaultScheme());
if (!dlg->needsFullSpace())
taskPanel->addStretch();
@@ -764,7 +764,7 @@ void TaskView::addTaskWatcher()
}
#endif
taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme());
taskPanel->setScheme(QSint::ActionPanelScheme::defaultScheme());
}
void TaskView::saveCurrentWidth()
@@ -870,14 +870,14 @@ void TaskView::clicked (QAbstractButton * button)
void TaskView::clearActionStyle()
{
static_cast<QSint::FreeCADPanelScheme*>(QSint::FreeCADPanelScheme::defaultScheme())->clearActionStyle();
taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme());
static_cast<QSint::ActionPanelScheme*>(QSint::ActionPanelScheme::defaultScheme())->clearActionStyle();
taskPanel->setScheme(QSint::ActionPanelScheme::defaultScheme());
}
void TaskView::restoreActionStyle()
{
static_cast<QSint::FreeCADPanelScheme*>(QSint::FreeCADPanelScheme::defaultScheme())->restoreActionStyle();
taskPanel->setScheme(QSint::FreeCADPanelScheme::defaultScheme());
static_cast<QSint::ActionPanelScheme*>(QSint::ActionPanelScheme::defaultScheme())->restoreActionStyle();
taskPanel->setScheme(QSint::ActionPanelScheme::defaultScheme());
}