| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qsplitter.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qsplitter.h" | - | ||||||||||||||||||
| 41 | #ifndef QT_NO_SPLITTER | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include "qapplication.h" | - | ||||||||||||||||||
| 44 | #include "qcursor.h" | - | ||||||||||||||||||
| 45 | #include "qdrawutil.h" | - | ||||||||||||||||||
| 46 | #include "qevent.h" | - | ||||||||||||||||||
| 47 | #include "qlayout.h" | - | ||||||||||||||||||
| 48 | #include "qlist.h" | - | ||||||||||||||||||
| 49 | #include "qpainter.h" | - | ||||||||||||||||||
| 50 | #include "qrubberband.h" | - | ||||||||||||||||||
| 51 | #include "qstyle.h" | - | ||||||||||||||||||
| 52 | #include "qstyleoption.h" | - | ||||||||||||||||||
| 53 | #include "qtextstream.h" | - | ||||||||||||||||||
| 54 | #include "qvarlengtharray.h" | - | ||||||||||||||||||
| 55 | #include "qvector.h" | - | ||||||||||||||||||
| 56 | #include "private/qlayoutengine_p.h" | - | ||||||||||||||||||
| 57 | #include "private/qsplitter_p.h" | - | ||||||||||||||||||
| 58 | #include "qtimer.h" | - | ||||||||||||||||||
| 59 | #include "qdebug.h" | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | #include <ctype.h> | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | //#define QSPLITTER_DEBUG | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | QSplitterPrivate::~QSplitterPrivate() | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | } | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | /*! | - | ||||||||||||||||||
| 72 | \class QSplitterHandle | - | ||||||||||||||||||
| 73 | \brief The QSplitterHandle class provides handle functionality for the splitter. | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | \ingroup organizers | - | ||||||||||||||||||
| 76 | \inmodule QtWidgets | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | QSplitterHandle is typically what people think about when they think about | - | ||||||||||||||||||
| 79 | a splitter. It is the handle that is used to resize the widgets. | - | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | A typical developer using QSplitter will never have to worry about | - | ||||||||||||||||||
| 82 | QSplitterHandle. It is provided for developers who want splitter handles | - | ||||||||||||||||||
| 83 | that provide extra features, such as popup menus. | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | The typical way one would create splitter handles is to subclass QSplitter and then | - | ||||||||||||||||||
| 86 | reimplement QSplitter::createHandle() to instantiate the custom splitter | - | ||||||||||||||||||
| 87 | handle. For example, a minimum QSplitter subclass might look like this: | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | \snippet splitterhandle/splitter.h 0 | - | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | The \l{QSplitter::}{createHandle()} implementation simply constructs a | - | ||||||||||||||||||
| 92 | custom splitter handle, called \c Splitter in this example: | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | \snippet splitterhandle/splitter.cpp 1 | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | Information about a given handle can be obtained using functions like | - | ||||||||||||||||||
| 97 | orientation() and opaqueResize(), and is retrieved from its parent splitter. | - | ||||||||||||||||||
| 98 | Details like these can be used to give custom handles different appearances | - | ||||||||||||||||||
| 99 | depending on the splitter's orientation. | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | The complexity of a custom handle subclass depends on the tasks that it | - | ||||||||||||||||||
| 102 | needs to perform. A simple subclass might only provide a paintEvent() | - | ||||||||||||||||||
| 103 | implementation: | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | \snippet splitterhandle/splitter.cpp 0 | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | In this example, a predefined gradient is set up differently depending on | - | ||||||||||||||||||
| 108 | the orientation of the handle. QSplitterHandle provides a reasonable | - | ||||||||||||||||||
| 109 | size hint for the handle, so the subclass does not need to provide a | - | ||||||||||||||||||
| 110 | reimplementation of sizeHint() unless the handle has special size | - | ||||||||||||||||||
| 111 | requirements. | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | \sa QSplitter | - | ||||||||||||||||||
| 114 | */ | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | /*! | - | ||||||||||||||||||
| 117 | Creates a QSplitter handle with the given \a orientation and | - | ||||||||||||||||||
| 118 | \a parent. | - | ||||||||||||||||||
| 119 | */ | - | ||||||||||||||||||
| 120 | QSplitterHandle::QSplitterHandle(Qt::Orientation orientation, QSplitter *parent) | - | ||||||||||||||||||
| 121 | : QWidget(*new QSplitterHandlePrivate, parent, 0) | - | ||||||||||||||||||
| 122 | { | - | ||||||||||||||||||
| 123 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 124 | d->s = parent; | - | ||||||||||||||||||
| 125 | setOrientation(orientation); | - | ||||||||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | /*! | - | ||||||||||||||||||
| 129 | Destructor. | - | ||||||||||||||||||
| 130 | */ | - | ||||||||||||||||||
| 131 | QSplitterHandle::~QSplitterHandle() | - | ||||||||||||||||||
| 132 | { | - | ||||||||||||||||||
| 133 | } | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | /*! | - | ||||||||||||||||||
| 136 | Sets the orientation of the splitter handle to \a orientation. | - | ||||||||||||||||||
| 137 | This is usually propagated from the QSplitter. | - | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | \sa QSplitter::setOrientation() | - | ||||||||||||||||||
| 140 | */ | - | ||||||||||||||||||
| 141 | void QSplitterHandle::setOrientation(Qt::Orientation orientation) | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 144 | d->orient = orientation; | - | ||||||||||||||||||
| 145 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
| 146 | setCursor(orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor); | - | ||||||||||||||||||
| 147 | #endif | - | ||||||||||||||||||
| 148 | } never executed: end of block | 0 | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | /*! | - | ||||||||||||||||||
| 151 | Returns the handle's orientation. This is usually propagated from the QSplitter. | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | \sa QSplitter::orientation() | - | ||||||||||||||||||
| 154 | */ | - | ||||||||||||||||||
| 155 | Qt::Orientation QSplitterHandle::orientation() const | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | Q_D(const QSplitterHandle); | - | ||||||||||||||||||
| 158 | return d->orient; never executed: return d->orient; | 0 | ||||||||||||||||||
| 159 | } | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | /*! | - | ||||||||||||||||||
| 163 | Returns \c true if widgets are resized dynamically (opaquely), otherwise | - | ||||||||||||||||||
| 164 | returns \c false. This value is controlled by the QSplitter. | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | \sa QSplitter::opaqueResize() | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | */ | - | ||||||||||||||||||
| 169 | bool QSplitterHandle::opaqueResize() const | - | ||||||||||||||||||
| 170 | { | - | ||||||||||||||||||
| 171 | Q_D(const QSplitterHandle); | - | ||||||||||||||||||
| 172 | return d->s->opaqueResize(); never executed: return d->s->opaqueResize(); | 0 | ||||||||||||||||||
| 173 | } | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | /*! | - | ||||||||||||||||||
| 177 | Returns the splitter associated with this splitter handle. | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | \sa QSplitter::handle() | - | ||||||||||||||||||
| 180 | */ | - | ||||||||||||||||||
| 181 | QSplitter *QSplitterHandle::splitter() const | - | ||||||||||||||||||
| 182 | { | - | ||||||||||||||||||
| 183 | return d_func()->s; never executed: return d_func()->s; | 0 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | /*! | - | ||||||||||||||||||
| 187 | Tells the splitter to move this handle to position \a pos, which is | - | ||||||||||||||||||
| 188 | the distance from the left or top edge of the widget. | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | Note that \a pos is also measured from the left (or top) for | - | ||||||||||||||||||
| 191 | right-to-left languages. This function will map \a pos to the | - | ||||||||||||||||||
| 192 | appropriate position before calling QSplitter::moveSplitter(). | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | \sa QSplitter::moveSplitter(), closestLegalPosition() | - | ||||||||||||||||||
| 195 | */ | - | ||||||||||||||||||
| 196 | void QSplitterHandle::moveSplitter(int pos) | - | ||||||||||||||||||
| 197 | { | - | ||||||||||||||||||
| 198 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 199 | if (d->s->isRightToLeft() && d->orient == Qt::Horizontal)
| 0 | ||||||||||||||||||
| 200 | pos = d->s->contentsRect().width() - pos; never executed: pos = d->s->contentsRect().width() - pos; | 0 | ||||||||||||||||||
| 201 | d->s->moveSplitter(pos, d->s->indexOf(this)); | - | ||||||||||||||||||
| 202 | } never executed: end of block | 0 | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | /*! | - | ||||||||||||||||||
| 205 | Returns the closest legal position to \a pos of the splitter | - | ||||||||||||||||||
| 206 | handle. The positions are measured from the left or top edge of | - | ||||||||||||||||||
| 207 | the splitter, even for right-to-left languages. | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | \sa QSplitter::closestLegalPosition(), moveSplitter() | - | ||||||||||||||||||
| 210 | */ | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | int QSplitterHandle::closestLegalPosition(int pos) | - | ||||||||||||||||||
| 213 | { | - | ||||||||||||||||||
| 214 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 215 | QSplitter *s = d->s; | - | ||||||||||||||||||
| 216 | if (s->isRightToLeft() && d->orient == Qt::Horizontal) {
| 0 | ||||||||||||||||||
| 217 | int w = s->contentsRect().width(); | - | ||||||||||||||||||
| 218 | return w - s->closestLegalPosition(w - pos, s->indexOf(this)); never executed: return w - s->closestLegalPosition(w - pos, s->indexOf(this)); | 0 | ||||||||||||||||||
| 219 | } | - | ||||||||||||||||||
| 220 | return s->closestLegalPosition(pos, s->indexOf(this)); never executed: return s->closestLegalPosition(pos, s->indexOf(this)); | 0 | ||||||||||||||||||
| 221 | } | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | /*! | - | ||||||||||||||||||
| 224 | \reimp | - | ||||||||||||||||||
| 225 | */ | - | ||||||||||||||||||
| 226 | QSize QSplitterHandle::sizeHint() const | - | ||||||||||||||||||
| 227 | { | - | ||||||||||||||||||
| 228 | Q_D(const QSplitterHandle); | - | ||||||||||||||||||
| 229 | int hw = d->s->handleWidth(); | - | ||||||||||||||||||
| 230 | QStyleOption opt(0); | - | ||||||||||||||||||
| 231 | opt.init(d->s); | - | ||||||||||||||||||
| 232 | opt.state = QStyle::State_None; | - | ||||||||||||||||||
| 233 | return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s) never executed: return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s) .expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||||||||
| 234 | .expandedTo(QApplication::globalStrut()); never executed: return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s) .expandedTo(QApplication::globalStrut()); | 0 | ||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | /*! | - | ||||||||||||||||||
| 238 | \reimp | - | ||||||||||||||||||
| 239 | */ | - | ||||||||||||||||||
| 240 | void QSplitterHandle::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||
| 241 | { | - | ||||||||||||||||||
| 242 | Q_D(const QSplitterHandle); | - | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | // When splitters are only 1 or 0 pixel large we increase the | - | ||||||||||||||||||
| 245 | // actual grab area to five pixels | - | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | // Note that QSplitter uses contentsRect for layouting | - | ||||||||||||||||||
| 248 | // and ensures that handles are drawn on top of widgets | - | ||||||||||||||||||
| 249 | // We simply use the contents margins for draggin and only | - | ||||||||||||||||||
| 250 | // paint the mask area | - | ||||||||||||||||||
| 251 | bool useTinyMode = (d->s->handleWidth() <= 1); | - | ||||||||||||||||||
| 252 | setAttribute(Qt::WA_MouseNoMask, useTinyMode); | - | ||||||||||||||||||
| 253 | if (useTinyMode) {
| 0 | ||||||||||||||||||
| 254 | if (orientation() == Qt::Horizontal)
| 0 | ||||||||||||||||||
| 255 | setContentsMargins(2, 0, 2, 0); never executed: setContentsMargins(2, 0, 2, 0); | 0 | ||||||||||||||||||
| 256 | else | - | ||||||||||||||||||
| 257 | setContentsMargins(0, 2, 0, 2); never executed: setContentsMargins(0, 2, 0, 2); | 0 | ||||||||||||||||||
| 258 | setMask(QRegion(contentsRect())); | - | ||||||||||||||||||
| 259 | } never executed: end of block | 0 | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | QWidget::resizeEvent(event); | - | ||||||||||||||||||
| 262 | } never executed: end of block | 0 | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | /*! | - | ||||||||||||||||||
| 265 | \reimp | - | ||||||||||||||||||
| 266 | */ | - | ||||||||||||||||||
| 267 | bool QSplitterHandle::event(QEvent *event) | - | ||||||||||||||||||
| 268 | { | - | ||||||||||||||||||
| 269 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 270 | switch(event->type()) { | - | ||||||||||||||||||
| 271 | case QEvent::HoverEnter: never executed: case QEvent::HoverEnter: | 0 | ||||||||||||||||||
| 272 | d->hover = true; | - | ||||||||||||||||||
| 273 | update(); | - | ||||||||||||||||||
| 274 | break; never executed: break; | 0 | ||||||||||||||||||
| 275 | case QEvent::HoverLeave: never executed: case QEvent::HoverLeave: | 0 | ||||||||||||||||||
| 276 | d->hover = false; | - | ||||||||||||||||||
| 277 | update(); | - | ||||||||||||||||||
| 278 | break; never executed: break; | 0 | ||||||||||||||||||
| 279 | default: never executed: default: | 0 | ||||||||||||||||||
| 280 | break; never executed: break; | 0 | ||||||||||||||||||
| 281 | } | - | ||||||||||||||||||
| 282 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | /*! | - | ||||||||||||||||||
| 286 | \reimp | - | ||||||||||||||||||
| 287 | */ | - | ||||||||||||||||||
| 288 | void QSplitterHandle::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 289 | { | - | ||||||||||||||||||
| 290 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 291 | if (!(e->buttons() & Qt::LeftButton))
| 0 | ||||||||||||||||||
| 292 | return; never executed: return; | 0 | ||||||||||||||||||
| 293 | int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos())) | - | ||||||||||||||||||
| 294 | - d->mouseOffset; | - | ||||||||||||||||||
| 295 | if (opaqueResize()) {
| 0 | ||||||||||||||||||
| 296 | moveSplitter(pos); | - | ||||||||||||||||||
| 297 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 298 | d->s->setRubberBand(closestLegalPosition(pos)); | - | ||||||||||||||||||
| 299 | } never executed: end of block | 0 | ||||||||||||||||||
| 300 | } | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | /*! | - | ||||||||||||||||||
| 303 | \reimp | - | ||||||||||||||||||
| 304 | */ | - | ||||||||||||||||||
| 305 | void QSplitterHandle::mousePressEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 306 | { | - | ||||||||||||||||||
| 307 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 308 | if (e->button() == Qt::LeftButton) {
| 0 | ||||||||||||||||||
| 309 | d->mouseOffset = d->pick(e->pos()); | - | ||||||||||||||||||
| 310 | d->pressed = true; | - | ||||||||||||||||||
| 311 | update(); | - | ||||||||||||||||||
| 312 | } never executed: end of block | 0 | ||||||||||||||||||
| 313 | } never executed: end of block | 0 | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | /*! | - | ||||||||||||||||||
| 316 | \reimp | - | ||||||||||||||||||
| 317 | */ | - | ||||||||||||||||||
| 318 | void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||
| 319 | { | - | ||||||||||||||||||
| 320 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 321 | if (!opaqueResize() && e->button() == Qt::LeftButton) {
| 0 | ||||||||||||||||||
| 322 | int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos())) | - | ||||||||||||||||||
| 323 | - d->mouseOffset; | - | ||||||||||||||||||
| 324 | d->s->setRubberBand(-1); | - | ||||||||||||||||||
| 325 | moveSplitter(pos); | - | ||||||||||||||||||
| 326 | } never executed: end of block | 0 | ||||||||||||||||||
| 327 | if (e->button() == Qt::LeftButton) {
| 0 | ||||||||||||||||||
| 328 | d->pressed = false; | - | ||||||||||||||||||
| 329 | update(); | - | ||||||||||||||||||
| 330 | } never executed: end of block | 0 | ||||||||||||||||||
| 331 | } never executed: end of block | 0 | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | /*! | - | ||||||||||||||||||
| 334 | \reimp | - | ||||||||||||||||||
| 335 | */ | - | ||||||||||||||||||
| 336 | void QSplitterHandle::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
| 337 | { | - | ||||||||||||||||||
| 338 | Q_D(QSplitterHandle); | - | ||||||||||||||||||
| 339 | QPainter p(this); | - | ||||||||||||||||||
| 340 | QStyleOption opt(0); | - | ||||||||||||||||||
| 341 | opt.rect = contentsRect(); | - | ||||||||||||||||||
| 342 | opt.palette = palette(); | - | ||||||||||||||||||
| 343 | if (orientation() == Qt::Horizontal)
| 0 | ||||||||||||||||||
| 344 | opt.state = QStyle::State_Horizontal; never executed: opt.state = QStyle::State_Horizontal; | 0 | ||||||||||||||||||
| 345 | else | - | ||||||||||||||||||
| 346 | opt.state = QStyle::State_None; never executed: opt.state = QStyle::State_None; | 0 | ||||||||||||||||||
| 347 | if (d->hover)
| 0 | ||||||||||||||||||
| 348 | opt.state |= QStyle::State_MouseOver; never executed: opt.state |= QStyle::State_MouseOver; | 0 | ||||||||||||||||||
| 349 | if (d->pressed)
| 0 | ||||||||||||||||||
| 350 | opt.state |= QStyle::State_Sunken; never executed: opt.state |= QStyle::State_Sunken; | 0 | ||||||||||||||||||
| 351 | if (isEnabled())
| 0 | ||||||||||||||||||
| 352 | opt.state |= QStyle::State_Enabled; never executed: opt.state |= QStyle::State_Enabled; | 0 | ||||||||||||||||||
| 353 | parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s); | - | ||||||||||||||||||
| 354 | } never executed: end of block | 0 | ||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | int QSplitterLayoutStruct::getWidgetSize(Qt::Orientation orient) | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | if (sizer == -1) {
| 0 | ||||||||||||||||||
| 360 | QSize s = widget->sizeHint(); | - | ||||||||||||||||||
| 361 | const int presizer = pick(s, orient); | - | ||||||||||||||||||
| 362 | const int realsize = pick(widget->size(), orient); | - | ||||||||||||||||||
| 363 | if (!s.isValid() || (widget->testAttribute(Qt::WA_Resized) && (realsize > presizer))) {
| 0 | ||||||||||||||||||
| 364 | sizer = pick(widget->size(), orient); | - | ||||||||||||||||||
| 365 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 366 | sizer = presizer; | - | ||||||||||||||||||
| 367 | } never executed: end of block | 0 | ||||||||||||||||||
| 368 | QSizePolicy p = widget->sizePolicy(); | - | ||||||||||||||||||
| 369 | int sf = (orient == Qt::Horizontal) ? p.horizontalStretch() : p.verticalStretch();
| 0 | ||||||||||||||||||
| 370 | if (sf > 1)
| 0 | ||||||||||||||||||
| 371 | sizer *= sf; never executed: sizer *= sf; | 0 | ||||||||||||||||||
| 372 | } never executed: end of block | 0 | ||||||||||||||||||
| 373 | return sizer; never executed: return sizer; | 0 | ||||||||||||||||||
| 374 | } | - | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | int QSplitterLayoutStruct::getHandleSize(Qt::Orientation orient) | - | ||||||||||||||||||
| 377 | { | - | ||||||||||||||||||
| 378 | return pick(handle->sizeHint(), orient); never executed: return pick(handle->sizeHint(), orient); | 0 | ||||||||||||||||||
| 379 | } | - | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | void QSplitterPrivate::init() | - | ||||||||||||||||||
| 382 | { | - | ||||||||||||||||||
| 383 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 384 | QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred); | - | ||||||||||||||||||
| 385 | if (orient == Qt::Vertical)
| 0 | ||||||||||||||||||
| 386 | sp.transpose(); never executed: sp.transpose(); | 0 | ||||||||||||||||||
| 387 | q->setSizePolicy(sp); | - | ||||||||||||||||||
| 388 | q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||||||||
| 389 | } never executed: end of block | 0 | ||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | void QSplitterPrivate::recalc(bool update) | - | ||||||||||||||||||
| 392 | { | - | ||||||||||||||||||
| 393 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 394 | int n = list.count(); | - | ||||||||||||||||||
| 395 | /* | - | ||||||||||||||||||
| 396 | Splitter handles before the first visible widget or right | - | ||||||||||||||||||
| 397 | before a hidden widget must be hidden. | - | ||||||||||||||||||
| 398 | */ | - | ||||||||||||||||||
| 399 | bool first = true; | - | ||||||||||||||||||
| 400 | bool allInvisible = n != 0; | - | ||||||||||||||||||
| 401 | for (int i = 0; i < n ; ++i) {
| 0 | ||||||||||||||||||
| 402 | QSplitterLayoutStruct *s = list.at(i); | - | ||||||||||||||||||
| 403 | bool widgetHidden = s->widget->isHidden(); | - | ||||||||||||||||||
| 404 | if (allInvisible && !widgetHidden && !s->collapsed)
| 0 | ||||||||||||||||||
| 405 | allInvisible = false; never executed: allInvisible = false; | 0 | ||||||||||||||||||
| 406 | s->handle->setHidden(first || widgetHidden); | - | ||||||||||||||||||
| 407 | if (!widgetHidden)
| 0 | ||||||||||||||||||
| 408 | first = false; never executed: first = false; | 0 | ||||||||||||||||||
| 409 | } never executed: end of block | 0 | ||||||||||||||||||
| 410 | - | |||||||||||||||||||
| 411 | if (allInvisible)
| 0 | ||||||||||||||||||
| 412 | for (int i = 0; i < n ; ++i) {
| 0 | ||||||||||||||||||
| 413 | QSplitterLayoutStruct *s = list.at(i); | - | ||||||||||||||||||
| 414 | if (!s->widget->isHidden()) {
| 0 | ||||||||||||||||||
| 415 | s->collapsed = false; | - | ||||||||||||||||||
| 416 | break; never executed: break; | 0 | ||||||||||||||||||
| 417 | } | - | ||||||||||||||||||
| 418 | } never executed: end of block | 0 | ||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | int fi = 2 * q->frameWidth(); | - | ||||||||||||||||||
| 421 | int maxl = fi; | - | ||||||||||||||||||
| 422 | int minl = fi; | - | ||||||||||||||||||
| 423 | int maxt = QWIDGETSIZE_MAX; | - | ||||||||||||||||||
| 424 | int mint = fi; | - | ||||||||||||||||||
| 425 | /* | - | ||||||||||||||||||
| 426 | calculate min/max sizes for the whole splitter | - | ||||||||||||||||||
| 427 | */ | - | ||||||||||||||||||
| 428 | bool empty = true; | - | ||||||||||||||||||
| 429 | for (int j = 0; j < n; j++) {
| 0 | ||||||||||||||||||
| 430 | QSplitterLayoutStruct *s = list.at(j); | - | ||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | if (!s->widget->isHidden()) {
| 0 | ||||||||||||||||||
| 433 | empty = false; | - | ||||||||||||||||||
| 434 | if (!s->handle->isHidden()) {
| 0 | ||||||||||||||||||
| 435 | minl += s->getHandleSize(orient); | - | ||||||||||||||||||
| 436 | maxl += s->getHandleSize(orient); | - | ||||||||||||||||||
| 437 | } never executed: end of block | 0 | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | QSize minS = qSmartMinSize(s->widget); | - | ||||||||||||||||||
| 440 | minl += pick(minS); | - | ||||||||||||||||||
| 441 | maxl += pick(s->widget->maximumSize()); | - | ||||||||||||||||||
| 442 | mint = qMax(mint, trans(minS)); | - | ||||||||||||||||||
| 443 | int tm = trans(s->widget->maximumSize()); | - | ||||||||||||||||||
| 444 | if (tm > 0)
| 0 | ||||||||||||||||||
| 445 | maxt = qMin(maxt, tm); never executed: maxt = qMin(maxt, tm); | 0 | ||||||||||||||||||
| 446 | } never executed: end of block | 0 | ||||||||||||||||||
| 447 | } never executed: end of block | 0 | ||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | if (empty) {
| 0 | ||||||||||||||||||
| 450 | if (qobject_cast<QSplitter *>(parent)) {
| 0 | ||||||||||||||||||
| 451 | // nested splitters; be nice | - | ||||||||||||||||||
| 452 | maxl = maxt = 0; | - | ||||||||||||||||||
| 453 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 454 | // QSplitter with no children yet | - | ||||||||||||||||||
| 455 | maxl = QWIDGETSIZE_MAX; | - | ||||||||||||||||||
| 456 | } never executed: end of block | 0 | ||||||||||||||||||
| 457 | } else { | - | ||||||||||||||||||
| 458 | maxl = qMin<int>(maxl, QWIDGETSIZE_MAX); | - | ||||||||||||||||||
| 459 | } never executed: end of block | 0 | ||||||||||||||||||
| 460 | if (maxt < mint)
| 0 | ||||||||||||||||||
| 461 | maxt = mint; never executed: maxt = mint; | 0 | ||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | if (update) {
| 0 | ||||||||||||||||||
| 464 | if (orient == Qt::Horizontal) {
| 0 | ||||||||||||||||||
| 465 | q->setMaximumSize(maxl, maxt); | - | ||||||||||||||||||
| 466 | if (q->isWindow())
| 0 | ||||||||||||||||||
| 467 | q->setMinimumSize(minl,mint); never executed: q->setMinimumSize(minl,mint); | 0 | ||||||||||||||||||
| 468 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 469 | q->setMaximumSize(maxt, maxl); | - | ||||||||||||||||||
| 470 | if (q->isWindow())
| 0 | ||||||||||||||||||
| 471 | q->setMinimumSize(mint,minl); never executed: q->setMinimumSize(mint,minl); | 0 | ||||||||||||||||||
| 472 | } never executed: end of block | 0 | ||||||||||||||||||
| 473 | doResize(); | - | ||||||||||||||||||
| 474 | q->updateGeometry(); | - | ||||||||||||||||||
| 475 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 476 | firstShow = true; | - | ||||||||||||||||||
| 477 | } never executed: end of block | 0 | ||||||||||||||||||
| 478 | } | - | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | void QSplitterPrivate::doResize() | - | ||||||||||||||||||
| 481 | { | - | ||||||||||||||||||
| 482 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 483 | QRect r = q->contentsRect(); | - | ||||||||||||||||||
| 484 | int n = list.count(); | - | ||||||||||||||||||
| 485 | QVector<QLayoutStruct> a(n*2); | - | ||||||||||||||||||
| 486 | int i; | - | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | bool noStretchFactorsSet = true; | - | ||||||||||||||||||
| 489 | for (i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||
| 490 | QSizePolicy p = list.at(i)->widget->sizePolicy(); | - | ||||||||||||||||||
| 491 | int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch();
| 0 | ||||||||||||||||||
| 492 | if (sf != 0) {
| 0 | ||||||||||||||||||
| 493 | noStretchFactorsSet = false; | - | ||||||||||||||||||
| 494 | break; never executed: break; | 0 | ||||||||||||||||||
| 495 | } | - | ||||||||||||||||||
| 496 | } never executed: end of block | 0 | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | int j=0; | - | ||||||||||||||||||
| 499 | for (i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||
| 500 | QSplitterLayoutStruct *s = list.at(i); | - | ||||||||||||||||||
| 501 | #ifdef QSPLITTER_DEBUG | - | ||||||||||||||||||
| 502 | qDebug("widget %d hidden: %d collapsed: %d handle hidden: %d", i, s->widget->isHidden(), | - | ||||||||||||||||||
| 503 | s->collapsed, s->handle->isHidden()); | - | ||||||||||||||||||
| 504 | #endif | - | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | a[j].init(); | - | ||||||||||||||||||
| 507 | if (s->handle->isHidden()) {
| 0 | ||||||||||||||||||
| 508 | a[j].maximumSize = 0; | - | ||||||||||||||||||
| 509 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 510 | a[j].sizeHint = a[j].minimumSize = a[j].maximumSize = s->getHandleSize(orient); | - | ||||||||||||||||||
| 511 | a[j].empty = false; | - | ||||||||||||||||||
| 512 | } never executed: end of block | 0 | ||||||||||||||||||
| 513 | ++j; | - | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | a[j].init(); | - | ||||||||||||||||||
| 516 | if (s->widget->isHidden() || s->collapsed) {
| 0 | ||||||||||||||||||
| 517 | a[j].maximumSize = 0; | - | ||||||||||||||||||
| 518 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 519 | a[j].minimumSize = pick(qSmartMinSize(s->widget)); | - | ||||||||||||||||||
| 520 | a[j].maximumSize = pick(s->widget->maximumSize()); | - | ||||||||||||||||||
| 521 | a[j].empty = false; | - | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | bool stretch = noStretchFactorsSet; | - | ||||||||||||||||||
| 524 | if (!stretch) {
| 0 | ||||||||||||||||||
| 525 | QSizePolicy p = s->widget->sizePolicy(); | - | ||||||||||||||||||
| 526 | int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch();
| 0 | ||||||||||||||||||
| 527 | stretch = (sf != 0); | - | ||||||||||||||||||
| 528 | } never executed: end of block | 0 | ||||||||||||||||||
| 529 | if (stretch) {
| 0 | ||||||||||||||||||
| 530 | a[j].stretch = s->getWidgetSize(orient); | - | ||||||||||||||||||
| 531 | a[j].sizeHint = a[j].minimumSize; | - | ||||||||||||||||||
| 532 | a[j].expansive = true; | - | ||||||||||||||||||
| 533 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 534 | a[j].sizeHint = qMax(s->getWidgetSize(orient), a[j].minimumSize); | - | ||||||||||||||||||
| 535 | } never executed: end of block | 0 | ||||||||||||||||||
| 536 | } | - | ||||||||||||||||||
| 537 | ++j; | - | ||||||||||||||||||
| 538 | } never executed: end of block | 0 | ||||||||||||||||||
| 539 | - | |||||||||||||||||||
| 540 | qGeomCalc(a, 0, n*2, pick(r.topLeft()), pick(r.size()), 0); | - | ||||||||||||||||||
| 541 | - | |||||||||||||||||||
| 542 | #ifdef QSPLITTER_DEBUG | - | ||||||||||||||||||
| 543 | for (i = 0; i < n*2; ++i) { | - | ||||||||||||||||||
| 544 | qDebug("%*s%d: stretch %d, sh %d, minS %d, maxS %d, exp %d, emp %d -> %d, %d", | - | ||||||||||||||||||
| 545 | i, "", i, | - | ||||||||||||||||||
| 546 | a[i].stretch, | - | ||||||||||||||||||
| 547 | a[i].sizeHint, | - | ||||||||||||||||||
| 548 | a[i].minimumSize, | - | ||||||||||||||||||
| 549 | a[i].maximumSize, | - | ||||||||||||||||||
| 550 | a[i].expansive, | - | ||||||||||||||||||
| 551 | a[i].empty, | - | ||||||||||||||||||
| 552 | a[i].pos, | - | ||||||||||||||||||
| 553 | a[i].size); | - | ||||||||||||||||||
| 554 | } | - | ||||||||||||||||||
| 555 | #endif | - | ||||||||||||||||||
| 556 | - | |||||||||||||||||||
| 557 | for (i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||
| 558 | QSplitterLayoutStruct *s = list.at(i); | - | ||||||||||||||||||
| 559 | setGeo(s, a[i*2+1].pos, a[i*2+1].size, false); | - | ||||||||||||||||||
| 560 | } never executed: end of block | 0 | ||||||||||||||||||
| 561 | } never executed: end of block | 0 | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | void QSplitterPrivate::storeSizes() | - | ||||||||||||||||||
| 564 | { | - | ||||||||||||||||||
| 565 | for (int i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 566 | QSplitterLayoutStruct *sls = list.at(i); | - | ||||||||||||||||||
| 567 | sls->sizer = pick(sls->rect.size()); | - | ||||||||||||||||||
| 568 | } never executed: end of block | 0 | ||||||||||||||||||
| 569 | } never executed: end of block | 0 | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | void QSplitterPrivate::addContribution(int index, int *min, int *max, bool mayCollapse) const | - | ||||||||||||||||||
| 572 | { | - | ||||||||||||||||||
| 573 | QSplitterLayoutStruct *s = list.at(index); | - | ||||||||||||||||||
| 574 | if (!s->widget->isHidden()) {
| 0 | ||||||||||||||||||
| 575 | if (!s->handle->isHidden()) {
| 0 | ||||||||||||||||||
| 576 | *min += s->getHandleSize(orient); | - | ||||||||||||||||||
| 577 | *max += s->getHandleSize(orient); | - | ||||||||||||||||||
| 578 | } never executed: end of block | 0 | ||||||||||||||||||
| 579 | if (mayCollapse || !s->collapsed)
| 0 | ||||||||||||||||||
| 580 | *min += pick(qSmartMinSize(s->widget)); never executed: *min += pick(qSmartMinSize(s->widget)); | 0 | ||||||||||||||||||
| 581 | - | |||||||||||||||||||
| 582 | *max += pick(s->widget->maximumSize()); | - | ||||||||||||||||||
| 583 | } never executed: end of block | 0 | ||||||||||||||||||
| 584 | } never executed: end of block | 0 | ||||||||||||||||||
| 585 | - | |||||||||||||||||||
| 586 | int QSplitterPrivate::findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const | - | ||||||||||||||||||
| 587 | { | - | ||||||||||||||||||
| 588 | if (delta < 0)
| 0 | ||||||||||||||||||
| 589 | index += delta; never executed: index += delta; | 0 | ||||||||||||||||||
| 590 | do { | - | ||||||||||||||||||
| 591 | QWidget *w = list.at(index)->widget; | - | ||||||||||||||||||
| 592 | if (!w->isHidden()) {
| 0 | ||||||||||||||||||
| 593 | if (collapsible(list.at(index)))
| 0 | ||||||||||||||||||
| 594 | collapsibleSize = pick(qSmartMinSize(w)); never executed: collapsibleSize = pick(qSmartMinSize(w)); | 0 | ||||||||||||||||||
| 595 | return index; never executed: return index; | 0 | ||||||||||||||||||
| 596 | } | - | ||||||||||||||||||
| 597 | index += delta; | - | ||||||||||||||||||
| 598 | } while (index >= 0 && index < list.count()); never executed: end of block
| 0 | ||||||||||||||||||
| 599 | - | |||||||||||||||||||
| 600 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 601 | } | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | /* | - | ||||||||||||||||||
| 604 | For the splitter handle with index \a index, \a min and \a max give the range without collapsing any widgets, | - | ||||||||||||||||||
| 605 | and \a farMin and farMax give the range with collapsing included. | - | ||||||||||||||||||
| 606 | */ | - | ||||||||||||||||||
| 607 | void QSplitterPrivate::getRange(int index, int *farMin, int *min, int *max, int *farMax) const | - | ||||||||||||||||||
| 608 | { | - | ||||||||||||||||||
| 609 | Q_Q(const QSplitter); | - | ||||||||||||||||||
| 610 | int n = list.count(); | - | ||||||||||||||||||
| 611 | if (index <= 0 || index >= n)
| 0 | ||||||||||||||||||
| 612 | return; never executed: return; | 0 | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | int collapsibleSizeBefore = 0; | - | ||||||||||||||||||
| 615 | int idJustBefore = findWidgetJustBeforeOrJustAfter(index, -1, collapsibleSizeBefore); | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | int collapsibleSizeAfter = 0; | - | ||||||||||||||||||
| 618 | int idJustAfter = findWidgetJustBeforeOrJustAfter(index, +1, collapsibleSizeAfter); | - | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | int minBefore = 0; | - | ||||||||||||||||||
| 621 | int minAfter = 0; | - | ||||||||||||||||||
| 622 | int maxBefore = 0; | - | ||||||||||||||||||
| 623 | int maxAfter = 0; | - | ||||||||||||||||||
| 624 | int i; | - | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | for (i = 0; i < index; ++i)
| 0 | ||||||||||||||||||
| 627 | addContribution(i, &minBefore, &maxBefore, i == idJustBefore); never executed: addContribution(i, &minBefore, &maxBefore, i == idJustBefore); | 0 | ||||||||||||||||||
| 628 | for (i = index; i < n; ++i)
| 0 | ||||||||||||||||||
| 629 | addContribution(i, &minAfter, &maxAfter, i == idJustAfter); never executed: addContribution(i, &minAfter, &maxAfter, i == idJustAfter); | 0 | ||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | QRect r = q->contentsRect(); | - | ||||||||||||||||||
| 632 | int farMinVal; | - | ||||||||||||||||||
| 633 | int minVal; | - | ||||||||||||||||||
| 634 | int maxVal; | - | ||||||||||||||||||
| 635 | int farMaxVal; | - | ||||||||||||||||||
| 636 | - | |||||||||||||||||||
| 637 | int smartMinBefore = qMax(minBefore, pick(r.size()) - maxAfter); | - | ||||||||||||||||||
| 638 | int smartMaxBefore = qMin(maxBefore, pick(r.size()) - minAfter); | - | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | minVal = pick(r.topLeft()) + smartMinBefore; | - | ||||||||||||||||||
| 641 | maxVal = pick(r.topLeft()) + smartMaxBefore; | - | ||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | farMinVal = minVal; | - | ||||||||||||||||||
| 644 | if (minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter)
| 0 | ||||||||||||||||||
| 645 | farMinVal -= collapsibleSizeBefore; never executed: farMinVal -= collapsibleSizeBefore; | 0 | ||||||||||||||||||
| 646 | farMaxVal = maxVal; | - | ||||||||||||||||||
| 647 | if (pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore)
| 0 | ||||||||||||||||||
| 648 | farMaxVal += collapsibleSizeAfter; never executed: farMaxVal += collapsibleSizeAfter; | 0 | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | if (farMin)
| 0 | ||||||||||||||||||
| 651 | *farMin = farMinVal; never executed: *farMin = farMinVal; | 0 | ||||||||||||||||||
| 652 | if (min)
| 0 | ||||||||||||||||||
| 653 | *min = minVal; never executed: *min = minVal; | 0 | ||||||||||||||||||
| 654 | if (max)
| 0 | ||||||||||||||||||
| 655 | *max = maxVal; never executed: *max = maxVal; | 0 | ||||||||||||||||||
| 656 | if (farMax)
| 0 | ||||||||||||||||||
| 657 | *farMax = farMaxVal; never executed: *farMax = farMaxVal; | 0 | ||||||||||||||||||
| 658 | } never executed: end of block | 0 | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | int QSplitterPrivate::adjustPos(int pos, int index, int *farMin, int *min, int *max, int *farMax) const | - | ||||||||||||||||||
| 661 | { | - | ||||||||||||||||||
| 662 | const int Threshold = 40; | - | ||||||||||||||||||
| 663 | - | |||||||||||||||||||
| 664 | getRange(index, farMin, min, max, farMax); | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | if (pos >= *min) {
| 0 | ||||||||||||||||||
| 667 | if (pos <= *max) {
| 0 | ||||||||||||||||||
| 668 | return pos; never executed: return pos; | 0 | ||||||||||||||||||
| 669 | } else { | - | ||||||||||||||||||
| 670 | int delta = pos - *max; | - | ||||||||||||||||||
| 671 | int width = *farMax - *max; | - | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | if (delta > width / 2 && delta >= qMin(Threshold, width)) {
| 0 | ||||||||||||||||||
| 674 | return *farMax; never executed: return *farMax; | 0 | ||||||||||||||||||
| 675 | } else { | - | ||||||||||||||||||
| 676 | return *max; never executed: return *max; | 0 | ||||||||||||||||||
| 677 | } | - | ||||||||||||||||||
| 678 | } | - | ||||||||||||||||||
| 679 | } else { | - | ||||||||||||||||||
| 680 | int delta = *min - pos; | - | ||||||||||||||||||
| 681 | int width = *min - *farMin; | - | ||||||||||||||||||
| 682 | - | |||||||||||||||||||
| 683 | if (delta > width / 2 && delta >= qMin(Threshold, width)) {
| 0 | ||||||||||||||||||
| 684 | return *farMin; never executed: return *farMin; | 0 | ||||||||||||||||||
| 685 | } else { | - | ||||||||||||||||||
| 686 | return *min; never executed: return *min; | 0 | ||||||||||||||||||
| 687 | } | - | ||||||||||||||||||
| 688 | } | - | ||||||||||||||||||
| 689 | } | - | ||||||||||||||||||
| 690 | - | |||||||||||||||||||
| 691 | bool QSplitterPrivate::collapsible(QSplitterLayoutStruct *s) const | - | ||||||||||||||||||
| 692 | { | - | ||||||||||||||||||
| 693 | if (s->collapsible != Default) {
| 0 | ||||||||||||||||||
| 694 | return (bool)s->collapsible; never executed: return (bool)s->collapsible; | 0 | ||||||||||||||||||
| 695 | } else { | - | ||||||||||||||||||
| 696 | return childrenCollapsible; never executed: return childrenCollapsible; | 0 | ||||||||||||||||||
| 697 | } | - | ||||||||||||||||||
| 698 | } | - | ||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | void QSplitterPrivate::updateHandles() | - | ||||||||||||||||||
| 701 | { | - | ||||||||||||||||||
| 702 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 703 | recalc(q->isVisible()); | - | ||||||||||||||||||
| 704 | } never executed: end of block | 0 | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | void QSplitterPrivate::setSizes_helper(const QList<int> &sizes, bool clampNegativeSize) | - | ||||||||||||||||||
| 707 | { | - | ||||||||||||||||||
| 708 | int j = 0; | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | for (int i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 711 | QSplitterLayoutStruct *s = list.at(i); | - | ||||||||||||||||||
| 712 | - | |||||||||||||||||||
| 713 | s->collapsed = false; | - | ||||||||||||||||||
| 714 | s->sizer = sizes.value(j++); | - | ||||||||||||||||||
| 715 | if (clampNegativeSize && s->sizer < 0)
| 0 | ||||||||||||||||||
| 716 | s->sizer = 0; never executed: s->sizer = 0; | 0 | ||||||||||||||||||
| 717 | int smartMinSize = pick(qSmartMinSize(s->widget)); | - | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | // Make sure that we reset the collapsed state. | - | ||||||||||||||||||
| 720 | if (s->sizer == 0) {
| 0 | ||||||||||||||||||
| 721 | if (collapsible(s) && smartMinSize > 0) {
| 0 | ||||||||||||||||||
| 722 | s->collapsed = true; | - | ||||||||||||||||||
| 723 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 724 | s->sizer = smartMinSize; | - | ||||||||||||||||||
| 725 | } never executed: end of block | 0 | ||||||||||||||||||
| 726 | } else { | - | ||||||||||||||||||
| 727 | if (s->sizer < smartMinSize)
| 0 | ||||||||||||||||||
| 728 | s->sizer = smartMinSize; never executed: s->sizer = smartMinSize; | 0 | ||||||||||||||||||
| 729 | } never executed: end of block | 0 | ||||||||||||||||||
| 730 | } | - | ||||||||||||||||||
| 731 | doResize(); | - | ||||||||||||||||||
| 732 | } never executed: end of block | 0 | ||||||||||||||||||
| 733 | - | |||||||||||||||||||
| 734 | void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool allowCollapse) | - | ||||||||||||||||||
| 735 | { | - | ||||||||||||||||||
| 736 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 737 | QWidget *w = sls->widget; | - | ||||||||||||||||||
| 738 | QRect r; | - | ||||||||||||||||||
| 739 | QRect contents = q->contentsRect(); | - | ||||||||||||||||||
| 740 | if (orient == Qt::Horizontal) {
| 0 | ||||||||||||||||||
| 741 | r.setRect(p, contents.y(), s, contents.height()); | - | ||||||||||||||||||
| 742 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 743 | r.setRect(contents.x(), p, contents.width(), s); | - | ||||||||||||||||||
| 744 | } never executed: end of block | 0 | ||||||||||||||||||
| 745 | sls->rect = r; | - | ||||||||||||||||||
| 746 | - | |||||||||||||||||||
| 747 | int minSize = pick(qSmartMinSize(w)); | - | ||||||||||||||||||
| 748 | - | |||||||||||||||||||
| 749 | if (orient == Qt::Horizontal && q->isRightToLeft())
| 0 | ||||||||||||||||||
| 750 | r.moveRight(contents.width() - r.left()); never executed: r.moveRight(contents.width() - r.left()); | 0 | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | if (allowCollapse)
| 0 | ||||||||||||||||||
| 753 | sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden(); never executed: sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden();
| 0 | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | // Hide the child widget, but without calling hide() so that | - | ||||||||||||||||||
| 756 | // the splitter handle is still shown. | - | ||||||||||||||||||
| 757 | if (sls->collapsed)
| 0 | ||||||||||||||||||
| 758 | r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1)); never executed: r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1)); | 0 | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | w->setGeometry(r); | - | ||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | if (!sls->handle->isHidden()) {
| 0 | ||||||||||||||||||
| 763 | QSplitterHandle *h = sls->handle; | - | ||||||||||||||||||
| 764 | QSize hs = h->sizeHint(); | - | ||||||||||||||||||
| 765 | int left, top, right, bottom; | - | ||||||||||||||||||
| 766 | h->getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||
| 767 | if (orient==Qt::Horizontal) {
| 0 | ||||||||||||||||||
| 768 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||
| 769 | p = contents.width() - p + hs.width(); never executed: p = contents.width() - p + hs.width(); | 0 | ||||||||||||||||||
| 770 | h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height()); | - | ||||||||||||||||||
| 771 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 772 | h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom); | - | ||||||||||||||||||
| 773 | } never executed: end of block | 0 | ||||||||||||||||||
| 774 | } | - | ||||||||||||||||||
| 775 | } never executed: end of block | 0 | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | void QSplitterPrivate::doMove(bool backwards, int hPos, int index, int delta, bool mayCollapse, | - | ||||||||||||||||||
| 778 | int *positions, int *widths) | - | ||||||||||||||||||
| 779 | { | - | ||||||||||||||||||
| 780 | if (index < 0 || index >= list.count())
| 0 | ||||||||||||||||||
| 781 | return; never executed: return; | 0 | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | #ifdef QSPLITTER_DEBUG | - | ||||||||||||||||||
| 784 | qDebug() << "QSplitterPrivate::doMove" << backwards << hPos << index << delta << mayCollapse; | - | ||||||||||||||||||
| 785 | #endif | - | ||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | QSplitterLayoutStruct *s = list.at(index); | - | ||||||||||||||||||
| 788 | QWidget *w = s->widget; | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | int nextId = backwards ? index - delta : index + delta;
| 0 | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | if (w->isHidden()) {
| 0 | ||||||||||||||||||
| 793 | doMove(backwards, hPos, nextId, delta, collapsible(nextId), positions, widths); | - | ||||||||||||||||||
| 794 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 795 | int hs =s->handle->isHidden() ? 0 : s->getHandleSize(orient);
| 0 | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | int ws = backwards ? hPos - pick(s->rect.topLeft())
| 0 | ||||||||||||||||||
| 798 | : pick(s->rect.bottomRight()) - hPos -hs + 1; | - | ||||||||||||||||||
| 799 | if (ws > 0 || (!s->collapsed && !mayCollapse)) {
| 0 | ||||||||||||||||||
| 800 | ws = qMin(ws, pick(w->maximumSize())); | - | ||||||||||||||||||
| 801 | ws = qMax(ws, pick(qSmartMinSize(w))); | - | ||||||||||||||||||
| 802 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 803 | ws = 0; | - | ||||||||||||||||||
| 804 | } never executed: end of block | 0 | ||||||||||||||||||
| 805 | positions[index] = backwards ? hPos - ws : hPos + hs;
| 0 | ||||||||||||||||||
| 806 | widths[index] = ws; | - | ||||||||||||||||||
| 807 | doMove(backwards, backwards ? hPos - ws - hs : hPos + hs + ws, nextId, delta, | - | ||||||||||||||||||
| 808 | collapsible(nextId), positions, widths); | - | ||||||||||||||||||
| 809 | } never executed: end of block | 0 | ||||||||||||||||||
| 810 | - | |||||||||||||||||||
| 811 | } | - | ||||||||||||||||||
| 812 | - | |||||||||||||||||||
| 813 | QSplitterLayoutStruct *QSplitterPrivate::findWidget(QWidget *w) const | - | ||||||||||||||||||
| 814 | { | - | ||||||||||||||||||
| 815 | for (int i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 816 | if (list.at(i)->widget == w)
| 0 | ||||||||||||||||||
| 817 | return list.at(i); never executed: return list.at(i); | 0 | ||||||||||||||||||
| 818 | } never executed: end of block | 0 | ||||||||||||||||||
| 819 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 820 | } | - | ||||||||||||||||||
| 821 | - | |||||||||||||||||||
| 822 | - | |||||||||||||||||||
| 823 | /*! | - | ||||||||||||||||||
| 824 | \internal | - | ||||||||||||||||||
| 825 | */ | - | ||||||||||||||||||
| 826 | void QSplitterPrivate::insertWidget_helper(int index, QWidget *widget, bool show) | - | ||||||||||||||||||
| 827 | { | - | ||||||||||||||||||
| 828 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 829 | QBoolBlocker b(blockChildAdd); | - | ||||||||||||||||||
| 830 | bool needShow = show && q->isVisible() &&
| 0 | ||||||||||||||||||
| 831 | !(widget->isHidden() && widget->testAttribute(Qt::WA_WState_ExplicitShowHide));
| 0 | ||||||||||||||||||
| 832 | if (widget->parentWidget() != q)
| 0 | ||||||||||||||||||
| 833 | widget->setParent(q); never executed: widget->setParent(q); | 0 | ||||||||||||||||||
| 834 | if (needShow)
| 0 | ||||||||||||||||||
| 835 | widget->show(); never executed: widget->show(); | 0 | ||||||||||||||||||
| 836 | insertWidget(index, widget); | - | ||||||||||||||||||
| 837 | recalc(q->isVisible()); | - | ||||||||||||||||||
| 838 | } never executed: end of block | 0 | ||||||||||||||||||
| 839 | - | |||||||||||||||||||
| 840 | /* | - | ||||||||||||||||||
| 841 | Inserts the widget \a w at position \a index in the splitter's list of widgets. | - | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | If \a w is already in the splitter, it will be moved to the new position. | - | ||||||||||||||||||
| 844 | */ | - | ||||||||||||||||||
| 845 | - | |||||||||||||||||||
| 846 | QSplitterLayoutStruct *QSplitterPrivate::insertWidget(int index, QWidget *w) | - | ||||||||||||||||||
| 847 | { | - | ||||||||||||||||||
| 848 | Q_Q(QSplitter); | - | ||||||||||||||||||
| 849 | QSplitterLayoutStruct *sls = 0; | - | ||||||||||||||||||
| 850 | int i; | - | ||||||||||||||||||
| 851 | int last = list.count(); | - | ||||||||||||||||||
| 852 | for (i = 0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||
| 853 | QSplitterLayoutStruct *s = list.at(i); | - | ||||||||||||||||||
| 854 | if (s->widget == w) {
| 0 | ||||||||||||||||||
| 855 | sls = s; | - | ||||||||||||||||||
| 856 | --last; | - | ||||||||||||||||||
| 857 | break; never executed: break; | 0 | ||||||||||||||||||
| 858 | } | - | ||||||||||||||||||
| 859 | } never executed: end of block | 0 | ||||||||||||||||||
| 860 | if (index < 0 || index > last)
| 0 | ||||||||||||||||||
| 861 | index = last; never executed: index = last; | 0 | ||||||||||||||||||
| 862 | - | |||||||||||||||||||
| 863 | if (sls) {
| 0 | ||||||||||||||||||
| 864 | list.move(i,index); | - | ||||||||||||||||||
| 865 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 866 | QSplitterHandle *newHandle = 0; | - | ||||||||||||||||||
| 867 | sls = new QSplitterLayoutStruct; | - | ||||||||||||||||||
| 868 | QString tmp = QLatin1String("qt_splithandle_"); | - | ||||||||||||||||||
| 869 | tmp += w->objectName(); | - | ||||||||||||||||||
| 870 | newHandle = q->createHandle(); | - | ||||||||||||||||||
| 871 | newHandle->setObjectName(tmp); | - | ||||||||||||||||||
| 872 | sls->handle = newHandle; | - | ||||||||||||||||||
| 873 | sls->widget = w; | - | ||||||||||||||||||
| 874 | w->lower(); | - | ||||||||||||||||||
| 875 | list.insert(index,sls); | - | ||||||||||||||||||
| 876 | - | |||||||||||||||||||
| 877 | if (newHandle && q->isVisible())
| 0 | ||||||||||||||||||
| 878 | newHandle->show(); // will trigger sending of post events never executed: newHandle->show(); | 0 | ||||||||||||||||||
| 879 | - | |||||||||||||||||||
| 880 | } never executed: end of block | 0 | ||||||||||||||||||
| 881 | return sls; never executed: return sls; | 0 | ||||||||||||||||||
| 882 | } | - | ||||||||||||||||||
| 883 | - | |||||||||||||||||||
| 884 | /*! | - | ||||||||||||||||||
| 885 | \class QSplitter | - | ||||||||||||||||||
| 886 | \brief The QSplitter class implements a splitter widget. | - | ||||||||||||||||||
| 887 | - | |||||||||||||||||||
| 888 | \ingroup organizers | - | ||||||||||||||||||
| 889 | \inmodule QtWidgets | - | ||||||||||||||||||
| 890 | - | |||||||||||||||||||
| 891 | - | |||||||||||||||||||
| 892 | A splitter lets the user control the size of child widgets by dragging the | - | ||||||||||||||||||
| 893 | boundary between them. Any number of widgets may be controlled by a | - | ||||||||||||||||||
| 894 | single splitter. The typical use of a QSplitter is to create several | - | ||||||||||||||||||
| 895 | widgets and add them using insertWidget() or addWidget(). | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | The following example will show a QListView, QTreeView, and | - | ||||||||||||||||||
| 898 | QTextEdit side by side, with two splitter handles: | - | ||||||||||||||||||
| 899 | - | |||||||||||||||||||
| 900 | \snippet splitter/splitter.cpp 0 | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | If a widget is already inside a QSplitter when insertWidget() or | - | ||||||||||||||||||
| 903 | addWidget() is called, it will move to the new position. This can be used | - | ||||||||||||||||||
| 904 | to reorder widgets in the splitter later. You can use indexOf(), | - | ||||||||||||||||||
| 905 | widget(), and count() to get access to the widgets inside the splitter. | - | ||||||||||||||||||
| 906 | - | |||||||||||||||||||
| 907 | A default QSplitter lays out its children horizontally (side by side); you | - | ||||||||||||||||||
| 908 | can use setOrientation(Qt::Vertical) to lay its | - | ||||||||||||||||||
| 909 | children out vertically. | - | ||||||||||||||||||
| 910 | - | |||||||||||||||||||
| 911 | By default, all widgets can be as large or as small as the user | - | ||||||||||||||||||
| 912 | wishes, between the \l minimumSizeHint() (or \l minimumSize()) | - | ||||||||||||||||||
| 913 | and \l maximumSize() of the widgets. | - | ||||||||||||||||||
| 914 | - | |||||||||||||||||||
| 915 | QSplitter resizes its children dynamically by default. If you | - | ||||||||||||||||||
| 916 | would rather have QSplitter resize the children only at the end of | - | ||||||||||||||||||
| 917 | a resize operation, call setOpaqueResize(false). | - | ||||||||||||||||||
| 918 | - | |||||||||||||||||||
| 919 | The initial distribution of size between the widgets is determined by | - | ||||||||||||||||||
| 920 | multiplying the initial size with the stretch factor. | - | ||||||||||||||||||
| 921 | You can also use setSizes() to set the sizes | - | ||||||||||||||||||
| 922 | of all the widgets. The function sizes() returns the sizes set by the user. | - | ||||||||||||||||||
| 923 | Alternatively, you can save and restore the sizes of the widgets from a | - | ||||||||||||||||||
| 924 | QByteArray using saveState() and restoreState() respectively. | - | ||||||||||||||||||
| 925 | - | |||||||||||||||||||
| 926 | When you hide() a child, its space will be distributed among the | - | ||||||||||||||||||
| 927 | other children. It will be reinstated when you show() it again. | - | ||||||||||||||||||
| 928 | - | |||||||||||||||||||
| 929 | \note Adding a QLayout to a QSplitter is not supported (either through | - | ||||||||||||||||||
| 930 | setLayout() or making the QSplitter a parent of the QLayout); use addWidget() | - | ||||||||||||||||||
| 931 | instead (see example above). | - | ||||||||||||||||||
| 932 | - | |||||||||||||||||||
| 933 | \sa QSplitterHandle, QHBoxLayout, QVBoxLayout, QTabWidget | - | ||||||||||||||||||
| 934 | */ | - | ||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | - | |||||||||||||||||||
| 937 | /*! | - | ||||||||||||||||||
| 938 | Constructs a horizontal splitter with the \a parent | - | ||||||||||||||||||
| 939 | argument passed on to the QFrame constructor. | - | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | \sa setOrientation() | - | ||||||||||||||||||
| 942 | */ | - | ||||||||||||||||||
| 943 | QSplitter::QSplitter(QWidget *parent) | - | ||||||||||||||||||
| 944 | : QFrame(*new QSplitterPrivate, parent) | - | ||||||||||||||||||
| 945 | { | - | ||||||||||||||||||
| 946 | Q_D(QSplitter); | - | ||||||||||||||||||
| 947 | d->orient = Qt::Horizontal; | - | ||||||||||||||||||
| 948 | d->init(); | - | ||||||||||||||||||
| 949 | } never executed: end of block | 0 | ||||||||||||||||||
| 950 | - | |||||||||||||||||||
| 951 | - | |||||||||||||||||||
| 952 | /*! | - | ||||||||||||||||||
| 953 | Constructs a splitter with the given \a orientation and \a parent. | - | ||||||||||||||||||
| 954 | - | |||||||||||||||||||
| 955 | \sa setOrientation() | - | ||||||||||||||||||
| 956 | */ | - | ||||||||||||||||||
| 957 | QSplitter::QSplitter(Qt::Orientation orientation, QWidget *parent) | - | ||||||||||||||||||
| 958 | : QFrame(*new QSplitterPrivate, parent) | - | ||||||||||||||||||
| 959 | { | - | ||||||||||||||||||
| 960 | Q_D(QSplitter); | - | ||||||||||||||||||
| 961 | d->orient = orientation; | - | ||||||||||||||||||
| 962 | d->init(); | - | ||||||||||||||||||
| 963 | } never executed: end of block | 0 | ||||||||||||||||||
| 964 | - | |||||||||||||||||||
| 965 | - | |||||||||||||||||||
| 966 | /*! | - | ||||||||||||||||||
| 967 | Destroys the splitter. All children are deleted. | - | ||||||||||||||||||
| 968 | */ | - | ||||||||||||||||||
| 969 | - | |||||||||||||||||||
| 970 | QSplitter::~QSplitter() | - | ||||||||||||||||||
| 971 | { | - | ||||||||||||||||||
| 972 | Q_D(QSplitter); | - | ||||||||||||||||||
| 973 | delete d->rubberBand; | - | ||||||||||||||||||
| 974 | while (!d->list.isEmpty())
| 0 | ||||||||||||||||||
| 975 | delete d->list.takeFirst(); never executed: delete d->list.takeFirst(); | 0 | ||||||||||||||||||
| 976 | } never executed: end of block | 0 | ||||||||||||||||||
| 977 | - | |||||||||||||||||||
| 978 | /*! | - | ||||||||||||||||||
| 979 | Updates the splitter's state. You should not need to call this | - | ||||||||||||||||||
| 980 | function. | - | ||||||||||||||||||
| 981 | */ | - | ||||||||||||||||||
| 982 | void QSplitter::refresh() | - | ||||||||||||||||||
| 983 | { | - | ||||||||||||||||||
| 984 | Q_D(QSplitter); | - | ||||||||||||||||||
| 985 | d->recalc(true); | - | ||||||||||||||||||
| 986 | } never executed: end of block | 0 | ||||||||||||||||||
| 987 | - | |||||||||||||||||||
| 988 | /*! | - | ||||||||||||||||||
| 989 | \property QSplitter::orientation | - | ||||||||||||||||||
| 990 | \brief the orientation of the splitter | - | ||||||||||||||||||
| 991 | - | |||||||||||||||||||
| 992 | By default, the orientation is horizontal (i.e., the widgets are | - | ||||||||||||||||||
| 993 | laid out side by side). The possible orientations are | - | ||||||||||||||||||
| 994 | Qt::Horizontal and Qt::Vertical. | - | ||||||||||||||||||
| 995 | - | |||||||||||||||||||
| 996 | \sa QSplitterHandle::orientation() | - | ||||||||||||||||||
| 997 | */ | - | ||||||||||||||||||
| 998 | - | |||||||||||||||||||
| 999 | void QSplitter::setOrientation(Qt::Orientation orientation) | - | ||||||||||||||||||
| 1000 | { | - | ||||||||||||||||||
| 1001 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1002 | if (d->orient == orientation)
| 0 | ||||||||||||||||||
| 1003 | return; never executed: return; | 0 | ||||||||||||||||||
| 1004 | - | |||||||||||||||||||
| 1005 | if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) {
| 0 | ||||||||||||||||||
| 1006 | QSizePolicy sp = sizePolicy(); | - | ||||||||||||||||||
| 1007 | sp.transpose(); | - | ||||||||||||||||||
| 1008 | setSizePolicy(sp); | - | ||||||||||||||||||
| 1009 | setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||||||||
| 1010 | } never executed: end of block | 0 | ||||||||||||||||||
| 1011 | - | |||||||||||||||||||
| 1012 | d->orient = orientation; | - | ||||||||||||||||||
| 1013 | - | |||||||||||||||||||
| 1014 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||||||||
| 1015 | QSplitterLayoutStruct *s = d->list.at(i); | - | ||||||||||||||||||
| 1016 | s->handle->setOrientation(orientation); | - | ||||||||||||||||||
| 1017 | } never executed: end of block | 0 | ||||||||||||||||||
| 1018 | d->recalc(isVisible()); | - | ||||||||||||||||||
| 1019 | } never executed: end of block | 0 | ||||||||||||||||||
| 1020 | - | |||||||||||||||||||
| 1021 | Qt::Orientation QSplitter::orientation() const | - | ||||||||||||||||||
| 1022 | { | - | ||||||||||||||||||
| 1023 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1024 | return d->orient; never executed: return d->orient; | 0 | ||||||||||||||||||
| 1025 | } | - | ||||||||||||||||||
| 1026 | - | |||||||||||||||||||
| 1027 | /*! | - | ||||||||||||||||||
| 1028 | \property QSplitter::childrenCollapsible | - | ||||||||||||||||||
| 1029 | \brief whether child widgets can be resized down to size 0 by the user | - | ||||||||||||||||||
| 1030 | - | |||||||||||||||||||
| 1031 | By default, children are collapsible. It is possible to enable | - | ||||||||||||||||||
| 1032 | and disable the collapsing of individual children using | - | ||||||||||||||||||
| 1033 | setCollapsible(). | - | ||||||||||||||||||
| 1034 | - | |||||||||||||||||||
| 1035 | \sa setCollapsible() | - | ||||||||||||||||||
| 1036 | */ | - | ||||||||||||||||||
| 1037 | - | |||||||||||||||||||
| 1038 | void QSplitter::setChildrenCollapsible(bool collapse) | - | ||||||||||||||||||
| 1039 | { | - | ||||||||||||||||||
| 1040 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1041 | d->childrenCollapsible = collapse; | - | ||||||||||||||||||
| 1042 | } never executed: end of block | 0 | ||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | bool QSplitter::childrenCollapsible() const | - | ||||||||||||||||||
| 1045 | { | - | ||||||||||||||||||
| 1046 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1047 | return d->childrenCollapsible; never executed: return d->childrenCollapsible; | 0 | ||||||||||||||||||
| 1048 | } | - | ||||||||||||||||||
| 1049 | - | |||||||||||||||||||
| 1050 | /*! | - | ||||||||||||||||||
| 1051 | Sets whether the child widget at \a index is collapsible to \a collapse. | - | ||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | By default, children are collapsible, meaning that the user can | - | ||||||||||||||||||
| 1054 | resize them down to size 0, even if they have a non-zero | - | ||||||||||||||||||
| 1055 | minimumSize() or minimumSizeHint(). This behavior can be changed | - | ||||||||||||||||||
| 1056 | on a per-widget basis by calling this function, or globally for | - | ||||||||||||||||||
| 1057 | all the widgets in the splitter by setting the \l | - | ||||||||||||||||||
| 1058 | childrenCollapsible property. | - | ||||||||||||||||||
| 1059 | - | |||||||||||||||||||
| 1060 | \sa childrenCollapsible | - | ||||||||||||||||||
| 1061 | */ | - | ||||||||||||||||||
| 1062 | - | |||||||||||||||||||
| 1063 | void QSplitter::setCollapsible(int index, bool collapse) | - | ||||||||||||||||||
| 1064 | { | - | ||||||||||||||||||
| 1065 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1066 | - | |||||||||||||||||||
| 1067 | if (Q_UNLIKELY(index < 0 || index >= d->list.size())) {
| 0 | ||||||||||||||||||
| 1068 | qWarning("QSplitter::setCollapsible: Index %d out of range", index); | - | ||||||||||||||||||
| 1069 | return; never executed: return; | 0 | ||||||||||||||||||
| 1070 | } | - | ||||||||||||||||||
| 1071 | d->list.at(index)->collapsible = collapse ? 1 : 0;
| 0 | ||||||||||||||||||
| 1072 | } never executed: end of block | 0 | ||||||||||||||||||
| 1073 | - | |||||||||||||||||||
| 1074 | /*! | - | ||||||||||||||||||
| 1075 | Returns \c true if the widget at \a index is collapsible, otherwise returns \c false. | - | ||||||||||||||||||
| 1076 | */ | - | ||||||||||||||||||
| 1077 | bool QSplitter::isCollapsible(int index) const | - | ||||||||||||||||||
| 1078 | { | - | ||||||||||||||||||
| 1079 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1080 | if (Q_UNLIKELY(index < 0 || index >= d->list.size())) {
| 0 | ||||||||||||||||||
| 1081 | qWarning("QSplitter::isCollapsible: Index %d out of range", index); | - | ||||||||||||||||||
| 1082 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1083 | } | - | ||||||||||||||||||
| 1084 | return d->list.at(index)->collapsible; never executed: return d->list.at(index)->collapsible; | 0 | ||||||||||||||||||
| 1085 | } | - | ||||||||||||||||||
| 1086 | - | |||||||||||||||||||
| 1087 | /*! | - | ||||||||||||||||||
| 1088 | \reimp | - | ||||||||||||||||||
| 1089 | */ | - | ||||||||||||||||||
| 1090 | void QSplitter::resizeEvent(QResizeEvent *) | - | ||||||||||||||||||
| 1091 | { | - | ||||||||||||||||||
| 1092 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1093 | d->doResize(); | - | ||||||||||||||||||
| 1094 | } never executed: end of block | 0 | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | /*! | - | ||||||||||||||||||
| 1097 | Adds the given \a widget to the splitter's layout after all the other | - | ||||||||||||||||||
| 1098 | items. | - | ||||||||||||||||||
| 1099 | - | |||||||||||||||||||
| 1100 | If \a widget is already in the splitter, it will be moved to the new position. | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | \note The splitter takes ownership of the widget. | - | ||||||||||||||||||
| 1103 | - | |||||||||||||||||||
| 1104 | \sa insertWidget(), widget(), indexOf() | - | ||||||||||||||||||
| 1105 | */ | - | ||||||||||||||||||
| 1106 | void QSplitter::addWidget(QWidget *widget) | - | ||||||||||||||||||
| 1107 | { | - | ||||||||||||||||||
| 1108 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1109 | insertWidget(d->list.count(), widget); | - | ||||||||||||||||||
| 1110 | } never executed: end of block | 0 | ||||||||||||||||||
| 1111 | - | |||||||||||||||||||
| 1112 | /*! | - | ||||||||||||||||||
| 1113 | Inserts the \a widget specified into the splitter's layout at the | - | ||||||||||||||||||
| 1114 | given \a index. | - | ||||||||||||||||||
| 1115 | - | |||||||||||||||||||
| 1116 | If \a widget is already in the splitter, it will be moved to the new position. | - | ||||||||||||||||||
| 1117 | - | |||||||||||||||||||
| 1118 | If \a index is an invalid index, then the widget will be inserted at the end. | - | ||||||||||||||||||
| 1119 | - | |||||||||||||||||||
| 1120 | \note The splitter takes ownership of the widget. | - | ||||||||||||||||||
| 1121 | - | |||||||||||||||||||
| 1122 | \sa addWidget(), indexOf(), widget() | - | ||||||||||||||||||
| 1123 | */ | - | ||||||||||||||||||
| 1124 | void QSplitter::insertWidget(int index, QWidget *widget) | - | ||||||||||||||||||
| 1125 | { | - | ||||||||||||||||||
| 1126 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1127 | d->insertWidget_helper(index, widget, true); | - | ||||||||||||||||||
| 1128 | } never executed: end of block | 0 | ||||||||||||||||||
| 1129 | - | |||||||||||||||||||
| 1130 | /*! | - | ||||||||||||||||||
| 1131 | \fn int QSplitter::indexOf(QWidget *widget) const | - | ||||||||||||||||||
| 1132 | - | |||||||||||||||||||
| 1133 | Returns the index in the splitter's layout of the specified \a widget. This | - | ||||||||||||||||||
| 1134 | also works for handles. | - | ||||||||||||||||||
| 1135 | - | |||||||||||||||||||
| 1136 | Handles are numbered from 0. There are as many handles as there | - | ||||||||||||||||||
| 1137 | are child widgets, but the handle at position 0 is always hidden. | - | ||||||||||||||||||
| 1138 | - | |||||||||||||||||||
| 1139 | - | |||||||||||||||||||
| 1140 | \sa count(), widget() | - | ||||||||||||||||||
| 1141 | */ | - | ||||||||||||||||||
| 1142 | int QSplitter::indexOf(QWidget *w) const | - | ||||||||||||||||||
| 1143 | { | - | ||||||||||||||||||
| 1144 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1145 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||||||||
| 1146 | QSplitterLayoutStruct *s = d->list.at(i); | - | ||||||||||||||||||
| 1147 | if (s->widget == w || s->handle == w)
| 0 | ||||||||||||||||||
| 1148 | return i; never executed: return i; | 0 | ||||||||||||||||||
| 1149 | } never executed: end of block | 0 | ||||||||||||||||||
| 1150 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 1151 | } | - | ||||||||||||||||||
| 1152 | - | |||||||||||||||||||
| 1153 | /*! | - | ||||||||||||||||||
| 1154 | Returns a new splitter handle as a child widget of this splitter. | - | ||||||||||||||||||
| 1155 | This function can be reimplemented in subclasses to provide support | - | ||||||||||||||||||
| 1156 | for custom handles. | - | ||||||||||||||||||
| 1157 | - | |||||||||||||||||||
| 1158 | \sa handle(), indexOf() | - | ||||||||||||||||||
| 1159 | */ | - | ||||||||||||||||||
| 1160 | QSplitterHandle *QSplitter::createHandle() | - | ||||||||||||||||||
| 1161 | { | - | ||||||||||||||||||
| 1162 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1163 | return new QSplitterHandle(d->orient, this); never executed: return new QSplitterHandle(d->orient, this); | 0 | ||||||||||||||||||
| 1164 | } | - | ||||||||||||||||||
| 1165 | - | |||||||||||||||||||
| 1166 | /*! | - | ||||||||||||||||||
| 1167 | Returns the handle to the left (or above) for the item in the | - | ||||||||||||||||||
| 1168 | splitter's layout at the given \a index. The handle at index 0 is | - | ||||||||||||||||||
| 1169 | always hidden. | - | ||||||||||||||||||
| 1170 | - | |||||||||||||||||||
| 1171 | For right-to-left languages such as Arabic and Hebrew, the layout | - | ||||||||||||||||||
| 1172 | of horizontal splitters is reversed. The handle will be to the | - | ||||||||||||||||||
| 1173 | right of the widget at \a index. | - | ||||||||||||||||||
| 1174 | - | |||||||||||||||||||
| 1175 | \sa count(), widget(), indexOf(), createHandle(), setHandleWidth() | - | ||||||||||||||||||
| 1176 | */ | - | ||||||||||||||||||
| 1177 | QSplitterHandle *QSplitter::handle(int index) const | - | ||||||||||||||||||
| 1178 | { | - | ||||||||||||||||||
| 1179 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1180 | if (index < 0 || index >= d->list.size())
| 0 | ||||||||||||||||||
| 1181 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1182 | return d->list.at(index)->handle; never executed: return d->list.at(index)->handle; | 0 | ||||||||||||||||||
| 1183 | } | - | ||||||||||||||||||
| 1184 | - | |||||||||||||||||||
| 1185 | /*! | - | ||||||||||||||||||
| 1186 | Returns the widget at the given \a index in the splitter's layout. | - | ||||||||||||||||||
| 1187 | - | |||||||||||||||||||
| 1188 | \sa count(), handle(), indexOf(), insertWidget() | - | ||||||||||||||||||
| 1189 | */ | - | ||||||||||||||||||
| 1190 | QWidget *QSplitter::widget(int index) const | - | ||||||||||||||||||
| 1191 | { | - | ||||||||||||||||||
| 1192 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1193 | if (index < 0 || index >= d->list.size())
| 0 | ||||||||||||||||||
| 1194 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 1195 | return d->list.at(index)->widget; never executed: return d->list.at(index)->widget; | 0 | ||||||||||||||||||
| 1196 | } | - | ||||||||||||||||||
| 1197 | - | |||||||||||||||||||
| 1198 | /*! | - | ||||||||||||||||||
| 1199 | Returns the number of widgets contained in the splitter's layout. | - | ||||||||||||||||||
| 1200 | - | |||||||||||||||||||
| 1201 | \sa widget(), handle() | - | ||||||||||||||||||
| 1202 | */ | - | ||||||||||||||||||
| 1203 | int QSplitter::count() const | - | ||||||||||||||||||
| 1204 | { | - | ||||||||||||||||||
| 1205 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1206 | return d->list.count(); never executed: return d->list.count(); | 0 | ||||||||||||||||||
| 1207 | } | - | ||||||||||||||||||
| 1208 | - | |||||||||||||||||||
| 1209 | /*! | - | ||||||||||||||||||
| 1210 | \reimp | - | ||||||||||||||||||
| 1211 | - | |||||||||||||||||||
| 1212 | Tells the splitter that the child widget described by \a c has been | - | ||||||||||||||||||
| 1213 | inserted or removed. | - | ||||||||||||||||||
| 1214 | - | |||||||||||||||||||
| 1215 | This method is also used to handle the situation where a widget is created | - | ||||||||||||||||||
| 1216 | with the splitter as a parent but not explicitly added with insertWidget() | - | ||||||||||||||||||
| 1217 | or addWidget(). This is for compatibility and not the recommended way of | - | ||||||||||||||||||
| 1218 | putting widgets into a splitter in new code. Please use insertWidget() or | - | ||||||||||||||||||
| 1219 | addWidget() in new code. | - | ||||||||||||||||||
| 1220 | - | |||||||||||||||||||
| 1221 | \sa addWidget(), insertWidget() | - | ||||||||||||||||||
| 1222 | */ | - | ||||||||||||||||||
| 1223 | - | |||||||||||||||||||
| 1224 | void QSplitter::childEvent(QChildEvent *c) | - | ||||||||||||||||||
| 1225 | { | - | ||||||||||||||||||
| 1226 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1227 | if (!c->child()->isWidgetType()) {
| 0 | ||||||||||||||||||
| 1228 | if (Q_UNLIKELY(c->type() == QEvent::ChildAdded && qobject_cast<QLayout *>(c->child())))
| 0 | ||||||||||||||||||
| 1229 | qWarning("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 | ||||||||||||||||||
| 1230 | return; never executed: return; | 0 | ||||||||||||||||||
| 1231 | } | - | ||||||||||||||||||
| 1232 | QWidget *w = static_cast<QWidget*>(c->child()); | - | ||||||||||||||||||
| 1233 | if (w->isWindow())
| 0 | ||||||||||||||||||
| 1234 | return; never executed: return; | 0 | ||||||||||||||||||
| 1235 | if (c->added() && !d->blockChildAdd && !d->findWidget(w)) {
| 0 | ||||||||||||||||||
| 1236 | d->insertWidget_helper(d->list.count(), w, false); | - | ||||||||||||||||||
| 1237 | } else if (c->polished() && !d->blockChildAdd) { never executed: end of block
| 0 | ||||||||||||||||||
| 1238 | if (isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide)))
| 0 | ||||||||||||||||||
| 1239 | w->show(); never executed: w->show(); | 0 | ||||||||||||||||||
| 1240 | } else if (c->type() == QEvent::ChildRemoved) { never executed: end of block
| 0 | ||||||||||||||||||
| 1241 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||||||||
| 1242 | QSplitterLayoutStruct *s = d->list.at(i); | - | ||||||||||||||||||
| 1243 | if (s->widget == w) {
| 0 | ||||||||||||||||||
| 1244 | d->list.removeAt(i); | - | ||||||||||||||||||
| 1245 | delete s; | - | ||||||||||||||||||
| 1246 | d->recalc(isVisible()); | - | ||||||||||||||||||
| 1247 | return; never executed: return; | 0 | ||||||||||||||||||
| 1248 | } | - | ||||||||||||||||||
| 1249 | } never executed: end of block | 0 | ||||||||||||||||||
| 1250 | } never executed: end of block | 0 | ||||||||||||||||||
| 1251 | } never executed: end of block | 0 | ||||||||||||||||||
| 1252 | - | |||||||||||||||||||
| 1253 | - | |||||||||||||||||||
| 1254 | /*! | - | ||||||||||||||||||
| 1255 | Displays a rubber band at position \a pos. If \a pos is negative, the | - | ||||||||||||||||||
| 1256 | rubber band is removed. | - | ||||||||||||||||||
| 1257 | */ | - | ||||||||||||||||||
| 1258 | - | |||||||||||||||||||
| 1259 | void QSplitter::setRubberBand(int pos) | - | ||||||||||||||||||
| 1260 | { | - | ||||||||||||||||||
| 1261 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1262 | if (pos < 0) {
| 0 | ||||||||||||||||||
| 1263 | if (d->rubberBand)
| 0 | ||||||||||||||||||
| 1264 | d->rubberBand->deleteLater(); never executed: d->rubberBand->deleteLater(); | 0 | ||||||||||||||||||
| 1265 | return; never executed: return; | 0 | ||||||||||||||||||
| 1266 | } | - | ||||||||||||||||||
| 1267 | QRect r = contentsRect(); | - | ||||||||||||||||||
| 1268 | const int rBord = 3; // customizable? | - | ||||||||||||||||||
| 1269 | int hw = handleWidth(); | - | ||||||||||||||||||
| 1270 | if (!d->rubberBand) {
| 0 | ||||||||||||||||||
| 1271 | QBoolBlocker b(d->blockChildAdd); | - | ||||||||||||||||||
| 1272 | d->rubberBand = new QRubberBand(QRubberBand::Line, this); | - | ||||||||||||||||||
| 1273 | // For accessibility to identify this special widget. | - | ||||||||||||||||||
| 1274 | d->rubberBand->setObjectName(QLatin1String("qt_rubberband")); | - | ||||||||||||||||||
| 1275 | } never executed: end of block | 0 | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | const QRect newGeom = d->orient == Qt::Horizontal ? QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height()))
| 0 | ||||||||||||||||||
| 1278 | : QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord)); | - | ||||||||||||||||||
| 1279 | d->rubberBand->setGeometry(newGeom); | - | ||||||||||||||||||
| 1280 | d->rubberBand->show(); | - | ||||||||||||||||||
| 1281 | } never executed: end of block | 0 | ||||||||||||||||||
| 1282 | - | |||||||||||||||||||
| 1283 | /*! | - | ||||||||||||||||||
| 1284 | \reimp | - | ||||||||||||||||||
| 1285 | */ | - | ||||||||||||||||||
| 1286 | - | |||||||||||||||||||
| 1287 | bool QSplitter::event(QEvent *e) | - | ||||||||||||||||||
| 1288 | { | - | ||||||||||||||||||
| 1289 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1290 | switch (e->type()) { | - | ||||||||||||||||||
| 1291 | case QEvent::Hide: never executed: case QEvent::Hide: | 0 | ||||||||||||||||||
| 1292 | // Reset firstShow to false here since things can be done to the splitter in between | - | ||||||||||||||||||
| 1293 | if (!d->firstShow)
| 0 | ||||||||||||||||||
| 1294 | d->firstShow = true; never executed: d->firstShow = true; | 0 | ||||||||||||||||||
| 1295 | break; never executed: break; | 0 | ||||||||||||||||||
| 1296 | case QEvent::Show: never executed: case QEvent::Show: | 0 | ||||||||||||||||||
| 1297 | if (!d->firstShow)
| 0 | ||||||||||||||||||
| 1298 | break; never executed: break; | 0 | ||||||||||||||||||
| 1299 | d->firstShow = false; | - | ||||||||||||||||||
| 1300 | // fall through | - | ||||||||||||||||||
| 1301 | case QEvent::HideToParent: code before this statement never executed: case QEvent::HideToParent:never executed: case QEvent::HideToParent: | 0 | ||||||||||||||||||
| 1302 | case QEvent::ShowToParent: never executed: case QEvent::ShowToParent: | 0 | ||||||||||||||||||
| 1303 | case QEvent::LayoutRequest: never executed: case QEvent::LayoutRequest: | 0 | ||||||||||||||||||
| 1304 | d->recalc(isVisible()); | - | ||||||||||||||||||
| 1305 | break; never executed: break; | 0 | ||||||||||||||||||
| 1306 | default: never executed: default: | 0 | ||||||||||||||||||
| 1307 | ; | - | ||||||||||||||||||
| 1308 | } never executed: end of block | 0 | ||||||||||||||||||
| 1309 | return QWidget::event(e); never executed: return QWidget::event(e); | 0 | ||||||||||||||||||
| 1310 | } | - | ||||||||||||||||||
| 1311 | - | |||||||||||||||||||
| 1312 | /*! | - | ||||||||||||||||||
| 1313 | \fn QSplitter::splitterMoved(int pos, int index) | - | ||||||||||||||||||
| 1314 | - | |||||||||||||||||||
| 1315 | This signal is emitted when the splitter handle at a particular \a | - | ||||||||||||||||||
| 1316 | index has been moved to position \a pos. | - | ||||||||||||||||||
| 1317 | - | |||||||||||||||||||
| 1318 | For right-to-left languages such as Arabic and Hebrew, the layout | - | ||||||||||||||||||
| 1319 | of horizontal splitters is reversed. \a pos is then the | - | ||||||||||||||||||
| 1320 | distance from the right edge of the widget. | - | ||||||||||||||||||
| 1321 | - | |||||||||||||||||||
| 1322 | \sa moveSplitter() | - | ||||||||||||||||||
| 1323 | */ | - | ||||||||||||||||||
| 1324 | - | |||||||||||||||||||
| 1325 | /*! | - | ||||||||||||||||||
| 1326 | Moves the left or top edge of the splitter handle at \a index as | - | ||||||||||||||||||
| 1327 | close as possible to position \a pos, which is the distance from the | - | ||||||||||||||||||
| 1328 | left or top edge of the widget. | - | ||||||||||||||||||
| 1329 | - | |||||||||||||||||||
| 1330 | For right-to-left languages such as Arabic and Hebrew, the layout | - | ||||||||||||||||||
| 1331 | of horizontal splitters is reversed. \a pos is then the distance | - | ||||||||||||||||||
| 1332 | from the right edge of the widget. | - | ||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | \sa splitterMoved(), closestLegalPosition(), getRange() | - | ||||||||||||||||||
| 1335 | */ | - | ||||||||||||||||||
| 1336 | void QSplitter::moveSplitter(int pos, int index) | - | ||||||||||||||||||
| 1337 | { | - | ||||||||||||||||||
| 1338 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1339 | QSplitterLayoutStruct *s = d->list.at(index); | - | ||||||||||||||||||
| 1340 | int farMin; | - | ||||||||||||||||||
| 1341 | int min; | - | ||||||||||||||||||
| 1342 | int max; | - | ||||||||||||||||||
| 1343 | int farMax; | - | ||||||||||||||||||
| 1344 | - | |||||||||||||||||||
| 1345 | #ifdef QSPLITTER_DEBUG | - | ||||||||||||||||||
| 1346 | int debugp = pos; | - | ||||||||||||||||||
| 1347 | #endif | - | ||||||||||||||||||
| 1348 | - | |||||||||||||||||||
| 1349 | pos = d->adjustPos(pos, index, &farMin, &min, &max, &farMax); | - | ||||||||||||||||||
| 1350 | int oldP = d->pick(s->rect.topLeft()); | - | ||||||||||||||||||
| 1351 | #ifdef QSPLITTER_DEBUG | - | ||||||||||||||||||
| 1352 | qDebug() << "QSplitter::moveSplitter" << debugp << index << "adjusted" << pos << "oldP" << oldP; | - | ||||||||||||||||||
| 1353 | #endif | - | ||||||||||||||||||
| 1354 | - | |||||||||||||||||||
| 1355 | QVarLengthArray<int, 32> poss(d->list.count()); | - | ||||||||||||||||||
| 1356 | QVarLengthArray<int, 32> ws(d->list.count()); | - | ||||||||||||||||||
| 1357 | bool upLeft; | - | ||||||||||||||||||
| 1358 | - | |||||||||||||||||||
| 1359 | d->doMove(false, pos, index, +1, (d->collapsible(s) && (pos > max)), poss.data(), ws.data()); | - | ||||||||||||||||||
| 1360 | d->doMove(true, pos, index - 1, +1, (d->collapsible(index - 1) && (pos < min)), poss.data(), ws.data()); | - | ||||||||||||||||||
| 1361 | upLeft = (pos < oldP); | - | ||||||||||||||||||
| 1362 | - | |||||||||||||||||||
| 1363 | int wid, delta, count = d->list.count(); | - | ||||||||||||||||||
| 1364 | if (upLeft) {
| 0 | ||||||||||||||||||
| 1365 | wid = 0; | - | ||||||||||||||||||
| 1366 | delta = 1; | - | ||||||||||||||||||
| 1367 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1368 | wid = count - 1; | - | ||||||||||||||||||
| 1369 | delta = -1; | - | ||||||||||||||||||
| 1370 | } never executed: end of block | 0 | ||||||||||||||||||
| 1371 | for (; wid >= 0 && wid < count; wid += delta) {
| 0 | ||||||||||||||||||
| 1372 | QSplitterLayoutStruct *sls = d->list.at( wid ); | - | ||||||||||||||||||
| 1373 | if (!sls->widget->isHidden())
| 0 | ||||||||||||||||||
| 1374 | d->setGeo(sls, poss[wid], ws[wid], true); never executed: d->setGeo(sls, poss[wid], ws[wid], true); | 0 | ||||||||||||||||||
| 1375 | } never executed: end of block | 0 | ||||||||||||||||||
| 1376 | d->storeSizes(); | - | ||||||||||||||||||
| 1377 | - | |||||||||||||||||||
| 1378 | emit splitterMoved(pos, index); | - | ||||||||||||||||||
| 1379 | } never executed: end of block | 0 | ||||||||||||||||||
| 1380 | - | |||||||||||||||||||
| 1381 | - | |||||||||||||||||||
| 1382 | /*! | - | ||||||||||||||||||
| 1383 | Returns the valid range of the splitter at \a index in | - | ||||||||||||||||||
| 1384 | *\a{min} and *\a{max} if \a min and \a max are not 0. | - | ||||||||||||||||||
| 1385 | */ | - | ||||||||||||||||||
| 1386 | - | |||||||||||||||||||
| 1387 | void QSplitter::getRange(int index, int *min, int *max) const | - | ||||||||||||||||||
| 1388 | { | - | ||||||||||||||||||
| 1389 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1390 | d->getRange(index, min, 0, 0, max); | - | ||||||||||||||||||
| 1391 | } never executed: end of block | 0 | ||||||||||||||||||
| 1392 | - | |||||||||||||||||||
| 1393 | - | |||||||||||||||||||
| 1394 | /*! | - | ||||||||||||||||||
| 1395 | Returns the closest legal position to \a pos of the widget at \a index. | - | ||||||||||||||||||
| 1396 | - | |||||||||||||||||||
| 1397 | For right-to-left languages such as Arabic and Hebrew, the layout | - | ||||||||||||||||||
| 1398 | of horizontal splitters is reversed. Positions are then measured | - | ||||||||||||||||||
| 1399 | from the right edge of the widget. | - | ||||||||||||||||||
| 1400 | - | |||||||||||||||||||
| 1401 | \sa getRange() | - | ||||||||||||||||||
| 1402 | */ | - | ||||||||||||||||||
| 1403 | - | |||||||||||||||||||
| 1404 | int QSplitter::closestLegalPosition(int pos, int index) | - | ||||||||||||||||||
| 1405 | { | - | ||||||||||||||||||
| 1406 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1407 | int x, i, n, u; | - | ||||||||||||||||||
| 1408 | return d->adjustPos(pos, index, &u, &n, &i, &x); never executed: return d->adjustPos(pos, index, &u, &n, &i, &x); | 0 | ||||||||||||||||||
| 1409 | } | - | ||||||||||||||||||
| 1410 | - | |||||||||||||||||||
| 1411 | /*! | - | ||||||||||||||||||
| 1412 | \property QSplitter::opaqueResize | - | ||||||||||||||||||
| 1413 | \brief whether resizing is opaque | - | ||||||||||||||||||
| 1414 | - | |||||||||||||||||||
| 1415 | The default resize behavior is style dependent (determined by the | - | ||||||||||||||||||
| 1416 | SH_Splitter_OpaqueResize style hint). However, you can override it | - | ||||||||||||||||||
| 1417 | by calling setOpaqueResize() | - | ||||||||||||||||||
| 1418 | - | |||||||||||||||||||
| 1419 | \sa QStyle::StyleHint | - | ||||||||||||||||||
| 1420 | */ | - | ||||||||||||||||||
| 1421 | - | |||||||||||||||||||
| 1422 | bool QSplitter::opaqueResize() const | - | ||||||||||||||||||
| 1423 | { | - | ||||||||||||||||||
| 1424 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1425 | return d->opaqueResizeSet ? d->opaque : style()->styleHint(QStyle::SH_Splitter_OpaqueResize, 0, this); never executed: return d->opaqueResizeSet ? d->opaque : style()->styleHint(QStyle::SH_Splitter_OpaqueResize, 0, this); | 0 | ||||||||||||||||||
| 1426 | } | - | ||||||||||||||||||
| 1427 | - | |||||||||||||||||||
| 1428 | - | |||||||||||||||||||
| 1429 | void QSplitter::setOpaqueResize(bool on) | - | ||||||||||||||||||
| 1430 | { | - | ||||||||||||||||||
| 1431 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1432 | d->opaqueResizeSet = true; | - | ||||||||||||||||||
| 1433 | d->opaque = on; | - | ||||||||||||||||||
| 1434 | } never executed: end of block | 0 | ||||||||||||||||||
| 1435 | - | |||||||||||||||||||
| 1436 | - | |||||||||||||||||||
| 1437 | /*! | - | ||||||||||||||||||
| 1438 | \reimp | - | ||||||||||||||||||
| 1439 | */ | - | ||||||||||||||||||
| 1440 | QSize QSplitter::sizeHint() const | - | ||||||||||||||||||
| 1441 | { | - | ||||||||||||||||||
| 1442 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1443 | ensurePolished(); | - | ||||||||||||||||||
| 1444 | int l = 0; | - | ||||||||||||||||||
| 1445 | int t = 0; | - | ||||||||||||||||||
| 1446 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||||||||
| 1447 | QWidget *w = d->list.at(i)->widget; | - | ||||||||||||||||||
| 1448 | if (w->isHidden())
| 0 | ||||||||||||||||||
| 1449 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1450 | QSize s = w->sizeHint(); | - | ||||||||||||||||||
| 1451 | if (s.isValid()) {
| 0 | ||||||||||||||||||
| 1452 | l += d->pick(s); | - | ||||||||||||||||||
| 1453 | t = qMax(t, d->trans(s)); | - | ||||||||||||||||||
| 1454 | } never executed: end of block | 0 | ||||||||||||||||||
| 1455 | } never executed: end of block | 0 | ||||||||||||||||||
| 1456 | return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); never executed: return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); | 0 | ||||||||||||||||||
| 1457 | } | - | ||||||||||||||||||
| 1458 | - | |||||||||||||||||||
| 1459 | - | |||||||||||||||||||
| 1460 | /*! | - | ||||||||||||||||||
| 1461 | \reimp | - | ||||||||||||||||||
| 1462 | */ | - | ||||||||||||||||||
| 1463 | - | |||||||||||||||||||
| 1464 | QSize QSplitter::minimumSizeHint() const | - | ||||||||||||||||||
| 1465 | { | - | ||||||||||||||||||
| 1466 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1467 | ensurePolished(); | - | ||||||||||||||||||
| 1468 | int l = 0; | - | ||||||||||||||||||
| 1469 | int t = 0; | - | ||||||||||||||||||
| 1470 | - | |||||||||||||||||||
| 1471 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||||||||
| 1472 | QSplitterLayoutStruct *s = d->list.at(i); | - | ||||||||||||||||||
| 1473 | if (!s || !s->widget)
| 0 | ||||||||||||||||||
| 1474 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1475 | if (s->widget->isHidden())
| 0 | ||||||||||||||||||
| 1476 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1477 | QSize widgetSize = qSmartMinSize(s->widget); | - | ||||||||||||||||||
| 1478 | if (widgetSize.isValid()) {
| 0 | ||||||||||||||||||
| 1479 | l += d->pick(widgetSize); | - | ||||||||||||||||||
| 1480 | t = qMax(t, d->trans(widgetSize)); | - | ||||||||||||||||||
| 1481 | } never executed: end of block | 0 | ||||||||||||||||||
| 1482 | if (!s->handle || s->handle->isHidden())
| 0 | ||||||||||||||||||
| 1483 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1484 | QSize splitterSize = s->handle->sizeHint(); | - | ||||||||||||||||||
| 1485 | if (splitterSize.isValid()) {
| 0 | ||||||||||||||||||
| 1486 | l += d->pick(splitterSize); | - | ||||||||||||||||||
| 1487 | t = qMax(t, d->trans(splitterSize)); | - | ||||||||||||||||||
| 1488 | } never executed: end of block | 0 | ||||||||||||||||||
| 1489 | } never executed: end of block | 0 | ||||||||||||||||||
| 1490 | return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); never executed: return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); | 0 | ||||||||||||||||||
| 1491 | } | - | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | - | |||||||||||||||||||
| 1494 | /*! | - | ||||||||||||||||||
| 1495 | Returns a list of the size parameters of all the widgets in this splitter. | - | ||||||||||||||||||
| 1496 | - | |||||||||||||||||||
| 1497 | If the splitter's orientation is horizontal, the list contains the | - | ||||||||||||||||||
| 1498 | widgets width in pixels, from left to right; if the orientation is | - | ||||||||||||||||||
| 1499 | vertical, the list contains the widgets' heights in pixels, | - | ||||||||||||||||||
| 1500 | from top to bottom. | - | ||||||||||||||||||
| 1501 | - | |||||||||||||||||||
| 1502 | Giving the values to another splitter's setSizes() function will | - | ||||||||||||||||||
| 1503 | produce a splitter with the same layout as this one. | - | ||||||||||||||||||
| 1504 | - | |||||||||||||||||||
| 1505 | Note that invisible widgets have a size of 0. | - | ||||||||||||||||||
| 1506 | - | |||||||||||||||||||
| 1507 | \sa setSizes() | - | ||||||||||||||||||
| 1508 | */ | - | ||||||||||||||||||
| 1509 | - | |||||||||||||||||||
| 1510 | QList<int> QSplitter::sizes() const | - | ||||||||||||||||||
| 1511 | { | - | ||||||||||||||||||
| 1512 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1513 | ensurePolished(); | - | ||||||||||||||||||
| 1514 | - | |||||||||||||||||||
| 1515 | const int numSizes = d->list.size(); | - | ||||||||||||||||||
| 1516 | QList<int> list; | - | ||||||||||||||||||
| 1517 | list.reserve(numSizes); | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | for (int i = 0; i < numSizes; ++i) {
| 0 | ||||||||||||||||||
| 1520 | QSplitterLayoutStruct *s = d->list.at(i); | - | ||||||||||||||||||
| 1521 | list.append(d->pick(s->rect.size())); | - | ||||||||||||||||||
| 1522 | } never executed: end of block | 0 | ||||||||||||||||||
| 1523 | return list; never executed: return list; | 0 | ||||||||||||||||||
| 1524 | } | - | ||||||||||||||||||
| 1525 | - | |||||||||||||||||||
| 1526 | /*! | - | ||||||||||||||||||
| 1527 | Sets the child widgets' respective sizes to the values given in the \a list. | - | ||||||||||||||||||
| 1528 | - | |||||||||||||||||||
| 1529 | If the splitter is horizontal, the values set the width of each | - | ||||||||||||||||||
| 1530 | widget in pixels, from left to right. If the splitter is vertical, the | - | ||||||||||||||||||
| 1531 | height of each widget is set, from top to bottom. | - | ||||||||||||||||||
| 1532 | - | |||||||||||||||||||
| 1533 | Extra values in the \a list are ignored. If \a list contains too few | - | ||||||||||||||||||
| 1534 | values, the result is undefined, but the program will still be well-behaved. | - | ||||||||||||||||||
| 1535 | - | |||||||||||||||||||
| 1536 | The overall size of the splitter widget is not affected. | - | ||||||||||||||||||
| 1537 | Instead, any additional/missing space is distributed amongst the | - | ||||||||||||||||||
| 1538 | widgets according to the relative weight of the sizes. | - | ||||||||||||||||||
| 1539 | - | |||||||||||||||||||
| 1540 | If you specify a size of 0, the widget will be invisible. The size policies | - | ||||||||||||||||||
| 1541 | of the widgets are preserved. That is, a value smaller than the minimal size | - | ||||||||||||||||||
| 1542 | hint of the respective widget will be replaced by the value of the hint. | - | ||||||||||||||||||
| 1543 | - | |||||||||||||||||||
| 1544 | \sa sizes() | - | ||||||||||||||||||
| 1545 | */ | - | ||||||||||||||||||
| 1546 | - | |||||||||||||||||||
| 1547 | void QSplitter::setSizes(const QList<int> &list) | - | ||||||||||||||||||
| 1548 | { | - | ||||||||||||||||||
| 1549 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1550 | d->setSizes_helper(list, true); | - | ||||||||||||||||||
| 1551 | } never executed: end of block | 0 | ||||||||||||||||||
| 1552 | - | |||||||||||||||||||
| 1553 | /*! | - | ||||||||||||||||||
| 1554 | \property QSplitter::handleWidth | - | ||||||||||||||||||
| 1555 | \brief the width of the splitter handles | - | ||||||||||||||||||
| 1556 | - | |||||||||||||||||||
| 1557 | By default, this property contains a value that depends on the user's platform | - | ||||||||||||||||||
| 1558 | and style preferences. | - | ||||||||||||||||||
| 1559 | - | |||||||||||||||||||
| 1560 | If you set handleWidth to 1 or 0, the actual grab area will grow to overlap a | - | ||||||||||||||||||
| 1561 | few pixels of its respective widgets. | - | ||||||||||||||||||
| 1562 | */ | - | ||||||||||||||||||
| 1563 | - | |||||||||||||||||||
| 1564 | int QSplitter::handleWidth() const | - | ||||||||||||||||||
| 1565 | { | - | ||||||||||||||||||
| 1566 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1567 | if (d->handleWidth >= 0) {
| 0 | ||||||||||||||||||
| 1568 | return d->handleWidth; never executed: return d->handleWidth; | 0 | ||||||||||||||||||
| 1569 | } else { | - | ||||||||||||||||||
| 1570 | return style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this); never executed: return style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this); | 0 | ||||||||||||||||||
| 1571 | } | - | ||||||||||||||||||
| 1572 | } | - | ||||||||||||||||||
| 1573 | - | |||||||||||||||||||
| 1574 | void QSplitter::setHandleWidth(int width) | - | ||||||||||||||||||
| 1575 | { | - | ||||||||||||||||||
| 1576 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1577 | d->handleWidth = width; | - | ||||||||||||||||||
| 1578 | d->updateHandles(); | - | ||||||||||||||||||
| 1579 | } never executed: end of block | 0 | ||||||||||||||||||
| 1580 | - | |||||||||||||||||||
| 1581 | /*! | - | ||||||||||||||||||
| 1582 | \reimp | - | ||||||||||||||||||
| 1583 | */ | - | ||||||||||||||||||
| 1584 | void QSplitter::changeEvent(QEvent *ev) | - | ||||||||||||||||||
| 1585 | { | - | ||||||||||||||||||
| 1586 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1587 | if(ev->type() == QEvent::StyleChange)
| 0 | ||||||||||||||||||
| 1588 | d->updateHandles(); never executed: d->updateHandles(); | 0 | ||||||||||||||||||
| 1589 | QFrame::changeEvent(ev); | - | ||||||||||||||||||
| 1590 | } never executed: end of block | 0 | ||||||||||||||||||
| 1591 | - | |||||||||||||||||||
| 1592 | static const qint32 SplitterMagic = 0xff; | - | ||||||||||||||||||
| 1593 | - | |||||||||||||||||||
| 1594 | /*! | - | ||||||||||||||||||
| 1595 | Saves the state of the splitter's layout. | - | ||||||||||||||||||
| 1596 | - | |||||||||||||||||||
| 1597 | Typically this is used in conjunction with QSettings to remember the size | - | ||||||||||||||||||
| 1598 | for a future session. A version number is stored as part of the data. | - | ||||||||||||||||||
| 1599 | Here is an example: | - | ||||||||||||||||||
| 1600 | - | |||||||||||||||||||
| 1601 | \snippet splitter/splitter.cpp 1 | - | ||||||||||||||||||
| 1602 | - | |||||||||||||||||||
| 1603 | \sa restoreState() | - | ||||||||||||||||||
| 1604 | */ | - | ||||||||||||||||||
| 1605 | QByteArray QSplitter::saveState() const | - | ||||||||||||||||||
| 1606 | { | - | ||||||||||||||||||
| 1607 | Q_D(const QSplitter); | - | ||||||||||||||||||
| 1608 | int version = 1; | - | ||||||||||||||||||
| 1609 | QByteArray data; | - | ||||||||||||||||||
| 1610 | QDataStream stream(&data, QIODevice::WriteOnly); | - | ||||||||||||||||||
| 1611 | - | |||||||||||||||||||
| 1612 | stream << qint32(SplitterMagic); | - | ||||||||||||||||||
| 1613 | stream << qint32(version); | - | ||||||||||||||||||
| 1614 | const int numSizes = d->list.size(); | - | ||||||||||||||||||
| 1615 | QList<int> list; | - | ||||||||||||||||||
| 1616 | list.reserve(numSizes); | - | ||||||||||||||||||
| 1617 | for (int i = 0; i < numSizes; ++i) {
| 0 | ||||||||||||||||||
| 1618 | QSplitterLayoutStruct *s = d->list.at(i); | - | ||||||||||||||||||
| 1619 | list.append(s->sizer); | - | ||||||||||||||||||
| 1620 | } never executed: end of block | 0 | ||||||||||||||||||
| 1621 | stream << list; | - | ||||||||||||||||||
| 1622 | stream << childrenCollapsible(); | - | ||||||||||||||||||
| 1623 | stream << qint32(d->handleWidth); | - | ||||||||||||||||||
| 1624 | stream << opaqueResize(); | - | ||||||||||||||||||
| 1625 | stream << qint32(orientation()); | - | ||||||||||||||||||
| 1626 | stream << d->opaqueResizeSet; | - | ||||||||||||||||||
| 1627 | return data; never executed: return data; | 0 | ||||||||||||||||||
| 1628 | } | - | ||||||||||||||||||
| 1629 | - | |||||||||||||||||||
| 1630 | /*! | - | ||||||||||||||||||
| 1631 | Restores the splitter's layout to the \a state specified. | - | ||||||||||||||||||
| 1632 | Returns \c true if the state is restored; otherwise returns \c false. | - | ||||||||||||||||||
| 1633 | - | |||||||||||||||||||
| 1634 | Typically this is used in conjunction with QSettings to restore the size | - | ||||||||||||||||||
| 1635 | from a past session. Here is an example: | - | ||||||||||||||||||
| 1636 | - | |||||||||||||||||||
| 1637 | Restore the splitter's state: | - | ||||||||||||||||||
| 1638 | - | |||||||||||||||||||
| 1639 | \snippet splitter/splitter.cpp 2 | - | ||||||||||||||||||
| 1640 | - | |||||||||||||||||||
| 1641 | A failure to restore the splitter's layout may result from either | - | ||||||||||||||||||
| 1642 | invalid or out-of-date data in the supplied byte array. | - | ||||||||||||||||||
| 1643 | - | |||||||||||||||||||
| 1644 | \sa saveState() | - | ||||||||||||||||||
| 1645 | */ | - | ||||||||||||||||||
| 1646 | bool QSplitter::restoreState(const QByteArray &state) | - | ||||||||||||||||||
| 1647 | { | - | ||||||||||||||||||
| 1648 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1649 | int version = 1; | - | ||||||||||||||||||
| 1650 | QByteArray sd = state; | - | ||||||||||||||||||
| 1651 | QDataStream stream(&sd, QIODevice::ReadOnly); | - | ||||||||||||||||||
| 1652 | QList<int> list; | - | ||||||||||||||||||
| 1653 | bool b; | - | ||||||||||||||||||
| 1654 | qint32 i; | - | ||||||||||||||||||
| 1655 | qint32 marker; | - | ||||||||||||||||||
| 1656 | qint32 v; | - | ||||||||||||||||||
| 1657 | - | |||||||||||||||||||
| 1658 | stream >> marker; | - | ||||||||||||||||||
| 1659 | stream >> v; | - | ||||||||||||||||||
| 1660 | if (marker != SplitterMagic || v > version)
| 0 | ||||||||||||||||||
| 1661 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 1662 | - | |||||||||||||||||||
| 1663 | stream >> list; | - | ||||||||||||||||||
| 1664 | d->setSizes_helper(list, false); | - | ||||||||||||||||||
| 1665 | - | |||||||||||||||||||
| 1666 | stream >> b; | - | ||||||||||||||||||
| 1667 | setChildrenCollapsible(b); | - | ||||||||||||||||||
| 1668 | - | |||||||||||||||||||
| 1669 | stream >> i; | - | ||||||||||||||||||
| 1670 | setHandleWidth(i); | - | ||||||||||||||||||
| 1671 | - | |||||||||||||||||||
| 1672 | stream >> b; | - | ||||||||||||||||||
| 1673 | setOpaqueResize(b); | - | ||||||||||||||||||
| 1674 | - | |||||||||||||||||||
| 1675 | stream >> i; | - | ||||||||||||||||||
| 1676 | setOrientation(Qt::Orientation(i)); | - | ||||||||||||||||||
| 1677 | d->doResize(); | - | ||||||||||||||||||
| 1678 | - | |||||||||||||||||||
| 1679 | if (v >= 1)
| 0 | ||||||||||||||||||
| 1680 | stream >> d->opaqueResizeSet; never executed: stream >> d->opaqueResizeSet; | 0 | ||||||||||||||||||
| 1681 | - | |||||||||||||||||||
| 1682 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1683 | } | - | ||||||||||||||||||
| 1684 | - | |||||||||||||||||||
| 1685 | /*! | - | ||||||||||||||||||
| 1686 | Updates the size policy of the widget at position \a index to | - | ||||||||||||||||||
| 1687 | have a stretch factor of \a stretch. | - | ||||||||||||||||||
| 1688 | - | |||||||||||||||||||
| 1689 | \a stretch is not the effective stretch factor; the effective | - | ||||||||||||||||||
| 1690 | stretch factor is calculated by taking the initial size of the | - | ||||||||||||||||||
| 1691 | widget and multiplying it with \a stretch. | - | ||||||||||||||||||
| 1692 | - | |||||||||||||||||||
| 1693 | This function is provided for convenience. It is equivalent to | - | ||||||||||||||||||
| 1694 | - | |||||||||||||||||||
| 1695 | \snippet code/src_gui_widgets_qsplitter.cpp 0 | - | ||||||||||||||||||
| 1696 | - | |||||||||||||||||||
| 1697 | \sa setSizes(), widget() | - | ||||||||||||||||||
| 1698 | */ | - | ||||||||||||||||||
| 1699 | void QSplitter::setStretchFactor(int index, int stretch) | - | ||||||||||||||||||
| 1700 | { | - | ||||||||||||||||||
| 1701 | Q_D(QSplitter); | - | ||||||||||||||||||
| 1702 | if (index <= -1 || index >= d->list.count())
| 0 | ||||||||||||||||||
| 1703 | return; never executed: return; | 0 | ||||||||||||||||||
| 1704 | - | |||||||||||||||||||
| 1705 | QWidget *widget = d->list.at(index)->widget; | - | ||||||||||||||||||
| 1706 | QSizePolicy sp = widget->sizePolicy(); | - | ||||||||||||||||||
| 1707 | sp.setHorizontalStretch(stretch); | - | ||||||||||||||||||
| 1708 | sp.setVerticalStretch(stretch); | - | ||||||||||||||||||
| 1709 | widget->setSizePolicy(sp); | - | ||||||||||||||||||
| 1710 | } never executed: end of block | 0 | ||||||||||||||||||
| 1711 | - | |||||||||||||||||||
| 1712 | - | |||||||||||||||||||
| 1713 | /*! | - | ||||||||||||||||||
| 1714 | \relates QSplitter | - | ||||||||||||||||||
| 1715 | \obsolete | - | ||||||||||||||||||
| 1716 | - | |||||||||||||||||||
| 1717 | Use \a ts << \a{splitter}.saveState() instead. | - | ||||||||||||||||||
| 1718 | */ | - | ||||||||||||||||||
| 1719 | - | |||||||||||||||||||
| 1720 | QTextStream& operator<<(QTextStream& ts, const QSplitter& splitter) | - | ||||||||||||||||||
| 1721 | { | - | ||||||||||||||||||
| 1722 | ts << splitter.saveState() << endl; | - | ||||||||||||||||||
| 1723 | return ts; never executed: return ts; | 0 | ||||||||||||||||||
| 1724 | } | - | ||||||||||||||||||
| 1725 | - | |||||||||||||||||||
| 1726 | /*! | - | ||||||||||||||||||
| 1727 | \relates QSplitter | - | ||||||||||||||||||
| 1728 | \obsolete | - | ||||||||||||||||||
| 1729 | - | |||||||||||||||||||
| 1730 | Use \a ts >> \a{splitter}.restoreState() instead. | - | ||||||||||||||||||
| 1731 | */ | - | ||||||||||||||||||
| 1732 | - | |||||||||||||||||||
| 1733 | QTextStream& operator>>(QTextStream& ts, QSplitter& splitter) | - | ||||||||||||||||||
| 1734 | { | - | ||||||||||||||||||
| 1735 | QString line = ts.readLine(); | - | ||||||||||||||||||
| 1736 | line = line.simplified(); | - | ||||||||||||||||||
| 1737 | line.replace(QLatin1Char(' '), QString()); | - | ||||||||||||||||||
| 1738 | line = line.toUpper(); | - | ||||||||||||||||||
| 1739 | - | |||||||||||||||||||
| 1740 | splitter.restoreState(line.toLatin1()); | - | ||||||||||||||||||
| 1741 | return ts; never executed: return ts; | 0 | ||||||||||||||||||
| 1742 | } | - | ||||||||||||||||||
| 1743 | - | |||||||||||||||||||
| 1744 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 1745 | - | |||||||||||||||||||
| 1746 | #include "moc_qsplitter.cpp" | - | ||||||||||||||||||
| 1747 | - | |||||||||||||||||||
| 1748 | #endif // QT_NO_SPLITTER | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |