Qt 4.8
Public Types | Public Functions | Public Variables | Properties | List of all members
QDockWidgetLayout Class Reference

#include <qdockwidget_p.h>

Inheritance diagram for QDockWidgetLayout:
QLayout QObject QLayoutItem

Public Types

enum  Role {
  Content, CloseButton, FloatButton, TitleBar,
  RoleCount
}
 
- Public Types inherited from QLayout
enum  SizeConstraint {
  SetDefaultConstraint, SetNoConstraint, SetMinimumSize, SetFixedSize,
  SetMaximumSize, SetMinAndMaxSize
}
 The possible values are: More...
 

Public Functions

void addItem (QLayoutItem *item)
 Implemented in subclasses to add an item. More...
 
int count () const
 Must be implemented in subclasses to return the number of items in the layout. More...
 
QLayoutItemitemAt (int index) const
 Must be implemented in subclasses to return the layout item at index. More...
 
QLayoutItemitemForRole (Role r) const
 
QSize maximumSize () const
 Returns the maximum size of this layout. More...
 
QSize minimumSize () const
 Returns the minimum size of this layout. More...
 
int minimumTitleWidth () const
 
bool nativeWindowDeco () const
 
bool nativeWindowDeco (bool floating) const
 
 QDockWidgetLayout (QWidget *parent=0)
 
void setGeometry (const QRect &r)
 Reimplemented Function More...
 
void setVerticalTitleBar (bool b)
 
void setWidgetForRole (Role r, QWidget *w)
 
QSize sizeFromContent (const QSize &content, bool floating) const
 
QSize sizeHint () const
 Implemented in subclasses to return the preferred size of this item. More...
 
QLayoutItemtakeAt (int index)
 Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. More...
 
QRect titleArea () const
 
int titleHeight () const
 
void updateMaxSize ()
 
QWidgetwidgetForRole (Role r) const
 
 ~QDockWidgetLayout ()
 
- Public Functions inherited from QLayout
bool activate ()
 Redoes the layout for parentWidget() if necessary. More...
 
void addWidget (QWidget *w)
 Adds widget w to this layout in a manner specific to the layout. More...
 
QMargins contentsMargins () const
 Returns the margins used around the layout. More...
 
QRect contentsRect () const
 Returns the layout's geometry() rectangle, but taking into account the contents margins. More...
 
Qt::Orientations expandingDirections () const
 Returns whether this layout can make use of more space than sizeHint(). More...
 
QRect geometry () const
 Reimplemented Function More...
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
virtual int indexOf (QWidget *) const
 Searches for widget widget in this layout (not including child layouts). More...
 
void invalidate ()
 Reimplemented Function More...
 
bool isEmpty () const
 Reimplemented Function More...
 
bool isEnabled () const
 Returns true if the layout is enabled; otherwise returns false. More...
 
QLayoutlayout ()
 Reimplemented Function More...
 
int margin () const
 
QWidgetmenuBar () const
 Returns the menu bar set for this layout, or 0 if no menu bar is set. More...
 
QWidgetparentWidget () const
 Returns the parent widget of this layout, or 0 if this layout is not installed on any widget. More...
 
 QLayout (QWidget *parent)
 Constructs a new top-level QLayout, with parent parent. More...
 
 QLayout ()
 Constructs a new child QLayout. More...
 
void removeItem (QLayoutItem *)
 Removes the layout item item from the layout. More...
 
void removeWidget (QWidget *w)
 Removes the widget widget from the layout. More...
 
bool setAlignment (QWidget *w, Qt::Alignment alignment)
 Sets the alignment for widget w to alignment and returns true if w is found in this layout (not including child layouts); otherwise returns false. More...
 
bool setAlignment (QLayout *l, Qt::Alignment alignment)
 Sets the alignment for the layout l to alignment and returns true if l is found in this layout (not including child layouts); otherwise returns false. More...
 
void setContentsMargins (int left, int top, int right, int bottom)
 Sets the left, top, right, and bottom margins to use around the layout. More...
 
void setContentsMargins (const QMargins &margins)
 Sets the margins to use around the layout. More...
 
void setEnabled (bool)
 Enables this layout if enable is true, otherwise disables it. More...
 
void setMargin (int)
 
void setMenuBar (QWidget *w)
 Tells the geometry manager to place the menu bar widget at the top of parentWidget(), outside QWidget::contentsMargins(). More...
 
void setSizeConstraint (SizeConstraint)
 
void setSpacing (int)
 
SizeConstraint sizeConstraint () const
 
int spacing () const
 
int totalHeightForWidth (int w) const
 Also takes contentsMargins and menu bar into account. More...
 
QSize totalMaximumSize () const
 Also takes contentsMargins and menu bar into account. More...
 
QSize totalMinimumSize () const
 Also takes contentsMargins and menu bar into account. More...
 
QSize totalSizeHint () const
 Also takes contentsMargins and menu bar into account. More...
 
void update ()
 Updates the layout for parentWidget(). More...
 
 ~QLayout ()
 Destroys the layout, deleting all child layouts. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QLayoutItem
Qt::Alignment alignment () const
 Returns the alignment of this item. More...
 
QSizePolicy::ControlTypes controlTypes () const
 Returns the control type(s) for the layout item. More...
 
virtual bool hasHeightForWidth () const
 Returns true if this layout's preferred height depends on its width; otherwise returns false. More...
 
virtual int heightForWidth (int) const
 Returns the preferred height for this layout item, given the width w. More...
 
virtual int minimumHeightForWidth (int) const
 Returns the minimum height this widget needs for the given width, w. More...
 
 QLayoutItem (Qt::Alignment alignment=0)
 Constructs a layout item with an alignment. More...
 
void setAlignment (Qt::Alignment a)
 Sets the alignment of this item to alignment. More...
 
virtual QSpacerItemspacerItem ()
 If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise 0 is returned. More...
 
virtual QWidgetwidget ()
 If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned. More...
 
virtual ~QLayoutItem ()
 Destroys the QLayoutItem. More...
 

Public Variables

bool verticalTitleBar
 

Properties

QRect _titleArea
 
QVector< QLayoutItem * > item_list
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QLayout
static QSize closestAcceptableSize (const QWidget *w, const QSize &s)
 Returns a size that satisfies all size constraints on widget, including heightForWidth() and that is as close as possible to size. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QLayout
void addChildLayout (QLayout *l)
 This function is called from addLayout() or insertLayout() functions in subclasses to add layout l as a sub-layout. More...
 
void addChildWidget (QWidget *w)
 This function is called from addWidget() functions in subclasses to add w as a managed widget of a layout. More...
 
bool adoptLayout (QLayout *layout)
 
QRect alignmentRect (const QRect &) const
 Returns the rectangle that should be covered when the geometry of this layout is set to r, provided that this layout supports setAlignment(). More...
 
void childEvent (QChildEvent *e)
 Reimplemented Function More...
 
 QLayout (QLayoutPrivate &d, QLayout *, QWidget *)
 
void widgetEvent (QEvent *)
 Performs child widget layout when the parent widget is resized. More...
 
- Protected Functions inherited from QObject
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Variables inherited from QLayoutItem
Qt::Alignment align
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 131 of file qdockwidget_p.h.

Enumerations

◆ Role

Constructors and Destructors

◆ QDockWidgetLayout()

QDockWidgetLayout::QDockWidgetLayout ( QWidget parent = 0)

Definition at line 193 of file qdockwidget.cpp.

194  : QLayout(parent), verticalTitleBar(false), item_list(RoleCount, 0)
195 {
196 }
QLayout()
Constructs a new child QLayout.
Definition: qlayout.cpp:127
QVector< QLayoutItem * > item_list

◆ ~QDockWidgetLayout()

QDockWidgetLayout::~QDockWidgetLayout ( )

Definition at line 198 of file qdockwidget.cpp.

199 {
201 }
QVector< QLayoutItem * > item_list
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ addItem()

void QDockWidgetLayout::addItem ( QLayoutItem item)
virtual

Implemented in subclasses to add an item.

How it is added is specific to each subclass.

This function is not usually called in application code. To add a widget to a layout, use the addWidget() function; to add a child layout, use the addLayout() function provided by the relevant QLayout subclass.

Note: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.

See also
addWidget(), QBoxLayout::addLayout(), QGridLayout::addLayout()

Implements QLayout.

Definition at line 219 of file qdockwidget.cpp.

220 {
221  qWarning() << "QDockWidgetLayout::addItem(): please use QDockWidgetLayout::setWidget()";
222  return;
223 }
Q_CORE_EXPORT void qWarning(const char *,...)

◆ count()

int QDockWidgetLayout::count ( ) const
virtual

Must be implemented in subclasses to return the number of items in the layout.

See also
itemAt()

Implements QLayout.

Definition at line 255 of file qdockwidget.cpp.

256 {
257  int result = 0;
258  for (int i = 0; i < item_list.count(); ++i) {
259  if (item_list.at(i))
260  ++result;
261  }
262  return result;
263 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< QLayoutItem * > item_list
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350

◆ itemAt()

QLayoutItem * QDockWidgetLayout::itemAt ( int  index) const
virtual

Must be implemented in subclasses to return the layout item at index.

If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.

static void paintLayout(QPainter *painter, QLayoutItem *item)
{
QLayout *layout = item->layout();
if (layout) {
for (int i = 0; i < layout->count(); ++i)
paintLayout(painter, layout->itemAt(i));
}
painter->drawRect(item->geometry());
}
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if (layout())
paintLayout(&painter, layout());
}
See also
count(), takeAt()

Implements QLayout.

Definition at line 225 of file qdockwidget.cpp.

226 {
227  int cnt = 0;
228  for (int i = 0; i < item_list.count(); ++i) {
229  QLayoutItem *item = item_list.at(i);
230  if (item == 0)
231  continue;
232  if (index == cnt++)
233  return item;
234  }
235  return 0;
236 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
QVector< QLayoutItem * > item_list
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
quint16 index

◆ itemForRole()

QLayoutItem * QDockWidgetLayout::itemForRole ( Role  r) const

Definition at line 371 of file qdockwidget.cpp.

372 {
373  return item_list.at(r);
374 }
QVector< QLayoutItem * > item_list
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350

◆ maximumSize()

QSize QDockWidgetLayout::maximumSize ( ) const
virtual

Returns the maximum size of this layout.

This is the largest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar().

The default implementation allows unlimited resizing.

Reimplemented from QLayout.

Definition at line 343 of file qdockwidget.cpp.

344 {
345  if (item_list[Content] != 0) {
346  const QSize content = item_list[Content]->maximumSize();
347  return sizeFromContent(content, parentWidget()->isWindow());
348  } else {
349  return parentWidget()->maximumSize();
350  }
351 
352 }
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
QSize sizeFromContent(const QSize &content, bool floating) const
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
QVector< QLayoutItem * > item_list
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ minimumSize()

QSize QDockWidgetLayout::minimumSize ( ) const
virtual

Returns the minimum size of this layout.

This is the smallest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar().

The default implementation allows unlimited resizing.

Reimplemented from QLayout.

Definition at line 354 of file qdockwidget.cpp.

355 {
357 
358  QSize content(0, 0);
359  if (item_list[Content] != 0)
360  content = item_list[Content]->minimumSize();
361 
362  return sizeFromContent(content, w->isFloating());
363 }
QSize sizeFromContent(const QSize &content, bool floating) const
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
QVector< QLayoutItem * > item_list
bool isFloating() const
Definition: qdockwidget.h:96
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ minimumTitleWidth()

int QDockWidgetLayout::minimumTitleWidth ( ) const

Definition at line 405 of file qdockwidget.cpp.

Referenced by sizeFromContent().

406 {
408 
409  if (QWidget *title = widgetForRole(TitleBar))
410  return pick(verticalTitleBar, title->minimumSizeHint());
411 
412  QSize closeSize(0, 0);
413  QSize floatSize(0, 0);
415  if (QLayoutItem *item = item_list[CloseButton])
416  closeSize = item->widget()->sizeHint();
417  }
419  if (QLayoutItem *item = item_list[FloatButton])
420  floatSize = item->widget()->sizeHint();
421  }
422 
423  int titleHeight = this->titleHeight();
424 
425  int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
426  int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q);
427 
428  return pick(verticalTitleBar, closeSize)
429  + pick(verticalTitleBar, floatSize)
430  + titleHeight + 2*fw + 3*mw;
431 }
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QStyle * style() const
Definition: qwidget.cpp:2742
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
QVector< QLayoutItem * > item_list
int titleHeight() const
static bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
Definition: qdockwidget.cpp:74
static int pick(bool vertical, const QSize &size)
QWidget * widgetForRole(Role r) const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ nativeWindowDeco() [1/2]

bool QDockWidgetLayout::nativeWindowDeco ( ) const

◆ nativeWindowDeco() [2/2]

bool QDockWidgetLayout::nativeWindowDeco ( bool  floating) const

Definition at line 208 of file qdockwidget.cpp.

209 {
210 #if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_WINCE)
211  Q_UNUSED(floating);
212  return false;
213 #else
214  return floating && item_list[QDockWidgetLayout::TitleBar] == 0;
215 #endif
216 }
QVector< QLayoutItem * > item_list
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setGeometry()

void QDockWidgetLayout::setGeometry ( const QRect r)
virtual

Reimplemented Function

Reimplemented from QLayout.

Definition at line 464 of file qdockwidget.cpp.

465 {
467 
468  bool nativeDeco = nativeWindowDeco();
469 
470  int fw = q->isFloating() && !nativeDeco
472  : 0;
473 
474  if (nativeDeco) {
475  if (QLayoutItem *item = item_list[Content])
476  item->setGeometry(geometry);
477  } else {
478  int titleHeight = this->titleHeight();
479 
480  if (verticalTitleBar) {
481  _titleArea = QRect(QPoint(fw, fw),
482  QSize(titleHeight, geometry.height() - (fw * 2)));
483  } else {
484  _titleArea = QRect(QPoint(fw, fw),
485  QSize(geometry.width() - (fw * 2), titleHeight));
486  }
487 
488  if (QLayoutItem *item = item_list[TitleBar]) {
489  item->setGeometry(_titleArea);
490  } else {
492  q->initStyleOption(&opt);
493 
494  if (QLayoutItem *item = item_list[CloseButton]) {
495  if (!item->isEmpty()) {
496  QRect r = q->style()
498  &opt, q);
499  if (!r.isNull())
500  item->setGeometry(r);
501  }
502  }
503 
504  if (QLayoutItem *item = item_list[FloatButton]) {
505  if (!item->isEmpty()) {
506  QRect r = q->style()
508  &opt, q);
509  if (!r.isNull())
510  item->setGeometry(r);
511  }
512  }
513  }
514 
515  if (QLayoutItem *item = item_list[Content]) {
516  QRect r = geometry;
517  if (verticalTitleBar) {
518  r.setLeft(_titleArea.right() + 1);
519  r.adjust(0, fw, -fw, -fw);
520  } else {
521  r.setTop(_titleArea.bottom() + 1);
522  r.adjust(fw, 0, -fw, -fw);
523  }
524  item->setGeometry(r);
525  }
526  }
527 }
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QStyle * style() const
Definition: qwidget.cpp:2742
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
QVector< QLayoutItem * > item_list
int titleHeight() const
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
bool nativeWindowDeco() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isFloating() const
Definition: qdockwidget.h:96
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QRect geometry() const
Reimplemented Function
Definition: qlayout.cpp:664
void initStyleOption(QStyleOptionDockWidget *option) const
Initialize option with the values from this QDockWidget.

◆ setVerticalTitleBar()

void QDockWidgetLayout::setVerticalTitleBar ( bool  b)

Definition at line 529 of file qdockwidget.cpp.

Referenced by QDockWidget::setFeatures().

530 {
531  if (b == verticalTitleBar)
532  return;
533  verticalTitleBar = b;
534  invalidate();
535  parentWidget()->update();
536 }
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883

◆ setWidgetForRole()

void QDockWidgetLayout::setWidgetForRole ( Role  r,
QWidget w 
)

Definition at line 376 of file qdockwidget.cpp.

Referenced by QDockWidgetPrivate::init(), QDockWidget::setTitleBarWidget(), and QDockWidget::setWidget().

377 {
378  QWidget *old = widgetForRole(r);
379  if (old != 0) {
380  old->hide();
381  removeWidget(old);
382  }
383 
384  if (w != 0) {
385  addChildWidget(w);
386  item_list[r] = new QWidgetItemV2(w);
387  w->show();
388  } else {
389  item_list[r] = 0;
390  }
391 
392  invalidate();
393 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
QVector< QLayoutItem * > item_list
void show()
Shows the widget and its child widgets.
void hide()
Hides the widget.
Definition: qwidget.h:501
void addChildWidget(QWidget *w)
This function is called from addWidget() functions in subclasses to add w as a managed widget of a la...
Definition: qlayout.cpp:1045
QWidget * widgetForRole(Role r) const
void removeWidget(QWidget *w)
Removes the widget widget from the layout.
Definition: qlayout.cpp:1516

◆ sizeFromContent()

QSize QDockWidgetLayout::sizeFromContent ( const QSize content,
bool  floating 
) const

Definition at line 265 of file qdockwidget.cpp.

Referenced by maximumSize(), QDockWidgetItem::maximumSize(), minimumSize(), QDockWidgetItem::minimumSize(), sizeHint(), and QDockWidgetItem::sizeHint().

266 {
267  QSize result = content;
268 
269  if (verticalTitleBar) {
270  result.setHeight(qMax(result.height(), minimumTitleWidth()));
271  result.setWidth(qMax(content.width(), 0));
272  } else {
273  result.setHeight(qMax(result.height(), 0));
274  result.setWidth(qMax(content.width(), minimumTitleWidth()));
275  }
276 
278  const bool nativeDeco = nativeWindowDeco(floating);
279 
280  int fw = floating && !nativeDeco
282  : 0;
283 
284  const int th = titleHeight();
285  if (!nativeDeco) {
286  if (verticalTitleBar)
287  result += QSize(th + 2*fw, 2*fw);
288  else
289  result += QSize(2*fw, th + 2*fw);
290  }
291 
292  result.setHeight(qMin(result.height(), (int) QWIDGETSIZE_MAX));
293  result.setWidth(qMin(result.width(), (int) QWIDGETSIZE_MAX));
294 
295  if (content.width() < 0)
296  result.setWidth(-1);
297  if (content.height() < 0)
298  result.setHeight(-1);
299 
300  int left, top, right, bottom;
301  w->getContentsMargins(&left, &top, &right, &bottom);
302  //we need to substract the contents margin (it will be added by the caller)
303  QSize min = w->minimumSize() - QSize(left + right, top + bottom);
304  QSize max = w->maximumSize() - QSize(left + right, top + bottom);
305 
306  /* A floating dockwidget will automatically get its minimumSize set to the layout's
307  minimum size + deco. We're *not* interested in this, we only take minimumSize()
308  into account if the user set it herself. Otherwise we end up expanding the result
309  of a calculation for a non-floating dock widget to a floating dock widget's
310  minimum size + window decorations. */
311 
312  uint explicitMin = 0;
313  uint explicitMax = 0;
314  if (w->d_func()->extra != 0) {
315  explicitMin = w->d_func()->extra->explicitMinSize;
316  explicitMax = w->d_func()->extra->explicitMaxSize;
317  }
318 
319  if (!(explicitMin & Qt::Horizontal) || min.width() == 0)
320  min.setWidth(-1);
321  if (!(explicitMin & Qt::Vertical) || min.height() == 0)
322  min.setHeight(-1);
323 
324  if (!(explicitMax & Qt::Horizontal))
326  if (!(explicitMax & Qt::Vertical))
328 
329  return result.boundedTo(max).expandedTo(min);
330 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
int width() const
Returns the width.
Definition: qsize.h:126
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
unsigned int uint
Definition: qglobal.h:996
int titleHeight() const
int minimumTitleWidth() const
bool nativeWindowDeco() const
QSize maximumSize() const
int height() const
Returns the height.
Definition: qsize.h:129
QSize minimumSize() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ sizeHint()

QSize QDockWidgetLayout::sizeHint ( ) const
virtual

Implemented in subclasses to return the preferred size of this item.

Implements QLayoutItem.

Definition at line 332 of file qdockwidget.cpp.

333 {
335 
336  QSize content(-1, -1);
337  if (item_list[Content] != 0)
338  content = item_list[Content]->sizeHint();
339 
340  return sizeFromContent(content, w->isFloating());
341 }
QSize sizeFromContent(const QSize &content, bool floating) const
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
QVector< QLayoutItem * > item_list
bool isFloating() const
Definition: qdockwidget.h:96
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ takeAt()

QLayoutItem * QDockWidgetLayout::takeAt ( int  index)
virtual

Must be implemented in subclasses to remove the layout item at index from the layout, and return the item.

If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is removed, other items will be renumbered.

The following code fragment shows a safe way to remove all items from a layout:

QLayoutItem *child;
while ((child = layout->takeAt(0)) != 0) {
...
delete child;
}
See also
itemAt(), count()

Implements QLayout.

Definition at line 238 of file qdockwidget.cpp.

239 {
240  int j = 0;
241  for (int i = 0; i < item_list.count(); ++i) {
242  QLayoutItem *item = item_list.at(i);
243  if (item == 0)
244  continue;
245  if (index == j) {
246  item_list[i] = 0;
247  invalidate();
248  return item;
249  }
250  ++j;
251  }
252  return 0;
253 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
QVector< QLayoutItem * > item_list
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
quint16 index

◆ titleArea()

QRect QDockWidgetLayout::titleArea ( ) const
inline

◆ titleHeight()

int QDockWidgetLayout::titleHeight ( ) const

Definition at line 433 of file qdockwidget.cpp.

Referenced by dockedGeometry(), minimumTitleWidth(), QMainWindowLayout::plug(), setGeometry(), sizeFromContent(), and QDockWidgetPrivate::unplug().

434 {
436 
437  if (QWidget *title = widgetForRole(TitleBar))
438  return perp(verticalTitleBar, title->sizeHint());
439 
440  QSize closeSize(0, 0);
441  QSize floatSize(0, 0);
442  if (QLayoutItem *item = item_list[CloseButton])
443  closeSize = item->widget()->sizeHint();
444  if (QLayoutItem *item = item_list[FloatButton])
445  floatSize = item->widget()->sizeHint();
446 
447  int buttonHeight = qMax(perp(verticalTitleBar, closeSize),
448  perp(verticalTitleBar, floatSize));
449 
450  QFontMetrics titleFontMetrics = q->fontMetrics();
451 #ifdef Q_WS_MAC
452  if (qobject_cast<QMacStyle *>(q->style())) {
453  //### this breaks on proxy styles. (But is this code still called?)
454  QFont font = qt_app_fonts_hash()->value("QToolButton", q->font());
455  titleFontMetrics = QFontMetrics(font);
456  }
457 #endif
458 
459  int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
460 
461  return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw);
462 }
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-l...
Definition: qdockwidget.h:60
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
T * qobject_cast(QObject *object)
Definition: qobject.h:375
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
QWidget * parentWidget() const
Returns the parent widget of this layout, or 0 if this layout is not installed on any widget...
Definition: qlayout.cpp:616
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
QVector< QLayoutItem * > item_list
FontHash * qt_app_fonts_hash()
static int perp(bool vertical, const QSize &size)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QWidget * widgetForRole(Role r) const
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int height() const
Returns the height of the font.

◆ updateMaxSize()

void QDockWidgetLayout::updateMaxSize ( )

◆ widgetForRole()

QWidget * QDockWidgetLayout::widgetForRole ( Role  r) const

Definition at line 365 of file qdockwidget.cpp.

Referenced by QAccessibleTitleBar::childCount(), QAccessibleTitleBar::doAction(), QDockWidgetPrivate::endDrag(), minimumTitleWidth(), QAccessibleTitleBar::navigate(), QDockWidget::paintEvent(), QAccessibleTitleBar::rect(), setWidgetForRole(), QAccessibleTitleBar::state(), QDockWidget::titleBarWidget(), titleHeight(), QDockWidgetPrivate::updateButtons(), and QDockWidget::widget().

366 {
367  QLayoutItem *item = item_list.at(r);
368  return item == 0 ? 0 : item->widget();
369 }
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
QVector< QLayoutItem * > item_list
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.

Properties

◆ _titleArea

QRect QDockWidgetLayout::_titleArea
private

Definition at line 169 of file qdockwidget_p.h.

Referenced by setGeometry().

◆ item_list

QVector<QLayoutItem*> QDockWidgetLayout::item_list
private

◆ verticalTitleBar

bool QDockWidgetLayout::verticalTitleBar

The documentation for this class was generated from the following files: