File indexing completed on 2024-05-19 04:36:40

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2014 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TIKZUI_TOOL_LAYOUT_H
0021 #define TIKZUI_TOOL_LAYOUT_H
0022 
0023 #include <QRect>
0024 #include <QLayout>
0025 #include <QLayoutItem>
0026 
0027 /**
0028  * The ToolLayout layouts the added widgets in a grid.
0029  * It places the child widgets such that as many widgets as possible fit into
0030  * a line. Typical applications are toolboxes of graphical programs like in
0031  * The Gimp or Krita.
0032  */
0033 class ToolLayout : public QLayout
0034 {
0035 public:
0036     /**
0037      * Constructor with @p parent.
0038      */
0039     ToolLayout(QWidget *parent = nullptr);
0040 
0041     /**
0042      * Virtual destructor.
0043      */
0044     virtual ~ToolLayout();
0045 
0046     /**
0047      * Add @p item to the layout.
0048      */
0049     void addItem(QLayoutItem *item) override;
0050 
0051     /**
0052      * Returns the item with the given @p index.
0053      */
0054     QLayoutItem *itemAt(int index) const override;
0055 
0056     /**
0057      * Remove @p index from the layout. Afterwards, the returned QLayoutItem
0058      * is not managed by this layout anymore.
0059      */
0060     QLayoutItem *takeAt(int index) override;
0061 
0062     /**
0063      * Returns the number of items managed by this layout.
0064      */
0065     int count() const override;
0066 
0067     /**
0068      * Reimplement to return no expanding directions.
0069      */
0070     Qt::Orientations expandingDirections() const override;
0071 
0072     /**
0073      * Return @e true, since this layout supports heightForWidth().
0074      */
0075     bool hasHeightForWidth() const override;
0076 
0077     /**
0078      * Returns the required height for @p width, taking margins into account.
0079      */
0080     int heightForWidth(int width) const override;
0081 
0082     /**
0083      * Returns the minimum size of the layout, which equals the size of the
0084      * largest child widget extended by the contents margins.
0085      */
0086     QSize minimumSize() const override;
0087 
0088     /**
0089      * Returns the minimumSize().
0090      */
0091     QSize sizeHint() const override;
0092 
0093     /**
0094      * Relayouts the child widgets in the available @p rect.
0095      */
0096     void setGeometry(const QRect &rect) override;
0097 
0098 private:
0099     int doLayout(const QRect &rect, bool dryRun = false) const;
0100 
0101     QList<QLayoutItem *> m_items;
0102 };
0103 
0104 #endif // TIKZUI_TOOL_LAYOUT_H
0105 
0106 // kate: indent-width 4; replace-tabs on;