File indexing completed on 2025-04-27 03:58:30
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2014-09-12 0007 * Description : Vertical and horizontal layout widget helpers. 0008 * 0009 * SPDX-FileCopyrightText: 2014-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dlayoutbox.h" 0016 0017 // Qt includes 0018 0019 #include <QHBoxLayout> 0020 #include <QVBoxLayout> 0021 #include <QApplication> 0022 0023 // Local includes 0024 0025 #include "digikam_debug.h" 0026 0027 namespace Digikam 0028 { 0029 0030 DHBox::DHBox(QWidget* const parent) 0031 : QFrame(parent) 0032 { 0033 QHBoxLayout* const layout = new QHBoxLayout(this); 0034 layout->setContentsMargins(QMargins()); 0035 layout->setSpacing(0); 0036 setLayout(layout); 0037 } 0038 0039 DHBox::DHBox(bool /*vertical*/, QWidget* const parent) 0040 : QFrame(parent) 0041 { 0042 QVBoxLayout* const layout = new QVBoxLayout(this); 0043 layout->setContentsMargins(QMargins()); 0044 layout->setSpacing(0); 0045 setLayout(layout); 0046 } 0047 0048 DHBox::~DHBox() 0049 { 0050 } 0051 0052 void DHBox::childEvent(QChildEvent* e) 0053 { 0054 switch (e->type()) 0055 { 0056 case QEvent::ChildAdded: 0057 { 0058 QChildEvent* const ce = static_cast<QChildEvent*>(e); 0059 0060 if (ce->child()->isWidgetType()) 0061 { 0062 QWidget* const w = static_cast<QWidget*>(ce->child()); 0063 static_cast<QBoxLayout*>(layout())->addWidget(w); 0064 } 0065 0066 break; 0067 } 0068 0069 case QEvent::ChildRemoved: 0070 { 0071 QChildEvent* const ce = static_cast<QChildEvent*>(e); 0072 0073 if (ce->child()->isWidgetType()) 0074 { 0075 QWidget* const w = static_cast<QWidget*>(ce->child()); 0076 static_cast<QBoxLayout*>(layout())->removeWidget(w); 0077 } 0078 0079 break; 0080 } 0081 0082 default: 0083 { 0084 break; 0085 } 0086 } 0087 0088 QFrame::childEvent(e); 0089 } 0090 0091 QSize DHBox::sizeHint() const 0092 { 0093 DHBox* const b = const_cast<DHBox*>(this); 0094 QApplication::sendPostedEvents(b, QEvent::ChildAdded); 0095 0096 return QFrame::sizeHint(); 0097 } 0098 0099 QSize DHBox::minimumSizeHint() const 0100 { 0101 DHBox* const b = const_cast<DHBox*>(this); 0102 QApplication::sendPostedEvents(b, QEvent::ChildAdded); 0103 0104 return QFrame::minimumSizeHint(); 0105 } 0106 0107 void DHBox::setSpacing(int spacing) 0108 { 0109 layout()->setSpacing(spacing); 0110 } 0111 0112 void DHBox::setContentsMargins(const QMargins& margins) 0113 { 0114 layout()->setContentsMargins(margins); 0115 } 0116 0117 void DHBox::setContentsMargins(int left, int top, int right, int bottom) 0118 { 0119 layout()->setContentsMargins(left, top, right, bottom); 0120 } 0121 0122 void DHBox::setStretchFactor(QWidget* const widget, int stretch) 0123 { 0124 static_cast<QBoxLayout*>(layout())->setStretchFactor(widget, stretch); 0125 } 0126 0127 // ------------------------------------------------------------------------------------ 0128 0129 DVBox::DVBox(QWidget* const parent) 0130 : DHBox(true, parent) 0131 { 0132 } 0133 0134 DVBox::~DVBox() 0135 { 0136 } 0137 0138 } // namespace Digikam 0139 0140 #include "moc_dlayoutbox.cpp"