Qt 4.8
Enumerations | Functions | Variables
qdockarealayout.cpp File Reference
#include "QtGui/qapplication.h"
#include "QtGui/qwidget.h"
#include "QtGui/qtabbar.h"
#include "QtGui/qstyle.h"
#include "QtGui/qdesktopwidget.h"
#include "QtCore/qvariant.h"
#include "qdockarealayout_p.h"
#include "qdockwidget.h"
#include "qmainwindow.h"
#include "qwidgetanimator_p.h"
#include "qmainwindowlayout_p.h"
#include "qdockwidget_p.h"
#include <private/qlayoutengine_p.h>
#include <qpainter.h>
#include <qstyleoption.h>

Go to the source code of this file.

Enumerations

enum  { StateFlagVisible = 1, StateFlagFloating = 2 }
 

Functions

static QRect constrainedRect (QRect rect, const QRect &desktop)
 
static QRect dockedGeometry (QWidget *widget)
 
static QInternal::DockPosition dockPosHelper (const QRect &rect, const QPoint &_pos, Qt::Orientation o, bool nestingEnabled, QDockAreaLayoutInfo::TabMode tabMode)
 
static int grow (QLayoutStruct &ls, int delta)
 
static void paintSep (QPainter *p, QWidget *w, const QRect &r, Qt::Orientation o, bool mouse_over)
 
static int qMax (int i1, int i2, int i3)
 
static int qMin (int i1, int i2, int i3)
 
QMainWindowLayoutqt_mainwindow_layout (const QMainWindow *window)
 
static int realMaxSize (const QDockAreaLayoutInfo &info)
 
static int realMinSize (const QDockAreaLayoutInfo &info)
 
static int separatorMoveHelper (QVector< QLayoutStruct > &list, int index, int delta, int sep)
 
static int shrink (QLayoutStruct &ls, int delta)
 
static quintptr tabId (const QDockAreaLayoutItem &item)
 
static Qt::DockWidgetArea toDockWidgetArea (QInternal::DockPosition pos)
 

Variables

static const int zero = 0
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
StateFlagVisible 
StateFlagFloating 

Definition at line 66 of file qdockarealayout.cpp.

Function Documentation

◆ constrainedRect()

static QRect constrainedRect ( QRect  rect,
const QRect desktop 
)
static

Definition at line 1864 of file qdockarealayout.cpp.

Referenced by QDockAreaLayout::restoreDockWidget(), and QDockAreaLayoutInfo::restoreState().

1865 {
1866  if (desktop.isValid()) {
1867  rect.setWidth(qMin(rect.width(), desktop.width()));
1868  rect.setHeight(qMin(rect.height(), desktop.height()));
1869  rect.moveLeft(qMax(rect.left(), desktop.left()));
1870  rect.moveTop(qMax(rect.top(), desktop.top()));
1871  rect.moveRight(qMin(rect.right(), desktop.right()));
1872  rect.moveBottom(qMin(rect.bottom(), desktop.bottom()));
1873  }
1874 
1875  return rect;
1876 }
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
static int qMax(int i1, int i2, int i3)
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:356
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
static int qMin(int i1, int i2, int i3)
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
void moveBottom(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s bottom edge at the given y coordinate...
Definition: qrect.h:362
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237

◆ dockedGeometry()

static QRect dockedGeometry ( QWidget widget)
static

Definition at line 1135 of file qdockarealayout.cpp.

Referenced by QDockAreaLayoutInfo::insertGap().

1136 {
1137  int titleHeight = 0;
1138 
1140  = qobject_cast<QDockWidgetLayout*>(widget->layout());
1141  if(layout != 0 && layout->nativeWindowDeco())
1142  titleHeight = layout->titleHeight();
1143 
1144  QRect result = widget->geometry();
1145  result.adjust(0, -titleHeight, 0, 0);
1146  return result;
1147 }
T * qobject_cast(QObject *object)
Definition: qobject.h:375
const char * layout
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
int titleHeight() const
bool nativeWindowDeco() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158

◆ dockPosHelper()

static QInternal::DockPosition dockPosHelper ( const QRect rect,
const QPoint _pos,
Qt::Orientation  o,
bool  nestingEnabled,
QDockAreaLayoutInfo::TabMode  tabMode 
)
static

Definition at line 643 of file qdockarealayout.cpp.

Referenced by QDockAreaLayoutInfo::gapIndex().

647 {
648  if (tabMode == QDockAreaLayoutInfo::ForceTabs)
649  return QInternal::DockCount;
650 
651  QPoint pos = _pos - rect.topLeft();
652 
653  int x = pos.x();
654  int y = pos.y();
655  int w = rect.width();
656  int h = rect.height();
657 
658  if (tabMode != QDockAreaLayoutInfo::NoTabs) {
659  // is it in the center?
660  if (nestingEnabled) {
661  /* 2/3
662  +--------------+
663  | |
664  | CCCCCCCC |
665  2/3 | CCCCCCCC |
666  | CCCCCCCC |
667  | |
668  +--------------+ */
669 
670  QRect center(w/6, h/6, 2*w/3, 2*h/3);
671  if (center.contains(pos))
672  return QInternal::DockCount;
673  } else if (o == Qt::Horizontal) {
674  /* 2/3
675  +--------------+
676  | CCCCCCCC |
677  | CCCCCCCC |
678  | CCCCCCCC |
679  | CCCCCCCC |
680  | CCCCCCCC |
681  +--------------+ */
682 
683  if (x > w/6 && x < w*5/6)
684  return QInternal::DockCount;
685  } else {
686  /*
687  +--------------+
688  | |
689  2/3 |CCCCCCCCCCCCCC|
690  |CCCCCCCCCCCCCC|
691  | |
692  +--------------+ */
693  if (y > h/6 && y < 5*h/6)
694  return QInternal::DockCount;
695  }
696  }
697 
698  // not in the center. which edge?
699  if (nestingEnabled) {
700  if (o == Qt::Horizontal) {
701  /* 1/3 1/3 1/3
702  +------------+ (we've already ruled out the center)
703  |LLLLTTTTRRRR|
704  |LLLLTTTTRRRR|
705  |LLLLBBBBRRRR|
706  |LLLLBBBBRRRR|
707  +------------+ */
708 
709  if (x < w/3)
710  return QInternal::LeftDock;
711  if (x > 2*w/3)
712  return QInternal::RightDock;
713  if (y < h/2)
714  return QInternal::TopDock;
715  return QInternal::BottomDock;
716  } else {
717  /* +------------+ (we've already ruled out the center)
718  1/3 |TTTTTTTTTTTT|
719  |LLLLLLRRRRRR|
720  1/3 |LLLLLLRRRRRR|
721  1/3 |BBBBBBBBBBBB|
722  +------------+ */
723 
724  if (y < h/3)
725  return QInternal::TopDock;
726  if (y > 2*h/3)
727  return QInternal::BottomDock;
728  if (x < w/2)
729  return QInternal::LeftDock;
730  return QInternal::RightDock;
731  }
732  } else {
733  if (o == Qt::Horizontal) {
734  return x < w/2
737  } else {
738  return y < h/2
741  }
742  }
743 }
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
QTextStream & center(QTextStream &stream)
Calls QTextStream::setFieldAlignment(QTextStream::AlignCenter) on stream and returns stream...
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
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ grow()

static int grow ( QLayoutStruct ls,
int  delta 
)
inlinestatic

Definition at line 845 of file qdockarealayout.cpp.

Referenced by separatorMoveHelper().

846 {
847  if (ls.empty)
848  return 0;
849  int old_size = ls.size;
850  ls.size = qMin(ls.size + delta, ls.maximumSize);
851  return ls.size - old_size;
852 }
static int qMin(int i1, int i2, int i3)

◆ paintSep()

static void paintSep ( QPainter p,
QWidget w,
const QRect r,
Qt::Orientation  o,
bool  mouse_over 
)
static

Definition at line 1573 of file qdockarealayout.cpp.

Referenced by QDockAreaLayoutInfo::paintSeparators(), and QDockAreaLayout::paintSeparators().

1574 {
1575  QStyleOption opt(0);
1576  opt.state = QStyle::State_None;
1577  if (w->isEnabled())
1578  opt.state |= QStyle::State_Enabled;
1579  if (o != Qt::Horizontal)
1580  opt.state |= QStyle::State_Horizontal;
1581  if (mouse_over)
1582  opt.state |= QStyle::State_MouseOver;
1583  opt.rect = r;
1584  opt.palette = w->palette();
1585 
1587 }
QPalette palette
the widget&#39;s palette
Definition: qwidget.h:180
QStyle * style() const
Definition: qwidget.cpp:2742
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
bool isEnabled() const
Definition: qwidget.h:948
if(void) toggleToolbarShown

◆ qMax()

static int qMax ( int  i1,
int  i2,
int  i3 
)
inlinestatic

◆ qMin()

static int qMin ( int  i1,
int  i2,
int  i3 
)
inlinestatic

Definition at line 2580 of file qdockarealayout.cpp.

Referenced by constrainedRect(), grow(), QDockAreaLayoutInfo::maximumSize(), and QDockAreaLayoutInfo::sizeHint().

2580 { return qMin(i1, qMin(i2, i3)); }
static int qMin(int i1, int i2, int i3)

◆ qt_mainwindow_layout()

QMainWindowLayout* qt_mainwindow_layout ( const QMainWindow window)

Definition at line 111 of file qmainwindow.cpp.

Referenced by QDockAreaLayout::apply(), QDockAreaLayoutInfo::mainWindowLayout(), and QDockAreaLayout::updateSeparatorWidgets().

112 {
113  return QMainWindowPrivate::mainWindowLayout(mainWindow);
114 }
static QMainWindowLayout * mainWindowLayout(const QMainWindow *mainWindow)

◆ realMaxSize()

static int realMaxSize ( const QDockAreaLayoutInfo info)
static

Definition at line 508 of file qdockarealayout.cpp.

Referenced by QDockAreaLayoutInfo::fitItems().

509 {
510  int result = 0;
511  bool first = true;
512  for (int i = 0; i < info.item_list.size(); ++i) {
513  const QDockAreaLayoutItem &item = info.item_list.at(i);
514  if (item.skip())
515  continue;
516 
517  int max = 0;
518  if ((item.flags & QDockAreaLayoutItem::KeepSize) && item.size != -1)
519  max = item.size;
520  else
521  max = pick(info.o, item.maximumSize());
522 
523  if (!first)
524  result += *info.sep;
525  result += max;
526 
527  if (result >= QWIDGETSIZE_MAX)
528  return QWIDGETSIZE_MAX;
529 
530  first = false;
531  }
532 
533  return result;
534 }
QList< QDockAreaLayoutItem > item_list
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QSize maximumSize() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static int pick(bool vertical, const QSize &size)

◆ realMinSize()

static int realMinSize ( const QDockAreaLayoutInfo info)
static

Definition at line 483 of file qdockarealayout.cpp.

Referenced by QDockAreaLayoutInfo::fitItems().

484 {
485  int result = 0;
486  bool first = true;
487  for (int i = 0; i < info.item_list.size(); ++i) {
488  const QDockAreaLayoutItem &item = info.item_list.at(i);
489  if (item.skip())
490  continue;
491 
492  int min = 0;
493  if ((item.flags & QDockAreaLayoutItem::KeepSize) && item.size != -1)
494  min = item.size;
495  else
496  min = pick(info.o, item.minimumSize());
497 
498  if (!first)
499  result += *info.sep;
500  result += min;
501 
502  first = false;
503  }
504 
505  return result;
506 }
QList< QDockAreaLayoutItem > item_list
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static int pick(bool vertical, const QSize &size)
QSize minimumSize() const

◆ separatorMoveHelper()

static int separatorMoveHelper ( QVector< QLayoutStruct > &  list,
int  index,
int  delta,
int  sep 
)
static

Definition at line 854 of file qdockarealayout.cpp.

Referenced by QDockAreaLayoutInfo::separatorMove(), and QDockAreaLayout::separatorMove().

855 {
856  // adjust sizes
857  int pos = -1;
858  for (int i = 0; i < list.size(); ++i) {
859  const QLayoutStruct &ls = list.at(i);
860  if (!ls.empty) {
861  pos = ls.pos;
862  break;
863  }
864  }
865  if (pos == -1)
866  return 0;
867 
868  if (delta > 0) {
869  int growlimit = 0;
870  for (int i = 0; i<=index; ++i) {
871  const QLayoutStruct &ls = list.at(i);
872  if (ls.empty)
873  continue;
874  if (ls.maximumSize == QLAYOUTSIZE_MAX) {
875  growlimit = QLAYOUTSIZE_MAX;
876  break;
877  }
878  growlimit += ls.maximumSize - ls.size;
879  }
880  if (delta > growlimit)
881  delta = growlimit;
882 
883  int d = 0;
884  for (int i = index + 1; d < delta && i < list.count(); ++i)
885  d += shrink(list[i], delta - d);
886  delta = d;
887  d = 0;
888  for (int i = index; d < delta && i >= 0; --i)
889  d += grow(list[i], delta - d);
890  } else if (delta < 0) {
891  int growlimit = 0;
892  for (int i = index + 1; i < list.count(); ++i) {
893  const QLayoutStruct &ls = list.at(i);
894  if (ls.empty)
895  continue;
896  if (ls.maximumSize == QLAYOUTSIZE_MAX) {
897  growlimit = QLAYOUTSIZE_MAX;
898  break;
899  }
900  growlimit += ls.maximumSize - ls.size;
901  }
902  if (-delta > growlimit)
903  delta = -growlimit;
904 
905  int d = 0;
906  for (int i = index; d < -delta && i >= 0; --i)
907  d += shrink(list[i], -delta - d);
908  delta = -d;
909  d = 0;
910  for (int i = index + 1; d < -delta && i < list.count(); ++i)
911  d += grow(list[i], -delta - d);
912  }
913 
914  // adjust positions
915  bool first = true;
916  for (int i = 0; i < list.size(); ++i) {
917  QLayoutStruct &ls = list[i];
918  if (ls.empty) {
919  ls.pos = pos + (first ? 0 : sep);
920  continue;
921  }
922  if (!first)
923  pos += sep;
924  ls.pos = pos;
925  pos += ls.size;
926  first = false;
927  }
928 
929  return delta;
930 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
static int grow(QLayoutStruct &ls, int delta)
static int shrink(QLayoutStruct &ls, int delta)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
quint16 index
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ shrink()

static int shrink ( QLayoutStruct ls,
int  delta 
)
inlinestatic

Definition at line 836 of file qdockarealayout.cpp.

Referenced by separatorMoveHelper().

837 {
838  if (ls.empty)
839  return 0;
840  int old_size = ls.size;
841  ls.size = qMax(ls.size - delta, ls.minimumSize);
842  return old_size - ls.size;
843 }
static int qMax(int i1, int i2, int i3)

◆ tabId()

static quintptr tabId ( const QDockAreaLayoutItem item)
static

Definition at line 218 of file qdockarealayout.cpp.

Referenced by QDockAreaLayout::addDockWidget(), QDockAreaLayoutInfo::itemRect(), QDockAreaLayoutInfo::restoreState(), QDockAreaLayoutInfo::saveState(), and QDockAreaLayoutInfo::updateTabBar().

219 {
220  if (item.widgetItem == 0)
221  return 0;
222  return reinterpret_cast<quintptr>(item.widgetItem->widget());
223 }
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
QLayoutItem * widgetItem

◆ toDockWidgetArea()

static Qt::DockWidgetArea toDockWidgetArea ( QInternal::DockPosition  pos)
static

Variable Documentation

◆ zero

const int zero = 0
static