VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFlowLayout.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: QIFlowLayout.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Qt extensions: QIFlowLayout class declaration.
4 */
5
6/*
7 * Copyright (C) 2017-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28#ifndef FEQT_INCLUDED_SRC_extensions_QIFlowLayout_h
29#define FEQT_INCLUDED_SRC_extensions_QIFlowLayout_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QLayout>
36#include <QStyle>
37
38/* GUI includes: */
39#include "UILibraryDefs.h"
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. */
46class SHARED_LIBRARY_STUFF QIFlowLayout : public QLayout
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. */
68 QLayoutItem *item;
69 /** Holds the layout item expand policy. */
70 ExpandPolicy policy;
71 /** Holds the layout item desired width. */
72 int width;
73 };
74 /** Layout item data list. */
75 typedef QList<LayoutData> LayoutDataList;
76 /** Layout item data table. */
77 typedef QList<LayoutDataList> LayoutDataTable;
78
79public:
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. */
94 virtual ~QIFlowLayout() RT_OVERRIDE;
95
96 /** Returns the number of layout items. */
97 virtual int count() const RT_OVERRIDE;
98 /** Adds @a pItem into layout. */
99 virtual void addItem(QLayoutItem *pItem) RT_OVERRIDE;
100 /** Returns the layout item at passed @a iIndex. */
101 virtual QLayoutItem *itemAt(int iIndex) const RT_OVERRIDE;
102 /** Removes the layout item at passed @a iIndex and returns it. */
103 virtual QLayoutItem *takeAt(int index) RT_OVERRIDE;
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. */
108 virtual Qt::Orientations expandingDirections() const RT_OVERRIDE;
109
110 /** Returns whether this layout's preferred height depends on its width. */
111 virtual bool hasHeightForWidth() const RT_OVERRIDE;
112 /** Returns the preferred height for this layout item, given the width. */
113 virtual int heightForWidth(int) const RT_OVERRIDE;
114
115 /** Returns the minimum layout size. */
116 virtual QSize minimumSize() const RT_OVERRIDE;
117 /** Returns this item's preferred size. */
118 virtual QSize sizeHint() const RT_OVERRIDE;
119
120 /** Defines this item's geometry to @a rect. */
121 virtual void setGeometry(const QRect &rect) RT_OVERRIDE;
122
123private:
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
146#endif /* !FEQT_INCLUDED_SRC_extensions_QIFlowLayout_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use