Warning, file /office/skrooge/skgbasegui/skgflowlayout.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGFLOWLAYOUT_H
0007 #define SKGFLOWLAYOUT_H
0008 /** @file
0009 * This file defines classes SKGFlowLayout.
0010 *
0011 * @author Stephane MANKOWSKI / Guillaume DE BURE
0012 */
0013 #include <qlayout.h>
0014 #include <qstyle.h>
0015 
0016 #include "skgbasegui_export.h"
0017 
0018 /**
0019  * This file is a flow layout
0020  */
0021 class SKGBASEGUI_EXPORT SKGFlowLayout : public QLayout
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     /**
0027      * Constructor
0028      * @param iParent the parent
0029      * @param iMargin margin
0030      * @param hSpacing horizontal spacing
0031      * @param vSpacing vertical spacing
0032      */
0033     explicit SKGFlowLayout(QWidget* iParent, int iMargin = -1, int hSpacing = -1, int vSpacing = -1);
0034 
0035     /**
0036      * Constructor
0037      * @param iMargin margin
0038      * @param hSpacing horizontal spacing
0039      * @param vSpacing vertical spacing
0040      */
0041     explicit SKGFlowLayout(int iMargin = -1, int hSpacing = -1, int vSpacing = -1);
0042 
0043     /**
0044      * Default Destructor
0045      */
0046     ~SKGFlowLayout() override;
0047 
0048     /**
0049      * Add an item
0050      * @param item the item to add
0051      */
0052     void addItem(QLayoutItem* item) override;
0053 
0054     /**
0055      * Set horizontal and vertical spacing
0056      * @param space the space
0057      */
0058     virtual void setSpacing(int space);
0059 
0060     /**
0061      * Get horizontal spacing
0062      * @return horizontal spacing
0063      */
0064     virtual int horizontalSpacing() const;
0065 
0066     /**
0067      * Get vertical spacing
0068      * @return vertical spacing
0069      */
0070     virtual int verticalSpacing() const;
0071 
0072     /**
0073      * Get expanding directions
0074      * @return expanding directions
0075      */
0076     Qt::Orientations expandingDirections() const override;
0077 
0078     /**
0079      * Returns true if this layout's preferred height depends on its width; otherwise returns false.
0080      * The default implementation returns false.
0081      * Reimplement this function in layout managers that support height for width.
0082      * @return true of false
0083      */
0084     bool hasHeightForWidth() const override;
0085 
0086     /**
0087      * Returns the preferred height for this layout item, given the width w.
0088      * The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the function hasHeightForWidth() will typically be much faster than calling this function and testing for -1.
0089      * Reimplement this function in layout managers that support height for width
0090      * @return height
0091      */
0092     int heightForWidth(int /*width*/ /*unused*/) const override;
0093 
0094     /**
0095      * Returns the number of items
0096      * @return number of items
0097      */
0098     int count() const override;
0099 
0100     /**
0101      * Returns the item for an index
0102      * @param index the index
0103      * @return the item
0104      */
0105     QLayoutItem* itemAt(int index) const override;
0106 
0107     /**
0108      * Returns the minimum size
0109      * @return the minimum size
0110      */
0111     QSize minimumSize() const override;
0112 
0113     /**
0114      * Set the geometry
0115      * @param rect the geometry
0116      */
0117     void setGeometry(const QRect& rect) override;
0118 
0119     /**
0120      * Returns the preferred size
0121      * @return the preferred size
0122      */
0123     QSize sizeHint() const override;
0124 
0125     /**
0126      * Takes the item for an index
0127      * @param index the index
0128      * @return the item
0129      */
0130     QLayoutItem* takeAt(int index) override;
0131 
0132 
0133 private:
0134     int doLayout(QRect rect, bool testOnly) const;
0135     int smartSpacing(QStyle::PixelMetric pm) const;
0136 
0137     QList<QLayoutItem*> m_itemList;
0138     int m_hSpace;
0139     int m_vSpace;
0140 };
0141 
0142 #endif