| 1 |
/* This file is part of the KDE libraries |
| 2 |
SPDX-FileCopyrightText: 2005 David Faure <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-only |
| 5 |
*/ |
| 6 |
|
| 7 |
// clazy:excludeall=qstring-arg |
| 8 |
#include "KoVBox.h" |
| 9 |
|
| 10 |
#include <QEvent> |
| 11 |
#include <QApplication> |
| 12 |
#include <QVBoxLayout> |
| 13 |
|
| 14 |
KoVBox::KoVBox(QWidget *parent) |
| 15 |
: QFrame(parent), |
| 16 |
d(nullptr) |
| 17 |
{ |
| 18 |
QVBoxLayout *layout = new QVBoxLayout(this); |
| 19 |
layout->setSpacing(0); |
| 20 |
layout->setContentsMargins(0, 0, 0, 0); |
| 21 |
|
| 22 |
setLayout(layout); |
| 23 |
} |
| 24 |
|
| 25 |
KoVBox::~KoVBox() |
| 26 |
{ |
| 27 |
} |
| 28 |
|
| 29 |
void KoVBox::childEvent(QChildEvent *event) |
| 30 |
{ |
| 31 |
switch (event->type()) { |
| 32 |
case QEvent::ChildAdded: { |
| 33 |
QChildEvent *childEvent = static_cast<QChildEvent *>(event); |
| 34 |
if (childEvent->child()->isWidgetType()) { |
| 35 |
QWidget *widget = static_cast<QWidget *>(childEvent->child()); |
| 36 |
static_cast<QBoxLayout *>(layout())->addWidget(widget); |
| 37 |
} |
| 38 |
|
| 39 |
break; |
| 40 |
} |
| 41 |
case QEvent::ChildRemoved: { |
| 42 |
QChildEvent *childEvent = static_cast<QChildEvent *>(event); |
| 43 |
if (childEvent->child()->isWidgetType()) { |
| 44 |
QWidget *widget = static_cast<QWidget *>(childEvent->child()); |
| 45 |
static_cast<QBoxLayout *>(layout())->removeWidget(widget); |
| 46 |
} |
| 47 |
|
| 48 |
break; |
| 49 |
} |
| 50 |
default: |
| 51 |
break; |
| 52 |
} |
| 53 |
QFrame::childEvent(event); |
| 54 |
} |
| 55 |
|
| 56 |
QSize KoVBox::sizeHint() const |
| 57 |
{ |
| 58 |
KoVBox *that = const_cast<KoVBox *>(this); |
| 59 |
QApplication::sendPostedEvents(that, QEvent::ChildAdded); |
| 60 |
|
| 61 |
return QFrame::sizeHint(); |
| 62 |
} |
| 63 |
|
| 64 |
QSize KoVBox::minimumSizeHint() const |
| 65 |
{ |
| 66 |
KoVBox *that = const_cast<KoVBox *>(this); |
| 67 |
QApplication::sendPostedEvents(that, QEvent::ChildAdded); |
| 68 |
|
| 69 |
return QFrame::minimumSizeHint(); |
| 70 |
} |
| 71 |
|
| 72 |
void KoVBox::setSpacing(int spacing) |
| 73 |
{ |
| 74 |
layout()->setSpacing(spacing); |
| 75 |
} |
| 76 |
|
| 77 |
void KoVBox::setStretchFactor(QWidget *widget, int stretch) |
| 78 |
{ |
| 79 |
static_cast<QBoxLayout *>(layout())->setStretchFactor(widget, stretch); |
| 80 |
} |
| 81 |
|
| 82 |
void KoVBox::setMargin(int margin) |
| 83 |
{ |
| 84 |
layout()->setContentsMargins(margin, margin, margin, margin); |
| 85 |
} |
| 86 |
|