refactor: actionpanel with more moder structure

This commit is contained in:
Alfredo Monclus
2025-02-04 13:36:45 -03:00
parent 6ccb6672bd
commit 96ae7bb65e

View File

@@ -11,21 +11,17 @@
#include <QVariant>
namespace QSint
{
ActionPanel::ActionPanel(QWidget *parent) :
BaseClass(parent), mySpacer(nullptr)
{
setProperty("class", "panel");
setScheme(ActionPanelScheme::defaultScheme());
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
QVBoxLayout *vbl = new QVBoxLayout();
auto *vbl = new QVBoxLayout();
vbl->setContentsMargins(4, 8, 4, 8);
vbl->setSpacing(8);
setLayout(vbl);
@@ -33,88 +29,73 @@ ActionPanel::ActionPanel(QWidget *parent) :
void ActionPanel::setScheme(ActionPanelScheme *scheme)
{
if (scheme) {
if (!scheme) return;
myScheme = scheme;
setStyleSheet(myScheme->actionStyle);
// set scheme for children
QObjectList list(children());
Q_FOREACH(QObject *obj, list) {
if (dynamic_cast<ActionGroup*>(obj)) {
((ActionGroup*)obj)->setScheme(scheme);
continue;
}
// Set scheme for children
for (QObject *obj : children()) {
if (auto *group = qobject_cast<ActionGroup*>(obj)) {
group->setScheme(scheme);
}
}
update();
}
}
//void ActionPanel::paintEvent ( QPaintEvent * event )
//{
// //QPainter p(this);
// //p.setOpacity(0.5);
// //p.fillRect(rect(), myScheme->panelBackground);
//}
void ActionPanel::addWidget(QWidget *w)
{
if (w)
layout()->addWidget(w);
if (w) layout()->addWidget(w);
}
void ActionPanel::removeWidget(QWidget *w)
{
if (w)
layout()->removeWidget(w);
if (w) layout()->removeWidget(w);
}
void ActionPanel::addStretch(int s)
void ActionPanel::addStretch(int /*s*/)
{
Q_UNUSED(s);
//((QVBoxLayout*)layout())->addStretch(s);
if (!mySpacer) {
mySpacer = new QSpacerItem(0,0,QSizePolicy::Minimum, QSizePolicy::Expanding);
layout()->addItem(mySpacer);
}
if (!mySpacer) {
mySpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout()->addItem(mySpacer);
}
}
void ActionPanel::removeStretch()
{
if (mySpacer) {
layout()->removeItem(mySpacer);
delete mySpacer;
mySpacer = nullptr;
}
if (mySpacer) {
layout()->removeItem(mySpacer);
delete mySpacer;
mySpacer = nullptr;
}
}
ActionGroup * ActionPanel::createGroup()
ActionGroup *ActionPanel::createGroup()
{
ActionGroup * group = new ActionGroup(this);
auto *group = new ActionGroup(this);
addWidget(group);
return group;
}
ActionGroup * ActionPanel::createGroup(const QString &title, bool expandable)
ActionGroup *ActionPanel::createGroup(const QString &title, bool expandable)
{
ActionGroup * box = new ActionGroup(title, expandable, this);
addWidget(box);
return box;
auto *group = new ActionGroup(title, expandable, this);
addWidget(group);
return group;
}
ActionGroup * ActionPanel::createGroup(const QPixmap &icon, const QString &title, bool expandable)
ActionGroup *ActionPanel::createGroup(const QPixmap &icon, const QString &title, bool expandable)
{
ActionGroup * box = new ActionGroup(icon, title, expandable, this);
addWidget(box);
return box;
auto *group = new ActionGroup(icon, title, expandable, this);
addWidget(group);
return group;
}
QSize ActionPanel::minimumSizeHint() const
{
return {200,150};
}
} // namespace QSint
} // namespace