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