43 #ifndef QT_NO_SPLITTER 58 #include "private/qlayoutengine_p.h" 59 #include "private/qsplitter_p.h" 165 return d->s->opaqueResize();
193 pos =
d->s->contentsRect().width() -
pos;
194 d->s->moveSplitter(pos,
d->s->indexOf(
this));
222 int hw =
d->s->handleWidth();
244 bool useTinyMode = (
d->s->handleWidth() == 1);
263 switch(event->
type()) {
302 d->mouseOffset =
d->pick(e->
pos());
317 d->s->setRubberBand(-1);
354 const int presizer =
pick(s, orient);
371 return pick(handle->sizeHint(), orient);
380 q->setSizePolicy(sp);
387 int n = list.count();
393 bool allInvisible = n != 0;
394 for (
int i = 0; i < n ; ++i) {
397 if (allInvisible && !widgetHidden && !s->
collapsed)
398 allInvisible =
false;
405 for (
int i = 0; i < n ; ++i) {
413 int fi = 2 * q->frameWidth();
422 for (
int j = 0; j < n; j++) {
435 mint =
qMax(mint, trans(minS));
438 maxt =
qMin(maxt, tm);
443 if (qobject_cast<QSplitter *>(
parent)) {
458 q->setMaximumSize(maxl, maxt);
460 q->setMinimumSize(minl,mint);
462 q->setMaximumSize(maxt, maxl);
464 q->setMinimumSize(mint,minl);
476 QRect r = q->contentsRect();
477 int n = list.count();
481 bool noStretchFactorsSet =
true;
482 for (i = 0; i < n; ++i) {
486 noStretchFactorsSet =
false;
492 for (i = 0; i < n; ++i) {
494 #ifdef QSPLITTER_DEBUG 501 a[j].maximumSize = 0;
503 a[j].sizeHint = a[j].minimumSize = a[j].maximumSize = s->
getHandleSize(orient);
510 a[j].maximumSize = 0;
516 bool stretch = noStretchFactorsSet;
524 a[j].sizeHint = a[j].minimumSize;
525 a[j].expansive =
true;
535 #ifdef QSPLITTER_DEBUG 536 for (i = 0; i < n*2; ++i) {
537 qDebug(
"%*s%d: stretch %d, sh %d, minS %d, maxS %d, exp %d, emp %d -> %d, %d",
550 for (i = 0; i < n; ++i) {
552 setGeo(s, a[i*2+1].
pos, a[i*2+1].
size,
false);
558 for (
int i = 0; i < list.size(); ++i) {
584 QWidget *w = list.at(index)->widget;
586 if (collapsible(list.at(index)))
591 }
while (index >= 0 && index < list.count());
603 int n = list.count();
604 if (index <= 0 || index >= n)
607 int collapsibleSizeBefore = 0;
608 int idJustBefore = findWidgetJustBeforeOrJustAfter(index, -1, collapsibleSizeBefore);
610 int collapsibleSizeAfter = 0;
611 int idJustAfter = findWidgetJustBeforeOrJustAfter(index, +1, collapsibleSizeAfter);
619 for (i = 0; i <
index; ++i)
620 addContribution(i, &minBefore, &maxBefore, i == idJustBefore);
621 for (i = index; i < n; ++i)
622 addContribution(i, &minAfter, &maxAfter, i == idJustAfter);
624 QRect r = q->contentsRect();
630 int smartMinBefore =
qMax(minBefore,
pick(r.
size()) - maxAfter);
631 int smartMaxBefore =
qMin(maxBefore,
pick(r.
size()) - minAfter);
637 if (minBefore - collapsibleSizeBefore >=
pick(r.
size()) - maxAfter)
638 farMinVal -= collapsibleSizeBefore;
640 if (
pick(r.
size()) - (minAfter - collapsibleSizeAfter) <= maxBefore)
641 farMaxVal += collapsibleSizeAfter;
655 const int Threshold = 40;
657 getRange(index, farMin, min, max, farMax);
663 int delta = pos - *max;
664 int width = *farMax - *max;
666 if (delta > width / 2 && delta >=
qMin(Threshold, width)) {
673 int delta = *min -
pos;
674 int width = *min - *farMin;
676 if (delta > width / 2 && delta >=
qMin(Threshold, width)) {
689 return childrenCollapsible;
696 recalc(q->isVisible());
703 for (
int i = 0; i < list.size(); ++i) {
708 if (clampNegativeSize && s->
sizer < 0)
714 if (collapsible(s) && smartMinSize > 0) {
717 s->
sizer = smartMinSize;
720 if (s->
sizer < smartMinSize)
721 s->
sizer = smartMinSize;
732 QRect contents = q->contentsRect();
761 if (q->isRightToLeft())
773 if (index < 0 || index >= list.count())
776 #ifdef QSPLITTER_DEBUG 777 qDebug() <<
"QSplitterPrivate::doMove" << backwards << hPos << index << delta << mayCollapse;
783 int nextId = backwards ? index - delta : index + delta;
786 doMove(backwards, hPos, nextId, delta, collapsible(nextId), positions, widths);
792 if (ws > 0 || (!s->
collapsed && !mayCollapse)) {
798 positions[
index] = backwards ? hPos -
ws : hPos + hs;
800 doMove(backwards, backwards ? hPos - ws - hs : hPos + hs + ws, nextId, delta,
801 collapsible(nextId), positions, widths);
808 for (
int i = 0; i < list.size(); ++i) {
809 if (list.at(i)->widget == w)
816 static void setStretch(
QWidget *w,
int sf)
824 static int getStretch(
const QWidget *w)
830 void QSplitter::setResizeMode(
QWidget *w, ResizeMode mode)
854 bool metWidget =
false;
855 if (!
d->compatMode) {
856 d->compatMode =
true;
857 for (
int i = 0; i <
d->list.size(); ++i) {
861 if (getStretch(s->
widget) == 0)
866 if (mode == KeepSize)
867 sf = metWidget ? 0 : 243;
908 bool needShow = show && q->isVisible() &&
914 insertWidget(index, widget);
915 recalc(q->isVisible());
929 int last = list.count();
930 for (i = 0; i < list.size(); ++i) {
938 if (index < 0 || index > last)
948 newHandle = q->createHandle();
953 list.insert(index,sls);
960 int sf = getStretch(sls->
widget);
962 setStretch(sls->
widget, 0);
964 setStretch(sls->
widget, 1);
1058 delete d->rubberBand;
1059 while (!
d->list.isEmpty())
1060 delete d->list.takeFirst();
1090 if (
d->orient == orientation)
1102 for (
int i = 0; i <
d->list.size(); ++i) {
1132 d->childrenCollapsible = collapse;
1138 return d->childrenCollapsible;
1157 if (index < 0 || index >=
d->list.size()) {
1158 qWarning(
"QSplitter::setCollapsible: Index %d out of range", index);
1161 d->list.at(index)->collapsible = collapse ? 1 : 0;
1170 if (index < 0 || index >=
d->list.size()) {
1171 qWarning(
"QSplitter::isCollapsible: Index %d out of range", index);
1174 return d->list.at(index)->collapsible;
1213 d->insertWidget_helper(index, widget,
true);
1231 for (
int i = 0; i <
d->list.size(); ++i) {
1266 if (index < 0 || index >=
d->list.size())
1268 return d->list.at(index)->handle;
1279 if (index < 0 || index >=
d->list.size())
1281 return d->list.at(index)->widget;
1292 return d->list.count();
1319 if (c->
added() && !
d->blockChildAdd && !w->
isWindow() && !
d->findWidget(w)) {
1320 d->insertWidget_helper(
d->list.count(), w,
false);
1321 }
else if (c->
polished() && !
d->blockChildAdd) {
1325 for (
int i = 0; i <
d->list.size(); ++i) {
1328 d->list.removeAt(i);
1348 d->rubberBand->deleteLater();
1352 const int rBord = 3;
1354 if (!
d->rubberBand) {
1363 d->rubberBand->setGeometry(newGeom);
1364 d->rubberBand->show();
1374 switch (e->
type()) {
1378 d->firstShow =
true;
1383 d->firstShow =
false;
1389 case QEvent::LayoutHint:
1435 #ifdef QSPLITTER_DEBUG 1439 pos =
d->adjustPos(pos, index, &farMin, &min, &max, &farMax);
1441 #ifdef QSPLITTER_DEBUG 1442 qDebug() <<
"QSplitter::moveSplitter" << debugp << index <<
"adjusted" << pos <<
"oldP" << oldP;
1449 d->doMove(
false, pos, index, +1, (
d->collapsible(s) && (pos > max)), poss.data(),
ws.data());
1450 d->doMove(
true, pos, index - 1, +1, (
d->collapsible(index - 1) && (pos < min)), poss.data(),
ws.data());
1451 upLeft = (pos < oldP);
1453 int wid, delta,
count =
d->list.count();
1461 for (; wid >= 0 && wid <
count; wid += delta) {
1464 d->setGeo(sls, poss[wid],
ws[wid],
true);
1480 d->getRange(index, min, 0, 0, max);
1499 return d->adjustPos(pos, index, &u, &n, &i, &x);
1610 for (
int i = 0; i <
d->list.size(); ++i) {
1611 QWidget *w =
d->list.at(i)->widget;
1617 t =
qMax(t,
d->trans(s));
1635 for (
int i = 0; i <
d->list.size(); ++i) {
1643 l +=
d->pick(widgetSize);
1644 t =
qMax(t,
d->trans(widgetSize));
1650 l +=
d->pick(splitterSize);
1651 t =
qMax(t,
d->trans(splitterSize));
1680 for (
int i = 0; i <
d->list.size(); ++i) {
1711 d->setSizes_helper(list,
true);
1731 if (
d->handleWidth > 0) {
1732 return d->handleWidth;
1777 stream <<
qint32(version);
1779 for (
int i = 0; i <
d->list.size(); ++i) {
1825 d->setSizes_helper(list,
false);
1860 if (index <= -1 || index >=
d->list.count())
1872 #ifndef QT_NO_TEXTSTREAM 1909 #endif // QT_NO_TEXTSTREAM 1914 #endif // QT_NO_SPLITTER QSplitterHandle * handle(int index) const
Returns the handle to the left (or above) for the item in the splitter's layout at the given index...
The QPainter class performs low-level painting on widgets and other paint devices.
bool collapsible(QSplitterLayoutStruct *) const
QSize sizeHint() const
Reimplemented Function
void setHorizontalStretch(uchar stretchFactor)
void setSizes(const QList< int > &list)
Sets the child widgets respective sizes to the values given in the list.
QList< int > sizes() const
Returns a list of the size parameters of all the widgets in this splitter.
void setSizes_helper(const QList< int > &sizes, bool clampNegativeSize=false)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
Q_GUI_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, const QSize &minSize, const QSize &maxSize, const QSizePolicy &sizePolicy)
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
QString readLine(qint64 maxlen=0)
Reads one line of text from the stream, and returns it as a QString.
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
bool polished() const
Returns true if type() is QEvent::ChildPolished; otherwise returns false.
bool opaqueResize() const
Returns true if widgets are resized dynamically (opaquely), otherwise returns false.
QStyle::State state
the style flags that are used when drawing the control
void setCollapsible(int index, bool)
Sets whether the child widget at index index is collapsible to collapse.
static QSize globalStrut()
bool added() const
Returns true if type() is QEvent::ChildAdded; otherwise returns false.
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QString & replace(int i, int len, QChar after)
The QByteArray class provides an array of bytes.
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
int getWidgetSize(Qt::Orientation orient)
void resizeEvent(QResizeEvent *)
Reimplemented Function
void setChildrenCollapsible(bool)
void resizeEvent(QResizeEvent *)
Reimplemented Function
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate...
bool isCollapsible(int index) const
Returns true if the widget at index is collapsible, otherwise returns false.
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
int left() const
Returns the x-coordinate of the rectangle's left edge.
int width() const
Returns the width of the rectangle.
void addWidget(QWidget *widget)
Adds the given widget to the splitter's layout after all the other items.
bool restoreState(const QByteArray &state)
Restores the splitter's layout to the state specified.
void init(const QWidget *w)
Use initFrom(widget) instead.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
long ASN1_INTEGER_get ASN1_INTEGER * a
virtual QSplitterHandle * createHandle()
Returns a new splitter handle as a child widget of this splitter.
int closestLegalPosition(int, int)
Returns the closest legal position to pos of the widget with index index.
int height() const
Returns the height of the rectangle.
void insertWidget_helper(int index, QWidget *widget, bool show)
The QString class provides a Unicode character string.
QSplitterLayoutStruct * insertWidget(int index, QWidget *)
int getHandleSize(Qt::Orientation orient)
bool empty() const
This function is provided for STL compatibility.
The QSplitterHandle class provides handle functionality of the splitter.
int horizontalStretch() const
Qt::Orientation orientation() const
Returns the handle's orientation.
void moveSplitter(int p)
Tells the splitter to move this handle to position pos, which is the distance from the left or top ed...
void childEvent(QChildEvent *)
Tells the splitter that the child widget described by c has been inserted or removed.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void setOrientation(Qt::Orientation)
QWidget * widget(int index) const
Returns the widget at the given index in the splitter's layout.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void doMove(bool backwards, int pos, int index, int delta, bool mayCollapse, int *positions, int *widths)
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
void setObjectName(const QString &name)
static const uint Default
void paintEvent(QPaintEvent *)
Reimplemented Function
int closestLegalPosition(int p)
Returns the closest legal position to pos of the splitter handle.
Q_CORE_EXPORT void qDebug(const char *,...)
QTextStream & operator<<(QTextStream &ts, const QSplitter &splitter)
Use ts << {splitter}.
QSplitterLayoutStruct * findWidget(QWidget *) const
int width() const
Returns the width.
QSize minimumSizeHint() const
Reimplemented Function
void append(const T &t)
Inserts value at the end of the list.
void recalc(bool update=false)
#define QT_BEGIN_NAMESPACE
This macro expands to.
QPoint bottomRight() const
Returns the position of the rectangle's bottom-right corner.
friend class QSplitterHandle
void setRubberBand(int position)
Displays a rubber band at position pos.
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
int count() const
Returns the number of widgets contained in the splitter's layout.
The QStyleOption class stores the parameters used by QStyle functions.
~QSplitter()
Destroys the splitter.
static const qint32 SplitterMagic
static const QCssKnownValue positions[NumKnownPositionModes - 1]
QSize sizeHint() const
Reimplemented Function
QByteArray saveState() const
Saves the state of the splitter's layout.
QSize size() const
Returns the size of the rectangle.
void setOrientation(Qt::Orientation o)
Sets the orientation of the splitter handle to orientation.
void mouseMoveEvent(QMouseEvent *)
Reimplemented Function
The QResizeEvent class contains event parameters for resize events.
Q_CORE_EXPORT void qWarning(const char *,...)
int verticalStretch() const
void moveSplitter(int pos, int index)
Moves the left or top edge of the splitter handle at index as close as possible to position pos...
The QRegion class specifies a clip region for a painter.
T value(int i) const
Returns the value at index position i in the list.
QSplitter(QWidget *parent=0)
Constructs a horizontal splitter with the parent argument passed on to the QFrame constructor...
Qt::MouseButton button() const
Returns the button that caused the event.
void refresh()
Updates the splitter's state.
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
The QMouseEvent class contains parameters that describe a mouse event.
void qGeomCalc(QVector< QLayoutStruct > &chain, int start, int count, int pos, int space, int spacer)
The QChildEvent class contains event parameters for child object events.
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
QSplitterHandle(Qt::Orientation o, QSplitter *parent)
Creates a QSplitter handle with the given orientation and QSplitter parent.
void insertWidget(int index, QWidget *widget)
Inserts the widget specified into the splitter's layout at the given index.
void addContribution(int, int *, int *, bool) const
QPalette palette
the palette that should be used when painting the control
bool childrenCollapsible() const
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
QTextStream & operator>>(QTextStream &ts, QSplitter &splitter)
Use ts >> {splitter}.
void getRange(int index, int *, int *) const
Returns the valid range of the splitter with index index in {min} and *{max} if min and max are not 0...
void mouseReleaseEvent(QMouseEvent *)
Reimplemented Function
The QTextStream class provides a convenient interface for reading and writing text.
int y() const
Returns the y-coordinate of the rectangle's top edge.
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
void setStretchFactor(int index, int stretch)
Updates the size policy of the widget at position index to have a stretch factor of stretch...
int findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
The QPoint class defines a point in the plane using integer precision.
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
void splitterMoved(int pos, int index)
This signal is emitted when the splitter handle at a particular index has been moved to position pos...
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
QString objectName() const
bool event(QEvent *)
Reimplemented Function
int height() const
Returns the height.
The QRect class defines a rectangle in the plane using integer precision.
void setOpaqueResize(bool opaque=true)
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
bool event(QEvent *)
Reimplemented Function
int adjustPos(int, int, int *, int *, int *, int *) const
void mousePressEvent(QMouseEvent *)
Reimplemented Function
bool opaqueResize() const
The QSize class defines the size of a two-dimensional object using integer point precision.
The QDataStream class provides serialization of binary data to a QIODevice.
void setGeo(QSplitterLayoutStruct *s, int pos, int size, bool allowCollapse)
QSplitter * splitter() const
Returns the splitter associated with this splitter handle.
int indexOf(QWidget *w) const
Returns the index in the splitter's layout of the specified widget.
void setVerticalStretch(uchar stretchFactor)
The QPaintEvent class contains event parameters for paint events.
The QEvent class is the base class of all event classes.
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary...
Type type() const
Returns the event type.
The QFrame class is the base class of widgets that can have a frame.
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void changeEvent(QEvent *)
Reimplemented Function
The QSplitter class implements a splitter widget.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QRect rect
the area that should be used for various calculations and painting
void getRange(int index, int *, int *, int *, int *) const
QObject * child() const
Returns the child object that was added or removed.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
Qt::Orientation orientation() const
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)