[67369] | 1 | /* $Id: QIFlowLayout.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[71894] | 3 | * VBox Qt GUI - Qt extensions: QIFlowLayout class declaration.
|
---|
[67369] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2017-2023 Oracle and/or its affiliates.
|
---|
[67369] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[67369] | 26 | */
|
---|
| 27 |
|
---|
[76581] | 28 | #ifndef FEQT_INCLUDED_SRC_extensions_QIFlowLayout_h
|
---|
| 29 | #define FEQT_INCLUDED_SRC_extensions_QIFlowLayout_h
|
---|
[76532] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[67369] | 33 |
|
---|
| 34 | /* Qt includes: */
|
---|
| 35 | #include <QLayout>
|
---|
| 36 | #include <QStyle>
|
---|
| 37 |
|
---|
[71894] | 38 | /* GUI includes: */
|
---|
| 39 | #include "UILibraryDefs.h"
|
---|
[67369] | 40 |
|
---|
| 41 | /** QLayout extension providing GUI with the possibility to build flow-layout.
|
---|
| 42 | * This kind of horizonal layout can wrap children down to the next line (row)
|
---|
| 43 | * performing calculations on the basis of layout size and children size-hints.
|
---|
| 44 | * It is also takes into account that some of the children can be expandable
|
---|
| 45 | * horizontally allowing them to grow up to all the available width. */
|
---|
[71894] | 46 | class SHARED_LIBRARY_STUFF QIFlowLayout : public QLayout
|
---|
[67369] | 47 | {
|
---|
| 48 | Q_OBJECT;
|
---|
| 49 |
|
---|
| 50 | /** Layout item expand policy. */
|
---|
| 51 | enum ExpandPolicy
|
---|
| 52 | {
|
---|
| 53 | ExpandPolicy_Fixed,
|
---|
| 54 | ExpandPolicy_Dynamic
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 | /** Layout item data. */
|
---|
| 58 | struct LayoutData
|
---|
| 59 | {
|
---|
| 60 | /** Constructs layout item data on the bases of passed @a pItem.
|
---|
| 61 | * @param enmPolicy Brings the layout item expand policy.
|
---|
| 62 | * @param iWidth Brings the layout item desired width. */
|
---|
| 63 | LayoutData(QLayoutItem *pItem, ExpandPolicy enmPolicy, int iWidth)
|
---|
| 64 | : item(pItem), policy(enmPolicy), width(iWidth)
|
---|
| 65 | {}
|
---|
| 66 |
|
---|
| 67 | /** Holds the layout item. */
|
---|
[71894] | 68 | QLayoutItem *item;
|
---|
[67369] | 69 | /** Holds the layout item expand policy. */
|
---|
[71894] | 70 | ExpandPolicy policy;
|
---|
[67369] | 71 | /** Holds the layout item desired width. */
|
---|
[71894] | 72 | int width;
|
---|
[67369] | 73 | };
|
---|
| 74 | /** Layout item data list. */
|
---|
| 75 | typedef QList<LayoutData> LayoutDataList;
|
---|
| 76 | /** Layout item data table. */
|
---|
| 77 | typedef QList<LayoutDataList> LayoutDataTable;
|
---|
| 78 |
|
---|
| 79 | public:
|
---|
| 80 |
|
---|
| 81 | /** Constructs flow-layout passing @a pParent to the base-class.
|
---|
| 82 | * @param iMargin Brings the layout contents margin.
|
---|
| 83 | * @param iSpacingH Brings the layout horizontal spacing.
|
---|
| 84 | * @param iSpacingV Brings the layout vertical spacing. */
|
---|
| 85 | QIFlowLayout(QWidget *pParent, int iMargin = -1, int iSpacingH = -1, int iSpacingV = -1);
|
---|
| 86 |
|
---|
| 87 | /** Constructs flow-layout.
|
---|
| 88 | * @param iMargin Brings the layout contents margin.
|
---|
| 89 | * @param iSpacingH Brings the layout horizontal spacing.
|
---|
| 90 | * @param iSpacingV Brings the layout vertical spacing. */
|
---|
| 91 | QIFlowLayout(int iMargin = -1, int iSpacingH = -1, int iSpacingV = -1);
|
---|
| 92 |
|
---|
| 93 | /** Destructs flow-layout. */
|
---|
[93990] | 94 | virtual ~QIFlowLayout() RT_OVERRIDE;
|
---|
[67369] | 95 |
|
---|
| 96 | /** Returns the number of layout items. */
|
---|
[93990] | 97 | virtual int count() const RT_OVERRIDE;
|
---|
[67369] | 98 | /** Adds @a pItem into layout. */
|
---|
[93990] | 99 | virtual void addItem(QLayoutItem *pItem) RT_OVERRIDE;
|
---|
[67369] | 100 | /** Returns the layout item at passed @a iIndex. */
|
---|
[93990] | 101 | virtual QLayoutItem *itemAt(int iIndex) const RT_OVERRIDE;
|
---|
[67369] | 102 | /** Removes the layout item at passed @a iIndex and returns it. */
|
---|
[93990] | 103 | virtual QLayoutItem *takeAt(int index) RT_OVERRIDE;
|
---|
[67369] | 104 |
|
---|
| 105 | /** Returns whether this layout can make use of more space than sizeHint().
|
---|
| 106 | * A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only one dimension,
|
---|
| 107 | * whereas Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions. */
|
---|
[93990] | 108 | virtual Qt::Orientations expandingDirections() const RT_OVERRIDE;
|
---|
[67369] | 109 |
|
---|
| 110 | /** Returns whether this layout's preferred height depends on its width. */
|
---|
[93990] | 111 | virtual bool hasHeightForWidth() const RT_OVERRIDE;
|
---|
[67369] | 112 | /** Returns the preferred height for this layout item, given the width. */
|
---|
[93990] | 113 | virtual int heightForWidth(int) const RT_OVERRIDE;
|
---|
[67369] | 114 |
|
---|
| 115 | /** Returns the minimum layout size. */
|
---|
[93990] | 116 | virtual QSize minimumSize() const RT_OVERRIDE;
|
---|
[67369] | 117 | /** Returns this item's preferred size. */
|
---|
[93990] | 118 | virtual QSize sizeHint() const RT_OVERRIDE;
|
---|
[67369] | 119 |
|
---|
| 120 | /** Defines this item's geometry to @a rect. */
|
---|
[93990] | 121 | virtual void setGeometry(const QRect &rect) RT_OVERRIDE;
|
---|
[67369] | 122 |
|
---|
| 123 | private:
|
---|
| 124 |
|
---|
| 125 | /** Recalculates layout on the basis of passed @a rect.
|
---|
| 126 | * Adjusts layout items if @a fDoLayout is true.
|
---|
| 127 | * @returns recalculated layout height. */
|
---|
| 128 | int relayout(const QRect &rect, bool fDoLayout) const;
|
---|
| 129 |
|
---|
| 130 | /** Returns smart spacing based on parent if present. */
|
---|
| 131 | int smartSpacing(QStyle::PixelMetric pm) const;
|
---|
| 132 | /** Returns horizontal spacing. */
|
---|
| 133 | int horizontalSpacing() const;
|
---|
| 134 | /** Returns vertical spacing. */
|
---|
| 135 | int verticalSpacing() const;
|
---|
| 136 |
|
---|
| 137 | /** Holds the layout item list. */
|
---|
| 138 | QList<QLayoutItem *> m_items;
|
---|
| 139 |
|
---|
| 140 | /** Holds the horizontal spacing. */
|
---|
| 141 | int m_iSpacingH;
|
---|
| 142 | /** Holds the vertical spacing. */
|
---|
| 143 | int m_iSpacingV;
|
---|
| 144 | };
|
---|
| 145 |
|
---|
[76581] | 146 | #endif /* !FEQT_INCLUDED_SRC_extensions_QIFlowLayout_h */
|
---|