Qt 4.8
qsplitter.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qsplitter.h"
43 #ifndef QT_NO_SPLITTER
44 
45 #include "qapplication.h"
46 #include "qcursor.h"
47 #include "qdrawutil.h"
48 #include "qevent.h"
49 #include "qlayout.h"
50 #include "qlist.h"
51 #include "qpainter.h"
52 #include "qrubberband.h"
53 #include "qstyle.h"
54 #include "qstyleoption.h"
55 #include "qtextstream.h"
56 #include "qvarlengtharray.h"
57 #include "qvector.h"
58 #include "private/qlayoutengine_p.h"
59 #include "private/qsplitter_p.h"
60 #include "qtimer.h"
61 #include "qdebug.h"
62 
63 #include <ctype.h>
64 
66 
67 //#define QSPLITTER_DEBUG
68 
121  : QWidget(*new QSplitterHandlePrivate, parent, 0)
122 {
124  d->s = parent;
125  setOrientation(orientation);
126 }
127 
135 {
137  d->orient = orientation;
138 #ifndef QT_NO_CURSOR
140 #endif
141 }
142 
149 {
150  Q_D(const QSplitterHandle);
151  return d->orient;
152 }
153 
154 
163 {
164  Q_D(const QSplitterHandle);
165  return d->s->opaqueResize();
166 }
167 
168 
175 {
176  return d_func()->s;
177 }
178 
190 {
192  if (d->s->isRightToLeft() && d->orient == Qt::Horizontal)
193  pos = d->s->contentsRect().width() - pos;
194  d->s->moveSplitter(pos, d->s->indexOf(this));
195 }
196 
206 {
208  QSplitter *s = d->s;
209  if (s->isRightToLeft() && d->orient == Qt::Horizontal) {
210  int w = s->contentsRect().width();
211  return w - s->closestLegalPosition(w - pos, s->indexOf(this));
212  }
213  return s->closestLegalPosition(pos, s->indexOf(this));
214 }
215 
220 {
221  Q_D(const QSplitterHandle);
222  int hw = d->s->handleWidth();
223  QStyleOption opt(0);
224  opt.init(d->s);
226  return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s)
228 }
229 
234 {
235  Q_D(const QSplitterHandle);
236 
237  // When splitters are only 1 pixel large we increase the
238  // actual grab area to five pixels
239 
240  // Note that QSplitter uses contentsRect for layouting
241  // and ensures that handles are drawn on top of widgets
242  // We simply use the contents margins for draggin and only
243  // paint the mask area
244  bool useTinyMode = (d->s->handleWidth() == 1);
245  setAttribute(Qt::WA_MouseNoMask, useTinyMode);
246  if (useTinyMode) {
247  if (orientation() == Qt::Horizontal)
248  setContentsMargins(2, 0, 2, 0);
249  else
250  setContentsMargins(0, 2, 0, 2);
252  }
253 
254  QWidget::resizeEvent(event);
255 }
256 
261 {
263  switch(event->type()) {
264  case QEvent::HoverEnter:
265  d->hover = true;
266  update();
267  break;
268  case QEvent::HoverLeave:
269  d->hover = false;
270  update();
271  break;
272  default:
273  break;
274  }
275  return QWidget::event(event);
276 }
277 
282 {
284  if (!(e->buttons() & Qt::LeftButton))
285  return;
286  int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos()))
287  - d->mouseOffset;
288  if (opaqueResize()) {
289  moveSplitter(pos);
290  } else {
291  d->s->setRubberBand(closestLegalPosition(pos));
292  }
293 }
294 
299 {
301  if (e->button() == Qt::LeftButton) {
302  d->mouseOffset = d->pick(e->pos());
303  d->pressed = true;
304  update();
305  }
306 }
307 
312 {
314  if (!opaqueResize() && e->button() == Qt::LeftButton) {
315  int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos()))
316  - d->mouseOffset;
317  d->s->setRubberBand(-1);
318  moveSplitter(pos);
319  }
320  if (e->button() == Qt::LeftButton) {
321  d->pressed = false;
322  update();
323  }
324 }
325 
330 {
332  QPainter p(this);
333  QStyleOption opt(0);
334  opt.rect = contentsRect();
335  opt.palette = palette();
336  if (orientation() == Qt::Horizontal)
338  else
340  if (d->hover)
342  if (d->pressed)
344  if (isEnabled())
346  parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s);
347 }
348 
349 
351 {
352  if (sizer == -1) {
353  QSize s = widget->sizeHint();
354  const int presizer = pick(s, orient);
355  const int realsize = pick(widget->size(), orient);
356  if (!s.isValid() || (widget->testAttribute(Qt::WA_Resized) && (realsize > presizer))) {
357  sizer = pick(widget->size(), orient);
358  } else {
359  sizer = presizer;
360  }
362  int sf = (orient == Qt::Horizontal) ? p.horizontalStretch() : p.verticalStretch();
363  if (sf > 1)
364  sizer *= sf;
365  }
366  return sizer;
367 }
368 
370 {
371  return pick(handle->sizeHint(), orient);
372 }
373 
375 {
376  Q_Q(QSplitter);
378  if (orient == Qt::Vertical)
379  sp.transpose();
380  q->setSizePolicy(sp);
381  q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);
382 }
383 
385 {
386  Q_Q(QSplitter);
387  int n = list.count();
388  /*
389  Splitter handles before the first visible widget or right
390  before a hidden widget must be hidden.
391  */
392  bool first = true;
393  bool allInvisible = n != 0;
394  for (int i = 0; i < n ; ++i) {
395  QSplitterLayoutStruct *s = list.at(i);
396  bool widgetHidden = s->widget->isHidden();
397  if (allInvisible && !widgetHidden && !s->collapsed)
398  allInvisible = false;
399  s->handle->setHidden(first || widgetHidden);
400  if (!widgetHidden)
401  first = false;
402  }
403 
404  if (allInvisible)
405  for (int i = 0; i < n ; ++i) {
406  QSplitterLayoutStruct *s = list.at(i);
407  if (!s->widget->isHidden()) {
408  s->collapsed = false;
409  break;
410  }
411  }
412 
413  int fi = 2 * q->frameWidth();
414  int maxl = fi;
415  int minl = fi;
416  int maxt = QWIDGETSIZE_MAX;
417  int mint = fi;
418  /*
419  calculate min/max sizes for the whole splitter
420  */
421  bool empty = true;
422  for (int j = 0; j < n; j++) {
423  QSplitterLayoutStruct *s = list.at(j);
424 
425  if (!s->widget->isHidden()) {
426  empty = false;
427  if (!s->handle->isHidden()) {
428  minl += s->getHandleSize(orient);
429  maxl += s->getHandleSize(orient);
430  }
431 
432  QSize minS = qSmartMinSize(s->widget);
433  minl += pick(minS);
434  maxl += pick(s->widget->maximumSize());
435  mint = qMax(mint, trans(minS));
436  int tm = trans(s->widget->maximumSize());
437  if (tm > 0)
438  maxt = qMin(maxt, tm);
439  }
440  }
441 
442  if (empty) {
443  if (qobject_cast<QSplitter *>(parent)) {
444  // nested splitters; be nice
445  maxl = maxt = 0;
446  } else {
447  // QSplitter with no children yet
448  maxl = QWIDGETSIZE_MAX;
449  }
450  } else {
451  maxl = qMin<int>(maxl, QWIDGETSIZE_MAX);
452  }
453  if (maxt < mint)
454  maxt = mint;
455 
456  if (update) {
457  if (orient == Qt::Horizontal) {
458  q->setMaximumSize(maxl, maxt);
459  if (q->isWindow())
460  q->setMinimumSize(minl,mint);
461  } else {
462  q->setMaximumSize(maxt, maxl);
463  if (q->isWindow())
464  q->setMinimumSize(mint,minl);
465  }
466  doResize();
467  q->updateGeometry();
468  } else {
469  firstShow = true;
470  }
471 }
472 
474 {
475  Q_Q(QSplitter);
476  QRect r = q->contentsRect();
477  int n = list.count();
479  int i;
480 
481  bool noStretchFactorsSet = true;
482  for (i = 0; i < n; ++i) {
483  QSizePolicy p = list.at(i)->widget->sizePolicy();
484  int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch();
485  if (sf != 0) {
486  noStretchFactorsSet = false;
487  break;
488  }
489  }
490 
491  int j=0;
492  for (i = 0; i < n; ++i) {
493  QSplitterLayoutStruct *s = list.at(i);
494 #ifdef QSPLITTER_DEBUG
495  qDebug("widget %d hidden: %d collapsed: %d handle hidden: %d", i, s->widget->isHidden(),
496  s->collapsed, s->handle->isHidden());
497 #endif
498 
499  a[j].init();
500  if (s->handle->isHidden()) {
501  a[j].maximumSize = 0;
502  } else {
503  a[j].sizeHint = a[j].minimumSize = a[j].maximumSize = s->getHandleSize(orient);
504  a[j].empty = false;
505  }
506  ++j;
507 
508  a[j].init();
509  if (s->widget->isHidden() || s->collapsed) {
510  a[j].maximumSize = 0;
511  } else {
512  a[j].minimumSize = pick(qSmartMinSize(s->widget));
513  a[j].maximumSize = pick(s->widget->maximumSize());
514  a[j].empty = false;
515 
516  bool stretch = noStretchFactorsSet;
517  if (!stretch) {
518  QSizePolicy p = s->widget->sizePolicy();
519  int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch();
520  stretch = (sf != 0);
521  }
522  if (stretch) {
523  a[j].stretch = s->getWidgetSize(orient);
524  a[j].sizeHint = a[j].minimumSize;
525  a[j].expansive = true;
526  } else {
527  a[j].sizeHint = qMax(s->getWidgetSize(orient), a[j].minimumSize);
528  }
529  }
530  ++j;
531  }
532 
533  qGeomCalc(a, 0, n*2, pick(r.topLeft()), pick(r.size()), 0);
534 
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",
538  i, "", i,
539  a[i].stretch,
540  a[i].sizeHint,
541  a[i].minimumSize,
542  a[i].maximumSize,
543  a[i].expansive,
544  a[i].empty,
545  a[i].pos,
546  a[i].size);
547  }
548 #endif
549 
550  for (i = 0; i < n; ++i) {
551  QSplitterLayoutStruct *s = list.at(i);
552  setGeo(s, a[i*2+1].pos, a[i*2+1].size, false);
553  }
554 }
555 
557 {
558  for (int i = 0; i < list.size(); ++i) {
559  QSplitterLayoutStruct *sls = list.at(i);
560  sls->sizer = pick(sls->rect.size());
561  }
562 }
563 
564 void QSplitterPrivate::addContribution(int index, int *min, int *max, bool mayCollapse) const
565 {
566  QSplitterLayoutStruct *s = list.at(index);
567  if (!s->widget->isHidden()) {
568  if (!s->handle->isHidden()) {
569  *min += s->getHandleSize(orient);
570  *max += s->getHandleSize(orient);
571  }
572  if (mayCollapse || !s->collapsed)
573  *min += pick(qSmartMinSize(s->widget));
574 
575  *max += pick(s->widget->maximumSize());
576  }
577 }
578 
579 int QSplitterPrivate::findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const
580 {
581  if (delta < 0)
582  index += delta;
583  do {
584  QWidget *w = list.at(index)->widget;
585  if (!w->isHidden()) {
586  if (collapsible(list.at(index)))
587  collapsibleSize = pick(qSmartMinSize(w));
588  return index;
589  }
590  index += delta;
591  } while (index >= 0 && index < list.count());
592 
593  return -1;
594 }
595 
596 /*
597  For the splitter handle with index \a index, \a min and \a max give the range without collapsing any widgets,
598  and \a farMin and farMax give the range with collapsing included.
599 */
600 void QSplitterPrivate::getRange(int index, int *farMin, int *min, int *max, int *farMax) const
601 {
602  Q_Q(const QSplitter);
603  int n = list.count();
604  if (index <= 0 || index >= n)
605  return;
606 
607  int collapsibleSizeBefore = 0;
608  int idJustBefore = findWidgetJustBeforeOrJustAfter(index, -1, collapsibleSizeBefore);
609 
610  int collapsibleSizeAfter = 0;
611  int idJustAfter = findWidgetJustBeforeOrJustAfter(index, +1, collapsibleSizeAfter);
612 
613  int minBefore = 0;
614  int minAfter = 0;
615  int maxBefore = 0;
616  int maxAfter = 0;
617  int i;
618 
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);
623 
624  QRect r = q->contentsRect();
625  int farMinVal;
626  int minVal;
627  int maxVal;
628  int farMaxVal;
629 
630  int smartMinBefore = qMax(minBefore, pick(r.size()) - maxAfter);
631  int smartMaxBefore = qMin(maxBefore, pick(r.size()) - minAfter);
632 
633  minVal = pick(r.topLeft()) + smartMinBefore;
634  maxVal = pick(r.topLeft()) + smartMaxBefore;
635 
636  farMinVal = minVal;
637  if (minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter)
638  farMinVal -= collapsibleSizeBefore;
639  farMaxVal = maxVal;
640  if (pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore)
641  farMaxVal += collapsibleSizeAfter;
642 
643  if (farMin)
644  *farMin = farMinVal;
645  if (min)
646  *min = minVal;
647  if (max)
648  *max = maxVal;
649  if (farMax)
650  *farMax = farMaxVal;
651 }
652 
653 int QSplitterPrivate::adjustPos(int pos, int index, int *farMin, int *min, int *max, int *farMax) const
654 {
655  const int Threshold = 40;
656 
657  getRange(index, farMin, min, max, farMax);
658 
659  if (pos >= *min) {
660  if (pos <= *max) {
661  return pos;
662  } else {
663  int delta = pos - *max;
664  int width = *farMax - *max;
665 
666  if (delta > width / 2 && delta >= qMin(Threshold, width)) {
667  return *farMax;
668  } else {
669  return *max;
670  }
671  }
672  } else {
673  int delta = *min - pos;
674  int width = *min - *farMin;
675 
676  if (delta > width / 2 && delta >= qMin(Threshold, width)) {
677  return *farMin;
678  } else {
679  return *min;
680  }
681  }
682 }
683 
685 {
686  if (s->collapsible != Default) {
687  return (bool)s->collapsible;
688  } else {
689  return childrenCollapsible;
690  }
691 }
692 
694 {
695  Q_Q(QSplitter);
696  recalc(q->isVisible());
697 }
698 
699 void QSplitterPrivate::setSizes_helper(const QList<int> &sizes, bool clampNegativeSize)
700 {
701  int j = 0;
702 
703  for (int i = 0; i < list.size(); ++i) {
704  QSplitterLayoutStruct *s = list.at(i);
705 
706  s->collapsed = false;
707  s->sizer = sizes.value(j++);
708  if (clampNegativeSize && s->sizer < 0)
709  s->sizer = 0;
710  int smartMinSize = pick(qSmartMinSize(s->widget));
711 
712  // Make sure that we reset the collapsed state.
713  if (s->sizer == 0) {
714  if (collapsible(s) && smartMinSize > 0) {
715  s->collapsed = true;
716  } else {
717  s->sizer = smartMinSize;
718  }
719  } else {
720  if (s->sizer < smartMinSize)
721  s->sizer = smartMinSize;
722  }
723  }
724  doResize();
725 }
726 
727 void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool allowCollapse)
728 {
729  Q_Q(QSplitter);
730  QWidget *w = sls->widget;
731  QRect r;
732  QRect contents = q->contentsRect();
733  if (orient == Qt::Horizontal) {
734  r.setRect(p, contents.y(), s, contents.height());
735  } else {
736  r.setRect(contents.x(), p, contents.width(), s);
737  }
738  sls->rect = r;
739 
740  int minSize = pick(qSmartMinSize(w));
741 
742  if (orient == Qt::Horizontal && q->isRightToLeft())
743  r.moveRight(contents.width() - r.left());
744 
745  if (allowCollapse)
746  sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden();
747 
748  // Hide the child widget, but without calling hide() so that
749  // the splitter handle is still shown.
750  if (sls->collapsed)
751  r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1));
752 
753  w->setGeometry(r);
754 
755  if (!sls->handle->isHidden()) {
756  QSplitterHandle *h = sls->handle;
757  QSize hs = h->sizeHint();
758  int left, top, right, bottom;
759  h->getContentsMargins(&left, &top, &right, &bottom);
760  if (orient==Qt::Horizontal) {
761  if (q->isRightToLeft())
762  p = contents.width() - p + hs.width();
763  h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height());
764  } else {
765  h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom);
766  }
767  }
768 }
769 
770 void QSplitterPrivate::doMove(bool backwards, int hPos, int index, int delta, bool mayCollapse,
771  int *positions, int *widths)
772 {
773  if (index < 0 || index >= list.count())
774  return;
775 
776 #ifdef QSPLITTER_DEBUG
777  qDebug() << "QSplitterPrivate::doMove" << backwards << hPos << index << delta << mayCollapse;
778 #endif
779 
780  QSplitterLayoutStruct *s = list.at(index);
781  QWidget *w = s->widget;
782 
783  int nextId = backwards ? index - delta : index + delta;
784 
785  if (w->isHidden()) {
786  doMove(backwards, hPos, nextId, delta, collapsible(nextId), positions, widths);
787  } else {
788  int hs =s->handle->isHidden() ? 0 : s->getHandleSize(orient);
789 
790  int ws = backwards ? hPos - pick(s->rect.topLeft())
791  : pick(s->rect.bottomRight()) - hPos -hs + 1;
792  if (ws > 0 || (!s->collapsed && !mayCollapse)) {
793  ws = qMin(ws, pick(w->maximumSize()));
794  ws = qMax(ws, pick(qSmartMinSize(w)));
795  } else {
796  ws = 0;
797  }
798  positions[index] = backwards ? hPos - ws : hPos + hs;
799  widths[index] = ws;
800  doMove(backwards, backwards ? hPos - ws - hs : hPos + hs + ws, nextId, delta,
801  collapsible(nextId), positions, widths);
802  }
803 
804 }
805 
807 {
808  for (int i = 0; i < list.size(); ++i) {
809  if (list.at(i)->widget == w)
810  return list.at(i);
811  }
812  return 0;
813 }
814 
815 #ifdef QT3_SUPPORT
816 static void setStretch(QWidget *w, int sf)
817 {
818  QSizePolicy sp = w->sizePolicy();
819  sp.setHorizontalStretch(sf);
820  sp.setVerticalStretch(sf);
821  w->setSizePolicy(sp);
822 }
823 
824 static int getStretch(const QWidget *w)
825 {
826  QSizePolicy sp = w->sizePolicy();
827  return qMax(sp.horizontalStretch(), sp.verticalStretch());
828 }
829 
830 void QSplitter::setResizeMode(QWidget *w, ResizeMode mode)
831 {
832  /*
833  Internal comment:
834 
835  This function tries to simulate the Qt 3.x ResizeMode
836  behavior using QSizePolicy stretch factors. This isn't easy,
837  because the default \link ResizeMode \endlink was \link Stretch \endlink , not \link KeepSize \endlink , whereas the default stetch factor is 0.
838 
839  So what we do is this: When the user calls setResizeMode()
840  the first time, we iterate through all the child widgets and
841  set their stretch factors to 1. Later on, if children are
842  added (using addWidget()), their stretch factors are also set
843  to 1.
844 
845  There is just one problem left: Often, setResizeMode() is
846  called \e{before} addWidget(), because addWidget() is called
847  from the event loop. In that case, we use a special value,
848  243, instead of 0 to prevent 0 from being overwritten with 1
849  in addWidget(). This is a wicked hack, but fortunately it
850  only occurs as a result of calling a \c QT3_SUPPORT function.
851  */
852 
853  Q_D(QSplitter);
854  bool metWidget = false;
855  if (!d->compatMode) {
856  d->compatMode = true;
857  for (int i = 0; i < d->list.size(); ++i) {
858  QSplitterLayoutStruct *s = d->list.at(i);
859  if (s->widget == w)
860  metWidget = true;
861  if (getStretch(s->widget) == 0)
862  setStretch(s->widget, 1);
863  }
864  }
865  int sf;
866  if (mode == KeepSize)
867  sf = metWidget ? 0 : 243;
868  else
869  sf = 1;
870  setStretch(w, sf);
871 }
872 
878  : QFrame(*new QSplitterPrivate, parent)
879 {
880  Q_D(QSplitter);
882  d->orient = Qt::Horizontal;
883  d->init();
884 }
885 
886 
892  : QFrame(*new QSplitterPrivate, parent)
893 {
894  Q_D(QSplitter);
896  d->orient = orientation;
897  d->init();
898 }
899 #endif
900 
905 {
906  Q_Q(QSplitter);
907  QBoolBlocker b(blockChildAdd);
908  bool needShow = show && q->isVisible() &&
909  !(widget->isHidden() && widget->testAttribute(Qt::WA_WState_ExplicitShowHide));
910  if (widget->parentWidget() != q)
911  widget->setParent(q);
912  if (needShow)
913  widget->show();
914  insertWidget(index, widget);
915  recalc(q->isVisible());
916 }
917 
918 /*
919  Inserts the widget \a w at position \a index in the splitter's list of widgets.
920 
921  If \a w is already in the splitter, it will be moved to the new position.
922 */
923 
925 {
926  Q_Q(QSplitter);
927  QSplitterLayoutStruct *sls = 0;
928  int i;
929  int last = list.count();
930  for (i = 0; i < list.size(); ++i) {
931  QSplitterLayoutStruct *s = list.at(i);
932  if (s->widget == w) {
933  sls = s;
934  --last;
935  break;
936  }
937  }
938  if (index < 0 || index > last)
939  index = last;
940 
941  if (sls) {
942  list.move(i,index);
943  } else {
944  QSplitterHandle *newHandle = 0;
945  sls = new QSplitterLayoutStruct;
946  QString tmp = QLatin1String("qt_splithandle_");
947  tmp += w->objectName();
948  newHandle = q->createHandle();
949  newHandle->setObjectName(tmp);
950  sls->handle = newHandle;
951  sls->widget = w;
952  w->lower();
953  list.insert(index,sls);
954 
955  if (newHandle && q->isVisible())
956  newHandle->show(); // will trigger sending of post events
957 
958 #ifdef QT3_SUPPORT
959  if (compatMode) {
960  int sf = getStretch(sls->widget);
961  if (sf == 243)
962  setStretch(sls->widget, 0);
963  else if (sf == 0)
964  setStretch(sls->widget, 1);
965  }
966 #endif
967  }
968  return sls;
969 }
970 
1029  : QFrame(*new QSplitterPrivate, parent)
1030 {
1031  Q_D(QSplitter);
1032  d->orient = Qt::Horizontal;
1033  d->init();
1034 }
1035 
1036 
1043  : QFrame(*new QSplitterPrivate, parent)
1044 {
1045  Q_D(QSplitter);
1046  d->orient = orientation;
1047  d->init();
1048 }
1049 
1050 
1056 {
1057  Q_D(QSplitter);
1058  delete d->rubberBand;
1059  while (!d->list.isEmpty())
1060  delete d->list.takeFirst();
1061 }
1062 
1068 {
1069  Q_D(QSplitter);
1070  d->recalc(true);
1071 }
1072 
1088 {
1089  Q_D(QSplitter);
1090  if (d->orient == orientation)
1091  return;
1092 
1094  QSizePolicy sp = sizePolicy();
1095  sp.transpose();
1096  setSizePolicy(sp);
1098  }
1099 
1100  d->orient = orientation;
1101 
1102  for (int i = 0; i < d->list.size(); ++i) {
1103  QSplitterLayoutStruct *s = d->list.at(i);
1104  s->handle->setOrientation(orientation);
1105  }
1106  d->recalc(isVisible());
1107 }
1108 
1110 {
1111  Q_D(const QSplitter);
1112  return d->orient;
1113 }
1114 
1130 {
1131  Q_D(QSplitter);
1132  d->childrenCollapsible = collapse;
1133 }
1134 
1135 bool QSplitter::childrenCollapsible() const
1136 {
1137  Q_D(const QSplitter);
1138  return d->childrenCollapsible;
1139 }
1140 
1153 void QSplitter::setCollapsible(int index, bool collapse)
1154 {
1155  Q_D(QSplitter);
1156 
1157  if (index < 0 || index >= d->list.size()) {
1158  qWarning("QSplitter::setCollapsible: Index %d out of range", index);
1159  return;
1160  }
1161  d->list.at(index)->collapsible = collapse ? 1 : 0;
1162 }
1163 
1168 {
1169  Q_D(const QSplitter);
1170  if (index < 0 || index >= d->list.size()) {
1171  qWarning("QSplitter::isCollapsible: Index %d out of range", index);
1172  return false;
1173  }
1174  return d->list.at(index)->collapsible;
1175 }
1176 
1181 {
1182  Q_D(QSplitter);
1183  d->doResize();
1184 }
1185 
1195 {
1196  Q_D(QSplitter);
1197  insertWidget(d->list.count(), widget);
1198 }
1199 
1211 {
1212  Q_D(QSplitter);
1213  d->insertWidget_helper(index, widget, true);
1214 }
1215 
1229 {
1230  Q_D(const QSplitter);
1231  for (int i = 0; i < d->list.size(); ++i) {
1232  QSplitterLayoutStruct *s = d->list.at(i);
1233  if (s->widget == w || s->handle == w)
1234  return i;
1235  }
1236  return -1;
1237 }
1238 
1247 {
1248  Q_D(QSplitter);
1249  return new QSplitterHandle(d->orient, this);
1250 }
1251 
1264 {
1265  Q_D(const QSplitter);
1266  if (index < 0 || index >= d->list.size())
1267  return 0;
1268  return d->list.at(index)->handle;
1269 }
1270 
1277 {
1278  Q_D(const QSplitter);
1279  if (index < 0 || index >= d->list.size())
1280  return 0;
1281  return d->list.at(index)->widget;
1282 }
1283 
1289 int QSplitter::count() const
1290 {
1291  Q_D(const QSplitter);
1292  return d->list.count();
1293 }
1294 
1314 {
1315  Q_D(QSplitter);
1316  if (!c->child()->isWidgetType())
1317  return;
1318  QWidget *w = static_cast<QWidget*>(c->child());
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) {
1323  w->show();
1324  } else if (c->type() == QEvent::ChildRemoved) {
1325  for (int i = 0; i < d->list.size(); ++i) {
1326  QSplitterLayoutStruct *s = d->list.at(i);
1327  if (s->widget == w) {
1328  d->list.removeAt(i);
1329  delete s;
1330  d->recalc(isVisible());
1331  return;
1332  }
1333  }
1334  }
1335 }
1336 
1337 
1344 {
1345  Q_D(QSplitter);
1346  if (pos < 0) {
1347  if (d->rubberBand)
1348  d->rubberBand->deleteLater();
1349  return;
1350  }
1351  QRect r = contentsRect();
1352  const int rBord = 3; // customizable?
1353  int hw = handleWidth();
1354  if (!d->rubberBand) {
1355  QBoolBlocker b(d->blockChildAdd);
1356  d->rubberBand = new QRubberBand(QRubberBand::Line, this);
1357  // For accessibility to identify this special widget.
1358  d->rubberBand->setObjectName(QLatin1String("qt_rubberband"));
1359  }
1360 
1361  const QRect newGeom = d->orient == Qt::Horizontal ? QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height()))
1362  : QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord));
1363  d->rubberBand->setGeometry(newGeom);
1364  d->rubberBand->show();
1365 }
1366 
1372 {
1373  Q_D(QSplitter);
1374  switch (e->type()) {
1375  case QEvent::Hide:
1376  // Reset firstShow to false here since things can be done to the splitter in between
1377  if (!d->firstShow)
1378  d->firstShow = true;
1379  break;
1380  case QEvent::Show:
1381  if (!d->firstShow)
1382  break;
1383  d->firstShow = false;
1384  // fall through
1385  case QEvent::HideToParent:
1386  case QEvent::ShowToParent:
1387  case QEvent::LayoutRequest:
1388 #ifdef QT3_SUPPORT
1389  case QEvent::LayoutHint:
1390 #endif
1391  d->recalc(isVisible());
1392  break;
1393  default:
1394  ;
1395  }
1396  return QWidget::event(e);
1397 }
1398 
1427 {
1428  Q_D(QSplitter);
1429  QSplitterLayoutStruct *s = d->list.at(index);
1430  int farMin;
1431  int min;
1432  int max;
1433  int farMax;
1434 
1435 #ifdef QSPLITTER_DEBUG
1436  int debugp = pos;
1437 #endif
1438 
1439  pos = d->adjustPos(pos, index, &farMin, &min, &max, &farMax);
1440  int oldP = d->pick(s->rect.topLeft());
1441 #ifdef QSPLITTER_DEBUG
1442  qDebug() << "QSplitter::moveSplitter" << debugp << index << "adjusted" << pos << "oldP" << oldP;
1443 #endif
1444 
1445  QVarLengthArray<int, 32> poss(d->list.count());
1446  QVarLengthArray<int, 32> ws(d->list.count());
1447  bool upLeft;
1448 
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);
1452 
1453  int wid, delta, count = d->list.count();
1454  if (upLeft) {
1455  wid = 0;
1456  delta = 1;
1457  } else {
1458  wid = count - 1;
1459  delta = -1;
1460  }
1461  for (; wid >= 0 && wid < count; wid += delta) {
1462  QSplitterLayoutStruct *sls = d->list.at( wid );
1463  if (!sls->widget->isHidden())
1464  d->setGeo(sls, poss[wid], ws[wid], true);
1465  }
1466  d->storeSizes();
1467 
1468  emit splitterMoved(pos, index);
1469 }
1470 
1471 
1477 void QSplitter::getRange(int index, int *min, int *max) const
1478 {
1479  Q_D(const QSplitter);
1480  d->getRange(index, min, 0, 0, max);
1481 }
1482 
1483 
1496 {
1497  Q_D(QSplitter);
1498  int x, i, n, u;
1499  return d->adjustPos(pos, index, &u, &n, &i, &x);
1500 }
1501 
1512 bool QSplitter::opaqueResize() const
1513 {
1514  Q_D(const QSplitter);
1515  return d->opaque;
1516 }
1517 
1518 
1520 {
1521  Q_D(QSplitter);
1522  d->opaque = on;
1523 }
1524 
1525 #ifdef QT3_SUPPORT
1526 
1599 #endif
1600 
1605 {
1606  Q_D(const QSplitter);
1607  ensurePolished();
1608  int l = 0;
1609  int t = 0;
1610  for (int i = 0; i < d->list.size(); ++i) {
1611  QWidget *w = d->list.at(i)->widget;
1612  if (w->isHidden())
1613  continue;
1614  QSize s = w->sizeHint();
1615  if (s.isValid()) {
1616  l += d->pick(s);
1617  t = qMax(t, d->trans(s));
1618  }
1619  }
1620  return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l);
1621 }
1622 
1623 
1629 {
1630  Q_D(const QSplitter);
1631  ensurePolished();
1632  int l = 0;
1633  int t = 0;
1634 
1635  for (int i = 0; i < d->list.size(); ++i) {
1636  QSplitterLayoutStruct *s = d->list.at(i);
1637  if (!s || !s->widget)
1638  continue;
1639  if (s->widget->isHidden())
1640  continue;
1641  QSize widgetSize = qSmartMinSize(s->widget);
1642  if (widgetSize.isValid()) {
1643  l += d->pick(widgetSize);
1644  t = qMax(t, d->trans(widgetSize));
1645  }
1646  if (!s->handle || s->handle->isHidden())
1647  continue;
1648  QSize splitterSize = s->handle->sizeHint();
1649  if (splitterSize.isValid()) {
1650  l += d->pick(splitterSize);
1651  t = qMax(t, d->trans(splitterSize));
1652  }
1653  }
1654  return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l);
1655 }
1656 
1657 
1675 {
1676  Q_D(const QSplitter);
1677  ensurePolished();
1678 
1679  QList<int> list;
1680  for (int i = 0; i < d->list.size(); ++i) {
1681  QSplitterLayoutStruct *s = d->list.at(i);
1682  list.append(d->pick(s->rect.size()));
1683  }
1684  return list;
1685 }
1686 
1709 {
1710  Q_D(QSplitter);
1711  d->setSizes_helper(list, true);
1712 }
1713 
1728 int QSplitter::handleWidth() const
1729 {
1730  Q_D(const QSplitter);
1731  if (d->handleWidth > 0) {
1732  return d->handleWidth;
1733  } else {
1734  return style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this);
1735  }
1736 }
1737 
1739 {
1740  Q_D(QSplitter);
1741  d->handleWidth = width;
1742  d->updateHandles();
1743 }
1744 
1749 {
1750  Q_D(QSplitter);
1751  if(ev->type() == QEvent::StyleChange)
1752  d->updateHandles();
1753  QFrame::changeEvent(ev);
1754 }
1755 
1756 static const qint32 SplitterMagic = 0xff;
1757 
1770 {
1771  Q_D(const QSplitter);
1772  int version = 0;
1773  QByteArray data;
1775 
1776  stream << qint32(SplitterMagic);
1777  stream << qint32(version);
1778  QList<int> list;
1779  for (int i = 0; i < d->list.size(); ++i) {
1780  QSplitterLayoutStruct *s = d->list.at(i);
1781  list.append(s->sizer);
1782  }
1783  stream << list;
1784  stream << childrenCollapsible();
1785  stream << qint32(handleWidth());
1786  stream << opaqueResize();
1787  stream << qint32(orientation());
1788  return data;
1789 }
1790 
1808 {
1809  Q_D(QSplitter);
1810  int version = 0;
1811  QByteArray sd = state;
1813  QList<int> list;
1814  bool b;
1815  qint32 i;
1816  qint32 marker;
1817  qint32 v;
1818 
1819  stream >> marker;
1820  stream >> v;
1821  if (marker != SplitterMagic || v != version)
1822  return false;
1823 
1824  stream >> list;
1825  d->setSizes_helper(list, false);
1826 
1827  stream >> b;
1829 
1830  stream >> i;
1831  setHandleWidth(i);
1832 
1833  stream >> b;
1834  setOpaqueResize(b);
1835 
1836  stream >> i;
1838  d->doResize();
1839 
1840  return true;
1841 }
1842 
1857 void QSplitter::setStretchFactor(int index, int stretch)
1858 {
1859  Q_D(QSplitter);
1860  if (index <= -1 || index >= d->list.count())
1861  return;
1862 
1863  QWidget *widget = d->list.at(index)->widget;
1864  QSizePolicy sp = widget->sizePolicy();
1865  sp.setHorizontalStretch(stretch);
1866  sp.setVerticalStretch(stretch);
1867  widget->setSizePolicy(sp);
1868 }
1869 
1870 
1871 //#ifdef QT3_SUPPORT
1872 #ifndef QT_NO_TEXTSTREAM
1873 
1884 {
1885  ts << splitter.saveState() << endl;
1886  return ts;
1887 }
1888 
1900 {
1901  QString line = ts.readLine();
1902  line = line.simplified();
1903  line.replace(QLatin1Char(' '), QString());
1904  line = line.toUpper();
1905 
1906  splitter.restoreState(line.toAscii());
1907  return ts;
1908 }
1909 #endif // QT_NO_TEXTSTREAM
1910 //#endif // QT3_SUPPORT
1911 
1913 
1914 #endif // QT_NO_SPLITTER
QSplitterHandle * handle(int index) const
Returns the handle to the left (or above) for the item in the splitter&#39;s layout at the given index...
Definition: qsplitter.cpp:1263
QPoint pos() const
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QSize maximumSize
the widget&#39;s maximum size in pixels
Definition: qwidget.h:173
bool collapsible(QSplitterLayoutStruct *) const
Definition: qsplitter.cpp:684
QSize sizeHint() const
Reimplemented Function
Definition: qsplitter.cpp:1604
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setHorizontalStretch(uchar stretchFactor)
Definition: qsizepolicy.h:146
void setSizes(const QList< int > &list)
Sets the child widgets respective sizes to the values given in the list.
Definition: qsplitter.cpp:1708
QList< int > sizes() const
Returns a list of the size parameters of all the widgets in this splitter.
Definition: qsplitter.cpp:1674
void setSizes_helper(const QList< int > &sizes, bool clampNegativeSize=false)
Definition: qsplitter.cpp:699
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
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.
QSize size() const
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
bool polished() const
Returns true if type() is QEvent::ChildPolished; otherwise returns false.
Definition: qcoreevent.h:363
bool opaqueResize() const
Returns true if widgets are resized dynamically (opaquely), otherwise returns false.
Definition: qsplitter.cpp:162
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
bool isVisible() const
Definition: qwidget.h:1005
void setCollapsible(int index, bool)
Sets whether the child widget at index index is collapsible to collapse.
Definition: qsplitter.cpp:1153
static QSize globalStrut()
bool added() const
Returns true if type() is QEvent::ChildAdded; otherwise returns false.
Definition: qcoreevent.h:359
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)
Definition: qstring.cpp:2005
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
int getWidgetSize(Qt::Orientation orient)
Definition: qsplitter.cpp:350
void resizeEvent(QResizeEvent *)
Reimplemented Function
Definition: qsplitter.cpp:233
void setChildrenCollapsible(bool)
Definition: qsplitter.cpp:1129
void resizeEvent(QResizeEvent *)
Reimplemented Function
Definition: qsplitter.cpp:1180
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:356
bool isCollapsible(int index) const
Returns true if the widget at index is collapsible, otherwise returns false.
Definition: qsplitter.cpp:1167
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
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
void addWidget(QWidget *widget)
Adds the given widget to the splitter&#39;s layout after all the other items.
Definition: qsplitter.cpp:1194
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
bool restoreState(const QByteArray &state)
Restores the splitter&#39;s layout to the state specified.
Definition: qsplitter.cpp:1807
void init(const QWidget *w)
Use initFrom(widget) instead.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
quint16 u
long ASN1_INTEGER_get ASN1_INTEGER * a
virtual QSplitterHandle * createHandle()
Returns a new splitter handle as a child widget of this splitter.
Definition: qsplitter.cpp:1246
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
int closestLegalPosition(int, int)
Returns the closest legal position to pos of the widget with index index.
Definition: qsplitter.cpp:1495
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void insertWidget_helper(int index, QWidget *widget, bool show)
Definition: qsplitter.cpp:904
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSplitterLayoutStruct * insertWidget(int index, QWidget *)
Definition: qsplitter.cpp:924
int getHandleSize(Qt::Orientation orient)
Definition: qsplitter.cpp:369
bool empty() const
This function is provided for STL compatibility.
Definition: qvector.h:285
The QSplitterHandle class provides handle functionality of the splitter.
Definition: qsplitter.h:158
#define Q_D(Class)
Definition: qglobal.h:2482
int handleWidth() const
int horizontalStretch() const
Definition: qsizepolicy.h:144
Qt::Orientation orientation() const
Returns the handle&#39;s orientation.
Definition: qsplitter.cpp:148
void moveSplitter(int p)
Tells the splitter to move this handle to position pos, which is the distance from the left or top ed...
Definition: qsplitter.cpp:189
void childEvent(QChildEvent *)
Tells the splitter that the child widget described by c has been inserted or removed.
Definition: qsplitter.cpp:1313
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void setOrientation(Qt::Orientation)
Definition: qsplitter.cpp:1087
QWidget * widget(int index) const
Returns the widget at the given index in the splitter&#39;s layout.
Definition: qsplitter.cpp:1276
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void doMove(bool backwards, int pos, int index, int delta, bool mayCollapse, int *positions, int *widths)
Definition: qsplitter.cpp:770
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
QStyle * style() const
Definition: qwidget.cpp:2742
void updateHandles()
Definition: qsplitter.cpp:693
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
static const uint Default
Definition: qsplitter_p.h:61
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void paintEvent(QPaintEvent *)
Reimplemented Function
Definition: qsplitter.cpp:329
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
int closestLegalPosition(int p)
Returns the closest legal position to pos of the splitter handle.
Definition: qsplitter.cpp:205
QSizePolicy sizePolicy() const
Q_CORE_EXPORT void qDebug(const char *,...)
QTextStream & operator<<(QTextStream &ts, const QSplitter &splitter)
Use ts << {splitter}.
Definition: qsplitter.cpp:1883
QSplitterLayoutStruct * findWidget(QWidget *) const
Definition: qsplitter.cpp:806
int width() const
Returns the width.
Definition: qsize.h:126
QSize minimumSizeHint() const
Reimplemented Function
Definition: qsplitter.cpp:1628
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void recalc(bool update=false)
Definition: qsplitter.cpp:384
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void lower()
Lowers the widget to the bottom of the parent widget&#39;s stack.
Definition: qwidget.cpp:11939
static FILE * stream
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
friend class QSplitterHandle
Definition: qsplitter.h:147
void setRubberBand(int position)
Displays a rubber band at position pos.
Definition: qsplitter.cpp:1343
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qframe.cpp:574
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
int count() const
Returns the number of widgets contained in the splitter&#39;s layout.
Definition: qsplitter.cpp:1289
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
~QSplitter()
Destroys the splitter.
Definition: qsplitter.cpp:1055
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static const qint32 SplitterMagic
Definition: qsplitter.cpp:1756
static const QCssKnownValue positions[NumKnownPositionModes - 1]
Definition: qcssparser.cpp:329
int width() const
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
Definition: qwidget.cpp:7449
QSize sizeHint() const
Reimplemented Function
Definition: qsplitter.cpp:219
QByteArray saveState() const
Saves the state of the splitter&#39;s layout.
Definition: qsplitter.cpp:1769
const char * name
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
void setOrientation(Qt::Orientation o)
Sets the orientation of the splitter handle to orientation.
Definition: qsplitter.cpp:134
#define emit
Definition: qobjectdefs.h:76
const QPalette & palette() const
void mouseMoveEvent(QMouseEvent *)
Reimplemented Function
Definition: qsplitter.cpp:281
QWidgetData * data
Definition: qwidget.h:815
void setHidden(bool hidden)
Convenience function, equivalent to setVisible(!hidden).
Definition: qwidget.h:495
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
int verticalStretch() const
Definition: qsizepolicy.h:145
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...
Definition: qsplitter.cpp:1426
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
QSplitter(QWidget *parent=0)
Constructs a horizontal splitter with the parent argument passed on to the QFrame constructor...
Definition: qsplitter.cpp:1028
void show()
Shows the widget and its child widgets.
void setMask(const QBitmap &)
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible...
Definition: qwidget.cpp:13309
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
void refresh()
Updates the splitter&#39;s state.
Definition: qsplitter.cpp:1067
bool isEnabled() const
Definition: qwidget.h:948
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
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.
Definition: qcoreevent.h:353
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.
Definition: qsplitter.cpp:120
void insertWidget(int index, QWidget *widget)
Inserts the widget specified into the splitter&#39;s layout at the given index.
Definition: qsplitter.cpp:1210
void addContribution(int, int *, int *, bool) const
Definition: qsplitter.cpp:564
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
bool childrenCollapsible() const
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int x() const
QTextStream & operator>>(QTextStream &ts, QSplitter &splitter)
Use ts >> {splitter}.
Definition: qsplitter.cpp:1899
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...
Definition: qsplitter.cpp:1477
void mouseReleaseEvent(QMouseEvent *)
Reimplemented Function
Definition: qsplitter.cpp:311
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
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...
Definition: qstring.cpp:4415
void setStretchFactor(int index, int stretch)
Updates the size policy of the widget at position index to have a stretch factor of stretch...
Definition: qsplitter.cpp:1857
int findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const
Definition: qsplitter.cpp:579
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition: qwidget.h:171
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
QSplitterHandle * handle
Definition: qsplitter_p.h:71
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QSize maximumSize() const
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.
Definition: qstring.cpp:4014
QString objectName() const
bool event(QEvent *)
Reimplemented Function
Definition: qsplitter.cpp:260
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
void setOpaqueResize(bool opaque=true)
Definition: qsplitter.cpp:1519
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
QFactoryLoader * l
QSize minimumSize() const
bool event(QEvent *)
Reimplemented Function
Definition: qsplitter.cpp:1371
int adjustPos(int, int, int *, int *, int *, int *) const
Definition: qsplitter.cpp:653
void mousePressEvent(QMouseEvent *)
Reimplemented Function
Definition: qsplitter.cpp:298
void setHandleWidth(int)
Definition: qsplitter.cpp:1738
void transpose()
Definition: qsizepolicy.h:229
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
quint16 index
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
static int pick(bool vertical, const QSize &size)
bool opaqueResize() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
bool isRightToLeft() const
Definition: qwidget.h:428
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
void setGeo(QSplitterLayoutStruct *s, int pos, int size, bool allowCollapse)
Definition: qsplitter.cpp:727
QSplitter * splitter() const
Returns the splitter associated with this splitter handle.
Definition: qsplitter.cpp:174
int indexOf(QWidget *w) const
Returns the index in the splitter&#39;s layout of the specified widget.
Definition: qsplitter.cpp:1228
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
void setVerticalStretch(uchar stretchFactor)
Definition: qsizepolicy.h:147
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
Orientation
Definition: qnamespace.h:174
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary...
Definition: qrubberband.h:58
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
const QPoint & globalPos() const
Returns the global position of the mouse cursor at the time of the event.
Definition: qevent.h:96
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void changeEvent(QEvent *)
Reimplemented Function
Definition: qsplitter.cpp:1748
The QSplitter class implements a splitter widget.
Definition: qsplitter.h:62
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
void getRange(int index, int *, int *, int *, int *) const
Definition: qsplitter.cpp:600
QObject * child() const
Returns the child object that was added or removed.
Definition: qcoreevent.h:358
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
Qt::Orientation orientation() const
Q_CORE_EXPORT QTextStream & endl(QTextStream &s)