| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qformlayout.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | namespace { | - | ||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | template <class T, int NumColumns> | - | ||||||||||||
| 8 | class FixedColumnMatrix { | - | ||||||||||||
| 9 | public: | - | ||||||||||||
| 10 | typedef QVector<T> Storage; | - | ||||||||||||
| 11 | - | |||||||||||||
| 12 | FixedColumnMatrix() { } | - | ||||||||||||
| 13 | - | |||||||||||||
| 14 | void clear() { m_storage.clear(); } | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | const T &operator()(int r, int c) const { return m_storage[r * NumColumns + c]; } | - | ||||||||||||
| 17 | T &operator()(int r, int c) { return m_storage[r * NumColumns + c]; } | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | int rowCount() const { return m_storage.size() / NumColumns; } | - | ||||||||||||
| 20 | void addRow(const T &value); | - | ||||||||||||
| voidinsertRow(int r, const T &value); | ||||||||||||||
| void removeRow(int r); | ||||||||||||||
| bool find(const T &value, int *rowPtr, int *colPtr) const ; | ||||||||||||||
| int count(const T &value) const { return m_storage.count(value); | ||||||||||||||
| 21 | - | |||||||||||||
| 22 | - | |||||||||||||
| 23 | }const Storage &storage() const { return m_storage; } | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | static void storageIndexToPosition(int idx, int *rowPtr, int *colPtr); | - | ||||||||||||
| 26 | - | |||||||||||||
| 27 | private: | - | ||||||||||||
| 28 | Storage m_storage; | - | ||||||||||||
| 29 | }; | - | ||||||||||||
| 30 | - | |||||||||||||
| template <class T, int NumColumns> | ||||||||||||||
| void FixedColumnMatrix<T, NumColumns>::addRow(const T &value) | ||||||||||||||
| { | ||||||||||||||
| for (int i = 0; i < NumColumns; ++i) | ||||||||||||||
| m_storage.append(value); | ||||||||||||||
| }template <class T, int NumColumns> | ||||||||||||||
| 32 | void FixedColumnMatrix<T, NumColumns>::insertRow(int r, const T &value) | - | ||||||||||||
| 33 | { | - | ||||||||||||
| 34 | typename Storage::iterator it = m_storage.begin(); | - | ||||||||||||
| 35 | it += r * NumColumns; | - | ||||||||||||
| 36 | m_storage.insert(it, NumColumns, value); | - | ||||||||||||
| } | ||||||||||||||
| template <class T, int NumColumns> | ||||||||||||||
| void FixedColumnMatrix<T, NumColumns>::removeRow(int r) | ||||||||||||||
| { | ||||||||||||||
| m_storage.remove(r * NumColumns, NumColumns); | ||||||||||||||
| } | ||||||||||||||
| template <class T, int NumColumns> | ||||||||||||||
| bool FixedColumnMatrix<T, NumColumns>::find(const T &value, int *rowPtr, int *colPtr) const | ||||||||||||||
| { | ||||||||||||||
| const int idx = m_storage.indexOf(value); | ||||||||||||||
| if (idx == -1) | ||||||||||||||
| return false; | ||||||||||||||
| storageIndexToPosition(idx, rowPtr, colPtr); | ||||||||||||||
| return true;} | ||||||||||||||
| 38 | - | |||||||||||||
| 39 | template <class T, int NumColumns> | - | ||||||||||||
| 40 | void FixedColumnMatrix<T, NumColumns>::storageIndexToPosition(int idx, int *rowPtr, int *colPtr) | - | ||||||||||||
| 41 | { | - | ||||||||||||
| 42 | *rowPtr = idx / NumColumns; | - | ||||||||||||
| 43 | *colPtr = idx % NumColumns; | - | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | } | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | - | |||||||||||||
| 48 | - | |||||||||||||
| 49 | const uint DefaultFieldGrowthPolicy = 255; | - | ||||||||||||
| 50 | const uint DefaultRowWrapPolicy = 255; | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | enum { ColumnCount = 2 }; | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | - | |||||||||||||
| 55 | - | |||||||||||||
| 56 | struct QFormLayoutItem | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | QFormLayoutItem(QLayoutItem* i) : item(i), fullRow(false), isHfw(false) { } | - | ||||||||||||
| 59 | ~QFormLayoutItem() { delete item; } | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | - | |||||||||||||
| 62 | QWidget *widget() const { return item->widget(); } | - | ||||||||||||
| 63 | QLayout *layout() const { return item->layout(); } | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | bool hasHeightForWidth() const { return item->hasHeightForWidth(); } | - | ||||||||||||
| 66 | int heightForWidth(int width) const { return item->heightForWidth(width); } | - | ||||||||||||
| 67 | int minimumHeightForWidth(int width) const { return item->minimumHeightForWidth(width); } | - | ||||||||||||
| 68 | Qt::Orientations expandingDirections() const { return item->expandingDirections(); } | - | ||||||||||||
| 69 | QSizePolicy::ControlTypes controlTypes() const { return item->controlTypes(); } | - | ||||||||||||
| 70 | int vStretch() const { return widget() ? widget()->sizePolicy().verticalStretch() : 0; } | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | void setGeometry(const QRect& r) { item->setGeometry(r); } | - | ||||||||||||
| 73 | QRect geometry() const { return item->geometry(); } | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | - | |||||||||||||
| 76 | bool operator==(const QFormLayoutItem& other) { return item == other.item; } | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | QLayoutItem *item; | - | ||||||||||||
| 79 | bool fullRow; | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | - | |||||||||||||
| 82 | bool isHfw; | - | ||||||||||||
| 83 | QSize minSize; | - | ||||||||||||
| 84 | QSize sizeHint; | - | ||||||||||||
| 85 | QSize maxSize; | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | - | |||||||||||||
| 88 | int sbsHSpace; | - | ||||||||||||
| 89 | int vSpace; | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | - | |||||||||||||
| 92 | bool sideBySide; | - | ||||||||||||
| 93 | int vLayoutIndex; | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | - | |||||||||||||
| 96 | int layoutPos; | - | ||||||||||||
| 97 | int layoutWidth; | - | ||||||||||||
| 98 | }; | - | ||||||||||||
| 99 | - | |||||||||||||
| 100 | class QFormLayoutPrivate : public QLayoutPrivate | - | ||||||||||||
| 101 | { | - | ||||||||||||
| 102 | inline QFormLayout* q_func() { return static_cast<QFormLayout *>(q_ptr); } inline const QFormLayout* q_func() const { return static_cast<const QFormLayout *>(q_ptr); } friend class QFormLayout; | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | public: | - | ||||||||||||
| 105 | typedef FixedColumnMatrix<QFormLayoutItem *, ColumnCount> ItemMatrix; | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | QFormLayoutPrivate(); | - | ||||||||||||
| 108 | ~QFormLayoutPrivate() { } | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | int insertRow(int row); | - | ||||||||||||
| 111 | void insertRows(int row, int count); | - | ||||||||||||
| 112 | bool setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item); | - | ||||||||||||
| 113 | void setLayout(int row, QFormLayout::ItemRole role, QLayout *layout); | - | ||||||||||||
| 114 | void setWidget(int row, QFormLayout::ItemRole role, QWidget *widget); | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | void arrangeWidgets(const QVector<QLayoutStruct>& layouts, QRect &rect); | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | void updateSizes(); | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | void setupVerticalLayoutData(int width); | - | ||||||||||||
| 121 | void setupHorizontalLayoutData(int width); | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | QStyle* getStyle() const; | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | inline bool haveHfwCached(int width) const | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | return (hfw_width == width) || (width == sh_width && hfw_sh_height >= 0); | - | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | void recalcHFW(int w); | - | ||||||||||||
| 131 | void setupHfwLayoutData(); | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | uint fieldGrowthPolicy : 8; | - | ||||||||||||
| 134 | uint rowWrapPolicy : 8; | - | ||||||||||||
| 135 | uint has_hfw : 2; | - | ||||||||||||
| 136 | uint dirty : 2; | - | ||||||||||||
| 137 | uint sizesDirty : 2; | - | ||||||||||||
| 138 | uint expandVertical : 1; | - | ||||||||||||
| 139 | uint expandHorizontal : 1; | - | ||||||||||||
| 140 | Qt::Alignment labelAlignment; | - | ||||||||||||
| 141 | Qt::Alignment formAlignment; | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | ItemMatrix m_matrix; | - | ||||||||||||
| 144 | QList<QFormLayoutItem *> m_things; | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | int layoutWidth; | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | int hfw_width; | - | ||||||||||||
| 149 | int hfw_height; | - | ||||||||||||
| 150 | int hfw_minheight; | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | int hfw_sh_height; | - | ||||||||||||
| 153 | int hfw_sh_minheight; | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | int min_width; | - | ||||||||||||
| 156 | int sh_width; | - | ||||||||||||
| 157 | int thresh_width; | - | ||||||||||||
| 158 | QSize minSize; | - | ||||||||||||
| 159 | QSize prefSize; | - | ||||||||||||
| 160 | int formMaxWidth; | - | ||||||||||||
| 161 | void calcSizeHints(); | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | QVector<QLayoutStruct> vLayouts; | - | ||||||||||||
| 164 | int vLayoutCount; | - | ||||||||||||
| 165 | int maxLabelWidth; | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | QVector<QLayoutStruct> hfwLayouts; | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | int hSpacing; | - | ||||||||||||
| 170 | int vSpacing; | - | ||||||||||||
| 171 | QLayoutItem* replaceAt(int index, QLayoutItem*) override; | - | ||||||||||||
| 172 | }; | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | QFormLayoutPrivate::QFormLayoutPrivate() | - | ||||||||||||
| 175 | : fieldGrowthPolicy(DefaultFieldGrowthPolicy), | - | ||||||||||||
| 176 | rowWrapPolicy(DefaultRowWrapPolicy), has_hfw(false), dirty(true), sizesDirty(true), | - | ||||||||||||
| 177 | expandVertical(0), expandHorizontal(0), labelAlignment(0), formAlignment(0), | - | ||||||||||||
| 178 | layoutWidth(-1), hfw_width(-1), hfw_sh_height(-1), min_width(-1), | - | ||||||||||||
| 179 | sh_width(-1), thresh_width(QLAYOUTSIZE_MAX), hSpacing(-1), vSpacing(-1) | - | ||||||||||||
| 180 | { | - | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | static Qt::Alignment fixedAlignment(Qt::Alignment alignment, Qt::LayoutDirection layoutDirection) | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | if (layoutDirection == Qt::RightToLeft && alignment & Qt::AlignAbsolute) { | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute)) | - | ||||||||||||
| 188 | | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0) | - | ||||||||||||
| 189 | | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0)); | - | ||||||||||||
| 190 | } else { | - | ||||||||||||
| 191 | return alignment & ~Qt::AlignAbsolute; | - | ||||||||||||
| 192 | } | - | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | static int storageIndexFromLayoutItem(const QFormLayoutPrivate::ItemMatrix &m, | - | ||||||||||||
| 196 | QFormLayoutItem *item) | - | ||||||||||||
| 197 | { | - | ||||||||||||
| 198 | if (item) { | - | ||||||||||||
| 199 | return m.storage().indexOf(item); | - | ||||||||||||
| 200 | } else { | - | ||||||||||||
| 201 | return -1; | - | ||||||||||||
| 202 | } | - | ||||||||||||
| 203 | } | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | static void updateFormLayoutItem(QFormLayoutItem *item, int userVSpacing, | - | ||||||||||||
| 206 | QFormLayout::FieldGrowthPolicy fieldGrowthPolicy, | - | ||||||||||||
| 207 | bool fullRow) | - | ||||||||||||
| 208 | { | - | ||||||||||||
| 209 | item->minSize = item->item->minimumSize(); | - | ||||||||||||
| 210 | item->sizeHint = item->item->sizeHint(); | - | ||||||||||||
| 211 | item->maxSize = item->item->maximumSize(); | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | if (!fullRow && (fieldGrowthPolicy == QFormLayout::FieldsStayAtSizeHint | - | ||||||||||||
| 214 | || (fieldGrowthPolicy == QFormLayout::ExpandingFieldsGrow | - | ||||||||||||
| 215 | && !(item->item->expandingDirections() & Qt::Horizontal)))) | - | ||||||||||||
| 216 | item->maxSize.setWidth(item->sizeHint.width()); | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 | item->isHfw = item->item->hasHeightForWidth(); | - | ||||||||||||
| 219 | item->vSpace = userVSpacing; | - | ||||||||||||
| 220 | } | - | ||||||||||||
| 221 | - | |||||||||||||
| 222 | - | |||||||||||||
| 223 | - | |||||||||||||
| 224 | - | |||||||||||||
| 225 | - | |||||||||||||
| 226 | - | |||||||||||||
| 227 | - | |||||||||||||
| 228 | void QFormLayoutPrivate::updateSizes() | - | ||||||||||||
| 229 | { | - | ||||||||||||
| 230 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 231 | - | |||||||||||||
| 232 | if (sizesDirty) { | - | ||||||||||||
| 233 | QFormLayout::RowWrapPolicy wrapPolicy = q->rowWrapPolicy(); | - | ||||||||||||
| 234 | bool wrapAllRows = (wrapPolicy == QFormLayout::WrapAllRows); | - | ||||||||||||
| 235 | bool dontWrapRows = (wrapPolicy == QFormLayout::DontWrapRows); | - | ||||||||||||
| 236 | int rr = m_matrix.rowCount(); | - | ||||||||||||
| 237 | - | |||||||||||||
| 238 | has_hfw = false; | - | ||||||||||||
| 239 | - | |||||||||||||
| 240 | - | |||||||||||||
| 241 | - | |||||||||||||
| 242 | bool expandH = false; | - | ||||||||||||
| 243 | bool expandV = false; | - | ||||||||||||
| 244 | - | |||||||||||||
| 245 | QFormLayoutItem *prevLbl = 0; | - | ||||||||||||
| 246 | QFormLayoutItem *prevFld = 0; | - | ||||||||||||
| 247 | - | |||||||||||||
| 248 | QWidget *parent = q->parentWidget(); | - | ||||||||||||
| 249 | QStyle *style = parent ? parent->style() : 0; | - | ||||||||||||
| 250 | - | |||||||||||||
| 251 | int userVSpacing = q->verticalSpacing(); | - | ||||||||||||
| 252 | int userHSpacing = wrapAllRows ? 0 : q->horizontalSpacing(); | - | ||||||||||||
| 253 | - | |||||||||||||
| 254 | int maxMinLblWidth = 0; | - | ||||||||||||
| 255 | int maxMinFldWidth = 0; | - | ||||||||||||
| 256 | int maxMinIfldWidth = 0; | - | ||||||||||||
| 257 | - | |||||||||||||
| 258 | int maxShLblWidth = 0; | - | ||||||||||||
| 259 | int maxShFldWidth = 0; | - | ||||||||||||
| 260 | int maxShIfldWidth = 0; | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | for (int i = 0; i < rr; ++i) { | - | ||||||||||||
| 263 | QFormLayoutItem *label = m_matrix(i, 0); | - | ||||||||||||
| 264 | QFormLayoutItem *field = m_matrix(i, 1); | - | ||||||||||||
| 265 | - | |||||||||||||
| 266 | - | |||||||||||||
| 267 | if (!label && !field) | - | ||||||||||||
| 268 | continue; | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | if (label) { | - | ||||||||||||
| 271 | updateFormLayoutItem(label, userVSpacing, q->fieldGrowthPolicy(), false); | - | ||||||||||||
| 272 | if (label->isHfw) | - | ||||||||||||
| 273 | has_hfw = true; | - | ||||||||||||
| 274 | Qt::Orientations o = label->expandingDirections(); | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | if (o & Qt::Vertical) | - | ||||||||||||
| 277 | expandV = true; | - | ||||||||||||
| 278 | if (o & Qt::Horizontal) | - | ||||||||||||
| 279 | expandH = true; | - | ||||||||||||
| 280 | } | - | ||||||||||||
| 281 | if (field) { | - | ||||||||||||
| 282 | updateFormLayoutItem(field, userVSpacing, q->fieldGrowthPolicy(), !label && field->fullRow); | - | ||||||||||||
| 283 | field->sbsHSpace = (!label && field->fullRow) ? 0 : userHSpacing; | - | ||||||||||||
| 284 | if (field->isHfw) | - | ||||||||||||
| 285 | has_hfw = true; | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | Qt::Orientations o = field->expandingDirections(); | - | ||||||||||||
| 288 | - | |||||||||||||
| 289 | if (o & Qt::Vertical) | - | ||||||||||||
| 290 | expandV = true; | - | ||||||||||||
| 291 | if (o & Qt::Horizontal) | - | ||||||||||||
| 292 | expandH = true; | - | ||||||||||||
| 293 | } | - | ||||||||||||
| 294 | - | |||||||||||||
| 295 | - | |||||||||||||
| 296 | if ((userHSpacing < 0 || userVSpacing < 0) && style) { | - | ||||||||||||
| 297 | QSizePolicy::ControlTypes lbltypes = | - | ||||||||||||
| 298 | QSizePolicy::ControlTypes(label ? label->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 299 | QSizePolicy::ControlTypes fldtypes = | - | ||||||||||||
| 300 | QSizePolicy::ControlTypes(field ? field->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 301 | - | |||||||||||||
| 302 | - | |||||||||||||
| 303 | if (userVSpacing < 0) { | - | ||||||||||||
| 304 | if (wrapAllRows) { | - | ||||||||||||
| 305 | - | |||||||||||||
| 306 | QFormLayoutItem *lbltop = prevFld ? prevFld : prevLbl; | - | ||||||||||||
| 307 | - | |||||||||||||
| 308 | QFormLayoutItem *fldtop = label ? label : lbltop; | - | ||||||||||||
| 309 | QSizePolicy::ControlTypes lbltoptypes = | - | ||||||||||||
| 310 | QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 311 | QSizePolicy::ControlTypes fldtoptypes = | - | ||||||||||||
| 312 | QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 313 | if (label && lbltop) | - | ||||||||||||
| 314 | label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 315 | if (field && fldtop) | - | ||||||||||||
| 316 | field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 317 | } else { | - | ||||||||||||
| 318 | - | |||||||||||||
| 319 | - | |||||||||||||
| 320 | QFormLayoutItem *lbltop = prevLbl ? prevLbl : prevFld; | - | ||||||||||||
| 321 | QFormLayoutItem *fldtop = prevFld; | - | ||||||||||||
| 322 | QSizePolicy::ControlTypes lbltoptypes = | - | ||||||||||||
| 323 | QSizePolicy::ControlTypes(lbltop ? lbltop->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 324 | QSizePolicy::ControlTypes fldtoptypes = | - | ||||||||||||
| 325 | QSizePolicy::ControlTypes(fldtop ? fldtop->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 326 | - | |||||||||||||
| 327 | - | |||||||||||||
| 328 | if (label) { | - | ||||||||||||
| 329 | if (!field) { | - | ||||||||||||
| 330 | int lblspacing = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 331 | int fldspacing = style->combinedLayoutSpacing(fldtoptypes, lbltypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 332 | label->vSpace = qMax(lblspacing, fldspacing); | - | ||||||||||||
| 333 | } else | - | ||||||||||||
| 334 | label->vSpace = style->combinedLayoutSpacing(lbltoptypes, lbltypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 335 | } | - | ||||||||||||
| 336 | - | |||||||||||||
| 337 | if (field) { | - | ||||||||||||
| 338 | - | |||||||||||||
| 339 | if (!label) { | - | ||||||||||||
| 340 | int lblspacing = style->combinedLayoutSpacing(lbltoptypes, fldtypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 341 | int fldspacing = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 342 | field->vSpace = qMax(lblspacing, fldspacing); | - | ||||||||||||
| 343 | } else | - | ||||||||||||
| 344 | field->vSpace = style->combinedLayoutSpacing(fldtoptypes, fldtypes, Qt::Vertical, 0, parent); | - | ||||||||||||
| 345 | } | - | ||||||||||||
| 346 | } | - | ||||||||||||
| 347 | } | - | ||||||||||||
| 348 | - | |||||||||||||
| 349 | - | |||||||||||||
| 350 | - | |||||||||||||
| 351 | - | |||||||||||||
| 352 | if (userHSpacing < 0 && !wrapAllRows && (label || !field->fullRow) && field) | - | ||||||||||||
| 353 | field->sbsHSpace = style->combinedLayoutSpacing(QSizePolicy::Label, QSizePolicy::LineEdit, Qt::Horizontal, 0, parent); | - | ||||||||||||
| 354 | } | - | ||||||||||||
| 355 | if (label) { | - | ||||||||||||
| 356 | maxMinLblWidth = qMax(maxMinLblWidth, label->minSize.width()); | - | ||||||||||||
| 357 | maxShLblWidth = qMax(maxShLblWidth, label->sizeHint.width()); | - | ||||||||||||
| 358 | if (field) { | - | ||||||||||||
| 359 | maxMinFldWidth = qMax(maxMinFldWidth, field->minSize.width() + field->sbsHSpace); | - | ||||||||||||
| 360 | maxShFldWidth = qMax(maxShFldWidth, field->sizeHint.width() + field->sbsHSpace); | - | ||||||||||||
| 361 | } | - | ||||||||||||
| 362 | } else if (field) { | - | ||||||||||||
| 363 | maxMinIfldWidth = qMax(maxMinIfldWidth, field->minSize.width()); | - | ||||||||||||
| 364 | maxShIfldWidth = qMax(maxShIfldWidth, field->sizeHint.width()); | - | ||||||||||||
| 365 | } | - | ||||||||||||
| 366 | - | |||||||||||||
| 367 | prevLbl = label; | - | ||||||||||||
| 368 | prevFld = field; | - | ||||||||||||
| 369 | } | - | ||||||||||||
| 370 | - | |||||||||||||
| 371 | - | |||||||||||||
| 372 | if (wrapAllRows) { | - | ||||||||||||
| 373 | sh_width = qMax(maxShLblWidth, qMax(maxShIfldWidth, maxShFldWidth)); | - | ||||||||||||
| 374 | min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth)); | - | ||||||||||||
| 375 | - | |||||||||||||
| 376 | thresh_width = 0; | - | ||||||||||||
| 377 | } else if (dontWrapRows) { | - | ||||||||||||
| 378 | - | |||||||||||||
| 379 | sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth); | - | ||||||||||||
| 380 | min_width = qMax(maxMinLblWidth + maxMinFldWidth, maxMinIfldWidth); | - | ||||||||||||
| 381 | thresh_width = ((1<<24)-1); | - | ||||||||||||
| 382 | } else { | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | sh_width = qMax(maxShLblWidth + maxShFldWidth, maxShIfldWidth); | - | ||||||||||||
| 385 | - | |||||||||||||
| 386 | - | |||||||||||||
| 387 | min_width = qMax(maxMinLblWidth, qMax(maxMinIfldWidth, maxMinFldWidth)); | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | thresh_width = maxShLblWidth + maxMinFldWidth; | - | ||||||||||||
| 390 | } | - | ||||||||||||
| 391 | - | |||||||||||||
| 392 | - | |||||||||||||
| 393 | expandVertical = expandV; | - | ||||||||||||
| 394 | expandHorizontal = expandH; | - | ||||||||||||
| 395 | } | - | ||||||||||||
| 396 | sizesDirty = false; | - | ||||||||||||
| 397 | } | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | void QFormLayoutPrivate::recalcHFW(int w) | - | ||||||||||||
| 400 | { | - | ||||||||||||
| 401 | setupHfwLayoutData(); | - | ||||||||||||
| 402 | - | |||||||||||||
| 403 | int h = 0; | - | ||||||||||||
| 404 | int mh = 0; | - | ||||||||||||
| 405 | - | |||||||||||||
| 406 | for (int r = 0; r < vLayoutCount; ++r) { | - | ||||||||||||
| 407 | int spacing = hfwLayouts.at(r).spacing; | - | ||||||||||||
| 408 | h += hfwLayouts.at(r).sizeHint + spacing; | - | ||||||||||||
| 409 | mh += hfwLayouts.at(r).minimumSize + spacing; | - | ||||||||||||
| 410 | } | - | ||||||||||||
| 411 | - | |||||||||||||
| 412 | if (sh_width > 0 && sh_width == w) { | - | ||||||||||||
| 413 | hfw_sh_height = qMin(QLAYOUTSIZE_MAX, h); | - | ||||||||||||
| 414 | hfw_sh_minheight = qMin(QLAYOUTSIZE_MAX, mh); | - | ||||||||||||
| 415 | } else { | - | ||||||||||||
| 416 | hfw_width = w; | - | ||||||||||||
| 417 | hfw_height = qMin(QLAYOUTSIZE_MAX, h); | - | ||||||||||||
| 418 | hfw_minheight = qMin(QLAYOUTSIZE_MAX, mh); | - | ||||||||||||
| 419 | } | - | ||||||||||||
| 420 | } | - | ||||||||||||
| 421 | - | |||||||||||||
| 422 | void QFormLayoutPrivate::setupHfwLayoutData() | - | ||||||||||||
| 423 | { | - | ||||||||||||
| 424 | int i; | - | ||||||||||||
| 425 | int rr = m_matrix.rowCount(); | - | ||||||||||||
| 426 | - | |||||||||||||
| 427 | hfwLayouts.clear(); | - | ||||||||||||
| 428 | hfwLayouts.resize(vLayoutCount); | - | ||||||||||||
| 429 | for (i = 0; i < vLayoutCount; ++i) | - | ||||||||||||
| 430 | hfwLayouts[i] = vLayouts.at(i); | - | ||||||||||||
| 431 | - | |||||||||||||
| 432 | for (i = 0; i < rr; ++i) { | - | ||||||||||||
| 433 | QFormLayoutItem *label = m_matrix(i, 0); | - | ||||||||||||
| 434 | QFormLayoutItem *field = m_matrix(i, 1); | - | ||||||||||||
| 435 | - | |||||||||||||
| 436 | if (label) { | - | ||||||||||||
| 437 | if (label->isHfw) { | - | ||||||||||||
| 438 | - | |||||||||||||
| 439 | - | |||||||||||||
| 440 | int hfw = label->heightForWidth(label->layoutWidth); | - | ||||||||||||
| 441 | hfwLayouts[label->vLayoutIndex].minimumSize = hfw; | - | ||||||||||||
| 442 | hfwLayouts[label->vLayoutIndex].sizeHint = hfw; | - | ||||||||||||
| 443 | } else { | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | - | |||||||||||||
| 446 | hfwLayouts[label->vLayoutIndex].sizeHint = label->sizeHint.height(); | - | ||||||||||||
| 447 | hfwLayouts[label->vLayoutIndex].minimumSize = label->minSize.height(); | - | ||||||||||||
| 448 | } | - | ||||||||||||
| 449 | } | - | ||||||||||||
| 450 | - | |||||||||||||
| 451 | if (field) { | - | ||||||||||||
| 452 | int hfw = field->isHfw ? field->heightForWidth(field->layoutWidth) : 0; | - | ||||||||||||
| 453 | int h = field->isHfw ? hfw : field->sizeHint.height(); | - | ||||||||||||
| 454 | int mh = field->isHfw ? hfw : field->minSize.height(); | - | ||||||||||||
| 455 | - | |||||||||||||
| 456 | if (field->sideBySide) { | - | ||||||||||||
| 457 | int oh = hfwLayouts.at(field->vLayoutIndex).sizeHint; | - | ||||||||||||
| 458 | int omh = hfwLayouts.at(field->vLayoutIndex).minimumSize; | - | ||||||||||||
| 459 | - | |||||||||||||
| 460 | hfwLayouts[field->vLayoutIndex].sizeHint = qMax(h, oh); | - | ||||||||||||
| 461 | hfwLayouts[field->vLayoutIndex].minimumSize = qMax(mh, omh); | - | ||||||||||||
| 462 | } else { | - | ||||||||||||
| 463 | hfwLayouts[field->vLayoutIndex].sizeHint = h; | - | ||||||||||||
| 464 | hfwLayouts[field->vLayoutIndex].minimumSize = mh; | - | ||||||||||||
| 465 | } | - | ||||||||||||
| 466 | } | - | ||||||||||||
| 467 | } | - | ||||||||||||
| 468 | } | - | ||||||||||||
| 469 | static inline int spacingHelper(QWidget* parent, QStyle *style, int userVSpacing, bool recalculate, QFormLayoutItem* item1, QFormLayoutItem* item2, QFormLayoutItem* prevItem1, QFormLayoutItem *prevItem2) | - | ||||||||||||
| 470 | { | - | ||||||||||||
| 471 | int spacing = userVSpacing; | - | ||||||||||||
| 472 | if (spacing < 0) { | - | ||||||||||||
| 473 | if (!recalculate) { | - | ||||||||||||
| 474 | if (item1) | - | ||||||||||||
| 475 | spacing = item1->vSpace; | - | ||||||||||||
| 476 | if (item2) | - | ||||||||||||
| 477 | spacing = qMax(spacing, item2->vSpace); | - | ||||||||||||
| 478 | } else { | - | ||||||||||||
| 479 | if (style && prevItem1) { | - | ||||||||||||
| 480 | QSizePolicy::ControlTypes itemtypes = | - | ||||||||||||
| 481 | QSizePolicy::ControlTypes(item1 ? item1->controlTypes() : QSizePolicy::DefaultType); | - | ||||||||||||
| 482 | int spacing2 = 0; | - | ||||||||||||
| 483 | - | |||||||||||||
| 484 | spacing = style->combinedLayoutSpacing(itemtypes, prevItem1->controlTypes(), Qt::Vertical, 0, parent); | - | ||||||||||||
| 485 | - | |||||||||||||
| 486 | - | |||||||||||||
| 487 | if (item2) | - | ||||||||||||
| 488 | spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, 0, parent); | - | ||||||||||||
| 489 | else if (prevItem2) | - | ||||||||||||
| 490 | spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, 0, parent); | - | ||||||||||||
| 491 | - | |||||||||||||
| 492 | spacing = qMax(spacing, spacing2); | - | ||||||||||||
| 493 | } | - | ||||||||||||
| 494 | } | - | ||||||||||||
| 495 | } else { | - | ||||||||||||
| 496 | if (prevItem1) { | - | ||||||||||||
| 497 | QWidget *wid = prevItem1->item->widget(); | - | ||||||||||||
| 498 | if (wid) | - | ||||||||||||
| 499 | spacing = qMax(spacing, prevItem1->geometry().top() - wid->geometry().top() ); | - | ||||||||||||
| 500 | } | - | ||||||||||||
| 501 | if (prevItem2) { | - | ||||||||||||
| 502 | QWidget *wid = prevItem2->item->widget(); | - | ||||||||||||
| 503 | if (wid) | - | ||||||||||||
| 504 | spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() ); | - | ||||||||||||
| 505 | } | - | ||||||||||||
| 506 | } | - | ||||||||||||
| 507 | return qMax(spacing, 0); | - | ||||||||||||
| 508 | } | - | ||||||||||||
| 509 | - | |||||||||||||
| 510 | static inline void initLayoutStruct(QLayoutStruct& sl, QFormLayoutItem* item) | - | ||||||||||||
| 511 | { | - | ||||||||||||
| 512 | sl.init(item->vStretch(), item->minSize.height()); | - | ||||||||||||
| 513 | sl.sizeHint = item->sizeHint.height(); | - | ||||||||||||
| 514 | sl.maximumSize = item->maxSize.height(); | - | ||||||||||||
| 515 | sl.expansive = (item->expandingDirections() & Qt::Vertical); | - | ||||||||||||
| 516 | sl.empty = false; | - | ||||||||||||
| 517 | } | - | ||||||||||||
| 518 | - | |||||||||||||
| 519 | void QFormLayoutPrivate::setupVerticalLayoutData(int width) | - | ||||||||||||
| 520 | { | - | ||||||||||||
| 521 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 522 | - | |||||||||||||
| 523 | - | |||||||||||||
| 524 | if ((width == layoutWidth || (width >= thresh_width && layoutWidth >= thresh_width)) && !dirty && !sizesDirty) | - | ||||||||||||
| 525 | return; | - | ||||||||||||
| 526 | - | |||||||||||||
| 527 | layoutWidth = width; | - | ||||||||||||
| 528 | - | |||||||||||||
| 529 | int rr = m_matrix.rowCount(); | - | ||||||||||||
| 530 | int vidx = 1; | - | ||||||||||||
| 531 | QFormLayout::RowWrapPolicy rowWrapPolicy = q->rowWrapPolicy(); | - | ||||||||||||
| 532 | bool wrapAllRows = (rowWrapPolicy == QFormLayout::WrapAllRows); | - | ||||||||||||
| 533 | bool addTopBottomStretch = true; | - | ||||||||||||
| 534 | - | |||||||||||||
| 535 | vLayouts.clear(); | - | ||||||||||||
| 536 | vLayouts.resize((2 * rr) + 2); | - | ||||||||||||
| 537 | - | |||||||||||||
| 538 | QStyle *style = 0; | - | ||||||||||||
| 539 | - | |||||||||||||
| 540 | int userVSpacing = q->verticalSpacing(); | - | ||||||||||||
| 541 | - | |||||||||||||
| 542 | if (userVSpacing < 0) { | - | ||||||||||||
| 543 | if (QWidget *widget = q->parentWidget()) | - | ||||||||||||
| 544 | style = widget->style(); | - | ||||||||||||
| 545 | } | - | ||||||||||||
| 546 | - | |||||||||||||
| 547 | - | |||||||||||||
| 548 | updateSizes(); | - | ||||||||||||
| 549 | - | |||||||||||||
| 550 | - | |||||||||||||
| 551 | - | |||||||||||||
| 552 | - | |||||||||||||
| 553 | - | |||||||||||||
| 554 | maxLabelWidth = 0; | - | ||||||||||||
| 555 | if (!wrapAllRows) { | - | ||||||||||||
| 556 | for (int i = 0; i < rr; ++i) { | - | ||||||||||||
| 557 | const QFormLayoutItem *label = m_matrix(i, 0); | - | ||||||||||||
| 558 | const QFormLayoutItem *field = m_matrix(i, 1); | - | ||||||||||||
| 559 | if (label && (label->sizeHint.width() + (field ? field->minSize.width() : 0) <= width)) | - | ||||||||||||
| 560 | maxLabelWidth = qMax(maxLabelWidth, label->sizeHint.width()); | - | ||||||||||||
| 561 | } | - | ||||||||||||
| 562 | } else { | - | ||||||||||||
| 563 | maxLabelWidth = width; | - | ||||||||||||
| 564 | } | - | ||||||||||||
| 565 | - | |||||||||||||
| 566 | QFormLayoutItem *prevItem1 = 0; | - | ||||||||||||
| 567 | QFormLayoutItem *prevItem2 = 0; | - | ||||||||||||
| 568 | bool prevRowSplit = false; | - | ||||||||||||
| 569 | - | |||||||||||||
| 570 | for (int i = 0; i < rr; ++i) { | - | ||||||||||||
| 571 | QFormLayoutItem *label = m_matrix(i, 0); | - | ||||||||||||
| 572 | QFormLayoutItem *field = m_matrix(i, 1); | - | ||||||||||||
| 573 | - | |||||||||||||
| 574 | - | |||||||||||||
| 575 | if (!label && !field) | - | ||||||||||||
| 576 | continue; | - | ||||||||||||
| 577 | - | |||||||||||||
| 578 | QSize min1; | - | ||||||||||||
| 579 | QSize min2; | - | ||||||||||||
| 580 | QSize sh1; | - | ||||||||||||
| 581 | QSize sh2; | - | ||||||||||||
| 582 | if (label) { | - | ||||||||||||
| 583 | min1 = label->minSize; | - | ||||||||||||
| 584 | sh1 = label->sizeHint; | - | ||||||||||||
| 585 | } | - | ||||||||||||
| 586 | if (field) { | - | ||||||||||||
| 587 | min2 = field->minSize; | - | ||||||||||||
| 588 | sh2 = field->sizeHint; | - | ||||||||||||
| 589 | } | - | ||||||||||||
| 590 | - | |||||||||||||
| 591 | - | |||||||||||||
| 592 | - | |||||||||||||
| 593 | bool splitSideBySide = (rowWrapPolicy == QFormLayout::WrapLongRows) | - | ||||||||||||
| 594 | && ((maxLabelWidth < sh1.width()) || (width < (maxLabelWidth + min2.width()))); | - | ||||||||||||
| 595 | - | |||||||||||||
| 596 | if (wrapAllRows || splitSideBySide) { | - | ||||||||||||
| 597 | if (label) { | - | ||||||||||||
| 598 | initLayoutStruct(vLayouts[vidx], label); | - | ||||||||||||
| 599 | - | |||||||||||||
| 600 | if (vidx > 1) | - | ||||||||||||
| 601 | vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, label, 0, prevItem1, prevItem2); | - | ||||||||||||
| 602 | - | |||||||||||||
| 603 | label->vLayoutIndex = vidx; | - | ||||||||||||
| 604 | label->sideBySide = false; | - | ||||||||||||
| 605 | - | |||||||||||||
| 606 | prevItem1 = label; | - | ||||||||||||
| 607 | prevItem2 = 0; | - | ||||||||||||
| 608 | - | |||||||||||||
| 609 | if (vLayouts[vidx].stretch > 0) | - | ||||||||||||
| 610 | addTopBottomStretch = false; | - | ||||||||||||
| 611 | - | |||||||||||||
| 612 | ++vidx; | - | ||||||||||||
| 613 | } | - | ||||||||||||
| 614 | - | |||||||||||||
| 615 | if (field) { | - | ||||||||||||
| 616 | initLayoutStruct(vLayouts[vidx], field); | - | ||||||||||||
| 617 | - | |||||||||||||
| 618 | if (vidx > 1) | - | ||||||||||||
| 619 | vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, splitSideBySide || prevRowSplit, field, 0, prevItem1, prevItem2); | - | ||||||||||||
| 620 | - | |||||||||||||
| 621 | field->vLayoutIndex = vidx; | - | ||||||||||||
| 622 | field->sideBySide = false; | - | ||||||||||||
| 623 | - | |||||||||||||
| 624 | prevItem1 = field; | - | ||||||||||||
| 625 | prevItem2 = 0; | - | ||||||||||||
| 626 | - | |||||||||||||
| 627 | if (vLayouts[vidx].stretch > 0) | - | ||||||||||||
| 628 | addTopBottomStretch = false; | - | ||||||||||||
| 629 | - | |||||||||||||
| 630 | ++vidx; | - | ||||||||||||
| 631 | } | - | ||||||||||||
| 632 | - | |||||||||||||
| 633 | prevRowSplit = splitSideBySide; | - | ||||||||||||
| 634 | } else { | - | ||||||||||||
| 635 | - | |||||||||||||
| 636 | QSize max1(((1<<24)-1), ((1<<24)-1)); | - | ||||||||||||
| 637 | QSize max2(((1<<24)-1), ((1<<24)-1)); | - | ||||||||||||
| 638 | - | |||||||||||||
| 639 | int stretch1 = 0; | - | ||||||||||||
| 640 | int stretch2 = 0; | - | ||||||||||||
| 641 | bool expanding = false; | - | ||||||||||||
| 642 | - | |||||||||||||
| 643 | if (label) { | - | ||||||||||||
| 644 | max1 = label->maxSize; | - | ||||||||||||
| 645 | if (label->expandingDirections() & Qt::Vertical) | - | ||||||||||||
| 646 | expanding = true; | - | ||||||||||||
| 647 | - | |||||||||||||
| 648 | label->sideBySide = (field != 0); | - | ||||||||||||
| 649 | label->vLayoutIndex = vidx; | - | ||||||||||||
| 650 | stretch1 = label->vStretch(); | - | ||||||||||||
| 651 | } | - | ||||||||||||
| 652 | - | |||||||||||||
| 653 | if (field) { | - | ||||||||||||
| 654 | max2 = field->maxSize; | - | ||||||||||||
| 655 | if (field->expandingDirections() & Qt::Vertical) | - | ||||||||||||
| 656 | expanding = true; | - | ||||||||||||
| 657 | - | |||||||||||||
| 658 | field->sideBySide = (label || !field->fullRow); | - | ||||||||||||
| 659 | field->vLayoutIndex = vidx; | - | ||||||||||||
| 660 | stretch2 = field->vStretch(); | - | ||||||||||||
| 661 | } | - | ||||||||||||
| 662 | - | |||||||||||||
| 663 | vLayouts[vidx].init(qMax(stretch1, stretch2), qMax(min1.height(), min2.height())); | - | ||||||||||||
| 664 | vLayouts[vidx].sizeHint = qMax(sh1.height(), sh2.height()); | - | ||||||||||||
| 665 | vLayouts[vidx].maximumSize = qMin(max1.height(), max2.height()); | - | ||||||||||||
| 666 | vLayouts[vidx].expansive = expanding || (vLayouts[vidx].stretch > 0); | - | ||||||||||||
| 667 | vLayouts[vidx].empty = false; | - | ||||||||||||
| 668 | - | |||||||||||||
| 669 | if (vLayouts[vidx].stretch > 0) | - | ||||||||||||
| 670 | addTopBottomStretch = false; | - | ||||||||||||
| 671 | - | |||||||||||||
| 672 | if (vidx > 1) | - | ||||||||||||
| 673 | vLayouts[vidx - 1].spacing = spacingHelper(q->parentWidget(), style, userVSpacing, prevRowSplit, label, field, prevItem1, prevItem2); | - | ||||||||||||
| 674 | - | |||||||||||||
| 675 | if (label) { | - | ||||||||||||
| 676 | prevItem1 = label; | - | ||||||||||||
| 677 | prevItem2 = field; | - | ||||||||||||
| 678 | } else { | - | ||||||||||||
| 679 | prevItem1 = field; | - | ||||||||||||
| 680 | prevItem2 = 0; | - | ||||||||||||
| 681 | } | - | ||||||||||||
| 682 | - | |||||||||||||
| 683 | prevRowSplit = false; | - | ||||||||||||
| 684 | ++vidx; | - | ||||||||||||
| 685 | } | - | ||||||||||||
| 686 | } | - | ||||||||||||
| 687 | - | |||||||||||||
| 688 | if (addTopBottomStretch) { | - | ||||||||||||
| 689 | Qt::Alignment formAlignment = q->formAlignment(); | - | ||||||||||||
| 690 | - | |||||||||||||
| 691 | if (!(formAlignment & Qt::AlignBottom)) { | - | ||||||||||||
| 692 | - | |||||||||||||
| 693 | vLayouts[vidx].init(1, 0); | - | ||||||||||||
| 694 | vLayouts[vidx].expansive = true; | - | ||||||||||||
| 695 | ++vidx; | - | ||||||||||||
| 696 | } | - | ||||||||||||
| 697 | - | |||||||||||||
| 698 | if (formAlignment & (Qt::AlignVCenter | Qt::AlignBottom)) { | - | ||||||||||||
| 699 | - | |||||||||||||
| 700 | vLayouts[0].init(1, 0); | - | ||||||||||||
| 701 | vLayouts[0].expansive = true; | - | ||||||||||||
| 702 | } else { | - | ||||||||||||
| 703 | vLayouts[0].init(0, 0); | - | ||||||||||||
| 704 | } | - | ||||||||||||
| 705 | } else { | - | ||||||||||||
| 706 | vLayouts[0].init(0, 0); | - | ||||||||||||
| 707 | } | - | ||||||||||||
| 708 | - | |||||||||||||
| 709 | vLayoutCount = vidx; | - | ||||||||||||
| 710 | dirty = false; | - | ||||||||||||
| 711 | } | - | ||||||||||||
| 712 | - | |||||||||||||
| 713 | void QFormLayoutPrivate::setupHorizontalLayoutData(int width) | - | ||||||||||||
| 714 | { | - | ||||||||||||
| 715 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 716 | - | |||||||||||||
| 717 | - | |||||||||||||
| 718 | - | |||||||||||||
| 719 | int fieldMaxWidth = 0; | - | ||||||||||||
| 720 | - | |||||||||||||
| 721 | int rr = m_matrix.rowCount(); | - | ||||||||||||
| 722 | bool wrapAllRows = (q->rowWrapPolicy() == QFormLayout::WrapAllRows); | - | ||||||||||||
| 723 | - | |||||||||||||
| 724 | for (int i = 0; i < rr; ++i) { | - | ||||||||||||
| 725 | QFormLayoutItem *label = m_matrix(i, 0); | - | ||||||||||||
| 726 | QFormLayoutItem *field = m_matrix(i, 1); | - | ||||||||||||
| 727 | - | |||||||||||||
| 728 | - | |||||||||||||
| 729 | if (!label && !field) | - | ||||||||||||
| 730 | continue; | - | ||||||||||||
| 731 | - | |||||||||||||
| 732 | if (label) { | - | ||||||||||||
| 733 | - | |||||||||||||
| 734 | - | |||||||||||||
| 735 | label->layoutWidth = (field && label->sideBySide) ? maxLabelWidth : label->sizeHint.width(); | - | ||||||||||||
| 736 | label->layoutPos = 0; | - | ||||||||||||
| 737 | } | - | ||||||||||||
| 738 | - | |||||||||||||
| 739 | if (field) { | - | ||||||||||||
| 740 | - | |||||||||||||
| 741 | int fldwidth = width - maxLabelWidth - field->sbsHSpace; | - | ||||||||||||
| 742 | - | |||||||||||||
| 743 | - | |||||||||||||
| 744 | - | |||||||||||||
| 745 | - | |||||||||||||
| 746 | if (!field->sideBySide) { | - | ||||||||||||
| 747 | if (wrapAllRows || (!label && field->fullRow) || field->sizeHint.width() > fldwidth) { | - | ||||||||||||
| 748 | field->layoutWidth = width; | - | ||||||||||||
| 749 | field->layoutPos = 0; | - | ||||||||||||
| 750 | } else { | - | ||||||||||||
| 751 | field->layoutWidth = fldwidth; | - | ||||||||||||
| 752 | field->layoutPos = width - fldwidth; | - | ||||||||||||
| 753 | } | - | ||||||||||||
| 754 | } else { | - | ||||||||||||
| 755 | - | |||||||||||||
| 756 | field->layoutWidth = fldwidth; | - | ||||||||||||
| 757 | field->layoutPos = width - fldwidth; | - | ||||||||||||
| 758 | } | - | ||||||||||||
| 759 | - | |||||||||||||
| 760 | fieldMaxWidth = qMax(fieldMaxWidth, field->maxSize.width()); | - | ||||||||||||
| 761 | } | - | ||||||||||||
| 762 | } | - | ||||||||||||
| 763 | - | |||||||||||||
| 764 | formMaxWidth = maxLabelWidth + fieldMaxWidth; | - | ||||||||||||
| 765 | } | - | ||||||||||||
| 766 | - | |||||||||||||
| 767 | void QFormLayoutPrivate::calcSizeHints() | - | ||||||||||||
| 768 | { | - | ||||||||||||
| 769 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 770 | - | |||||||||||||
| 771 | int leftMargin, topMargin, rightMargin, bottomMargin; | - | ||||||||||||
| 772 | q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - | ||||||||||||
| 773 | - | |||||||||||||
| 774 | updateSizes(); | - | ||||||||||||
| 775 | setupVerticalLayoutData(QLAYOUTSIZE_MAX); | - | ||||||||||||
| 776 | - | |||||||||||||
| 777 | - | |||||||||||||
| 778 | int h = topMargin + bottomMargin; | - | ||||||||||||
| 779 | int mh = topMargin + bottomMargin; | - | ||||||||||||
| 780 | - | |||||||||||||
| 781 | - | |||||||||||||
| 782 | int w = sh_width + leftMargin + rightMargin; | - | ||||||||||||
| 783 | int mw = min_width + leftMargin + rightMargin; | - | ||||||||||||
| 784 | - | |||||||||||||
| 785 | for (int i = 0; i < vLayoutCount; ++i) { | - | ||||||||||||
| 786 | int spacing = vLayouts.at(i).spacing; | - | ||||||||||||
| 787 | h += vLayouts.at(i).sizeHint + spacing; | - | ||||||||||||
| 788 | mh += vLayouts.at(i).minimumSize + spacing; | - | ||||||||||||
| 789 | } | - | ||||||||||||
| 790 | - | |||||||||||||
| 791 | minSize.rwidth() = qMin(mw, QLAYOUTSIZE_MAX); | - | ||||||||||||
| 792 | minSize.rheight() = qMin(mh, QLAYOUTSIZE_MAX); | - | ||||||||||||
| 793 | prefSize.rwidth() = qMin(w, QLAYOUTSIZE_MAX); | - | ||||||||||||
| 794 | prefSize.rheight() = qMin(h, QLAYOUTSIZE_MAX); | - | ||||||||||||
| 795 | } | - | ||||||||||||
| 796 | - | |||||||||||||
| 797 | int QFormLayoutPrivate::insertRow(int row) | - | ||||||||||||
| 798 | { | - | ||||||||||||
| 799 | int rowCnt = m_matrix.rowCount(); | - | ||||||||||||
| 800 | if (uint(row) > uint(rowCnt)) | - | ||||||||||||
| 801 | row = rowCnt; | - | ||||||||||||
| 802 | - | |||||||||||||
| 803 | insertRows(row, 1); | - | ||||||||||||
| 804 | return row; | - | ||||||||||||
| 805 | } | - | ||||||||||||
| 806 | - | |||||||||||||
| 807 | void QFormLayoutPrivate::insertRows(int row, int count) | - | ||||||||||||
| 808 | { | - | ||||||||||||
| 809 | while (count > 0) { | - | ||||||||||||
| 810 | m_matrix.insertRow(row, 0); | - | ||||||||||||
| 811 | --count; | - | ||||||||||||
| 812 | } | - | ||||||||||||
| 813 | } | - | ||||||||||||
| 814 | - | |||||||||||||
| 815 | bool QFormLayoutPrivate::setItem(int row, QFormLayout::ItemRole role, QLayoutItem *item) | - | ||||||||||||
| 816 | { | - | ||||||||||||
| 817 | const bool fullRow = role == QFormLayout::SpanningRole; | - | ||||||||||||
| 818 | const int column = role == QFormLayout::SpanningRole
| 0 | ||||||||||||
| 819 | if (__builtin_expect(!!(
| 0 | ||||||||||||
| 820 | QMessageLogger(__FILE__, 949927, __PRETTY_FUNCTION__).warning("QFormLayoutPrivate::setItem: Invalid cell (%d, %d)", row, column); | - | ||||||||||||
| 821 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 822 | } | - | ||||||||||||
| 823 | - | |||||||||||||
| 824 | if (!item
| 0 | ||||||||||||
| 825 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 826 | - | |||||||||||||
| 827 | if (__builtin_expect(!!(
| 0 | ||||||||||||
| 828 | QMessageLogger(__FILE__, 957935, __PRETTY_FUNCTION__).warning("QFormLayoutPrivate::setItem: Cell (%d, %d) already occupied", row, column); | - | ||||||||||||
| 829 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 830 | } | - | ||||||||||||
| 831 | - | |||||||||||||
| 832 | QFormLayoutItem *i = new QFormLayoutItem(item); | - | ||||||||||||
| 833 | i->fullRow = fullRow; | - | ||||||||||||
| 834 | m_matrix(row, column) = i; | - | ||||||||||||
| 835 | - | |||||||||||||
| 836 | m_things.append(i); | - | ||||||||||||
| 837 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 838 | } | - | ||||||||||||
| 839 | - | |||||||||||||
| 840 | void QFormLayoutPrivate::setLayout(int row, QFormLayout::ItemRole role, QLayout *layout) | - | ||||||||||||
| 841 | { | - | ||||||||||||
| 842 | if (layout) { | - | ||||||||||||
| 843 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 844 | if (q->adoptLayout(layout)) | - | ||||||||||||
| 845 | setItem(row, role, layout); | - | ||||||||||||
| 846 | } | - | ||||||||||||
| 847 | } | - | ||||||||||||
| 848 | - | |||||||||||||
| 849 | void QFormLayoutPrivate::setWidget(int row, QFormLayout::ItemRole role, QWidget *widget) | - | ||||||||||||
| 850 | { | - | ||||||||||||
| 851 | if (widget) { | - | ||||||||||||
| 852 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 853 | q->addChildWidget(widget); | - | ||||||||||||
| 854 | QWidgetItem *item = QLayoutPrivate::createWidgetItem(q, widget); | - | ||||||||||||
| 855 | if (!setItem(row, role, item)) | - | ||||||||||||
| 856 | delete item; | - | ||||||||||||
| 857 | } | - | ||||||||||||
| 858 | } | - | ||||||||||||
| 859 | - | |||||||||||||
| 860 | QStyle* QFormLayoutPrivate::getStyle() const | - | ||||||||||||
| 861 | { | - | ||||||||||||
| 862 | const QFormLayout * const q = q_func(); | - | ||||||||||||
| 863 | - | |||||||||||||
| 864 | - | |||||||||||||
| 865 | if (QWidget *parentWidget = q->parentWidget()) | - | ||||||||||||
| 866 | return parentWidget->style(); | - | ||||||||||||
| 867 | else | - | ||||||||||||
| 868 | return QApplication::style(); | - | ||||||||||||
| 869 | } | - | ||||||||||||
| 870 | - | |||||||||||||
| 871 | QLayoutItem* QFormLayoutPrivate::replaceAt(int index, QLayoutItem *newitem) | - | ||||||||||||
| 872 | { | - | ||||||||||||
| 873 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 874 | if (!newitem
| 0 | ||||||||||||
| 875 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 876 | const int storageIndex = storageIndexFromLayoutItem(m_matrix, m_things.value(index)); | - | ||||||||||||
| 877 | if (__builtin_expect(!!(
| 0 | ||||||||||||
| 878 | - | |||||||||||||
| 879 | QMessageLogger(__FILE__, 1008986, __PRETTY_FUNCTION__).warning("QFormLayoutPrivate::replaceAt: Invalid index %d", index); | - | ||||||||||||
| 880 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 881 | } | - | ||||||||||||
| 882 | - | |||||||||||||
| 883 | int row, col; | - | ||||||||||||
| 884 | QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); | - | ||||||||||||
| 885 | ((!(m_matrix(row, col))) ? qt_assert("m_matrix(row, col)",__FILE__,1014992) : qt_noop()); | - | ||||||||||||
| 886 | - | |||||||||||||
| 887 | QFormLayoutItem *item = m_matrix(row, col); | - | ||||||||||||
| 888 | ((!(item)) ? qt_assert("item",__FILE__,1017995) : qt_noop()); | - | ||||||||||||
| 889 | - | |||||||||||||
| 890 | QLayoutItem *olditem = item->item; | - | ||||||||||||
| 891 | item->item = newitem; | - | ||||||||||||
| 892 | - | |||||||||||||
| 893 | q->invalidate(); | - | ||||||||||||
| 894 | return never executed: olditem;return olditem;never executed: return olditem; | 0 | ||||||||||||
| 895 | } | - | ||||||||||||
| 896 | QFormLayout::QFormLayout(QWidget *parent) | - | ||||||||||||
| 897 | : QLayout(*new QFormLayoutPrivate, 0, parent) | - | ||||||||||||
| 898 | { | - | ||||||||||||
| 899 | } | - | ||||||||||||
| 900 | - | |||||||||||||
| 901 | - | |||||||||||||
| 902 | - | |||||||||||||
| 903 | - | |||||||||||||
| 904 | QFormLayout::~QFormLayout() | - | ||||||||||||
| 905 | { | - | ||||||||||||
| 906 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 907 | - | |||||||||||||
| 908 | - | |||||||||||||
| 909 | - | |||||||||||||
| 910 | - | |||||||||||||
| 911 | - | |||||||||||||
| 912 | - | |||||||||||||
| 913 | d->m_things.clear(); | - | ||||||||||||
| 914 | qDeleteAll(d->m_matrix.storage()); | - | ||||||||||||
| 915 | d->m_matrix.clear(); | - | ||||||||||||
| 916 | } | - | ||||||||||||
| 917 | - | |||||||||||||
| 918 | - | |||||||||||||
| 919 | - | |||||||||||||
| 920 | - | |||||||||||||
| 921 | - | |||||||||||||
| 922 | - | |||||||||||||
| 923 | - | |||||||||||||
| 924 | void QFormLayout::addRow(QWidget *label, QWidget *field) | - | ||||||||||||
| 925 | { | - | ||||||||||||
| 926 | insertRow(-1, label, field); | - | ||||||||||||
| 927 | } | - | ||||||||||||
| 928 | - | |||||||||||||
| 929 | - | |||||||||||||
| 930 | - | |||||||||||||
| 931 | - | |||||||||||||
| 932 | void QFormLayout::addRow(QWidget *label, QLayout *field) | - | ||||||||||||
| 933 | { | - | ||||||||||||
| 934 | insertRow(-1, label, field); | - | ||||||||||||
| 935 | } | - | ||||||||||||
| 936 | void QFormLayout::addRow(const QString &labelText, QWidget *field) | - | ||||||||||||
| 937 | { | - | ||||||||||||
| 938 | insertRow(-1, labelText, field); | - | ||||||||||||
| 939 | } | - | ||||||||||||
| 940 | - | |||||||||||||
| 941 | - | |||||||||||||
| 942 | - | |||||||||||||
| 943 | - | |||||||||||||
| 944 | - | |||||||||||||
| 945 | - | |||||||||||||
| 946 | - | |||||||||||||
| 947 | void QFormLayout::addRow(const QString &labelText, QLayout *field) | - | ||||||||||||
| 948 | { | - | ||||||||||||
| 949 | insertRow(-1, labelText, field); | - | ||||||||||||
| 950 | } | - | ||||||||||||
| 951 | - | |||||||||||||
| 952 | - | |||||||||||||
| 953 | - | |||||||||||||
| 954 | - | |||||||||||||
| 955 | - | |||||||||||||
| 956 | - | |||||||||||||
| 957 | - | |||||||||||||
| 958 | void QFormLayout::addRow(QWidget *widget) | - | ||||||||||||
| 959 | { | - | ||||||||||||
| 960 | insertRow(-1, widget); | - | ||||||||||||
| 961 | } | - | ||||||||||||
| 962 | - | |||||||||||||
| 963 | - | |||||||||||||
| 964 | - | |||||||||||||
| 965 | - | |||||||||||||
| 966 | - | |||||||||||||
| 967 | - | |||||||||||||
| 968 | - | |||||||||||||
| 969 | void QFormLayout::addRow(QLayout *layout) | - | ||||||||||||
| 970 | { | - | ||||||||||||
| 971 | insertRow(-1, layout); | - | ||||||||||||
| 972 | } | - | ||||||||||||
| 973 | void QFormLayout::insertRow(int row, QWidget *label, QWidget *field) | - | ||||||||||||
| 974 | { | - | ||||||||||||
| 975 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 976 | if ((label && !d->checkWidget(label)) || (field && !d->checkWidget(field))) | - | ||||||||||||
| 977 | return; | - | ||||||||||||
| 978 | - | |||||||||||||
| 979 | row = d->insertRow(row); | - | ||||||||||||
| 980 | if (label) | - | ||||||||||||
| 981 | d->setWidget(row, LabelRole, label); | - | ||||||||||||
| 982 | if (field) | - | ||||||||||||
| 983 | d->setWidget(row, FieldRole, field); | - | ||||||||||||
| 984 | invalidate(); | - | ||||||||||||
| 985 | } | - | ||||||||||||
| 986 | - | |||||||||||||
| 987 | - | |||||||||||||
| 988 | - | |||||||||||||
| 989 | - | |||||||||||||
| 990 | void QFormLayout::insertRow(int row, QWidget *label, QLayout *field) | - | ||||||||||||
| 991 | { | - | ||||||||||||
| 992 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 993 | if ((label && !d->checkWidget(label)) || (field && !d->checkLayout(field))) | - | ||||||||||||
| 994 | return; | - | ||||||||||||
| 995 | - | |||||||||||||
| 996 | row = d->insertRow(row); | - | ||||||||||||
| 997 | if (label) | - | ||||||||||||
| 998 | d->setWidget(row, LabelRole, label); | - | ||||||||||||
| 999 | if (field) | - | ||||||||||||
| 1000 | d->setLayout(row, FieldRole, field); | - | ||||||||||||
| 1001 | invalidate(); | - | ||||||||||||
| 1002 | } | - | ||||||||||||
| 1003 | void QFormLayout::insertRow(int row, const QString &labelText, QWidget *field) | - | ||||||||||||
| 1004 | { | - | ||||||||||||
| 1005 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1006 | if (field && !d->checkWidget(field)) | - | ||||||||||||
| 1007 | return; | - | ||||||||||||
| 1008 | - | |||||||||||||
| 1009 | QLabel *label = 0; | - | ||||||||||||
| 1010 | if (!labelText.isEmpty()) { | - | ||||||||||||
| 1011 | label = new QLabel(labelText); | - | ||||||||||||
| 1012 | - | |||||||||||||
| 1013 | label->setBuddy(field); | - | ||||||||||||
| 1014 | - | |||||||||||||
| 1015 | } | - | ||||||||||||
| 1016 | insertRow(row, label, field); | - | ||||||||||||
| 1017 | } | - | ||||||||||||
| 1018 | - | |||||||||||||
| 1019 | - | |||||||||||||
| 1020 | - | |||||||||||||
| 1021 | - | |||||||||||||
| 1022 | - | |||||||||||||
| 1023 | - | |||||||||||||
| 1024 | - | |||||||||||||
| 1025 | void QFormLayout::insertRow(int row, const QString &labelText, QLayout *field) | - | ||||||||||||
| 1026 | { | - | ||||||||||||
| 1027 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1028 | if (field && !d->checkLayout(field)) | - | ||||||||||||
| 1029 | return; | - | ||||||||||||
| 1030 | - | |||||||||||||
| 1031 | insertRow(row, labelText.isEmpty() ? 0 : new QLabel(labelText), field); | - | ||||||||||||
| 1032 | } | - | ||||||||||||
| 1033 | void QFormLayout::insertRow(int row, QWidget *widget) | - | ||||||||||||
| 1034 | { | - | ||||||||||||
| 1035 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1036 | if (!d->checkWidget(widget)) | - | ||||||||||||
| 1037 | return; | - | ||||||||||||
| 1038 | - | |||||||||||||
| 1039 | row = d->insertRow(row); | - | ||||||||||||
| 1040 | d->setWidget(row, SpanningRole, widget); | - | ||||||||||||
| 1041 | invalidate(); | - | ||||||||||||
| 1042 | } | - | ||||||||||||
| 1043 | void QFormLayout::insertRow(int row, QLayout *layout) | - | ||||||||||||
| 1044 | { | - | ||||||||||||
| 1045 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1046 | if (!d->checkLayout(layout)) | - | ||||||||||||
| 1047 | return; | - | ||||||||||||
| 1048 | - | |||||||||||||
| 1049 | row = d->insertRow(row); | - | ||||||||||||
| 1050 | d->setLayout(row, SpanningRole, layout); | - | ||||||||||||
| 1051 | invalidate(); | - | ||||||||||||
| 1052 | } | - | ||||||||||||
| 1053 | - | |||||||||||||
| 1054 | - | |||||||||||||
| 1055 | - | |||||||||||||
| 1056 | - | |||||||||||||
| 1057 | void QFormLayout::addItem(QLayoutItem *item) | - | ||||||||||||
| 1058 | { | - | ||||||||||||
| 1059 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1060 | - | |||||||||||||
| 1061 | int row = d->insertRow(d->m_matrix.rowCount()); | - | ||||||||||||
| 1062 | d->setItem(row, FieldRole, item); | - | ||||||||||||
| 1063 | invalidate(); | - | ||||||||||||
| 1064 | } | - | ||||||||||||
| 1065 | - | |||||||||||||
| 1066 | - | |||||||||||||
| 1067 | - | |||||||||||||
| 1068 | - | |||||||||||||
| 1069 | int QFormLayout::count() const | - | ||||||||||||
| 1070 | { | - | ||||||||||||
| 1071 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1072 | return d->m_things.count(); | - | ||||||||||||
| 1073 | } | - | ||||||||||||
| 1074 | - | |||||||||||||
| 1075 | - | |||||||||||||
| 1076 | - | |||||||||||||
| 1077 | - | |||||||||||||
| 1078 | QLayoutItem *QFormLayout::itemAt(int index) const | - | ||||||||||||
| 1079 | { | - | ||||||||||||
| 1080 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1081 | if (QFormLayoutItem *formItem = d->m_things.value(index)) | - | ||||||||||||
| 1082 | return formItem->item; | - | ||||||||||||
| 1083 | return 0; | - | ||||||||||||
| 1084 | } | - | ||||||||||||
| 1085 | - | |||||||||||||
| 1086 | - | |||||||||||||
| 1087 | - | |||||||||||||
| 1088 | - | |||||||||||||
| 1089 | QLayoutItem *QFormLayout::takeAt(int index) | - | ||||||||||||
| 1090 | { | - | ||||||||||||
| 1091 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1092 | - | |||||||||||||
| 1093 | const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index)); | - | ||||||||||||
| 1094 | if (__builtin_expect(!!(
| 0 | ||||||||||||
| 1095 | QMessageLogger(__FILE__, 14211399, __PRETTY_FUNCTION__).warning("QFormLayout::takeAt: Invalid index %d", index); | - | ||||||||||||
| 1096 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 1097 | } | - | ||||||||||||
| 1098 | - | |||||||||||||
| 1099 | int row, col; | - | ||||||||||||
| 1100 | QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); | - | ||||||||||||
| 1101 | ((!(d->m_matrix(row, col))) ? qt_assert("d->m_matrix(row, col)",__FILE__,14271405) : qt_noop()); | - | ||||||||||||
| 1102 | - | |||||||||||||
| 1103 | QFormLayoutItem *item = d->m_matrix(row, col); | - | ||||||||||||
| 1104 | ((!(item)) ? qt_assert("item",__FILE__,14301408) : qt_noop()); | - | ||||||||||||
| 1105 | d->m_things.removeAt(index); | - | ||||||||||||
| 1106 | d->m_matrix(row, col) = 0; | - | ||||||||||||
| 1107 | - | |||||||||||||
| 1108 | invalidate(); | - | ||||||||||||
| 1109 | - | |||||||||||||
| 1110 | - | |||||||||||||
| 1111 | QLayoutItem *i = item->item; | - | ||||||||||||
| 1112 | item->item = 0; | - | ||||||||||||
| 1113 | delete item; | - | ||||||||||||
| 1114 | - | |||||||||||||
| 1115 | if (QLayout *l = i->layout()
| 0 | ||||||||||||
| 1116 | - | |||||||||||||
| 1117 | if (l->parent() == this
| 0 | ||||||||||||
| 1118 | l->setParent(0); never executed: l->setParent(0); | 0 | ||||||||||||
| 1119 | } never executed: end of block | 0 | ||||||||||||
| 1120 | - | |||||||||||||
| 1121 | return never executed: i;return i;never executed: return i; | 0 | ||||||||||||
| 1122 | } | - | ||||||||||||
| 1123 | - | |||||||||||||
| 1124 | - | |||||||||||||
| 1125 | - | |||||||||||||
| 1126 | - | |||||||||||||
| 1127 | Qt::Orientations QFormLayout::expandingDirections() const | - | ||||||||||||
| 1128 | { | - | ||||||||||||
| 1129 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1130 | QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d); | - | ||||||||||||
| 1131 | e->updateSizes(); | - | ||||||||||||
| 1132 | - | |||||||||||||
| 1133 | Qt::Orientations o = 0; | - | ||||||||||||
| 1134 | if (e->expandHorizontal) | - | ||||||||||||
| 1135 | o = Qt::Horizontal; | - | ||||||||||||
| 1136 | if (e->expandVertical) | - | ||||||||||||
| 1137 | o |= Qt::Vertical; | - | ||||||||||||
| 1138 | return o; | - | ||||||||||||
| 1139 | } | - | ||||||||||||
| 1140 | - | |||||||||||||
| 1141 | - | |||||||||||||
| 1142 | - | |||||||||||||
| 1143 | - | |||||||||||||
| 1144 | bool QFormLayout::hasHeightForWidth() const | - | ||||||||||||
| 1145 | { | - | ||||||||||||
| 1146 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1147 | QFormLayoutPrivate *e = const_cast<QFormLayoutPrivate *>(d); | - | ||||||||||||
| 1148 | e->updateSizes(); | - | ||||||||||||
| 1149 | return (d->has_hfw || rowWrapPolicy() == WrapLongRows); | - | ||||||||||||
| 1150 | } | - | ||||||||||||
| 1151 | - | |||||||||||||
| 1152 | - | |||||||||||||
| 1153 | - | |||||||||||||
| 1154 | - | |||||||||||||
| 1155 | int QFormLayout::heightForWidth(int width) const | - | ||||||||||||
| 1156 | { | - | ||||||||||||
| 1157 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1158 | if (!hasHeightForWidth()) | - | ||||||||||||
| 1159 | return -1; | - | ||||||||||||
| 1160 | - | |||||||||||||
| 1161 | int leftMargin, topMargin, rightMargin, bottomMargin; | - | ||||||||||||
| 1162 | getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - | ||||||||||||
| 1163 | - | |||||||||||||
| 1164 | int targetWidth = width - leftMargin - rightMargin; | - | ||||||||||||
| 1165 | - | |||||||||||||
| 1166 | if (!d->haveHfwCached(targetWidth)) { | - | ||||||||||||
| 1167 | QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d); | - | ||||||||||||
| 1168 | dat->setupVerticalLayoutData(targetWidth); | - | ||||||||||||
| 1169 | dat->setupHorizontalLayoutData(targetWidth); | - | ||||||||||||
| 1170 | dat->recalcHFW(targetWidth); | - | ||||||||||||
| 1171 | } | - | ||||||||||||
| 1172 | if (targetWidth == d->sh_width) | - | ||||||||||||
| 1173 | return d->hfw_sh_height + topMargin + bottomMargin; | - | ||||||||||||
| 1174 | else | - | ||||||||||||
| 1175 | return d->hfw_height + topMargin + bottomMargin; | - | ||||||||||||
| 1176 | } | - | ||||||||||||
| 1177 | - | |||||||||||||
| 1178 | - | |||||||||||||
| 1179 | - | |||||||||||||
| 1180 | - | |||||||||||||
| 1181 | void QFormLayout::setGeometry(const QRect &rect) | - | ||||||||||||
| 1182 | { | - | ||||||||||||
| 1183 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1184 | if (d->dirty || rect != geometry()) { | - | ||||||||||||
| 1185 | QRect cr = rect; | - | ||||||||||||
| 1186 | int leftMargin, topMargin, rightMargin, bottomMargin; | - | ||||||||||||
| 1187 | getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - | ||||||||||||
| 1188 | cr.adjust(+leftMargin, +topMargin, -rightMargin, -bottomMargin); | - | ||||||||||||
| 1189 | - | |||||||||||||
| 1190 | bool hfw = hasHeightForWidth(); | - | ||||||||||||
| 1191 | d->setupVerticalLayoutData(cr.width()); | - | ||||||||||||
| 1192 | d->setupHorizontalLayoutData(cr.width()); | - | ||||||||||||
| 1193 | if (hfw && (!d->haveHfwCached(cr.width()) || d->hfwLayouts.size() != d->vLayoutCount)) | - | ||||||||||||
| 1194 | d->recalcHFW(cr.width()); | - | ||||||||||||
| 1195 | if (hfw) { | - | ||||||||||||
| 1196 | qGeomCalc(d->hfwLayouts, 0, d->vLayoutCount, cr.y(), cr.height()); | - | ||||||||||||
| 1197 | d->arrangeWidgets(d->hfwLayouts, cr); | - | ||||||||||||
| 1198 | } else { | - | ||||||||||||
| 1199 | qGeomCalc(d->vLayouts, 0, d->vLayoutCount, cr.y(), cr.height()); | - | ||||||||||||
| 1200 | d->arrangeWidgets(d->vLayouts, cr); | - | ||||||||||||
| 1201 | } | - | ||||||||||||
| 1202 | QLayout::setGeometry(rect); | - | ||||||||||||
| 1203 | } | - | ||||||||||||
| 1204 | } | - | ||||||||||||
| 1205 | - | |||||||||||||
| 1206 | - | |||||||||||||
| 1207 | - | |||||||||||||
| 1208 | - | |||||||||||||
| 1209 | QSize QFormLayout::sizeHint() const | - | ||||||||||||
| 1210 | { | - | ||||||||||||
| 1211 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1212 | if (!d->prefSize.isValid()) { | - | ||||||||||||
| 1213 | QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d); | - | ||||||||||||
| 1214 | dat->calcSizeHints(); | - | ||||||||||||
| 1215 | } | - | ||||||||||||
| 1216 | return d->prefSize; | - | ||||||||||||
| 1217 | } | - | ||||||||||||
| 1218 | - | |||||||||||||
| 1219 | - | |||||||||||||
| 1220 | - | |||||||||||||
| 1221 | - | |||||||||||||
| 1222 | QSize QFormLayout::minimumSize() const | - | ||||||||||||
| 1223 | { | - | ||||||||||||
| 1224 | - | |||||||||||||
| 1225 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1226 | if (!d->minSize.isValid()) { | - | ||||||||||||
| 1227 | QFormLayoutPrivate *dat = const_cast<QFormLayoutPrivate *>(d); | - | ||||||||||||
| 1228 | dat->calcSizeHints(); | - | ||||||||||||
| 1229 | } | - | ||||||||||||
| 1230 | return d->minSize; | - | ||||||||||||
| 1231 | } | - | ||||||||||||
| 1232 | - | |||||||||||||
| 1233 | - | |||||||||||||
| 1234 | - | |||||||||||||
| 1235 | - | |||||||||||||
| 1236 | void QFormLayout::invalidate() | - | ||||||||||||
| 1237 | { | - | ||||||||||||
| 1238 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1239 | d->dirty = true; | - | ||||||||||||
| 1240 | d->sizesDirty = true; | - | ||||||||||||
| 1241 | d->minSize = QSize(); | - | ||||||||||||
| 1242 | d->prefSize = QSize(); | - | ||||||||||||
| 1243 | d->formMaxWidth = -1; | - | ||||||||||||
| 1244 | d->hfw_width = -1; | - | ||||||||||||
| 1245 | d->sh_width = -1; | - | ||||||||||||
| 1246 | d->layoutWidth = -1; | - | ||||||||||||
| 1247 | d->hfw_sh_height = -1; | - | ||||||||||||
| 1248 | QLayout::invalidate(); | - | ||||||||||||
| 1249 | } | - | ||||||||||||
| 1250 | - | |||||||||||||
| 1251 | - | |||||||||||||
| 1252 | - | |||||||||||||
| 1253 | - | |||||||||||||
| 1254 | - | |||||||||||||
| 1255 | - | |||||||||||||
| 1256 | int QFormLayout::rowCount() const | - | ||||||||||||
| 1257 | { | - | ||||||||||||
| 1258 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1259 | return d->m_matrix.rowCount(); | - | ||||||||||||
| 1260 | } | - | ||||||||||||
| 1261 | - | |||||||||||||
| 1262 | - | |||||||||||||
| 1263 | - | |||||||||||||
| 1264 | - | |||||||||||||
| 1265 | - | |||||||||||||
| 1266 | - | |||||||||||||
| 1267 | - | |||||||||||||
| 1268 | QLayoutItem *QFormLayout::itemAt(int row, ItemRole role) const | - | ||||||||||||
| 1269 | { | - | ||||||||||||
| 1270 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1271 | if (uint(row) >= uint(d->m_matrix.rowCount())) | - | ||||||||||||
| 1272 | return 0; | - | ||||||||||||
| 1273 | switch (role) { | - | ||||||||||||
| 1274 | case SpanningRole: | - | ||||||||||||
| 1275 | if (QFormLayoutItem *item = d->m_matrix(row, 1)) | - | ||||||||||||
| 1276 | if (item->fullRow) | - | ||||||||||||
| 1277 | return item->item; | - | ||||||||||||
| 1278 | break; | - | ||||||||||||
| 1279 | case LabelRole: | - | ||||||||||||
| 1280 | case FieldRole: | - | ||||||||||||
| 1281 | if (QFormLayoutItem *item = d->m_matrix(row, (role == LabelRole) ? 0 : 1)) | - | ||||||||||||
| 1282 | return item->item; | - | ||||||||||||
| 1283 | break; | - | ||||||||||||
| 1284 | } | - | ||||||||||||
| 1285 | return 0; | - | ||||||||||||
| 1286 | } | - | ||||||||||||
| 1287 | void QFormLayout::getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const | - | ||||||||||||
| 1288 | { | - | ||||||||||||
| 1289 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1290 | int col = -1; | - | ||||||||||||
| 1291 | int row = -1; | - | ||||||||||||
| 1292 | - | |||||||||||||
| 1293 | const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(index)); | - | ||||||||||||
| 1294 | if (storageIndex != -1) | - | ||||||||||||
| 1295 | QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &row, &col); | - | ||||||||||||
| 1296 | - | |||||||||||||
| 1297 | if (rowPtr) | - | ||||||||||||
| 1298 | *rowPtr = row; | - | ||||||||||||
| 1299 | if (rolePtr && col != -1) { | - | ||||||||||||
| 1300 | const bool spanning = col == 1 && d->m_matrix(row, col)->fullRow; | - | ||||||||||||
| 1301 | if (spanning) { | - | ||||||||||||
| 1302 | *rolePtr = SpanningRole; | - | ||||||||||||
| 1303 | } else { | - | ||||||||||||
| 1304 | *rolePtr = ItemRole(col); | - | ||||||||||||
| 1305 | } | - | ||||||||||||
| 1306 | } | - | ||||||||||||
| 1307 | } | - | ||||||||||||
| 1308 | - | |||||||||||||
| 1309 | - | |||||||||||||
| 1310 | - | |||||||||||||
| 1311 | - | |||||||||||||
| 1312 | - | |||||||||||||
| 1313 | - | |||||||||||||
| 1314 | - | |||||||||||||
| 1315 | void QFormLayout::getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const | - | ||||||||||||
| 1316 | { | - | ||||||||||||
| 1317 | int n = count(); | - | ||||||||||||
| 1318 | int index = 0; | - | ||||||||||||
| 1319 | while (index < n) { | - | ||||||||||||
| 1320 | if (itemAt(index) == layout) | - | ||||||||||||
| 1321 | break; | - | ||||||||||||
| 1322 | ++index; | - | ||||||||||||
| 1323 | } | - | ||||||||||||
| 1324 | getItemPosition(index, rowPtr, rolePtr); | - | ||||||||||||
| 1325 | } | - | ||||||||||||
| 1326 | void QFormLayout::getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const | - | ||||||||||||
| 1327 | { | - | ||||||||||||
| 1328 | getItemPosition(indexOf(widget), rowPtr, rolePtr); | - | ||||||||||||
| 1329 | } | - | ||||||||||||
| 1330 | QWidget *QFormLayout::labelForField(QWidget *field) const | - | ||||||||||||
| 1331 | { | - | ||||||||||||
| 1332 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1333 | - | |||||||||||||
| 1334 | int row; | - | ||||||||||||
| 1335 | ItemRole role = LabelRole; | - | ||||||||||||
| 1336 | - | |||||||||||||
| 1337 | getWidgetPosition(field, &row, &role); | - | ||||||||||||
| 1338 | - | |||||||||||||
| 1339 | if (row != -1 && role == FieldRole) { | - | ||||||||||||
| 1340 | if (QFormLayoutItem *label = d->m_matrix(row, LabelRole)) | - | ||||||||||||
| 1341 | return label->widget(); | - | ||||||||||||
| 1342 | } | - | ||||||||||||
| 1343 | return 0; | - | ||||||||||||
| 1344 | } | - | ||||||||||||
| 1345 | - | |||||||||||||
| 1346 | - | |||||||||||||
| 1347 | - | |||||||||||||
| 1348 | - | |||||||||||||
| 1349 | QWidget *QFormLayout::labelForField(QLayout *field) const | - | ||||||||||||
| 1350 | { | - | ||||||||||||
| 1351 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1352 | - | |||||||||||||
| 1353 | int row; | - | ||||||||||||
| 1354 | ItemRole role; | - | ||||||||||||
| 1355 | - | |||||||||||||
| 1356 | getLayoutPosition(field, &row, &role); | - | ||||||||||||
| 1357 | - | |||||||||||||
| 1358 | if (row != -1 && role == FieldRole) { | - | ||||||||||||
| 1359 | if (QFormLayoutItem *label = d->m_matrix(row, LabelRole)) | - | ||||||||||||
| 1360 | return label->widget(); | - | ||||||||||||
| 1361 | } | - | ||||||||||||
| 1362 | return 0; | - | ||||||||||||
| 1363 | } | - | ||||||||||||
| 1364 | void QFormLayout::setFieldGrowthPolicy(FieldGrowthPolicy policy) | - | ||||||||||||
| 1365 | { | - | ||||||||||||
| 1366 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1367 | if (FieldGrowthPolicy(d->fieldGrowthPolicy) != policy) { | - | ||||||||||||
| 1368 | d->fieldGrowthPolicy = policy; | - | ||||||||||||
| 1369 | invalidate(); | - | ||||||||||||
| 1370 | } | - | ||||||||||||
| 1371 | } | - | ||||||||||||
| 1372 | - | |||||||||||||
| 1373 | QFormLayout::FieldGrowthPolicy QFormLayout::fieldGrowthPolicy() const | - | ||||||||||||
| 1374 | { | - | ||||||||||||
| 1375 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1376 | if (d->fieldGrowthPolicy == DefaultFieldGrowthPolicy) { | - | ||||||||||||
| 1377 | return QFormLayout::FieldGrowthPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutFieldGrowthPolicy)); | - | ||||||||||||
| 1378 | } else { | - | ||||||||||||
| 1379 | return QFormLayout::FieldGrowthPolicy(d->fieldGrowthPolicy); | - | ||||||||||||
| 1380 | } | - | ||||||||||||
| 1381 | } | - | ||||||||||||
| 1382 | void QFormLayout::setRowWrapPolicy(RowWrapPolicy policy) | - | ||||||||||||
| 1383 | { | - | ||||||||||||
| 1384 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1385 | if (RowWrapPolicy(d->rowWrapPolicy) != policy) { | - | ||||||||||||
| 1386 | d->rowWrapPolicy = policy; | - | ||||||||||||
| 1387 | invalidate(); | - | ||||||||||||
| 1388 | } | - | ||||||||||||
| 1389 | } | - | ||||||||||||
| 1390 | - | |||||||||||||
| 1391 | QFormLayout::RowWrapPolicy QFormLayout::rowWrapPolicy() const | - | ||||||||||||
| 1392 | { | - | ||||||||||||
| 1393 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1394 | if (d->rowWrapPolicy == DefaultRowWrapPolicy) { | - | ||||||||||||
| 1395 | return QFormLayout::RowWrapPolicy(d->getStyle()->styleHint(QStyle::SH_FormLayoutWrapPolicy)); | - | ||||||||||||
| 1396 | } else { | - | ||||||||||||
| 1397 | return QFormLayout::RowWrapPolicy(d->rowWrapPolicy); | - | ||||||||||||
| 1398 | } | - | ||||||||||||
| 1399 | } | - | ||||||||||||
| 1400 | void QFormLayout::setLabelAlignment(Qt::Alignment alignment) | - | ||||||||||||
| 1401 | { | - | ||||||||||||
| 1402 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1403 | if (d->labelAlignment != alignment) { | - | ||||||||||||
| 1404 | d->labelAlignment = alignment; | - | ||||||||||||
| 1405 | invalidate(); | - | ||||||||||||
| 1406 | } | - | ||||||||||||
| 1407 | } | - | ||||||||||||
| 1408 | - | |||||||||||||
| 1409 | Qt::Alignment QFormLayout::labelAlignment() const | - | ||||||||||||
| 1410 | { | - | ||||||||||||
| 1411 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1412 | if (!d->labelAlignment) { | - | ||||||||||||
| 1413 | return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutLabelAlignment)); | - | ||||||||||||
| 1414 | } else { | - | ||||||||||||
| 1415 | return d->labelAlignment; | - | ||||||||||||
| 1416 | } | - | ||||||||||||
| 1417 | } | - | ||||||||||||
| 1418 | void QFormLayout::setFormAlignment(Qt::Alignment alignment) | - | ||||||||||||
| 1419 | { | - | ||||||||||||
| 1420 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1421 | if (d->formAlignment != alignment) { | - | ||||||||||||
| 1422 | d->formAlignment = alignment; | - | ||||||||||||
| 1423 | invalidate(); | - | ||||||||||||
| 1424 | } | - | ||||||||||||
| 1425 | } | - | ||||||||||||
| 1426 | - | |||||||||||||
| 1427 | Qt::Alignment QFormLayout::formAlignment() const | - | ||||||||||||
| 1428 | { | - | ||||||||||||
| 1429 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1430 | if (!d->formAlignment) { | - | ||||||||||||
| 1431 | return Qt::Alignment(d->getStyle()->styleHint(QStyle::SH_FormLayoutFormAlignment)); | - | ||||||||||||
| 1432 | } else { | - | ||||||||||||
| 1433 | return d->formAlignment; | - | ||||||||||||
| 1434 | } | - | ||||||||||||
| 1435 | } | - | ||||||||||||
| 1436 | void QFormLayout::setHorizontalSpacing(int spacing) | - | ||||||||||||
| 1437 | { | - | ||||||||||||
| 1438 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1439 | if (spacing != d->hSpacing) { | - | ||||||||||||
| 1440 | d->hSpacing = spacing; | - | ||||||||||||
| 1441 | invalidate(); | - | ||||||||||||
| 1442 | } | - | ||||||||||||
| 1443 | } | - | ||||||||||||
| 1444 | - | |||||||||||||
| 1445 | int QFormLayout::horizontalSpacing() const | - | ||||||||||||
| 1446 | { | - | ||||||||||||
| 1447 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1448 | if (d->hSpacing >= 0) { | - | ||||||||||||
| 1449 | return d->hSpacing; | - | ||||||||||||
| 1450 | } else { | - | ||||||||||||
| 1451 | return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing); | - | ||||||||||||
| 1452 | } | - | ||||||||||||
| 1453 | } | - | ||||||||||||
| 1454 | void QFormLayout::setVerticalSpacing(int spacing) | - | ||||||||||||
| 1455 | { | - | ||||||||||||
| 1456 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1457 | if (spacing != d->vSpacing) { | - | ||||||||||||
| 1458 | d->vSpacing = spacing; | - | ||||||||||||
| 1459 | invalidate(); | - | ||||||||||||
| 1460 | } | - | ||||||||||||
| 1461 | } | - | ||||||||||||
| 1462 | - | |||||||||||||
| 1463 | int QFormLayout::verticalSpacing() const | - | ||||||||||||
| 1464 | { | - | ||||||||||||
| 1465 | const QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1466 | if (d->vSpacing >= 0) { | - | ||||||||||||
| 1467 | return d->vSpacing; | - | ||||||||||||
| 1468 | } else { | - | ||||||||||||
| 1469 | return qSmartSpacing(this, QStyle::PM_LayoutVerticalSpacing); | - | ||||||||||||
| 1470 | } | - | ||||||||||||
| 1471 | } | - | ||||||||||||
| 1472 | - | |||||||||||||
| 1473 | - | |||||||||||||
| 1474 | - | |||||||||||||
| 1475 | - | |||||||||||||
| 1476 | - | |||||||||||||
| 1477 | - | |||||||||||||
| 1478 | - | |||||||||||||
| 1479 | void QFormLayout::setSpacing(int spacing) | - | ||||||||||||
| 1480 | { | - | ||||||||||||
| 1481 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1482 | d->vSpacing = d->hSpacing = spacing; | - | ||||||||||||
| 1483 | invalidate(); | - | ||||||||||||
| 1484 | } | - | ||||||||||||
| 1485 | - | |||||||||||||
| 1486 | - | |||||||||||||
| 1487 | - | |||||||||||||
| 1488 | - | |||||||||||||
| 1489 | - | |||||||||||||
| 1490 | - | |||||||||||||
| 1491 | - | |||||||||||||
| 1492 | int QFormLayout::spacing() const | - | ||||||||||||
| 1493 | { | - | ||||||||||||
| 1494 | int hSpacing = horizontalSpacing(); | - | ||||||||||||
| 1495 | if (hSpacing == verticalSpacing()) { | - | ||||||||||||
| 1496 | return hSpacing; | - | ||||||||||||
| 1497 | } else { | - | ||||||||||||
| 1498 | return -1; | - | ||||||||||||
| 1499 | } | - | ||||||||||||
| 1500 | } | - | ||||||||||||
| 1501 | - | |||||||||||||
| 1502 | void QFormLayoutPrivate::arrangeWidgets(const QVector<QLayoutStruct>& layouts, QRect &rect) | - | ||||||||||||
| 1503 | { | - | ||||||||||||
| 1504 | QFormLayout * const q = q_func(); | - | ||||||||||||
| 1505 | - | |||||||||||||
| 1506 | int i; | - | ||||||||||||
| 1507 | const int rr = m_matrix.rowCount(); | - | ||||||||||||
| 1508 | QWidget *w = q->parentWidget(); | - | ||||||||||||
| 1509 | Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : QApplication::layoutDirection(); | - | ||||||||||||
| 1510 | - | |||||||||||||
| 1511 | Qt::Alignment formAlignment = fixedAlignment(q->formAlignment(), layoutDirection); | - | ||||||||||||
| 1512 | int leftOffset = 0; | - | ||||||||||||
| 1513 | int delta = rect.width() - formMaxWidth; | - | ||||||||||||
| 1514 | if (formAlignment & (Qt::AlignHCenter | Qt::AlignRight) && delta > 0) { | - | ||||||||||||
| 1515 | leftOffset = delta; | - | ||||||||||||
| 1516 | if (formAlignment & Qt::AlignHCenter) | - | ||||||||||||
| 1517 | leftOffset >>= 1; | - | ||||||||||||
| 1518 | } | - | ||||||||||||
| 1519 | - | |||||||||||||
| 1520 | for (i = 0; i < rr; ++i) { | - | ||||||||||||
| 1521 | QFormLayoutItem *label = m_matrix(i, 0); | - | ||||||||||||
| 1522 | QFormLayoutItem *field = m_matrix(i, 1); | - | ||||||||||||
| 1523 | - | |||||||||||||
| 1524 | if (label) { | - | ||||||||||||
| 1525 | int height = layouts.at(label->vLayoutIndex).size; | - | ||||||||||||
| 1526 | if ((label->expandingDirections() & Qt::Vertical) == 0) { | - | ||||||||||||
| 1527 | - | |||||||||||||
| 1528 | - | |||||||||||||
| 1529 | - | |||||||||||||
| 1530 | - | |||||||||||||
| 1531 | - | |||||||||||||
| 1532 | - | |||||||||||||
| 1533 | height = qMin(height, | - | ||||||||||||
| 1534 | qMin(label->sizeHint.height() * 7 / 4, | - | ||||||||||||
| 1535 | label->maxSize.height())); | - | ||||||||||||
| 1536 | } | - | ||||||||||||
| 1537 | - | |||||||||||||
| 1538 | QSize sz(qMin(label->layoutWidth, label->sizeHint.width()), height); | - | ||||||||||||
| 1539 | int x = leftOffset + rect.x() + label->layoutPos; | - | ||||||||||||
| 1540 | if (fixedAlignment(q->labelAlignment(), layoutDirection) & Qt::AlignRight) | - | ||||||||||||
| 1541 | x += label->layoutWidth - sz.width(); | - | ||||||||||||
| 1542 | QPoint p(x, layouts.at(label->vLayoutIndex).pos); | - | ||||||||||||
| 1543 | - | |||||||||||||
| 1544 | - | |||||||||||||
| 1545 | label->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz))); | - | ||||||||||||
| 1546 | } | - | ||||||||||||
| 1547 | - | |||||||||||||
| 1548 | if (field) { | - | ||||||||||||
| 1549 | QSize sz(field->layoutWidth, layouts.at(field->vLayoutIndex).size); | - | ||||||||||||
| 1550 | QPoint p(field->layoutPos + leftOffset + rect.x(), layouts.at(field->vLayoutIndex).pos); | - | ||||||||||||
| 1551 | - | |||||||||||||
| 1552 | - | |||||||||||||
| 1553 | - | |||||||||||||
| 1554 | - | |||||||||||||
| 1555 | - | |||||||||||||
| 1556 | - | |||||||||||||
| 1557 | if (field->maxSize.isValid()) | - | ||||||||||||
| 1558 | sz = sz.boundedTo(field->maxSize); | - | ||||||||||||
| 1559 | - | |||||||||||||
| 1560 | field->setGeometry(QStyle::visualRect(layoutDirection, rect, QRect(p, sz))); | - | ||||||||||||
| 1561 | } | - | ||||||||||||
| 1562 | } | - | ||||||||||||
| 1563 | } | - | ||||||||||||
| 1564 | void QFormLayout::setWidget(int row, ItemRole role, QWidget *widget) | - | ||||||||||||
| 1565 | { | - | ||||||||||||
| 1566 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1567 | int rowCnt = rowCount(); | - | ||||||||||||
| 1568 | if (row >= rowCnt) | - | ||||||||||||
| 1569 | d->insertRows(rowCnt, row - rowCnt + 1); | - | ||||||||||||
| 1570 | d->setWidget(row, role, widget); | - | ||||||||||||
| 1571 | } | - | ||||||||||||
| 1572 | void QFormLayout::setLayout(int row, ItemRole role, QLayout *layout) | - | ||||||||||||
| 1573 | { | - | ||||||||||||
| 1574 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1575 | int rowCnt = rowCount(); | - | ||||||||||||
| 1576 | if (row >= rowCnt) | - | ||||||||||||
| 1577 | d->insertRows(rowCnt, row - rowCnt + 1); | - | ||||||||||||
| 1578 | d->setLayout(row, role, layout); | - | ||||||||||||
| 1579 | } | - | ||||||||||||
| 1580 | void QFormLayout::setItem(int row, ItemRole role, QLayoutItem *item) | - | ||||||||||||
| 1581 | { | - | ||||||||||||
| 1582 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1583 | int rowCnt = rowCount(); | - | ||||||||||||
| 1584 | if (row >= rowCnt) | - | ||||||||||||
| 1585 | d->insertRows(rowCnt, row - rowCnt + 1); | - | ||||||||||||
| 1586 | d->setItem(row, role, item); | - | ||||||||||||
| 1587 | } | - | ||||||||||||
| 1588 | - | |||||||||||||
| 1589 | - | |||||||||||||
| 1590 | - | |||||||||||||
| 1591 | - | |||||||||||||
| 1592 | - | |||||||||||||
| 1593 | void QFormLayout::resetFieldGrowthPolicy() | - | ||||||||||||
| 1594 | { | - | ||||||||||||
| 1595 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1596 | d->fieldGrowthPolicy = DefaultFieldGrowthPolicy; | - | ||||||||||||
| 1597 | } | - | ||||||||||||
| 1598 | - | |||||||||||||
| 1599 | - | |||||||||||||
| 1600 | - | |||||||||||||
| 1601 | - | |||||||||||||
| 1602 | - | |||||||||||||
| 1603 | void QFormLayout::resetRowWrapPolicy() | - | ||||||||||||
| 1604 | { | - | ||||||||||||
| 1605 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1606 | d->rowWrapPolicy = DefaultRowWrapPolicy; | - | ||||||||||||
| 1607 | } | - | ||||||||||||
| 1608 | - | |||||||||||||
| 1609 | - | |||||||||||||
| 1610 | - | |||||||||||||
| 1611 | - | |||||||||||||
| 1612 | - | |||||||||||||
| 1613 | void QFormLayout::resetFormAlignment() | - | ||||||||||||
| 1614 | { | - | ||||||||||||
| 1615 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1616 | d->formAlignment = 0; | - | ||||||||||||
| 1617 | } | - | ||||||||||||
| 1618 | - | |||||||||||||
| 1619 | - | |||||||||||||
| 1620 | - | |||||||||||||
| 1621 | - | |||||||||||||
| 1622 | - | |||||||||||||
| 1623 | void QFormLayout::resetLabelAlignment() | - | ||||||||||||
| 1624 | { | - | ||||||||||||
| 1625 | QFormLayoutPrivate * const d = d_func(); | - | ||||||||||||
| 1626 | d->labelAlignment = 0; | - | ||||||||||||
| 1627 | } | - | ||||||||||||
| 1628 | - | |||||||||||||
| 1629 | - | |||||||||||||
| Switch to Source code | Preprocessed file |