Qt 4.8
Classes | Enumerations | Functions | Variables
qformlayout.cpp File Reference
#include "qapplication.h"
#include "qdebug.h"
#include "qformlayout.h"
#include "qlabel.h"
#include "qlayout_p.h"
#include "qlayoutengine_p.h"
#include "qrect.h"
#include "qvector.h"
#include "qwidget.h"

Go to the source code of this file.

Classes

struct  QFormLayoutItem
 
class  QFormLayoutPrivate
 

Enumerations

enum  { ColumnCount = 2 }
 

Functions

static Qt::Alignment fixedAlignment (Qt::Alignment alignment, Qt::LayoutDirection layoutDirection)
 
static void initLayoutStruct (QLayoutStruct &sl, QFormLayoutItem *item)
 
static int spacingHelper (QWidget *parent, QStyle *style, int userVSpacing, bool recalculate, QFormLayoutItem *item1, QFormLayoutItem *item2, QFormLayoutItem *prevItem1, QFormLayoutItem *prevItem2)
 
static int storageIndexFromLayoutItem (const QFormLayoutPrivate::ItemMatrix &m, QFormLayoutItem *item)
 
static void updateFormLayoutItem (QFormLayoutItem *item, int userVSpacing, QFormLayout::FieldGrowthPolicy fieldGrowthPolicy, bool fullRow)
 

Variables

const uint DefaultFieldGrowthPolicy = 255
 
const uint DefaultRowWrapPolicy = 255
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ColumnCount 

Definition at line 130 of file qformlayout.cpp.

130 { ColumnCount = 2 };

Function Documentation

◆ fixedAlignment()

static Qt::Alignment fixedAlignment ( Qt::Alignment  alignment,
Qt::LayoutDirection  layoutDirection 
)
static

Definition at line 260 of file qformlayout.cpp.

Referenced by QFormLayoutPrivate::arrangeWidgets().

261 {
262  if (layoutDirection == Qt::RightToLeft && alignment & Qt::AlignAbsolute) {
263  // swap left and right, and eliminate absolute flag
264  return Qt::Alignment((alignment & ~(Qt::AlignLeft | Qt::AlignRight | Qt::AlignAbsolute))
265  | ((alignment & Qt::AlignRight) ? Qt::AlignLeft : 0)
266  | ((alignment & Qt::AlignLeft) ? Qt::AlignRight : 0));
267  } else {
268  return alignment & ~Qt::AlignAbsolute;
269  }
270 }
Definition: qnamespace.h:54

◆ initLayoutStruct()

static void initLayoutStruct ( QLayoutStruct sl,
QFormLayoutItem item 
)
inlinestatic

Definition at line 646 of file qformlayout.cpp.

Referenced by QFormLayoutPrivate::setupVerticalLayoutData().

647 {
648  sl.init(item->vStretch(), item->minSize.height());
649  sl.sizeHint = item->sizeHint.height();
650  sl.maximumSize = item->maxSize.height();
651  sl.expansive = (item->expandingDirections() & Qt::Vertical);
652  sl.empty = false;
653 }
void init(int stretchFactor=0, int minSize=0)
int vStretch() const
int height() const
Returns the height.
Definition: qsize.h:129
Qt::Orientations expandingDirections() const

◆ spacingHelper()

static int spacingHelper ( QWidget parent,
QStyle style,
int  userVSpacing,
bool  recalculate,
QFormLayoutItem item1,
QFormLayoutItem item2,
QFormLayoutItem prevItem1,
QFormLayoutItem prevItem2 
)
inlinestatic

Definition at line 605 of file qformlayout.cpp.

Referenced by QFormLayoutPrivate::setupVerticalLayoutData().

606 {
607  int spacing = userVSpacing;
608  if (spacing < 0) {
609  if (!recalculate) {
610  if (item1)
611  spacing = item1->vSpace;
612  if (item2)
613  spacing = qMax(spacing, item2->vSpace);
614  } else {
615  if (style && prevItem1) {
616  QSizePolicy::ControlTypes itemtypes =
617  QSizePolicy::ControlTypes(item1 ? item1->controlTypes() : QSizePolicy::DefaultType);
618  int spacing2 = 0;
619 
620  spacing = style->combinedLayoutSpacing(itemtypes, prevItem1->controlTypes(), Qt::Vertical, 0, parent);
621 
622  // At most of one of item2 and prevItem2 will be nonnull
623  if (item2)
624  spacing2 = style->combinedLayoutSpacing(item2->controlTypes(), prevItem1->controlTypes(), Qt::Vertical, 0, parent);
625  else if (prevItem2)
626  spacing2 = style->combinedLayoutSpacing(itemtypes, prevItem2->controlTypes(), Qt::Vertical, 0, parent);
627 
628  spacing = qMax(spacing, spacing2);
629  }
630  }
631  } else {
632  if (prevItem1) {
633  QWidget *wid = prevItem1->item->widget();
634  if (wid)
635  spacing = qMax(spacing, prevItem1->geometry().top() - wid->geometry().top() );
636  }
637  if (prevItem2) {
638  QWidget *wid = prevItem2->item->widget();
639  if (wid)
640  spacing = qMax(spacing, prevItem2->geometry().top() - wid->geometry().top() );
641  }
642  }
643  return spacing;
644 }
QSizePolicy::ControlTypes controlTypes() const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect geometry() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
QLayoutItem * item
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, QSizePolicy::ControlTypes controls2, Qt::Orientation orientation, QStyleOption *option=0, QWidget *widget=0) const
Returns the spacing that should be used between controls1 and controls2 in a layout.
Definition: qstyle.cpp:2438

◆ storageIndexFromLayoutItem()

static int storageIndexFromLayoutItem ( const QFormLayoutPrivate::ItemMatrix m,
QFormLayoutItem item 
)
static

Definition at line 272 of file qformlayout.cpp.

Referenced by QFormLayout::getItemPosition(), and QFormLayout::takeAt().

274 {
275  if (item) {
276  return m.storage().indexOf(item);
277  } else {
278  return -1;
279  }
280 }

◆ updateFormLayoutItem()

static void updateFormLayoutItem ( QFormLayoutItem item,
int  userVSpacing,
QFormLayout::FieldGrowthPolicy  fieldGrowthPolicy,
bool  fullRow 
)
static

Definition at line 282 of file qformlayout.cpp.

Referenced by QFormLayoutPrivate::updateSizes().

285 {
286  item->minSize = item->item->minimumSize();
287  item->sizeHint = item->item->sizeHint();
288  item->maxSize = item->item->maximumSize();
289 
290  if (!fullRow && (fieldGrowthPolicy == QFormLayout::FieldsStayAtSizeHint
291  || (fieldGrowthPolicy == QFormLayout::ExpandingFieldsGrow
292  && !(item->item->expandingDirections() & Qt::Horizontal))))
293  item->maxSize.setWidth(item->sizeHint.width());
294 
295  item->isHfw = item->item->hasHeightForWidth();
296  item->vSpace = userVSpacing;
297 }
virtual Qt::Orientations expandingDirections() const =0
Returns whether this layout item can make use of more space than sizeHint().
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
int width() const
Returns the width.
Definition: qsize.h:126
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
virtual QSize maximumSize() const =0
Implemented in subclasses to return the maximum size of this item.
QLayoutItem * item

Variable Documentation

◆ DefaultFieldGrowthPolicy

const uint DefaultFieldGrowthPolicy = 255

Definition at line 127 of file qformlayout.cpp.

Referenced by QFormLayout::resetFieldGrowthPolicy().

◆ DefaultRowWrapPolicy

const uint DefaultRowWrapPolicy = 255

Definition at line 128 of file qformlayout.cpp.

Referenced by QFormLayout::resetRowWrapPolicy().