Qt 4.8
Public Slots | Public Functions | Public Variables | Private Functions | Properties | List of all members
QToolBarLayout Class Reference

#include <qtoolbarlayout_p.h>

Inheritance diagram for QToolBarLayout:
QLayout QObject QLayoutItem

Public Slots

void setExpanded (bool b)
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

void addItem (QLayoutItem *item)
 Implemented in subclasses to add an item. More...
 
void checkUsePopupMenu ()
 
int count () const
 Must be implemented in subclasses to return the number of items in the layout. More...
 
QSize expandedSize (const QSize &size) const
 
Qt::Orientations expandingDirections () const
 Returns whether this layout can make use of more space than sizeHint(). More...
 
bool hasExpandFlag () const
 
int indexOf (QAction *action) const
 
int indexOf (QWidget *widget) const
 Searches for widget widget in this layout (not including child layouts). More...
 
void insertAction (int index, QAction *action)
 
void invalidate ()
 Reimplemented Function More...
 
bool isEmpty () const
 Reimplemented Function More...
 
QLayoutItemitemAt (int index) const
 Must be implemented in subclasses to return the layout item at index. More...
 
bool layoutActions (const QSize &size)
 
QSize minimumSize () const
 Returns the minimum size of this layout. More...
 
bool movable () const
 
 QToolBarLayout (QWidget *parent=0)
 
void setGeometry (const QRect &r)
 Reimplemented Function More...
 
void setUsePopupMenu (bool set)
 
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...
 
void updateMarginAndSpacing ()
 
 ~QToolBarLayout ()
 
- 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...
 
QRect geometry () const
 Reimplemented Function More...
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
bool isEnabled () const
 Returns true if the layout is enabled; otherwise returns false. More...
 
QLayoutlayout ()
 Reimplemented Function More...
 
int margin () const
 
QSize maximumSize () const
 Returns the maximum size of this layout. More...
 
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 animating
 
bool expanded
 

Private Functions

QToolBarItemcreateItem (QAction *action)
 
void updateGeomArray () const
 

Properties

bool dirty
 
bool empty
 
bool expandFlag
 
bool expanding
 
QToolBarExtensionextension
 
QVector< QLayoutStructgeomArray
 
QRect handRect
 
QSize hint
 
QList< QToolBarItem * > items
 
QSize minSize
 
QMenupopupMenu
 

Additional Inherited Members

- Public Types inherited from QLayout
enum  SizeConstraint {
  SetDefaultConstraint, SetNoConstraint, SetMinimumSize, SetFixedSize,
  SetMaximumSize, SetMinAndMaxSize
}
 The possible values are: 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 78 of file qtoolbarlayout_p.h.

Constructors and Destructors

◆ QToolBarLayout()

QToolBarLayout::QToolBarLayout ( QWidget parent = 0)

Definition at line 81 of file qtoolbarlayout.cpp.

82  : QLayout(parent), expanded(false), animating(false), dirty(true),
83  expanding(false), empty(true), expandFlag(false), popupMenu(0)
84 {
86  if (!tb)
87  return;
88 
89  extension = new QToolBarExtension(tb);
91  extension->hide();
92  QObject::connect(tb, SIGNAL(orientationChanged(Qt::Orientation)),
93  extension, SLOT(setOrientation(Qt::Orientation)));
94 
95  setUsePopupMenu(qobject_cast<QMainWindow*>(tb->parentWidget()) == 0);
96 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
#define SLOT(a)
Definition: qobjectdefs.h:226
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QLayout()
Constructs a new child QLayout.
Definition: qlayout.cpp:127
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 rece...
Definition: qobject.cpp:2580
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
QToolBarExtension * extension
void hide()
Hides the widget.
Definition: qwidget.h:501
void setUsePopupMenu(bool set)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Orientation
Definition: qnamespace.h:174
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631

◆ ~QToolBarLayout()

QToolBarLayout::~QToolBarLayout ( )

Definition at line 98 of file qtoolbarlayout.cpp.

99 {
100  while (!items.isEmpty()) {
101  QToolBarItem *item = items.takeFirst();
102  if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action)) {
103  if (item->customWidget)
104  widgetAction->releaseWidget(item->widget());
105  }
106  delete item;
107  }
108 }
QAction * action
virtual QWidget * widget()
Returns the widget managed by this item.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
QList< QToolBarItem * > items
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action base...
Definition: qwidgetaction.h:57

Functions

◆ addItem()

void QToolBarLayout::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 158 of file qtoolbarlayout.cpp.

159 {
160  qWarning() << "QToolBarLayout::addItem(): please use addAction() instead";
161  return;
162 }
Q_CORE_EXPORT void qWarning(const char *,...)

◆ checkUsePopupMenu()

void QToolBarLayout::checkUsePopupMenu ( )

Definition at line 150 of file qtoolbarlayout.cpp.

Referenced by QToolBarPrivate::setWindowState().

151 {
152  QToolBar *tb = static_cast<QToolBar *>(parent());
153  QMainWindow *mw = qobject_cast<QMainWindow *>(tb->parent());
154  Qt::Orientation o = tb->orientation();
155  setUsePopupMenu(!mw || tb->isFloating() || perp(o, expandedSize(mw->size())) >= perp(o, mw->size()));
156 }
QSize size() const
QSize expandedSize(const QSize &size) const
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
static int perp(bool vertical, const QSize &size)
bool isFloating() const
Definition: qtoolbar.cpp:694
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
void setUsePopupMenu(bool set)
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
Orientation
Definition: qnamespace.h:174

◆ count()

int QToolBarLayout::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 214 of file qtoolbarlayout.cpp.

Referenced by expandedSize(), layoutActions(), and updateGeomArray().

215 {
216  return items.count();
217 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QToolBarItem * > items

◆ createItem()

QToolBarItem * QToolBarLayout::createItem ( QAction action)
private

Definition at line 693 of file qtoolbarlayout.cpp.

Referenced by insertAction().

694 {
695  bool customWidget = false;
696  bool standardButtonWidget = false;
697  QWidget *widget = 0;
699  if (!tb)
700  return (QToolBarItem *)0;
701 
702  if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(action)) {
703  widget = widgetAction->requestWidget(tb);
704  if (widget != 0) {
706  customWidget = true;
707  }
708  } else if (action->isSeparator()) {
709  QToolBarSeparator *sep = new QToolBarSeparator(tb);
710  connect(tb, SIGNAL(orientationChanged(Qt::Orientation)),
711  sep, SLOT(setOrientation(Qt::Orientation)));
712  widget = sep;
713  }
714 
715  if (!widget) {
716  QToolButton *button = new QToolButton(tb);
717  button->setAutoRaise(true);
718  button->setFocusPolicy(Qt::NoFocus);
719  button->setIconSize(tb->iconSize());
720  button->setToolButtonStyle(tb->toolButtonStyle());
721  QObject::connect(tb, SIGNAL(iconSizeChanged(QSize)),
722  button, SLOT(setIconSize(QSize)));
723  QObject::connect(tb, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
724  button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
725  button->setDefaultAction(action);
726  QObject::connect(button, SIGNAL(triggered(QAction*)), tb, SIGNAL(actionTriggered(QAction*)));
727  widget = button;
728  standardButtonWidget = true;
729  }
730 
731  widget->hide();
732  QToolBarItem *result = new QToolBarItem(widget);
733  if (standardButtonWidget)
735  result->customWidget = customWidget;
736  result->action = action;
737  return result;
738 }
bool isSeparator() const
Returns true if this action is a separator action; otherwise it returns false.
Definition: qaction.cpp:839
void setDefaultAction(QAction *)
Sets the default action to action.
#define SLOT(a)
Definition: qobjectdefs.h:226
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QAction * action
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
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
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 rece...
Definition: qobject.cpp:2580
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
void hide()
Hides the widget.
Definition: qwidget.h:501
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action base...
Definition: qwidgetaction.h:57
void setIconSize(const QSize &size)
QSize iconSize() const
size of icons in the toolbar.
Definition: qtoolbar.cpp:785
void setAutoRaise(bool enable)
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
ToolButtonStyle
Definition: qnamespace.h:1572
Qt::ToolButtonStyle toolButtonStyle
the style of toolbar buttons
Definition: qtoolbar.h:70
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
Orientation
Definition: qnamespace.h:174
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void setToolButtonStyle(Qt::ToolButtonStyle style)
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631

◆ expandedSize()

QSize QToolBarLayout::expandedSize ( const QSize size) const

Definition at line 566 of file qtoolbarlayout.cpp.

Referenced by QToolBarAreaLayout::apply(), and checkUsePopupMenu().

567 {
568  if (dirty)
569  updateGeomArray();
570 
572  if (!tb)
573  return QSize(0, 0);
575  Qt::Orientation o = tb->orientation();
576  QStyle *style = tb->style();
578  tb->initStyleOption(&opt);
579  const int handleExtent = movable()
580  ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
581  const int margin = this->margin();
582  const int spacing = this->spacing();
583  const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
584 
585  int total_w = 0;
586  int count = 0;
587  for (int x = 0; x < items.count(); ++x) {
588  if (!geomArray[x].empty) {
589  total_w += (count == 0 ? 0 : spacing) + geomArray[x].minimumSize;
590  ++count;
591  }
592  }
593  if (count == 0)
594  return QSize(0, 0);
595 
596  int min_w = pick(o, size);
597  int rows = (int)qSqrt(qreal(count));
598  if (rows == 1)
599  ++rows; // we want to expand to at least two rows
600  int space = total_w/rows + spacing + extensionExtent;
601  space = qMax(space, min_w - 2*margin - handleExtent);
602  if (win != 0)
603  space = qMin(space, pick(o, win->size()) - 2*margin - handleExtent);
604 
605  int w = 0;
606  int h = 0;
607  int i = 0;
608  while (i < items.count()) {
609  int count = 0;
610  int size = 0;
611  int prev = -1;
612  int rowHeight = 0;
613  for (; i < items.count(); ++i) {
614  if (geomArray[i].empty)
615  continue;
616 
617  int newSize = size + (count == 0 ? 0 : spacing) + geomArray[i].minimumSize;
618  rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));
619  if (prev != -1 && newSize > space) {
620  if (count > 1 && size + spacing + extensionExtent > space) {
621  size -= spacing + geomArray[prev].minimumSize;
622  i = prev;
623  }
624  break;
625  }
626 
627  size = newSize;
628  prev = i;
629  ++count;
630  }
631 
632  w = qMax(size, w);
633  h += rowHeight + spacing;
634  }
635 
636  w += 2*margin + handleExtent + spacing + extensionExtent;
637  w = qMax(w, min_w);
638  if (win != 0)
639  w = qMin(w, pick(o, win->size()));
640  h += 2*margin - spacing; //there is no spacing before the first row
641 
642  QSize result;
643  rpick(o, result) = w;
644  rperp(o, result) = h;
645  return result;
646 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QSize size() const
void updateGeomArray() const
QSize sizeHint() const
Reimplemented Function
int count() const
Must be implemented in subclasses to return the number of items in the layout.
QSize minimumSize() const
Returns the minimum size of this layout.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
static int & rpick(Qt::Orientation o, QPoint &pos)
bool movable() const
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int spacing() const
QVector< QLayoutStruct > geomArray
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 QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QToolBarItem * > items
static int perp(bool vertical, const QSize &size)
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
void initStyleOption(QStyleOptionToolBar *option) const
Definition: qtoolbar.cpp:1374
static int pick(bool vertical, const QSize &size)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static int & rperp(Qt::Orientation o, QPoint &pos)
int margin() const
Orientation
Definition: qnamespace.h:174
qreal qSqrt(qreal v)
Definition: qmath.h:205

◆ expandingDirections()

Qt::Orientations QToolBarLayout::expandingDirections ( ) const
virtual

Returns whether this layout can make use of more space than sizeHint().

A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only one dimension, whereas Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions.

The default implementation returns Qt::Horizontal | Qt::Vertical. Subclasses reimplement it to return a meaningful value based on their child widgets's size policies.

See also
sizeHint()

Reimplemented from QLayout.

Definition at line 232 of file qtoolbarlayout.cpp.

233 {
234  if (dirty)
235  updateGeomArray();
237  if (!tb)
238  return Qt::Orientations(0);
239  Qt::Orientation o = tb->orientation();
240  return expanding ? Qt::Orientations(o) : Qt::Orientations(0);
241 }
void updateGeomArray() const
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
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
Definition: qnamespace.h:54
Orientation
Definition: qnamespace.h:174

◆ hasExpandFlag()

bool QToolBarLayout::hasExpandFlag ( ) const

Definition at line 123 of file qtoolbarlayout.cpp.

Referenced by QMainWindowLayout::insertIntoMacToolbar().

124 {
125  return expandFlag;
126 }

◆ indexOf() [1/2]

int QToolBarLayout::indexOf ( QAction action) const

Definition at line 205 of file qtoolbarlayout.cpp.

206 {
207  for (int i = 0; i < items.count(); ++i) {
208  if (items.at(i)->action == action)
209  return i;
210  }
211  return -1;
212 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QAction * action
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QToolBarItem * > items

◆ indexOf() [2/2]

int QToolBarLayout::indexOf ( QWidget widget) const
inlinevirtual

Searches for widget widget in this layout (not including child layouts).

Returns the index of widget, or -1 if widget is not found.

The default implementation iterates over all items using itemAt()

Reimplemented from QLayout.

Definition at line 101 of file qtoolbarlayout_p.h.

101 { return QLayout::indexOf(widget); }
virtual int indexOf(QWidget *) const
Searches for widget widget in this layout (not including child layouts).
Definition: qlayout.cpp:1378

◆ insertAction()

void QToolBarLayout::insertAction ( int  index,
QAction action 
)

Definition at line 193 of file qtoolbarlayout.cpp.

194 {
195  index = qMax(0, index);
196  index = qMin(items.count(), index);
197 
198  QToolBarItem *item = createItem(action);
199  if (item) {
200  items.insert(index, item);
201  invalidate();
202  }
203 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QToolBarItem * createItem(QAction *action)
QList< QToolBarItem * > items
void invalidate()
Reimplemented Function
quint16 index

◆ invalidate()

void QToolBarLayout::invalidate ( )
virtual

Reimplemented Function

Reimplemented from QLayout.

Definition at line 226 of file qtoolbarlayout.cpp.

Referenced by insertAction(), setUsePopupMenu(), and takeAt().

227 {
228  dirty = true;
230 }
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673

◆ isEmpty()

bool QToolBarLayout::isEmpty ( ) const
virtual

Reimplemented Function

Reimplemented from QLayout.

Definition at line 219 of file qtoolbarlayout.cpp.

220 {
221  if (dirty)
222  updateGeomArray();
223  return empty;
224 }
void updateGeomArray() const

◆ itemAt()

QLayoutItem * QToolBarLayout::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 164 of file qtoolbarlayout.cpp.

165 {
166  if (index < 0 || index >= items.count())
167  return 0;
168  return items.at(index);
169 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QToolBarItem * > items
quint16 index

◆ layoutActions()

bool QToolBarLayout::layoutActions ( const QSize size)

Definition at line 418 of file qtoolbarlayout.cpp.

Referenced by QMainWindowLayout::animationFinished(), setExpanded(), and setGeometry().

419 {
420  if (dirty)
421  updateGeomArray();
422 
423  QRect rect(0, 0, size.width(), size.height());
424 
425  QList<QWidget*> showWidgets, hideWidgets;
426 
428  if (!tb)
429  return false;
430  QStyle *style = tb->style();
432  tb->initStyleOption(&opt);
433  const int handleExtent = movable()
434  ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
435  const int margin = this->margin();
436  const int spacing = this->spacing();
437  const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
438  Qt::Orientation o = tb->orientation();
439  bool extensionMenuContainsOnlyWidgetActions = true;
440 
441  int space = pick(o, rect.size()) - 2*margin - handleExtent;
442  if (space <= 0)
443  return false; // nothing to do.
444 
445  if(popupMenu)
446  popupMenu->clear();
447 
448  bool ranOutOfSpace = false;
449  int rows = 0;
450  int rowPos = perp(o, rect.topLeft()) + margin;
451  int i = 0;
452  while (i < items.count()) {
454 
455  int start = i;
456  int size = 0;
457  int prev = -1;
458  int rowHeight = 0;
459  int count = 0;
460  int maximumSize = 0;
461  bool expansiveRow = false;
462  for (; i < items.count(); ++i) {
463  if (a[i].empty)
464  continue;
465 
466  int newSize = size + (count == 0 ? 0 : spacing) + a[i].minimumSize;
467  if (prev != -1 && newSize > space) {
468  if (rows == 0)
469  ranOutOfSpace = true;
470  // do we have to move the previous item to the next line to make space for
471  // the extension button?
472  if (count > 1 && size + spacing + extensionExtent > space)
473  i = prev;
474  break;
475  }
476 
477  if (expanded)
478  rowHeight = qMax(rowHeight, perp(o, items.at(i)->sizeHint()));
479  expansiveRow = expansiveRow || a[i].expansive;
480  size = newSize;
481  maximumSize += spacing + (a[i].expansive ? a[i].maximumSize : a[i].smartSizeHint());
482  prev = i;
483  ++count;
484  }
485 
486  // stretch at the end
487  a[i].sizeHint = 0;
488  a[i].maximumSize = QWIDGETSIZE_MAX;
489  a[i].minimumSize = 0;
490  a[i].expansive = true;
491  a[i].stretch = 0;
492  a[i].empty = true;
493 
494  if (expansiveRow && maximumSize < space) {
495  expansiveRow = false;
496  a[i].maximumSize = space - maximumSize;
497  }
498 
499  qGeomCalc(a, start, i - start + (expansiveRow ? 0 : 1), 0,
500  space - (ranOutOfSpace ? (extensionExtent + spacing) : 0),
501  spacing);
502 
503  for (int j = start; j < i; ++j) {
504  QToolBarItem *item = items.at(j);
505 
506  if (a[j].empty) {
507  if (!item->widget()->isHidden())
508  hideWidgets << item->widget();
509  continue;
510  }
511 
512  QPoint pos;
513  rpick(o, pos) = margin + handleExtent + a[j].pos;
514  rperp(o, pos) = rowPos;
515  QSize size;
516  rpick(o, size) = a[j].size;
517  if (expanded)
518  rperp(o, size) = rowHeight;
519  else
520  rperp(o, size) = perp(o, rect.size()) - 2*margin;
521  QRect r(pos, size);
522 
523  if (o == Qt::Horizontal)
524  r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
525 
526  item->setGeometry(r);
527 
528  if (item->widget()->isHidden())
529  showWidgets << item->widget();
530  }
531 
532  if (!expanded) {
533  for (int j = i; j < items.count(); ++j) {
534  QToolBarItem *item = items.at(j);
535  if (!item->widget()->isHidden())
536  hideWidgets << item->widget();
537  if (popupMenu) {
538  if (!defaultWidgetAction(item)) {
539  popupMenu->addAction(item->action);
540  extensionMenuContainsOnlyWidgetActions = false;
541  }
542  }
543  }
544  break;
545  }
546 
547  rowPos += rowHeight + spacing;
548  ++rows;
549  }
550 
551  // if we are using a popup menu, not the expadning toolbar effect, we cannot move custom
552  // widgets into the menu. If only custom widget actions are chopped off, the popup menu
553  // is empty. So we show the little extension button to show something is chopped off,
554  // but we make it disabled.
555  extension->setEnabled(popupMenu == 0 || !extensionMenuContainsOnlyWidgetActions);
556 
557  // we have to do the show/hide here, because it triggers more calls to setGeometry :(
558  for (int i = 0; i < showWidgets.count(); ++i)
559  showWidgets.at(i)->show();
560  for (int i = 0; i < hideWidgets.count(); ++i)
561  hideWidgets.at(i)->hide();
562 
563  return ranOutOfSpace;
564 }
void updateGeomArray() const
QSize sizeHint() const
Reimplemented Function
int count() const
Must be implemented in subclasses to return the number of items in the layout.
QSize minimumSize() const
Returns the minimum size of this layout.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
static int & rpick(Qt::Orientation o, QPoint &pos)
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
bool movable() const
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QAction * action
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
int spacing() const
QVector< QLayoutStruct > geomArray
virtual QWidget * widget()
Returns the widget managed by this item.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
QSize maximumSize() const
Returns the maximum size of this layout.
Definition: qlayout.cpp:1181
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
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
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QToolBarItem * > items
QToolBarExtension * extension
void setEnabled(bool)
Definition: qwidget.cpp:3447
void clear()
Removes all the menu&#39;s actions.
Definition: qmenu.cpp:1755
static int perp(bool vertical, const QSize &size)
void qGeomCalc(QVector< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
void setGeometry(const QRect &)
Reimplemented Function
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
static bool defaultWidgetAction(QToolBarItem *item)
void initStyleOption(QStyleOptionToolBar *option) const
Definition: qtoolbar.cpp:1374
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static int pick(bool vertical, const QSize &size)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static int & rperp(Qt::Orientation o, QPoint &pos)
int margin() const
Orientation
Definition: qnamespace.h:174
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ minimumSize()

QSize QToolBarLayout::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 679 of file qtoolbarlayout.cpp.

Referenced by expandedSize(), and layoutActions().

680 {
681  if (dirty)
682  updateGeomArray();
683  return minSize;
684 }
void updateGeomArray() const

◆ movable()

bool QToolBarLayout::movable ( ) const

Definition at line 243 of file qtoolbarlayout.cpp.

Referenced by expandedSize(), layoutActions(), QToolBarPrivate::mousePressEvent(), and updateGeomArray().

244 {
246  if (!tb)
247  return false;
249  return tb->isMovable() && win != 0;
250 }
bool isMovable() const
Definition: qtoolbar.cpp:656
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
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
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63

◆ setExpanded

void QToolBarLayout::setExpanded ( bool  b)
slot

Definition at line 648 of file qtoolbarlayout.cpp.

Referenced by setUsePopupMenu(), and QToolBarPrivate::unplug().

649 {
651  if (!tb)
652  return;
653  if (exp == expanded && !tb->isWindow())
654  return;
655 
656  expanded = exp;
658 
659  if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) {
660 #ifdef QT_NO_DOCKWIDGET
661  animating = false;
662 #else
663  animating = !tb->isWindow() && win->isAnimated();
664 #endif
666  if (expanded) {
667  tb->raise();
668  } else {
669  QList<int> path = layout->layoutState.indexOf(tb);
670  if (!path.isEmpty()) {
671  QRect rect = layout->layoutState.itemRect(path);
672  layoutActions(rect.size());
673  }
674  }
676  }
677 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QRect itemRect(const QList< int > &path) const
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QMainWindowLayoutState layoutState
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
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 raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
bool layoutActions(const QSize &size)
QToolBarExtension * extension
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
QList< int > indexOf(QWidget *widget) const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QLayout * layout()
Reimplemented Function
void apply(bool animate)
QToolBarAreaLayout toolBarAreaLayout

◆ setGeometry()

void QToolBarLayout::setGeometry ( const QRect r)
virtual

Reimplemented Function

Reimplemented from QLayout.

Definition at line 358 of file qtoolbarlayout.cpp.

359 {
361  if (!tb)
362  return;
363  QStyle *style = tb->style();
365  tb->initStyleOption(&opt);
366  const int margin = this->margin();
367  const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
368  Qt::Orientation o = tb->orientation();
369 
370  QLayout::setGeometry(rect);
371 
372  bool ranOutOfSpace = false;
373  if (!animating)
374  ranOutOfSpace = layoutActions(rect.size());
375 
376  if (expanded || animating || ranOutOfSpace) {
378  if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget()))
379  area = win->toolBarArea(tb);
380  QSize hint = sizeHint();
381 
382  QPoint pos;
383  rpick(o, pos) = pick(o, rect.bottomRight()) - margin - extensionExtent + 2;
384  if (area == Qt::LeftToolBarArea || area == Qt::TopToolBarArea)
385  rperp(o, pos) = perp(o, rect.topLeft()) + margin;
386  else
387  rperp(o, pos) = perp(o, rect.bottomRight()) - margin - (perp(o, hint) - 2*margin) + 1;
388  QSize size;
389  rpick(o, size) = extensionExtent;
390  rperp(o, size) = perp(o, hint) - 2*margin;
391  QRect r(pos, size);
392 
393  if (o == Qt::Horizontal)
394  r = QStyle::visualRect(parentWidget()->layoutDirection(), rect, r);
395 
397 
398  if (extension->isHidden())
399  extension->show();
400  } else {
401  if (!extension->isHidden())
402  extension->hide();
403  }
404 #ifdef Q_WS_MAC
405  // Nothing to do for Carbon... probably
406 # ifdef QT_MAC_USE_COCOA
407  if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) {
408  Qt::ToolBarArea area = win->toolBarArea(tb);
409  if (win->unifiedTitleAndToolBarOnMac() && area == Qt::TopToolBarArea) {
411  }
412  }
413 # endif
414 #endif
415 
416 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
static int & rpick(Qt::Orientation o, QPoint &pos)
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
virtual void setGeometry(const QRect &)
Reimplemented Function
Definition: qlayout.cpp:655
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QStyle * style() const
Definition: qwidget.cpp:2742
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
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 QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
bool layoutActions(const QSize &size)
QToolBarExtension * extension
void show()
Shows the widget and its child widgets.
void hide()
Hides the widget.
Definition: qwidget.h:501
ToolBarArea
Definition: qnamespace.h:1353
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
static int perp(bool vertical, const QSize &size)
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
void initStyleOption(QStyleOptionToolBar *option) const
Definition: qtoolbar.cpp:1374
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static int pick(bool vertical, const QSize &size)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static int & rperp(Qt::Orientation o, QPoint &pos)
int margin() const
void fixSizeInUnifiedToolbar(QToolBar *tb) const
Orientation
Definition: qnamespace.h:174
static int area(const QSize &s)
Definition: qicon.cpp:155
QSize sizeHint() const
Implemented in subclasses to return the preferred size of this item.

◆ setUsePopupMenu()

void QToolBarLayout::setUsePopupMenu ( bool  set)

Definition at line 128 of file qtoolbarlayout.cpp.

Referenced by checkUsePopupMenu(), QMainWindowLayout::insertIntoMacToolbar(), and QToolBarLayout().

129 {
130  if (!dirty && ((popupMenu == 0) == set))
131  invalidate();
132  if (!set) {
133  QObject::connect(extension, SIGNAL(clicked(bool)),
134  this, SLOT(setExpanded(bool)), Qt::UniqueConnection);
136  extension->setMenu(0);
137  delete popupMenu;
138  popupMenu = 0;
139  } else {
140  QObject::disconnect(extension, SIGNAL(clicked(bool)),
141  this, SLOT(setExpanded(bool)));
143  if (!popupMenu) {
144  popupMenu = new QMenu(extension);
145  }
147  }
148 }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setExpanded(bool b)
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 rece...
Definition: qobject.cpp:2580
QToolBarExtension * extension
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.
Definition: qobject.cpp:2895
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void setMenu(QMenu *menu)
Associates the given menu with this tool button.
void invalidate()
Reimplemented Function
void setPopupMode(ToolButtonPopupMode mode)

◆ sizeHint()

QSize QToolBarLayout::sizeHint ( ) const
virtual

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

Implements QLayoutItem.

Definition at line 686 of file qtoolbarlayout.cpp.

Referenced by setGeometry().

687 {
688  if (dirty)
689  updateGeomArray();
690  return hint;
691 }
void updateGeomArray() const

◆ takeAt()

QLayoutItem * QToolBarLayout::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 171 of file qtoolbarlayout.cpp.

172 {
173  if (index < 0 || index >= items.count())
174  return 0;
175  QToolBarItem *item = items.takeAt(index);
176 
177  if (popupMenu)
178  popupMenu->removeAction(item->action);
179 
180  QWidgetAction *widgetAction = qobject_cast<QWidgetAction*>(item->action);
181  if (widgetAction != 0 && item->customWidget) {
182  widgetAction->releaseWidget(item->widget());
183  } else {
184  // destroy the QToolButton/QToolBarSeparator
185  item->widget()->hide();
186  item->widget()->deleteLater();
187  }
188 
189  invalidate();
190  return item;
191 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QAction * action
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual QWidget * widget()
Returns the widget managed by this item.
QList< QToolBarItem * > items
void hide()
Hides the widget.
Definition: qwidget.h:501
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action base...
Definition: qwidgetaction.h:57
void invalidate()
Reimplemented Function
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
quint16 index
void releaseWidget(QWidget *widget)
Releases the specified widget.
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

◆ updateGeomArray()

void QToolBarLayout::updateGeomArray ( ) const
private

Definition at line 252 of file qtoolbarlayout.cpp.

Referenced by expandedSize(), expandingDirections(), isEmpty(), layoutActions(), minimumSize(), and sizeHint().

253 {
254  if (!dirty)
255  return;
256 
257  QToolBarLayout *that = const_cast<QToolBarLayout*>(this);
258 
260  if (!tb)
261  return;
262  QStyle *style = tb->style();
264  tb->initStyleOption(&opt);
265  const int handleExtent = movable()
266  ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
267  const int margin = this->margin();
268  const int spacing = this->spacing();
269  const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
270  Qt::Orientation o = tb->orientation();
271 
272  that->minSize = QSize(0, 0);
273  that->hint = QSize(0, 0);
274  rperp(o, that->minSize) = style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb);
275  rperp(o, that->hint) = style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb);
276 
277  that->expanding = false;
278  that->empty = false;
279 
280  QVector<QLayoutStruct> a(items.count() + 1); // + 1 for the stretch
281 
282  int count = 0;
283  for (int i = 0; i < items.count(); ++i) {
284  QToolBarItem *item = items.at(i);
285 
286  QSize max = item->maximumSize();
287  QSize min = item->minimumSize();
288  QSize hint = item->sizeHint();
289  Qt::Orientations exp = item->expandingDirections();
290  bool empty = item->isEmpty();
291 
292  that->expanding = expanding || exp & o;
293 
294 
295  if (item->widget()) {
297  that->expandFlag = true;
298  }
299  }
300 
301  if (!empty) {
302  if (count == 0) // the minimum size only displays one widget
303  rpick(o, that->minSize) += pick(o, min);
304  int s = perp(o, minSize);
305  rperp(o, that->minSize) = qMax(s, perp(o, min));
306 
307  //we only add spacing before item (ie never before the first one)
308  rpick(o, that->hint) += (count == 0 ? 0 : spacing) + pick(o, hint);
309  s = perp(o, that->hint);
310  rperp(o, that->hint) = qMax(s, perp(o, hint));
311  ++count;
312  }
313 
314  a[i].sizeHint = pick(o, hint);
315  a[i].maximumSize = pick(o, max);
316  a[i].minimumSize = pick(o, min);
317  a[i].expansive = exp & o;
318  if (o == Qt::Horizontal)
319  a[i].stretch = item->widget()->sizePolicy().horizontalStretch();
320  else
321  a[i].stretch = item->widget()->sizePolicy().verticalStretch();
322  a[i].empty = empty;
323  }
324 
325  that->geomArray = a;
326  that->empty = count == 0;
327 
328  rpick(o, that->minSize) += handleExtent;
329  that->minSize += QSize(2*margin, 2*margin);
330  if (items.count() > 1)
331  rpick(o, that->minSize) += spacing + extensionExtent;
332 
333  rpick(o, that->hint) += handleExtent;
334  that->hint += QSize(2*margin, 2*margin);
335  that->dirty = false;
336 #ifdef Q_WS_MAC
337  if (QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget()->parentWidget())) {
338  if (mw->unifiedTitleAndToolBarOnMac()
339  && mw->toolBarArea(static_cast<QToolBar *>(parentWidget())) == Qt::TopToolBarArea) {
340  if (expandFlag) {
341  tb->setMaximumSize(0xFFFFFF, 0xFFFFFF);
342  } else {
343  tb->setMaximumSize(hint);
344  }
345  }
346  }
347 #endif
348 
349  that->dirty = false;
350 }
QSize maximumSize() const
Reimplemented Function
QSize sizeHint() const
Reimplemented Function
int count() const
Must be implemented in subclasses to return the number of items in the layout.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
Policy horizontalPolicy() const
Definition: qsizepolicy.h:118
static int & rpick(Qt::Orientation o, QPoint &pos)
bool movable() const
void setMaximumSize(const QSize &)
Definition: qwidget.h:972
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int spacing() const
QVector< QLayoutStruct > geomArray
int horizontalStretch() const
Definition: qsizepolicy.h:144
virtual QWidget * widget()
Returns the widget managed by this item.
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
Qt::Orientations expandingDirections() const
Reimplemented Function
bool isEmpty() const
Returns true if the widget is hidden; otherwise returns false.
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int verticalStretch() const
Definition: qsizepolicy.h:145
QList< QToolBarItem * > items
static int perp(bool vertical, const QSize &size)
QSize minimumSize() const
Reimplemented Function
Qt::Orientation orientation() const
orientation of the toolbar
Definition: qtoolbar.cpp:769
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition: qwidget.h:171
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
void initStyleOption(QStyleOptionToolBar *option) const
Definition: qtoolbar.cpp:1374
static int pick(bool vertical, const QSize &size)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static int & rperp(Qt::Orientation o, QPoint &pos)
int margin() const
Orientation
Definition: qnamespace.h:174

◆ updateMarginAndSpacing()

void QToolBarLayout::updateMarginAndSpacing ( )

Definition at line 110 of file qtoolbarlayout.cpp.

Referenced by QToolBarPrivate::init().

111 {
113  if (!tb)
114  return;
115  QStyle *style = tb->style();
117  tb->initStyleOption(&opt);
119  + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb));
121 }
void setSpacing(int)
Definition: qlayout.cpp:469
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
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 QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
void initStyleOption(QStyleOptionToolBar *option) const
Definition: qtoolbar.cpp:1374
void setMargin(int)
Definition: qlayout.cpp:464

Properties

◆ animating

bool QToolBarLayout::animating

◆ dirty

bool QToolBarLayout::dirty
private

◆ empty

bool QToolBarLayout::empty
private

Definition at line 120 of file qtoolbarlayout_p.h.

Referenced by expandedSize(), isEmpty(), layoutActions(), and updateGeomArray().

◆ expanded

bool QToolBarLayout::expanded

◆ expandFlag

bool QToolBarLayout::expandFlag
private

Definition at line 120 of file qtoolbarlayout_p.h.

Referenced by hasExpandFlag(), and updateGeomArray().

◆ expanding

bool QToolBarLayout::expanding
private

Definition at line 120 of file qtoolbarlayout_p.h.

Referenced by expandingDirections(), and updateGeomArray().

◆ extension

QToolBarExtension* QToolBarLayout::extension
private

◆ geomArray

QVector<QLayoutStruct> QToolBarLayout::geomArray
private

Definition at line 121 of file qtoolbarlayout_p.h.

Referenced by expandedSize(), layoutActions(), and updateGeomArray().

◆ handRect

QRect QToolBarLayout::handRect
private

Definition at line 122 of file qtoolbarlayout_p.h.

◆ hint

QSize QToolBarLayout::hint
private

Definition at line 119 of file qtoolbarlayout_p.h.

Referenced by setGeometry(), sizeHint(), and updateGeomArray().

◆ items

QList<QToolBarItem*> QToolBarLayout::items
private

◆ minSize

QSize QToolBarLayout::minSize
private

Definition at line 119 of file qtoolbarlayout_p.h.

Referenced by minimumSize(), and updateGeomArray().

◆ popupMenu

QMenu* QToolBarLayout::popupMenu
private

Definition at line 127 of file qtoolbarlayout_p.h.

Referenced by layoutActions(), setUsePopupMenu(), and takeAt().


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