qsplitter.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qsplitter.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10QSplitterPrivate::~QSplitterPrivate()-
11{-
12}-
13QSplitterHandle::QSplitterHandle(Qt::Orientation orientation, QSplitter *parent)-
14 : QWidget(*new QSplitterHandlePrivate, parent, 0)-
15{-
16 QSplitterHandlePrivate * const d = d_func();-
17 d->s = parent;-
18 setOrientation(orientation);-
19}-
20-
21-
22-
23-
24QSplitterHandle::~QSplitterHandle()-
25{-
26}-
27-
28-
29-
30-
31-
32-
33-
34void QSplitterHandle::setOrientation(Qt::Orientation orientation)-
35{-
36 QSplitterHandlePrivate * const d = d_func();-
37 d->orient = orientation;-
38-
39 setCursor(orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);-
40-
41}-
42-
43-
44-
45-
46-
47-
48Qt::Orientation QSplitterHandle::orientation() const-
49{-
50 const QSplitterHandlePrivate * const d = d_func();-
51 return d->orient;-
52}-
53bool QSplitterHandle::opaqueResize() const-
54{-
55 const QSplitterHandlePrivate * const d = d_func();-
56 return d->s->opaqueResize();-
57}-
58-
59-
60-
61-
62-
63-
64-
65QSplitter *QSplitterHandle::splitter() const-
66{-
67 return d_func()->s;-
68}-
69void QSplitterHandle::moveSplitter(int pos)-
70{-
71 QSplitterHandlePrivate * const d = d_func();-
72 if (d->s->isRightToLeft() && d->orient == Qt::Horizontal)-
73 pos = d->s->contentsRect().width() - pos;-
74 d->s->moveSplitter(pos, d->s->indexOf(this));-
75}-
76int QSplitterHandle::closestLegalPosition(int pos)-
77{-
78 QSplitterHandlePrivate * const d = d_func();-
79 QSplitter *s = d->s;-
80 if (s->isRightToLeft() && d->orient == Qt::Horizontal) {-
81 int w = s->contentsRect().width();-
82 return w - s->closestLegalPosition(w - pos, s->indexOf(this));-
83 }-
84 return s->closestLegalPosition(pos, s->indexOf(this));-
85}-
86-
87-
88-
89-
90QSize QSplitterHandle::sizeHint() const-
91{-
92 const QSplitterHandlePrivate * const d = d_func();-
93 int hw = d->s->handleWidth();-
94 QStyleOption opt(0);-
95 opt.init(d->s);-
96 opt.state = QStyle::State_None;-
97 return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s)-
98 .expandedTo(QApplication::globalStrut());-
99}-
100-
101-
102-
103-
104void QSplitterHandle::resizeEvent(QResizeEvent *event)-
105{-
106 const QSplitterHandlePrivate * const d = d_func();-
107 bool useTinyMode = (d->s->handleWidth() <= 1);-
108 setAttribute(Qt::WA_MouseNoMask, useTinyMode);-
109 if (useTinyMode) {-
110 if (orientation() == Qt::Horizontal)-
111 setContentsMargins(2, 0, 2, 0);-
112 else-
113 setContentsMargins(0, 2, 0, 2);-
114 setMask(QRegion(contentsRect()));-
115 }-
116-
117 QWidget::resizeEvent(event);-
118}-
119-
120-
121-
122-
123bool QSplitterHandle::event(QEvent *event)-
124{-
125 QSplitterHandlePrivate * const d = d_func();-
126 switch(event->type()) {-
127 case QEvent::HoverEnter:-
128 d->hover = true;-
129 update();-
130 break;-
131 case QEvent::HoverLeave:-
132 d->hover = false;-
133 update();-
134 break;-
135 default:-
136 break;-
137 }-
138 return QWidget::event(event);-
139}-
140-
141-
142-
143-
144void QSplitterHandle::mouseMoveEvent(QMouseEvent *e)-
145{-
146 QSplitterHandlePrivate * const d = d_func();-
147 if (!(e->buttons() & Qt::LeftButton))-
148 return;-
149 int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos()))-
150 - d->mouseOffset;-
151 if (opaqueResize()) {-
152 moveSplitter(pos);-
153 } else {-
154 d->s->setRubberBand(closestLegalPosition(pos));-
155 }-
156}-
157-
158-
159-
160-
161void QSplitterHandle::mousePressEvent(QMouseEvent *e)-
162{-
163 QSplitterHandlePrivate * const d = d_func();-
164 if (e->button() == Qt::LeftButton) {-
165 d->mouseOffset = d->pick(e->pos());-
166 d->pressed = true;-
167 update();-
168 }-
169}-
170-
171-
172-
173-
174void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e)-
175{-
176 QSplitterHandlePrivate * const d = d_func();-
177 if (!opaqueResize() && e->button() == Qt::LeftButton) {-
178 int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos()))-
179 - d->mouseOffset;-
180 d->s->setRubberBand(-1);-
181 moveSplitter(pos);-
182 }-
183 if (e->button() == Qt::LeftButton) {-
184 d->pressed = false;-
185 update();-
186 }-
187}-
188-
189-
190-
191-
192void QSplitterHandle::paintEvent(QPaintEvent *)-
193{-
194 QSplitterHandlePrivate * const d = d_func();-
195 QPainter p(this);-
196 QStyleOption opt(0);-
197 opt.rect = contentsRect();-
198 opt.palette = palette();-
199 if (orientation() == Qt::Horizontal)-
200 opt.state = QStyle::State_Horizontal;-
201 else-
202 opt.state = QStyle::State_None;-
203 if (d->hover)-
204 opt.state |= QStyle::State_MouseOver;-
205 if (d->pressed)-
206 opt.state |= QStyle::State_Sunken;-
207 if (isEnabled())-
208 opt.state |= QStyle::State_Enabled;-
209 parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s);-
210}-
211-
212-
213int QSplitterLayoutStruct::getWidgetSize(Qt::Orientation orient)-
214{-
215 if (sizer == -1) {-
216 QSize s = widget->sizeHint();-
217 const int presizer = pick(s, orient);-
218 const int realsize = pick(widget->size(), orient);-
219 if (!s.isValid() || (widget->testAttribute(Qt::WA_Resized) && (realsize > presizer))) {-
220 sizer = pick(widget->size(), orient);-
221 } else {-
222 sizer = presizer;-
223 }-
224 QSizePolicy p = widget->sizePolicy();-
225 int sf = (orient == Qt::Horizontal) ? p.horizontalStretch() : p.verticalStretch();-
226 if (sf > 1)-
227 sizer *= sf;-
228 }-
229 return sizer;-
230}-
231-
232int QSplitterLayoutStruct::getHandleSize(Qt::Orientation orient)-
233{-
234 return pick(handle->sizeHint(), orient);-
235}-
236-
237void QSplitterPrivate::init()-
238{-
239 QSplitter * const q = q_func();-
240 QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred);-
241 if (orient == Qt::Vertical)-
242 sp.transpose();-
243 q->setSizePolicy(sp);-
244 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);-
245}-
246-
247void QSplitterPrivate::recalc(bool update)-
248{-
249 QSplitter * const q = q_func();-
250 int n = list.count();-
251-
252-
253-
254-
255 bool first = true;-
256 bool allInvisible = n != 0;-
257 for (int i = 0; i < n ; ++i) {-
258 QSplitterLayoutStruct *s = list.at(i);-
259 bool widgetHidden = s->widget->isHidden();-
260 if (allInvisible && !widgetHidden && !s->collapsed)-
261 allInvisible = false;-
262 s->handle->setHidden(first || widgetHidden);-
263 if (!widgetHidden)-
264 first = false;-
265 }-
266-
267 if (allInvisible)-
268 for (int i = 0; i < n ; ++i) {-
269 QSplitterLayoutStruct *s = list.at(i);-
270 if (!s->widget->isHidden()) {-
271 s->collapsed = false;-
272 break;-
273 }-
274 }-
275-
276 int fi = 2 * q->frameWidth();-
277 int maxl = fi;-
278 int minl = fi;-
279 int maxt = ((1<<24)-1);-
280 int mint = fi;-
281-
282-
283-
284 bool empty = true;-
285 for (int j = 0; j < n; j++) {-
286 QSplitterLayoutStruct *s = list.at(j);-
287-
288 if (!s->widget->isHidden()) {-
289 empty = false;-
290 if (!s->handle->isHidden()) {-
291 minl += s->getHandleSize(orient);-
292 maxl += s->getHandleSize(orient);-
293 }-
294-
295 QSize minS = qSmartMinSize(s->widget);-
296 minl += pick(minS);-
297 maxl += pick(s->widget->maximumSize());-
298 mint = qMax(mint, trans(minS));-
299 int tm = trans(s->widget->maximumSize());-
300 if (tm > 0)-
301 maxt = qMin(maxt, tm);-
302 }-
303 }-
304-
305 if (empty) {-
306 if (qobject_cast<QSplitter *>(parent)) {-
307-
308 maxl = maxt = 0;-
309 } else {-
310-
311 maxl = ((1<<24)-1);-
312 }-
313 } else {-
314 maxl = qMin<int>(maxl, ((1<<24)-1));-
315 }-
316 if (maxt < mint)-
317 maxt = mint;-
318-
319 if (update) {-
320 if (orient == Qt::Horizontal) {-
321 q->setMaximumSize(maxl, maxt);-
322 if (q->isWindow())-
323 q->setMinimumSize(minl,mint);-
324 } else {-
325 q->setMaximumSize(maxt, maxl);-
326 if (q->isWindow())-
327 q->setMinimumSize(mint,minl);-
328 }-
329 doResize();-
330 q->updateGeometry();-
331 } else {-
332 firstShow = true;-
333 }-
334}-
335-
336void QSplitterPrivate::doResize()-
337{-
338 QSplitter * const q = q_func();-
339 QRect r = q->contentsRect();-
340 int n = list.count();-
341 QVector<QLayoutStruct> a(n*2);-
342 int i;-
343-
344 bool noStretchFactorsSet = true;-
345 for (i = 0; i < n; ++i) {-
346 QSizePolicy p = list.at(i)->widget->sizePolicy();-
347 int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch();-
348 if (sf != 0) {-
349 noStretchFactorsSet = false;-
350 break;-
351 }-
352 }-
353-
354 int j=0;-
355 for (i = 0; i < n; ++i) {-
356 QSplitterLayoutStruct *s = list.at(i);-
357-
358-
359-
360-
361-
362 a[j].init();-
363 if (s->handle->isHidden()) {-
364 a[j].maximumSize = 0;-
365 } else {-
366 a[j].sizeHint = a[j].minimumSize = a[j].maximumSize = s->getHandleSize(orient);-
367 a[j].empty = false;-
368 }-
369 ++j;-
370-
371 a[j].init();-
372 if (s->widget->isHidden() || s->collapsed) {-
373 a[j].maximumSize = 0;-
374 } else {-
375 a[j].minimumSize = pick(qSmartMinSize(s->widget));-
376 a[j].maximumSize = pick(s->widget->maximumSize());-
377 a[j].empty = false;-
378-
379 bool stretch = noStretchFactorsSet;-
380 if (!stretch) {-
381 QSizePolicy p = s->widget->sizePolicy();-
382 int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch();-
383 stretch = (sf != 0);-
384 }-
385 if (stretch) {-
386 a[j].stretch = s->getWidgetSize(orient);-
387 a[j].sizeHint = a[j].minimumSize;-
388 a[j].expansive = true;-
389 } else {-
390 a[j].sizeHint = qMax(s->getWidgetSize(orient), a[j].minimumSize);-
391 }-
392 }-
393 ++j;-
394 }-
395-
396 qGeomCalc(a, 0, n*2, pick(r.topLeft()), pick(r.size()), 0);-
397 for (i = 0; i < n; ++i) {-
398 QSplitterLayoutStruct *s = list.at(i);-
399 setGeo(s, a[i*2+1].pos, a[i*2+1].size, false);-
400 }-
401}-
402-
403void QSplitterPrivate::storeSizes()-
404{-
405 for (int i = 0; i < list.size(); ++i) {-
406 QSplitterLayoutStruct *sls = list.at(i);-
407 sls->sizer = pick(sls->rect.size());-
408 }-
409}-
410-
411void QSplitterPrivate::addContribution(int index, int *min, int *max, bool mayCollapse) const-
412{-
413 QSplitterLayoutStruct *s = list.at(index);-
414 if (!s->widget->isHidden()) {-
415 if (!s->handle->isHidden()) {-
416 *min += s->getHandleSize(orient);-
417 *max += s->getHandleSize(orient);-
418 }-
419 if (mayCollapse || !s->collapsed)-
420 *min += pick(qSmartMinSize(s->widget));-
421-
422 *max += pick(s->widget->maximumSize());-
423 }-
424}-
425-
426int QSplitterPrivate::findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const-
427{-
428 if (delta < 0)-
429 index += delta;-
430 do {-
431 QWidget *w = list.at(index)->widget;-
432 if (!w->isHidden()) {-
433 if (collapsible(list.at(index)))-
434 collapsibleSize = pick(qSmartMinSize(w));-
435 return index;-
436 }-
437 index += delta;-
438 } while (index >= 0 && index < list.count());-
439-
440 return -1;-
441}-
442-
443-
444-
445-
446-
447void QSplitterPrivate::getRange(int index, int *farMin, int *min, int *max, int *farMax) const-
448{-
449 const QSplitter * const q = q_func();-
450 int n = list.count();-
451 if (index <= 0 || index >= n)-
452 return;-
453-
454 int collapsibleSizeBefore = 0;-
455 int idJustBefore = findWidgetJustBeforeOrJustAfter(index, -1, collapsibleSizeBefore);-
456-
457 int collapsibleSizeAfter = 0;-
458 int idJustAfter = findWidgetJustBeforeOrJustAfter(index, +1, collapsibleSizeAfter);-
459-
460 int minBefore = 0;-
461 int minAfter = 0;-
462 int maxBefore = 0;-
463 int maxAfter = 0;-
464 int i;-
465-
466 for (i = 0; i < index; ++i)-
467 addContribution(i, &minBefore, &maxBefore, i == idJustBefore);-
468 for (i = index; i < n; ++i)-
469 addContribution(i, &minAfter, &maxAfter, i == idJustAfter);-
470-
471 QRect r = q->contentsRect();-
472 int farMinVal;-
473 int minVal;-
474 int maxVal;-
475 int farMaxVal;-
476-
477 int smartMinBefore = qMax(minBefore, pick(r.size()) - maxAfter);-
478 int smartMaxBefore = qMin(maxBefore, pick(r.size()) - minAfter);-
479-
480 minVal = pick(r.topLeft()) + smartMinBefore;-
481 maxVal = pick(r.topLeft()) + smartMaxBefore;-
482-
483 farMinVal = minVal;-
484 if (minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter)-
485 farMinVal -= collapsibleSizeBefore;-
486 farMaxVal = maxVal;-
487 if (pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore)-
488 farMaxVal += collapsibleSizeAfter;-
489-
490 if (farMin)-
491 *farMin = farMinVal;-
492 if (min)-
493 *min = minVal;-
494 if (max)-
495 *max = maxVal;-
496 if (farMax)-
497 *farMax = farMaxVal;-
498}-
499-
500int QSplitterPrivate::adjustPos(int pos, int index, int *farMin, int *min, int *max, int *farMax) const-
501{-
502 const int Threshold = 40;-
503-
504 getRange(index, farMin, min, max, farMax);-
505-
506 if (pos >= *min) {-
507 if (pos <= *max) {-
508 return pos;-
509 } else {-
510 int delta = pos - *max;-
511 int width = *farMax - *max;-
512-
513 if (delta > width / 2 && delta >= qMin(Threshold, width)) {-
514 return *farMax;-
515 } else {-
516 return *max;-
517 }-
518 }-
519 } else {-
520 int delta = *min - pos;-
521 int width = *min - *farMin;-
522-
523 if (delta > width / 2 && delta >= qMin(Threshold, width)) {-
524 return *farMin;-
525 } else {-
526 return *min;-
527 }-
528 }-
529}-
530-
531bool QSplitterPrivate::collapsible(QSplitterLayoutStruct *s) const-
532{-
533 if (s->collapsible != Default) {-
534 return (bool)s->collapsible;-
535 } else {-
536 return childrenCollapsible;-
537 }-
538}-
539-
540void QSplitterPrivate::updateHandles()-
541{-
542 QSplitter * const q = q_func();-
543 recalc(q->isVisible());-
544}-
545-
546void QSplitterPrivate::setSizes_helper(const QList<int> &sizes, bool clampNegativeSize)-
547{-
548 int j = 0;-
549-
550 for (int i = 0; i < list.size(); ++i) {-
551 QSplitterLayoutStruct *s = list.at(i);-
552-
553 s->collapsed = false;-
554 s->sizer = sizes.value(j++);-
555 if (clampNegativeSize && s->sizer < 0)-
556 s->sizer = 0;-
557 int smartMinSize = pick(qSmartMinSize(s->widget));-
558-
559-
560 if (s->sizer == 0) {-
561 if (collapsible(s) && smartMinSize > 0) {-
562 s->collapsed = true;-
563 } else {-
564 s->sizer = smartMinSize;-
565 }-
566 } else {-
567 if (s->sizer < smartMinSize)-
568 s->sizer = smartMinSize;-
569 }-
570 }-
571 doResize();-
572}-
573-
574void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool allowCollapse)-
575{-
576 QSplitter * const q = q_func();-
577 QWidget *w = sls->widget;-
578 QRect r;-
579 QRect contents = q->contentsRect();-
580 if (orient == Qt::Horizontal) {-
581 r.setRect(p, contents.y(), s, contents.height());-
582 } else {-
583 r.setRect(contents.x(), p, contents.width(), s);-
584 }-
585 sls->rect = r;-
586-
587 int minSize = pick(qSmartMinSize(w));-
588-
589 if (orient == Qt::Horizontal && q->isRightToLeft())-
590 r.moveRight(contents.width() - r.left());-
591-
592 if (allowCollapse)-
593 sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden();-
594-
595-
596-
597 if (sls->collapsed)-
598 r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1));-
599-
600 w->setGeometry(r);-
601-
602 if (!sls->handle->isHidden()) {-
603 QSplitterHandle *h = sls->handle;-
604 QSize hs = h->sizeHint();-
605 int left, top, right, bottom;-
606 h->getContentsMargins(&left, &top, &right, &bottom);-
607 if (orient==Qt::Horizontal) {-
608 if (q->isRightToLeft())-
609 p = contents.width() - p + hs.width();-
610 h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height());-
611 } else {-
612 h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom);-
613 }-
614 }-
615}-
616-
617void QSplitterPrivate::doMove(bool backwards, int hPos, int index, int delta, bool mayCollapse,-
618 int *positions, int *widths)-
619{-
620 if (index < 0 || index >= list.count())-
621 return;-
622-
623-
624-
625-
626-
627 QSplitterLayoutStruct *s = list.at(index);-
628 QWidget *w = s->widget;-
629-
630 int nextId = backwards ? index - delta : index + delta;-
631-
632 if (w->isHidden()) {-
633 doMove(backwards, hPos, nextId, delta, collapsible(nextId), positions, widths);-
634 } else {-
635 int hs =s->handle->isHidden() ? 0 : s->getHandleSize(orient);-
636-
637 int ws = backwards ? hPos - pick(s->rect.topLeft())-
638 : pick(s->rect.bottomRight()) - hPos -hs + 1;-
639 if (ws > 0 || (!s->collapsed && !mayCollapse)) {-
640 ws = qMin(ws, pick(w->maximumSize()));-
641 ws = qMax(ws, pick(qSmartMinSize(w)));-
642 } else {-
643 ws = 0;-
644 }-
645 positions[index] = backwards ? hPos - ws : hPos + hs;-
646 widths[index] = ws;-
647 doMove(backwards, backwards ? hPos - ws - hs : hPos + hs + ws, nextId, delta,-
648 collapsible(nextId), positions, widths);-
649 }-
650-
651}-
652-
653QSplitterLayoutStruct *QSplitterPrivate::findWidget(QWidget *w) const-
654{-
655 for (int i = 0; i < list.size(); ++i) {-
656 if (list.at(i)->widget == w)-
657 return list.at(i);-
658 }-
659 return 0;-
660}-
661-
662-
663-
664-
665-
666void QSplitterPrivate::insertWidget_helper(int index, QWidget *widget, bool show)-
667{-
668 QSplitter * const q = q_func();-
669 QBoolBlocker b(blockChildAdd);-
670 bool needShow = show && q->isVisible() &&-
671 !(widget->isHidden() && widget->testAttribute(Qt::WA_WState_ExplicitShowHide));-
672 if (widget->parentWidget() != q)-
673 widget->setParent(q);-
674 if (needShow)-
675 widget->show();-
676 insertWidget(index, widget);-
677 recalc(q->isVisible());-
678}-
679-
680-
681-
682-
683-
684-
685-
686QSplitterLayoutStruct *QSplitterPrivate::insertWidget(int index, QWidget *w)-
687{-
688 QSplitter * const q = q_func();-
689 QSplitterLayoutStruct *sls = 0;-
690 int i;-
691 int last = list.count();-
692 for (i = 0; i < list.size(); ++i) {-
693 QSplitterLayoutStruct *s = list.at(i);-
694 if (s->widget == w) {-
695 sls = s;-
696 --last;-
697 break;-
698 }-
699 }-
700 if (index < 0 || index > last)-
701 index = last;-
702-
703 if (sls) {-
704 list.move(i,index);-
705 } else {-
706 QSplitterHandle *newHandle = 0;-
707 sls = new QSplitterLayoutStruct;-
708 QString tmp = QLatin1String("qt_splithandle_");-
709 tmp += w->objectName();-
710 newHandle = q->createHandle();-
711 newHandle->setObjectName(tmp);-
712 sls->handle = newHandle;-
713 sls->widget = w;-
714 w->lower();-
715 list.insert(index,sls);-
716-
717 if (newHandle && q->isVisible())-
718 newHandle->show();-
719-
720 }-
721 return sls;-
722}-
723QSplitter::QSplitter(QWidget *parent)-
724 : QFrame(*new QSplitterPrivate, parent)-
725{-
726 QSplitterPrivate * const d = d_func();-
727 d->orient = Qt::Horizontal;-
728 d->init();-
729}-
730-
731-
732-
733-
734-
735-
736-
737QSplitter::QSplitter(Qt::Orientation orientation, QWidget *parent)-
738 : QFrame(*new QSplitterPrivate, parent)-
739{-
740 QSplitterPrivate * const d = d_func();-
741 d->orient = orientation;-
742 d->init();-
743}-
744-
745-
746-
747-
748-
749-
750QSplitter::~QSplitter()-
751{-
752 QSplitterPrivate * const d = d_func();-
753 delete d->rubberBand;-
754 while (!d->list.isEmpty())-
755 delete d->list.takeFirst();-
756}-
757-
758-
759-
760-
761-
762void QSplitter::refresh()-
763{-
764 QSplitterPrivate * const d = d_func();-
765 d->recalc(true);-
766}-
767void QSplitter::setOrientation(Qt::Orientation orientation)-
768{-
769 QSplitterPrivate * const d = d_func();-
770 if (d->orient == orientation)-
771 return;-
772-
773 if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {-
774 QSizePolicy sp = sizePolicy();-
775 sp.transpose();-
776 setSizePolicy(sp);-
777 setAttribute(Qt::WA_WState_OwnSizePolicy, false);-
778 }-
779-
780 d->orient = orientation;-
781-
782 for (int i = 0; i < d->list.size(); ++i) {-
783 QSplitterLayoutStruct *s = d->list.at(i);-
784 s->handle->setOrientation(orientation);-
785 }-
786 d->recalc(isVisible());-
787}-
788-
789Qt::Orientation QSplitter::orientation() const-
790{-
791 const QSplitterPrivate * const d = d_func();-
792 return d->orient;-
793}-
794void QSplitter::setChildrenCollapsible(bool collapse)-
795{-
796 QSplitterPrivate * const d = d_func();-
797 d->childrenCollapsible = collapse;-
798}-
799-
800bool QSplitter::childrenCollapsible() const-
801{-
802 const QSplitterPrivate * const d = d_func();-
803 return d->childrenCollapsible;-
804}-
805void QSplitter::setCollapsible(int index, bool collapse)-
806{-
807 QSplitterPrivate * const d = d_func();-
808-
809 if (__builtin_expect(!!(
__builtin_expe...ize()), false)Description
TRUEnever evaluated
FALSEnever evaluated
index < 0 || index >= d->list.size())()), false)
__builtin_expe...ize()), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
810 QMessageLogger(__FILE__, 10621068, __PRETTY_FUNCTION__).warning("QSplitter::setCollapsible: Index %d out of range", index);-
811 return;
never executed: return;
0
812 }-
813 d->list.at(index)->collapsible = collapse
collapseDescription
TRUEnever evaluated
FALSEnever evaluated
? 1 : 0;
0
814}
never executed: end of block
0
815-
816-
817-
818-
819bool QSplitter::isCollapsible(int index) const-
820{-
821 const QSplitterPrivate * const d = d_func();-
822 if (__builtin_expect(!!(
__builtin_expe...ize()), false)Description
TRUEnever evaluated
FALSEnever evaluated
index < 0 || index >= d->list.size())()), false)
__builtin_expe...ize()), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
823 QMessageLogger(__FILE__, 10751081, __PRETTY_FUNCTION__).warning("QSplitter::isCollapsible: Index %d out of range", index);-
824 return
never executed: return false;
false;
never executed: return false;
0
825 }-
826 return
never executed: return d->list.at(index)->collapsible;
d->list.at(index)->collapsible;
never executed: return d->list.at(index)->collapsible;
0
827}-
828-
829-
830-
831-
832void QSplitter::resizeEvent(QResizeEvent *)-
833{-
834 QSplitterPrivate * const d = d_func();-
835 d->doResize();-
836}-
837void QSplitter::addWidget(QWidget *widget)-
838{-
839 QSplitterPrivate * const d = d_func();-
840 insertWidget(d->list.count(), widget);-
841}-
842void QSplitter::insertWidget(int index, QWidget *widget)-
843{-
844 QSplitterPrivate * const d = d_func();-
845 d->insertWidget_helper(index, widget, true);-
846}-
847int QSplitter::indexOf(QWidget *w) const-
848{-
849 const QSplitterPrivate * const d = d_func();-
850 for (int i = 0; i < d->list.size(); ++i) {-
851 QSplitterLayoutStruct *s = d->list.at(i);-
852 if (s->widget == w || s->handle == w)-
853 return i;-
854 }-
855 return -1;-
856}-
857QSplitterHandle *QSplitter::createHandle()-
858{-
859 QSplitterPrivate * const d = d_func();-
860 return new QSplitterHandle(d->orient, this);-
861}-
862QSplitterHandle *QSplitter::handle(int index) const-
863{-
864 const QSplitterPrivate * const d = d_func();-
865 if (index < 0 || index >= d->list.size())-
866 return 0;-
867 return d->list.at(index)->handle;-
868}-
869-
870-
871-
872-
873-
874-
875QWidget *QSplitter::widget(int index) const-
876{-
877 const QSplitterPrivate * const d = d_func();-
878 if (index < 0 || index >= d->list.size())-
879 return 0;-
880 return d->list.at(index)->widget;-
881}-
882-
883-
884-
885-
886-
887-
888int QSplitter::count() const-
889{-
890 const QSplitterPrivate * const d = d_func();-
891 return d->list.count();-
892}-
893void QSplitter::childEvent(QChildEvent *c)-
894{-
895 QSplitterPrivate * const d = d_func();-
896 if (!c->child()->isWidgetType()
!c->child()->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
897 if (__builtin_expect(!!(
__builtin_expe...ld())), false)Description
TRUEnever evaluated
FALSEnever evaluated
c->type() == QEvent::ChildAdded && qobject_cast<QLayout *>(c->child()))())), false)
__builtin_expe...ld())), false)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
898 QMessageLogger(__FILE__, 12231229, __PRETTY_FUNCTION__).warning("Adding a QLayout to a QSplitter is not supported.");
never executed: QMessageLogger(__FILE__, 1229, __PRETTY_FUNCTION__).warning("Adding a QLayout to a QSplitter is not supported.");
0
899 return;
never executed: return;
0
900 }-
901 QWidget *w = static_cast<QWidget*>(c->child());-
902 if (w->isWindow()
w->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
903 return;
never executed: return;
0
904 if (c->added()
c->added()Description
TRUEnever evaluated
FALSEnever evaluated
&& !d->blockChildAdd
!d->blockChildAddDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d->findWidget(w)
!d->findWidget(w)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
905 d->insertWidget_helper(d->list.count(), w, false);-
906 }
never executed: end of block
else if (c->polished()
c->polished()Description
TRUEnever evaluated
FALSEnever evaluated
&& !d->blockChildAdd
!d->blockChildAddDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
907 if (isVisible()
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
&& !(w->isHidden()
w->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
&& w->testAttribute(Qt::WA_WState_ExplicitShowHide)
w->testAttribu...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
))
0
908 w->show();
never executed: w->show();
0
909 }
never executed: end of block
else if (c->type() == QEvent::ChildRemoved
c->type() == Q...::ChildRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
910 for (int i = 0; i < d->list.size()
i < d->list.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
911 QSplitterLayoutStruct *s = d->list.at(i);-
912 if (s->widget == w
s->widget == wDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
913 d->list.removeAt(i);-
914 delete s;-
915 d->recalc(isVisible());-
916 return;
never executed: return;
0
917 }-
918 }
never executed: end of block
0
919 }
never executed: end of block
0
920}
never executed: end of block
0
921-
922-
923-
924-
925-
926-
927-
928void QSplitter::setRubberBand(int pos)-
929{-
930 QSplitterPrivate * const d = d_func();-
931 if (pos < 0) {-
932 if (d->rubberBand)-
933 d->rubberBand->deleteLater();-
934 return;-
935 }-
936 QRect r = contentsRect();-
937 const int rBord = 3;-
938 int hw = handleWidth();-
939 if (!d->rubberBand) {-
940 QBoolBlocker b(d->blockChildAdd);-
941 d->rubberBand = new QRubberBand(QRubberBand::Line, this);-
942-
943 d->rubberBand->setObjectName(QLatin1String("qt_rubberband"));-
944 }-
945-
946 const QRect newGeom = d->orient == Qt::Horizontal ? QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height()))-
947 : QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord));-
948 d->rubberBand->setGeometry(newGeom);-
949 d->rubberBand->show();-
950}-
951-
952-
953-
954-
955-
956bool QSplitter::event(QEvent *e)-
957{-
958 QSplitterPrivate * const d = d_func();-
959 switch (e->type()) {-
960 case QEvent::Hide:-
961-
962 if (!d->firstShow)-
963 d->firstShow = true;-
964 break;-
965 case QEvent::Show:-
966 if (!d->firstShow)-
967 break;-
968 d->firstShow = false;-
969-
970 case QEvent::HideToParent:-
971 case QEvent::ShowToParent:-
972 case QEvent::LayoutRequest:-
973 d->recalc(isVisible());-
974 break;-
975 default:-
976 ;-
977 }-
978 return QWidget::event(e);-
979}-
980void QSplitter::moveSplitter(int pos, int index)-
981{-
982 QSplitterPrivate * const d = d_func();-
983 QSplitterLayoutStruct *s = d->list.at(index);-
984 int farMin;-
985 int min;-
986 int max;-
987 int farMax;-
988-
989-
990-
991-
992-
993 pos = d->adjustPos(pos, index, &farMin, &min, &max, &farMax);-
994 int oldP = d->pick(s->rect.topLeft());-
995-
996-
997-
998-
999 QVarLengthArray<int, 32> poss(d->list.count());-
1000 QVarLengthArray<int, 32> ws(d->list.count());-
1001 bool upLeft;-
1002-
1003 d->doMove(false, pos, index, +1, (d->collapsible(s) && (pos > max)), poss.data(), ws.data());-
1004 d->doMove(true, pos, index - 1, +1, (d->collapsible(index - 1) && (pos < min)), poss.data(), ws.data());-
1005 upLeft = (pos < oldP);-
1006-
1007 int wid, delta, count = d->list.count();-
1008 if (upLeft) {-
1009 wid = 0;-
1010 delta = 1;-
1011 } else {-
1012 wid = count - 1;-
1013 delta = -1;-
1014 }-
1015 for (; wid >= 0 && wid < count; wid += delta) {-
1016 QSplitterLayoutStruct *sls = d->list.at( wid );-
1017 if (!sls->widget->isHidden())-
1018 d->setGeo(sls, poss[wid], ws[wid], true);-
1019 }-
1020 d->storeSizes();-
1021-
1022 splitterMoved(pos, index);-
1023}-
1024-
1025-
1026-
1027-
1028-
1029-
1030-
1031void QSplitter::getRange(int index, int *min, int *max) const-
1032{-
1033 const QSplitterPrivate * const d = d_func();-
1034 d->getRange(index, min, 0, 0, max);-
1035}-
1036int QSplitter::closestLegalPosition(int pos, int index)-
1037{-
1038 QSplitterPrivate * const d = d_func();-
1039 int x, i, n, u;-
1040 return d->adjustPos(pos, index, &u, &n, &i, &x);-
1041}-
1042bool QSplitter::opaqueResize() const-
1043{-
1044 const QSplitterPrivate * const d = d_func();-
1045 return d->opaqueResizeSet ? d->opaque : style()->styleHint(QStyle::SH_Splitter_OpaqueResize, 0, this);-
1046}-
1047-
1048-
1049void QSplitter::setOpaqueResize(bool on)-
1050{-
1051 QSplitterPrivate * const d = d_func();-
1052 d->opaqueResizeSet = true;-
1053 d->opaque = on;-
1054}-
1055-
1056-
1057-
1058-
1059-
1060QSize QSplitter::sizeHint() const-
1061{-
1062 const QSplitterPrivate * const d = d_func();-
1063 ensurePolished();-
1064 int l = 0;-
1065 int t = 0;-
1066 for (int i = 0; i < d->list.size(); ++i) {-
1067 QWidget *w = d->list.at(i)->widget;-
1068 if (w->isHidden())-
1069 continue;-
1070 QSize s = w->sizeHint();-
1071 if (s.isValid()) {-
1072 l += d->pick(s);-
1073 t = qMax(t, d->trans(s));-
1074 }-
1075 }-
1076 return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l);-
1077}-
1078-
1079-
1080-
1081-
1082-
1083-
1084QSize QSplitter::minimumSizeHint() const-
1085{-
1086 const QSplitterPrivate * const d = d_func();-
1087 ensurePolished();-
1088 int l = 0;-
1089 int t = 0;-
1090-
1091 for (int i = 0; i < d->list.size(); ++i) {-
1092 QSplitterLayoutStruct *s = d->list.at(i);-
1093 if (!s || !s->widget)-
1094 continue;-
1095 if (s->widget->isHidden())-
1096 continue;-
1097 QSize widgetSize = qSmartMinSize(s->widget);-
1098 if (widgetSize.isValid()) {-
1099 l += d->pick(widgetSize);-
1100 t = qMax(t, d->trans(widgetSize));-
1101 }-
1102 if (!s->handle || s->handle->isHidden())-
1103 continue;-
1104 QSize splitterSize = s->handle->sizeHint();-
1105 if (splitterSize.isValid()) {-
1106 l += d->pick(splitterSize);-
1107 t = qMax(t, d->trans(splitterSize));-
1108 }-
1109 }-
1110 return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l);-
1111}-
1112QList<int> QSplitter::sizes() const-
1113{-
1114 const QSplitterPrivate * const d = d_func();-
1115 ensurePolished();-
1116-
1117 const int numSizes = d->list.size();-
1118 QList<int> list;-
1119 list.reserve(numSizes);-
1120-
1121 for (int i = 0; i < numSizes; ++i) {-
1122 QSplitterLayoutStruct *s = d->list.at(i);-
1123 list.append(d->pick(s->rect.size()));-
1124 }-
1125 return list;-
1126}-
1127void QSplitter::setSizes(const QList<int> &list)-
1128{-
1129 QSplitterPrivate * const d = d_func();-
1130 d->setSizes_helper(list, true);-
1131}-
1132int QSplitter::handleWidth() const-
1133{-
1134 const QSplitterPrivate * const d = d_func();-
1135 if (d->handleWidth >= 0) {-
1136 return d->handleWidth;-
1137 } else {-
1138 return style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this);-
1139 }-
1140}-
1141-
1142void QSplitter::setHandleWidth(int width)-
1143{-
1144 QSplitterPrivate * const d = d_func();-
1145 d->handleWidth = width;-
1146 d->updateHandles();-
1147}-
1148-
1149-
1150-
1151-
1152void QSplitter::changeEvent(QEvent *ev)-
1153{-
1154 QSplitterPrivate * const d = d_func();-
1155 if(ev->type() == QEvent::StyleChange)-
1156 d->updateHandles();-
1157 QFrame::changeEvent(ev);-
1158}-
1159-
1160static const qint32 SplitterMagic = 0xff;-
1161QByteArray QSplitter::saveState() const-
1162{-
1163 const QSplitterPrivate * const d = d_func();-
1164 int version = 1;-
1165 QByteArray data;-
1166 QDataStream stream(&data, QIODevice::WriteOnly);-
1167-
1168 stream << qint32(SplitterMagic);-
1169 stream << qint32(version);-
1170 const int numSizes = d->list.size();-
1171 QList<int> list;-
1172 list.reserve(numSizes);-
1173 for (int i = 0; i < numSizes; ++i) {-
1174 QSplitterLayoutStruct *s = d->list.at(i);-
1175 list.append(s->sizer);-
1176 }-
1177 stream << list;-
1178 stream << childrenCollapsible();-
1179 stream << qint32(d->handleWidth);-
1180 stream << opaqueResize();-
1181 stream << qint32(orientation());-
1182 stream << d->opaqueResizeSet;-
1183 return data;-
1184}-
1185bool QSplitter::restoreState(const QByteArray &state)-
1186{-
1187 QSplitterPrivate * const d = d_func();-
1188 int version = 1;-
1189 QByteArray sd = state;-
1190 QDataStream stream(&sd, QIODevice::ReadOnly);-
1191 QList<int> list;-
1192 bool b;-
1193 qint32 i;-
1194 qint32 marker;-
1195 qint32 v;-
1196-
1197 stream >> marker;-
1198 stream >> v;-
1199 if (marker != SplitterMagic || v > version)-
1200 return false;-
1201-
1202 stream >> list;-
1203 d->setSizes_helper(list, false);-
1204-
1205 stream >> b;-
1206 setChildrenCollapsible(b);-
1207-
1208 stream >> i;-
1209 setHandleWidth(i);-
1210-
1211 stream >> b;-
1212 setOpaqueResize(b);-
1213-
1214 stream >> i;-
1215 setOrientation(Qt::Orientation(i));-
1216 d->doResize();-
1217-
1218 if (v >= 1)-
1219 stream >> d->opaqueResizeSet;-
1220-
1221 return true;-
1222}-
1223void QSplitter::setStretchFactor(int index, int stretch)-
1224{-
1225 QSplitterPrivate * const d = d_func();-
1226 if (index <= -1 || index >= d->list.count())-
1227 return;-
1228-
1229 QWidget *widget = d->list.at(index)->widget;-
1230 QSizePolicy sp = widget->sizePolicy();-
1231 sp.setHorizontalStretch(stretch);-
1232 sp.setVerticalStretch(stretch);-
1233 widget->setSizePolicy(sp);-
1234}-
1235QTextStream& operator<<(QTextStream& ts, const QSplitter& splitter)-
1236{-
1237 ts << splitter.saveState() << endl;-
1238 return ts;-
1239}-
1240QTextStream& operator>>(QTextStream& ts, QSplitter& splitter)-
1241{-
1242 QString line = ts.readLine();-
1243 line = line.simplified();-
1244 line.replace(QLatin1Char(' '), QString());-
1245 line = line.toUpper();-
1246-
1247 splitter.restoreState(line.toLatin1());-
1248 return ts;-
1249}-
1250-
1251-
1252-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9