| 1 |
// SPDX-License-Identifier: LGPL-3.0-only |
| 2 |
/*************************************************************************** |
| 3 |
* * |
| 4 |
* Copyright: https://code.google.com/p/qsint/ * |
| 5 |
* License: LGPL * |
| 6 |
* * |
| 7 |
***************************************************************************/ |
| 8 |
|
| 9 |
#include "actionpanel.h" |
| 10 |
#include "actionpanelscheme.h" |
| 11 |
#include "actiongroup.h" |
| 12 |
|
| 13 |
#include <QVariant> |
| 14 |
|
| 15 |
namespace QSint |
| 16 |
{ |
| 17 |
|
| 18 |
ActionPanel::ActionPanel(QWidget *parent) : |
| 19 |
BaseClass(parent), mySpacer(nullptr) |
| 20 |
{ |
| 21 |
setProperty("class", "panel"); |
| 22 |
setScheme(ActionPanelScheme::defaultScheme()); |
| 23 |
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); |
| 24 |
|
| 25 |
auto *vbl = new QVBoxLayout(); |
| 26 |
vbl->setContentsMargins(4, 8, 4, 8); |
| 27 |
vbl->setSpacing(8); |
| 28 |
setLayout(vbl); |
| 29 |
} |
| 30 |
|
| 31 |
void ActionPanel::setScheme(ActionPanelScheme *scheme) |
| 32 |
{ |
| 33 |
if (!scheme) { |
| 34 |
return; |
| 35 |
} |
| 36 |
myScheme = scheme; |
| 37 |
// set scheme for children |
| 38 |
QObjectList list(children()); |
| 39 |
Q_FOREACH(QObject *obj, list) { |
| 40 |
if (dynamic_cast<ActionGroup*>(obj)) { |
| 41 |
((ActionGroup*)obj)->setScheme(scheme); |
| 42 |
continue; |
| 43 |
} |
| 44 |
} |
| 45 |
update(); |
| 46 |
} |
| 47 |
|
| 48 |
void ActionPanel::addWidget(QWidget *w) |
| 49 |
{ |
| 50 |
if (w) layout()->addWidget(w); |
| 51 |
} |
| 52 |
|
| 53 |
void ActionPanel::removeWidget(QWidget *w) |
| 54 |
{ |
| 55 |
if (w) layout()->removeWidget(w); |
| 56 |
} |
| 57 |
|
| 58 |
void ActionPanel::addStretch(int /*s*/) |
| 59 |
{ |
| 60 |
if (!mySpacer) { |
| 61 |
mySpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); |
| 62 |
layout()->addItem(mySpacer); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
void ActionPanel::removeStretch() |
| 67 |
{ |
| 68 |
if (mySpacer) { |
| 69 |
layout()->removeItem(mySpacer); |
| 70 |
delete mySpacer; |
| 71 |
mySpacer = nullptr; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
ActionGroup *ActionPanel::createGroup() |
| 76 |
{ |
| 77 |
auto *group = new ActionGroup(this); |
| 78 |
addWidget(group); |
| 79 |
return group; |
| 80 |
} |
| 81 |
|
| 82 |
ActionGroup *ActionPanel::createGroup(const QString &title, bool expandable) |
| 83 |
{ |
| 84 |
auto *group = new ActionGroup(title, expandable, this); |
| 85 |
addWidget(group); |
| 86 |
return group; |
| 87 |
} |
| 88 |
|
| 89 |
ActionGroup *ActionPanel::createGroup(const QPixmap &icon, const QString &title, bool expandable) |
| 90 |
{ |
| 91 |
auto *group = new ActionGroup(icon, title, expandable, this); |
| 92 |
addWidget(group); |
| 93 |
return group; |
| 94 |
} |
| 95 |
|
| 96 |
QSize ActionPanel::minimumSizeHint() const |
| 97 |
{ |
| 98 |
return {200,150}; |
| 99 |
} |
| 100 |
|
| 101 |
} // namespace QSint |
| 102 |
|