1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.widgets.layoutitem; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.namespace; 19 import qt.core.rect; 20 import qt.core.size; 21 import qt.helpers; 22 import qt.widgets.layout; 23 import qt.widgets.sizepolicy; 24 import qt.widgets.widget; 25 26 /+ Q_DECL_UNUSED +/ extern(D) static __gshared const(int) QLAYOUTSIZE_MAX = int.max/256/16; 27 28 /+ class QLayout; 29 class QLayoutItem; 30 class QSpacerItem; 31 class QWidget; 32 class QSize; +/ 33 34 interface QLayoutItemInterface 35 { 36 // ~this(); 37 /+ virtual +/ QSize sizeHint() const; 38 /+ virtual +/ QSize minimumSize() const; 39 /+ virtual +/ QSize maximumSize() const; 40 /+ virtual +/ /+ Qt::Orientations +/abstract qt.core.namespace.Orientations expandingDirections() const; 41 /+ virtual +/ void setGeometry(ref const(QRect) ); 42 /+ virtual +/ QRect geometry() const; 43 /+ virtual +/ bool isEmpty() const; 44 /+ virtual +/ bool hasHeightForWidth() const; 45 /+ virtual +/ int heightForWidth(int) const; 46 /+ virtual +/ int minimumHeightForWidth(int) const; 47 /+ virtual +/ void invalidate(); 48 /+ virtual +/ QWidget widget(); 49 /+ virtual +/ QLayout layout(); 50 /+ virtual +/ QSpacerItem spacerItem(); 51 /+ virtual +/ /+ QSizePolicy::ControlTypes +/QSizePolicy.ControlTypes controlTypes() const; 52 } 53 54 class /+ Q_WIDGETS_EXPORT +/ QLayoutItem 55 { 56 public: 57 /+ explicit +/pragma(inline, true) this(/+ Qt:: +/qt.core.namespace.Alignment aalignment = /+ Qt:: +/qt.core.namespace.Alignment()) 58 { 59 this.align_ = aalignment; 60 } 61 /+ virtual +/~this(); 62 /+ virtual +/ abstract QSize sizeHint() const; 63 /+ virtual +/ abstract QSize minimumSize() const; 64 /+ virtual +/ abstract QSize maximumSize() const; 65 /+ virtual +/ abstract /+ Qt:: +/qt.core.namespace.Orientations expandingDirections() const; 66 /+ virtual +/ abstract void setGeometry(ref const(QRect)); 67 /+ virtual +/ abstract QRect geometry() const; 68 /+ virtual +/ abstract bool isEmpty() const; 69 /+ virtual +/ bool hasHeightForWidth() const; 70 /+ virtual +/ int heightForWidth(int) const; 71 /+ virtual +/ int minimumHeightForWidth(int) const; 72 /+ virtual +/ void invalidate(); 73 74 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/ 75 /+ virtual +/ QWidget widget(); 76 /+ #else 77 virtual QWidget *widget() const; 78 #endif +/ 79 /+ virtual +/ QLayout layout(); 80 /+ virtual +/ QSpacerItem spacerItem(); 81 82 final /+ Qt:: +/qt.core.namespace.Alignment alignment() const { return align_; } 83 final void setAlignment(/+ Qt:: +/qt.core.namespace.Alignment a); 84 /+ virtual +/ QSizePolicy.ControlTypes controlTypes() const; 85 86 protected: 87 /+ Qt:: +/qt.core.namespace.Alignment align_; 88 } 89 90 class /+ Q_WIDGETS_EXPORT +/ QSpacerItem : QLayoutItem 91 { 92 public: 93 this(int w, int h, 94 QSizePolicy.Policy hData = QSizePolicy.Policy.Minimum, 95 QSizePolicy.Policy vData = QSizePolicy.Policy.Minimum) 96 { 97 this.width = w; 98 this.height = h; 99 this.sizeP = typeof(this.sizeP)(hData, vData); 100 } 101 ~this(); 102 103 final void changeSize(int w, int h, 104 QSizePolicy.Policy hData = QSizePolicy.Policy.Minimum, 105 QSizePolicy.Policy vData = QSizePolicy.Policy.Minimum); 106 override QSize sizeHint() const; 107 override QSize minimumSize() const; 108 override QSize maximumSize() const; 109 override /+ Qt:: +/qt.core.namespace.Orientations expandingDirections() const; 110 override bool isEmpty() const; 111 override void setGeometry(ref const(QRect)); 112 override QRect geometry() const; 113 override QSpacerItem spacerItem(); 114 final QSizePolicy sizePolicy() const { return sizeP; } 115 116 private: 117 int width; 118 int height; 119 QSizePolicy sizeP; 120 QRect rect; 121 } 122 123 class /+ Q_WIDGETS_EXPORT +/ QWidgetItem : QLayoutItem 124 { 125 private: 126 /+ Q_DISABLE_COPY(QWidgetItem) +/ 127 128 public: 129 /+ explicit +/this(QWidget w) 130 { 131 this.wid = w; 132 } 133 ~this(); 134 135 override QSize sizeHint() const; 136 override QSize minimumSize() const; 137 override QSize maximumSize() const; 138 override /+ Qt:: +/qt.core.namespace.Orientations expandingDirections() const; 139 override bool isEmpty() const; 140 override void setGeometry(ref const(QRect)); 141 override QRect geometry() const; 142 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/ 143 override QWidget widget(); 144 /+ #else 145 QWidget *widget() const override; 146 #endif +/ 147 148 override bool hasHeightForWidth() const; 149 override int heightForWidth(int) const; 150 override QSizePolicy.ControlTypes controlTypes() const; 151 protected: 152 QWidget wid; 153 } 154 155 class /+ Q_WIDGETS_EXPORT +/ QWidgetItemV2 : QWidgetItem 156 { 157 public: 158 /+ explicit +/this(QWidget widget); 159 ~this(); 160 161 override QSize sizeHint() const; 162 override QSize minimumSize() const; 163 override QSize maximumSize() const; 164 override int heightForWidth(int width) const; 165 166 private: 167 enum { Dirty = -123, HfwCacheMaxSize = 3 } 168 169 pragma(inline, true) final bool useSizeCache() const; 170 final void updateCacheIfNecessary() const; 171 pragma(inline, true) final void invalidateSizeCache() { 172 q_cachedMinimumSize.setWidth(Dirty); 173 q_hfwCacheSize = 0; 174 } 175 176 /+ mutable +/ QSize q_cachedMinimumSize; 177 /+ mutable +/ QSize q_cachedSizeHint; 178 /+ mutable +/ QSize q_cachedMaximumSize; 179 /+ mutable +/ QSize[HfwCacheMaxSize] q_cachedHfws; 180 /+ mutable +/ short q_firstCachedHfw; 181 /+ mutable +/ short q_hfwCacheSize; 182 void* d; 183 184 /+ friend class QWidgetPrivate; +/ 185 186 /+ Q_DISABLE_COPY(QWidgetItemV2) +/ 187 } 188 189 static assert(__traits(classInstanceSize, QLayoutItem) == (void*).sizeof + 4); 190 struct QLayoutItemFakeInheritance 191 { 192 void*[(__traits(classInstanceSize, QLayoutItem) + (void*).sizeof - 1) / (void*).sizeof - 1] data; 193 } 194