File indexing completed on 2024-12-22 04:13:14
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Juan Palacios <jpalaciosdev@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISSIZEGROUP_H 0008 #define KISSIZEGROUP_H 0009 0010 #include <QObject> 0011 #include "kritaui_export.h" 0012 0013 class QWidget; 0014 class KisSizeGroupPrivate; 0015 0016 /** 0017 * KisSizeGroup provides a mechanism to group widgets together so they all 0018 * request the same amount of space. Also, the widgets will share the same 0019 * amount of minimum space. The mode of KisSizeGroup determines the direction of 0020 * the space that are affected by the size group. 0021 * 0022 * All widgets inside of KisSizeGroup will use the same size hint value, computed 0023 * as the maximum of all of his size hint values. The same value is used for the 0024 * minimum size of all widgets. When KisSizeGroup ignore hidden widgets, the 0025 * size of widgets that are not visible don't count in the computation of the 0026 * current size value. When one of these widgets becomes visible again, a new 0027 * size value is computed and applied to all visible widgets. 0028 * 0029 * KisSizeGroup cannot share the same widget with other size groups, so one 0030 * widget can be in one, and only one, KisSizeGroup at time. 0031 * 0032 * NOTE: Added widgets in size groups must be laid out inside of a valid 0033 * layout. The current implementation supports widgets laid out inside of 0034 * QGridLayout, QFormLayout and QBoxLayout. If the parent widget layout is not 0035 * one of them, then the group size will not affect the widget size. 0036 */ 0037 class KRITAUI_EXPORT KisSizeGroup : public QObject 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 /** 0043 * Determines the direction in which the size group affects the requested 0044 * and minimum sizes of his component widgets. 0045 */ 0046 enum mode 0047 { 0048 KIS_SIZE_GROUP_NONE = 0, //! group has no effect 0049 KIS_SIZE_GROUP_HORIZONTAL = 1 << 0, //! group affects horizontal size 0050 KIS_SIZE_GROUP_VERTICAL = 1 << 1, //! group affects vertical size 0051 KIS_SIZE_GROUP_BOTH = (KIS_SIZE_GROUP_HORIZONTAL | KIS_SIZE_GROUP_VERTICAL)//! group affects horizontal and vertical size 0052 }; 0053 0054 /** 0055 * Creates a new size group. 0056 * 0057 * By default, the mode of the size group is KIS_SIZE_GROUP_HORIZONTAL and 0058 * the group will not ignore hidden widgets. 0059 */ 0060 explicit KisSizeGroup(QObject* parent = 0, 0061 KisSizeGroup::mode mode = KisSizeGroup::KIS_SIZE_GROUP_HORIZONTAL, 0062 bool ignoreHidden = false); 0063 0064 ~KisSizeGroup() override; 0065 0066 /// Changes the group size mode. 0067 void setMode(KisSizeGroup::mode mode); 0068 0069 /// Returns the current mode of the group size. 0070 KisSizeGroup::mode getMode() const; 0071 0072 /// Sets whether the group will ignore not visible widgets 0073 void setIgnoreHidden(bool ignoreHidden); 0074 0075 /// Returns whether the group ignores not visible widgets 0076 bool isIgnoreHidden() const; 0077 0078 /// Adds a new widget to the group. 0079 /// WARNING: adding the same widget to multiple size groups is not supported! 0080 void addWidget(QWidget *widget); 0081 0082 /// Removes a widget from the size group. 0083 void removeWidget(QWidget *widget); 0084 0085 private: 0086 KisSizeGroupPrivate* const d; 0087 }; 0088 0089 #endif // KISSIZEGROUP_H