File indexing completed on 2024-05-12 16:02:30
0001 /* This file is part of the KDE project 0002 * Author: Agata Cacko cacko.azh@gmail.com 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef KIS_WRAPPABLE_HBOX_LAYOUT_H 0008 #define KIS_WRAPPABLE_HBOX_LAYOUT_H 0009 0010 #include <QVector> 0011 #include <QLayout> 0012 #include "kritawidgetutils_export.h" 0013 0014 // code taken partially from https://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html 0015 // and https://doc.qt.io/qt-5/layout.html 0016 class KRITAWIDGETUTILS_EXPORT KisWrappableHBoxLayout : public QLayout 0017 { 0018 Q_OBJECT 0019 0020 public: 0021 explicit KisWrappableHBoxLayout(QWidget* parent = nullptr); 0022 ~KisWrappableHBoxLayout() override; 0023 0024 void addItem(QLayoutItem *item) override; 0025 QSize sizeHint() const override; 0026 QSize minimumSize() const override; 0027 int count() const override; 0028 QLayoutItem *itemAt(int) const override; 0029 QLayoutItem *takeAt(int) override; 0030 void setGeometry(const QRect &rect) override; 0031 bool hasHeightForWidth() const override; 0032 int heightForWidth(int width) const override; 0033 0034 protected: 0035 int doLayout(const QRect &rect, bool testOnly) const; 0036 0037 private: 0038 QVector<QLayoutItem*> m_items; 0039 int m_lastWidth {-1}; 0040 0041 }; 0042 0043 0044 #endif // KIS_WRAPPABLE_HBOX_LAYOUT_H