225 } |
225 } |
226 |
226 |
227 /*! |
227 /*! |
228 \reimp |
228 \reimp |
229 */ |
229 */ |
|
230 void QSplitterHandle::resizeEvent(QResizeEvent *event) |
|
231 { |
|
232 Q_D(const QSplitterHandle); |
|
233 |
|
234 // When splitters are only 1 pixel large we increase the |
|
235 // actual grab area to five pixels |
|
236 |
|
237 // Note that QSplitter uses contentsRect for layouting |
|
238 // and ensures that handles are drawn on top of widgets |
|
239 // We simply use the contents margins for draggin and only |
|
240 // paint the mask area |
|
241 bool useTinyMode = (d->s->handleWidth() == 1); |
|
242 setAttribute(Qt::WA_MouseNoMask, useTinyMode); |
|
243 if (useTinyMode) { |
|
244 if (orientation() == Qt::Horizontal) |
|
245 setContentsMargins(2, 0, 2, 0); |
|
246 else |
|
247 setContentsMargins(0, 2, 0, 2); |
|
248 setMask(QRegion(contentsRect())); |
|
249 } |
|
250 |
|
251 QWidget::resizeEvent(event); |
|
252 } |
|
253 |
|
254 /*! |
|
255 \reimp |
|
256 */ |
230 bool QSplitterHandle::event(QEvent *event) |
257 bool QSplitterHandle::event(QEvent *event) |
231 { |
258 { |
232 Q_D(QSplitterHandle); |
259 Q_D(QSplitterHandle); |
233 switch(event->type()) { |
260 switch(event->type()) { |
234 case QEvent::HoverEnter: |
261 case QEvent::HoverEnter: |
299 void QSplitterHandle::paintEvent(QPaintEvent *) |
326 void QSplitterHandle::paintEvent(QPaintEvent *) |
300 { |
327 { |
301 Q_D(QSplitterHandle); |
328 Q_D(QSplitterHandle); |
302 QPainter p(this); |
329 QPainter p(this); |
303 QStyleOption opt(0); |
330 QStyleOption opt(0); |
304 opt.rect = rect(); |
331 opt.rect = contentsRect(); |
305 opt.palette = palette(); |
332 opt.palette = palette(); |
306 if (orientation() == Qt::Horizontal) |
333 if (orientation() == Qt::Horizontal) |
307 opt.state = QStyle::State_Horizontal; |
334 opt.state = QStyle::State_Horizontal; |
308 else |
335 else |
309 opt.state = QStyle::State_None; |
336 opt.state = QStyle::State_None; |
1274 { |
1301 { |
1275 Q_D(QSplitter); |
1302 Q_D(QSplitter); |
1276 if (!c->child()->isWidgetType()) |
1303 if (!c->child()->isWidgetType()) |
1277 return; |
1304 return; |
1278 QWidget *w = static_cast<QWidget*>(c->child()); |
1305 QWidget *w = static_cast<QWidget*>(c->child()); |
1279 |
|
1280 if (c->added() && !d->blockChildAdd && !w->isWindow() && !d->findWidget(w)) { |
1306 if (c->added() && !d->blockChildAdd && !w->isWindow() && !d->findWidget(w)) { |
1281 d->insertWidget_helper(d->list.count(), w, false); |
1307 d->insertWidget_helper(d->list.count(), w, false); |
1282 } else if (c->polished() && !d->blockChildAdd) { |
1308 } else if (c->polished() && !d->blockChildAdd) { |
1283 if (isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide))) |
1309 if (isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide))) |
1284 w->show(); |
1310 w->show(); |
1304 void QSplitter::setRubberBand(int pos) |
1330 void QSplitter::setRubberBand(int pos) |
1305 { |
1331 { |
1306 Q_D(QSplitter); |
1332 Q_D(QSplitter); |
1307 if (pos < 0) { |
1333 if (pos < 0) { |
1308 if (d->rubberBand) |
1334 if (d->rubberBand) |
1309 QTimer::singleShot(0, d->rubberBand, SLOT(deleteLater())); |
1335 d->rubberBand->deleteLater(); |
1310 return; |
1336 return; |
1311 } |
1337 } |
1312 QRect r = contentsRect(); |
1338 QRect r = contentsRect(); |
1313 const int rBord = 3; // customizable? |
1339 const int rBord = 3; // customizable? |
1314 int hw = handleWidth(); |
1340 int hw = handleWidth(); |
1315 if (!d->rubberBand) { |
1341 if (!d->rubberBand) { |
1316 d->rubberBand = new QRubberBand(QRubberBand::Line); |
1342 QBoolBlocker b(d->blockChildAdd); |
|
1343 d->rubberBand = new QRubberBand(QRubberBand::Line, this); |
1317 // For accessibility to identify this special widget. |
1344 // For accessibility to identify this special widget. |
1318 d->rubberBand->setObjectName(QLatin1String("qt_rubberband")); |
1345 d->rubberBand->setObjectName(QLatin1String("qt_rubberband")); |
1319 } |
1346 } |
1320 if (d->orient == Qt::Horizontal) |
1347 |
1321 d->rubberBand->setGeometry(QRect(QPoint(pos + hw / 2 - rBord, r.y()), |
1348 const QRect newGeom = d->orient == Qt::Horizontal ? QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height())) |
1322 QSize(2 * rBord, r.height())).translated(mapToGlobal(QPoint()))); |
1349 : QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord)); |
1323 else |
1350 d->rubberBand->setGeometry(newGeom); |
1324 d->rubberBand->setGeometry(QRect(QPoint(r.x(), pos + hw / 2 - rBord), |
1351 d->rubberBand->show(); |
1325 QSize(r.width(), 2 * rBord)).translated(mapToGlobal(QPoint()))); |
|
1326 if (!d->rubberBand->isVisible()) |
|
1327 d->rubberBand->show(); |
|
1328 } |
1352 } |
1329 |
1353 |
1330 /*! |
1354 /*! |
1331 \reimp |
1355 \reimp |
1332 */ |
1356 */ |
1553 { |
1577 { |
1554 Q_D(const QSplitter); |
1578 Q_D(const QSplitter); |
1555 ensurePolished(); |
1579 ensurePolished(); |
1556 int l = 0; |
1580 int l = 0; |
1557 int t = 0; |
1581 int t = 0; |
1558 QObjectList childList = children(); |
1582 for (int i = 0; i < d->list.size(); ++i) { |
1559 for (int i = 0; i < childList.size(); ++i) { |
1583 QWidget *w = d->list.at(i)->widget; |
1560 if (QWidget *w = qobject_cast<QWidget *>(childList.at(i))) { |
1584 if (w->isHidden()) |
1561 if (w->isHidden()) |
1585 continue; |
1562 continue; |
1586 QSize s = w->sizeHint(); |
1563 QSize s = w->sizeHint(); |
1587 if (s.isValid()) { |
1564 if (s.isValid()) { |
1588 l += d->pick(s); |
1565 l += d->pick(s); |
1589 t = qMax(t, d->trans(s)); |
1566 t = qMax(t, d->trans(s)); |
|
1567 } |
|
1568 } |
1590 } |
1569 } |
1591 } |
1570 return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); |
1592 return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); |
1571 } |
1593 } |
1572 |
1594 |
1665 \property QSplitter::handleWidth |
1687 \property QSplitter::handleWidth |
1666 \brief the width of the splitter handles |
1688 \brief the width of the splitter handles |
1667 |
1689 |
1668 By default, this property contains a value that depends on the user's platform |
1690 By default, this property contains a value that depends on the user's platform |
1669 and style preferences. |
1691 and style preferences. |
|
1692 |
|
1693 If you set handleWidth to 1, the actual grab area will grow to overlap a |
|
1694 few pixels of it's respective widgets. |
1670 */ |
1695 */ |
1671 |
1696 |
1672 int QSplitter::handleWidth() const |
1697 int QSplitter::handleWidth() const |
1673 { |
1698 { |
1674 Q_D(const QSplitter); |
1699 Q_D(const QSplitter); |