| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qsizegrip.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 "qsizegrip.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include "qapplication.h" | - | ||||||||||||||||||
| 45 | #include "qevent.h" | - | ||||||||||||||||||
| 46 | #include "qpainter.h" | - | ||||||||||||||||||
| 47 | #include "qwindow.h" | - | ||||||||||||||||||
| 48 | #include <qpa/qplatformwindow.h> | - | ||||||||||||||||||
| 49 | #include "qstyle.h" | - | ||||||||||||||||||
| 50 | #include "qstyleoption.h" | - | ||||||||||||||||||
| 51 | #include "qlayout.h" | - | ||||||||||||||||||
| 52 | #include "qdebug.h" | - | ||||||||||||||||||
| 53 | #include <QDesktopWidget> | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 56 | #include <private/qt_mac_p.h> | - | ||||||||||||||||||
| 57 | #endif | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | #include <private/qwidget_p.h> | - | ||||||||||||||||||
| 60 | #include <QtWidgets/qabstractscrollarea.h> | - | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | static QWidget *qt_sizegrip_topLevelWidget(QWidget* w) | - | ||||||||||||||||||
| 65 | { | - | ||||||||||||||||||
| 66 | while (w && !w->isWindow() && w->windowType() != Qt::SubWindow)
| 0 | ||||||||||||||||||
| 67 | w = w->parentWidget(); never executed: w = w->parentWidget(); | 0 | ||||||||||||||||||
| 68 | return w; never executed: return w; | 0 | ||||||||||||||||||
| 69 | } | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | class QSizeGripPrivate : public QWidgetPrivate | - | ||||||||||||||||||
| 72 | { | - | ||||||||||||||||||
| 73 | Q_DECLARE_PUBLIC(QSizeGrip) | - | ||||||||||||||||||
| 74 | public: | - | ||||||||||||||||||
| 75 | QSizeGripPrivate(); | - | ||||||||||||||||||
| 76 | void init(); | - | ||||||||||||||||||
| 77 | QPoint p; | - | ||||||||||||||||||
| 78 | QRect r; | - | ||||||||||||||||||
| 79 | int d; | - | ||||||||||||||||||
| 80 | int dxMax; | - | ||||||||||||||||||
| 81 | int dyMax; | - | ||||||||||||||||||
| 82 | Qt::Corner m_corner; | - | ||||||||||||||||||
| 83 | bool gotMousePress; | - | ||||||||||||||||||
| 84 | QPointer<QWidget> tlw; | - | ||||||||||||||||||
| 85 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 86 | void updateMacSizer(bool hide) const; | - | ||||||||||||||||||
| 87 | #endif | - | ||||||||||||||||||
| 88 | Qt::Corner corner() const; | - | ||||||||||||||||||
| 89 | inline bool atBottom() const | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | return m_corner == Qt::BottomRightCorner || m_corner == Qt::BottomLeftCorner; never executed: return m_corner == Qt::BottomRightCorner || m_corner == Qt::BottomLeftCorner; | 0 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | inline bool atLeft() const | - | ||||||||||||||||||
| 95 | { | - | ||||||||||||||||||
| 96 | return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner; never executed: return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner; | 0 | ||||||||||||||||||
| 97 | } | - | ||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | void updateTopLevelWidget() | - | ||||||||||||||||||
| 100 | { | - | ||||||||||||||||||
| 101 | Q_Q(QSizeGrip); | - | ||||||||||||||||||
| 102 | QWidget *w = qt_sizegrip_topLevelWidget(q); | - | ||||||||||||||||||
| 103 | if (tlw == w)
| 0 | ||||||||||||||||||
| 104 | return; never executed: return; | 0 | ||||||||||||||||||
| 105 | if (tlw)
| 0 | ||||||||||||||||||
| 106 | tlw->removeEventFilter(q); never executed: tlw->removeEventFilter(q); | 0 | ||||||||||||||||||
| 107 | tlw = w; | - | ||||||||||||||||||
| 108 | if (tlw)
| 0 | ||||||||||||||||||
| 109 | tlw->installEventFilter(q); never executed: tlw->installEventFilter(q); | 0 | ||||||||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | // This slot is invoked by QLayout when the size grip is added to | - | ||||||||||||||||||
| 113 | // a layout or reparented after the tlw is shown. This re-implementation is basically | - | ||||||||||||||||||
| 114 | // the same as QWidgetPrivate::_q_showIfNotHidden except that it checks | - | ||||||||||||||||||
| 115 | // for Qt::WindowFullScreen and Qt::WindowMaximized as well. | - | ||||||||||||||||||
| 116 | void _q_showIfNotHidden() | - | ||||||||||||||||||
| 117 | { | - | ||||||||||||||||||
| 118 | Q_Q(QSizeGrip); | - | ||||||||||||||||||
| 119 | bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
| 0 | ||||||||||||||||||
| 120 | updateTopLevelWidget(); | - | ||||||||||||||||||
| 121 | if (tlw && showSizeGrip) {
| 0 | ||||||||||||||||||
| 122 | Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; | - | ||||||||||||||||||
| 123 | #ifndef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 124 | sizeGripNotVisibleState |= Qt::WindowMaximized; | - | ||||||||||||||||||
| 125 | #endif | - | ||||||||||||||||||
| 126 | // Don't show the size grip if the tlw is maximized or in full screen mode. | - | ||||||||||||||||||
| 127 | showSizeGrip = !(tlw->windowState() & sizeGripNotVisibleState); | - | ||||||||||||||||||
| 128 | } never executed: end of block | 0 | ||||||||||||||||||
| 129 | if (showSizeGrip)
| 0 | ||||||||||||||||||
| 130 | q->setVisible(true); never executed: q->setVisible(true); | 0 | ||||||||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | bool m_platformSizeGrip; | - | ||||||||||||||||||
| 134 | }; | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | QSizeGripPrivate::QSizeGripPrivate() | - | ||||||||||||||||||
| 137 | : dxMax(0) | - | ||||||||||||||||||
| 138 | , dyMax(0) | - | ||||||||||||||||||
| 139 | , gotMousePress(false) | - | ||||||||||||||||||
| 140 | , tlw(0) | - | ||||||||||||||||||
| 141 | , m_platformSizeGrip(false) | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | } never executed: end of block | 0 | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 146 | void QSizeGripPrivate::updateMacSizer(bool hide) const | - | ||||||||||||||||||
| 147 | { | - | ||||||||||||||||||
| 148 | Q_Q(const QSizeGrip); | - | ||||||||||||||||||
| 149 | if (QApplication::closingDown() || !parent) | - | ||||||||||||||||||
| 150 | return; | - | ||||||||||||||||||
| 151 | QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q)); | - | ||||||||||||||||||
| 152 | if(topLevelWindow && topLevelWindow->isWindow()) | - | ||||||||||||||||||
| 153 | QWidgetPrivate::qt_mac_update_sizer(topLevelWindow, hide ? -1 : 1); | - | ||||||||||||||||||
| 154 | } | - | ||||||||||||||||||
| 155 | #endif | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | Qt::Corner QSizeGripPrivate::corner() const | - | ||||||||||||||||||
| 158 | { | - | ||||||||||||||||||
| 159 | Q_Q(const QSizeGrip); | - | ||||||||||||||||||
| 160 | QWidget *tlw = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q)); | - | ||||||||||||||||||
| 161 | const QPoint sizeGripPos = q->mapTo(tlw, QPoint(0, 0)); | - | ||||||||||||||||||
| 162 | bool isAtBottom = sizeGripPos.y() >= tlw->height() / 2; | - | ||||||||||||||||||
| 163 | bool isAtLeft = sizeGripPos.x() <= tlw->width() / 2; | - | ||||||||||||||||||
| 164 | if (isAtLeft)
| 0 | ||||||||||||||||||
| 165 | return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner; never executed: return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner; | 0 | ||||||||||||||||||
| 166 | else | - | ||||||||||||||||||
| 167 | return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner; never executed: return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner; | 0 | ||||||||||||||||||
| 168 | } | - | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | /*! | - | ||||||||||||||||||
| 171 | \class QSizeGrip | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | \brief The QSizeGrip class provides a resize handle for resizing top-level windows. | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | \ingroup mainwindow-classes | - | ||||||||||||||||||
| 176 | \ingroup basicwidgets | - | ||||||||||||||||||
| 177 | \inmodule QtWidgets | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | This widget works like the standard Windows resize handle. In the | - | ||||||||||||||||||
| 180 | X11 version this resize handle generally works differently from | - | ||||||||||||||||||
| 181 | the one provided by the system if the X11 window manager does not | - | ||||||||||||||||||
| 182 | support necessary modern post-ICCCM specifications. | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | Put this widget anywhere in a widget tree and the user can use it | - | ||||||||||||||||||
| 185 | to resize the top-level window or any widget with the Qt::SubWindow | - | ||||||||||||||||||
| 186 | flag set. Generally, this should be in the lower right-hand corner. | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | Note that QStatusBar already uses this widget, so if you have a | - | ||||||||||||||||||
| 189 | status bar (e.g., you are using QMainWindow), then you don't need | - | ||||||||||||||||||
| 190 | to use this widget explicitly. The same goes for QDialog, for which | - | ||||||||||||||||||
| 191 | you can just call \l {QDialog::setSizeGripEnabled()} | - | ||||||||||||||||||
| 192 | {QDialog::setSizeGripEnabled()}. | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | On some platforms the size grip automatically hides itself when the | - | ||||||||||||||||||
| 195 | window is shown full screen or maximised. | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | \table 50% | - | ||||||||||||||||||
| 198 | \row \li \inlineimage fusion-statusbar-sizegrip.png Screenshot of a Fusion style size grip | - | ||||||||||||||||||
| 199 | \li A size grip widget at the bottom-right corner of a main window, shown in the | - | ||||||||||||||||||
| 200 | \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||||||||
| 201 | \endtable | - | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | The QSizeGrip class inherits QWidget and reimplements the \l | - | ||||||||||||||||||
| 204 | {QWidget::mousePressEvent()}{mousePressEvent()} and \l | - | ||||||||||||||||||
| 205 | {QWidget::mouseMoveEvent()}{mouseMoveEvent()} functions to feature | - | ||||||||||||||||||
| 206 | the resize functionality, and the \l | - | ||||||||||||||||||
| 207 | {QWidget::paintEvent()}{paintEvent()} function to render the | - | ||||||||||||||||||
| 208 | size grip widget. | - | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | \sa QStatusBar, QWidget::windowState() | - | ||||||||||||||||||
| 211 | */ | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | /*! | - | ||||||||||||||||||
| 215 | Constructs a resize corner as a child widget of the given \a | - | ||||||||||||||||||
| 216 | parent. | - | ||||||||||||||||||
| 217 | */ | - | ||||||||||||||||||
| 218 | QSizeGrip::QSizeGrip(QWidget * parent) | - | ||||||||||||||||||
| 219 | : QWidget(*new QSizeGripPrivate, parent, 0) | - | ||||||||||||||||||
| 220 | { | - | ||||||||||||||||||
| 221 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 222 | d->init(); | - | ||||||||||||||||||
| 223 | } never executed: end of block | 0 | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | void QSizeGripPrivate::init() | - | ||||||||||||||||||
| 227 | { | - | ||||||||||||||||||
| 228 | Q_Q(QSizeGrip); | - | ||||||||||||||||||
| 229 | m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
| 0 | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | #if !defined(QT_NO_CURSOR) && !defined(Q_DEAD_CODE_FROM_QT4_MAC) | - | ||||||||||||||||||
| 232 | q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner | - | ||||||||||||||||||
| 233 | ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor); | - | ||||||||||||||||||
| 234 | #endif | - | ||||||||||||||||||
| 235 | q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); | - | ||||||||||||||||||
| 236 | updateTopLevelWidget(); | - | ||||||||||||||||||
| 237 | } never executed: end of block | 0 | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | /*! | - | ||||||||||||||||||
| 241 | Destroys this size grip. | - | ||||||||||||||||||
| 242 | */ | - | ||||||||||||||||||
| 243 | QSizeGrip::~QSizeGrip() | - | ||||||||||||||||||
| 244 | { | - | ||||||||||||||||||
| 245 | } | - | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | /*! | - | ||||||||||||||||||
| 248 | \reimp | - | ||||||||||||||||||
| 249 | */ | - | ||||||||||||||||||
| 250 | QSize QSizeGrip::sizeHint() const | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | QStyleOption opt(0); | - | ||||||||||||||||||
| 253 | opt.init(this); | - | ||||||||||||||||||
| 254 | return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this). never executed: return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this). expandedTo(QApplication::globalStrut())); | 0 | ||||||||||||||||||
| 255 | expandedTo(QApplication::globalStrut())); never executed: return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this). expandedTo(QApplication::globalStrut())); | 0 | ||||||||||||||||||
| 256 | } | - | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | /*! | - | ||||||||||||||||||
| 259 | Paints the resize grip. | - | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | Resize grips are usually rendered as small diagonal textured lines | - | ||||||||||||||||||
| 262 | in the lower-right corner. The paint event is passed in the \a | - | ||||||||||||||||||
| 263 | event parameter. | - | ||||||||||||||||||
| 264 | */ | - | ||||||||||||||||||
| 265 | void QSizeGrip::paintEvent(QPaintEvent *event) | - | ||||||||||||||||||
| 266 | { | - | ||||||||||||||||||
| 267 | Q_UNUSED(event); | - | ||||||||||||||||||
| 268 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 269 | QPainter painter(this); | - | ||||||||||||||||||
| 270 | QStyleOptionSizeGrip opt; | - | ||||||||||||||||||
| 271 | opt.init(this); | - | ||||||||||||||||||
| 272 | opt.corner = d->m_corner; | - | ||||||||||||||||||
| 273 | style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this); | - | ||||||||||||||||||
| 274 | } never executed: end of block | 0 | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | /*! | - | ||||||||||||||||||
| 277 | \fn void QSizeGrip::mousePressEvent(QMouseEvent * event) | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | Receives the mouse press events for the widget, and primes the | - | ||||||||||||||||||
| 280 | resize operation. The mouse press event is passed in the \a event | - | ||||||||||||||||||
| 281 | parameter. | - | ||||||||||||||||||
| 282 | */ | - | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | void QSizeGrip::mousePressEvent(QMouseEvent * e) | - | ||||||||||||||||||
| 285 | { | - | ||||||||||||||||||
| 286 | if (e->button() != Qt::LeftButton) {
| 0 | ||||||||||||||||||
| 287 | QWidget::mousePressEvent(e); | - | ||||||||||||||||||
| 288 | return; never executed: return; | 0 | ||||||||||||||||||
| 289 | } | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 292 | QWidget *tlw = qt_sizegrip_topLevelWidget(this); | - | ||||||||||||||||||
| 293 | d->p = e->globalPos(); | - | ||||||||||||||||||
| 294 | d->gotMousePress = true; | - | ||||||||||||||||||
| 295 | d->r = tlw->geometry(); | - | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | // Does the platform provide size grip support? | - | ||||||||||||||||||
| 298 | d->m_platformSizeGrip = false; | - | ||||||||||||||||||
| 299 | if (tlw->isWindow()
| 0 | ||||||||||||||||||
| 300 | && tlw->windowHandle()
| 0 | ||||||||||||||||||
| 301 | && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
| 0 | ||||||||||||||||||
| 302 | && !tlw->testAttribute(Qt::WA_DontShowOnScreen)
| 0 | ||||||||||||||||||
| 303 | && !tlw->hasHeightForWidth()) {
| 0 | ||||||||||||||||||
| 304 | QPlatformWindow *platformWindow = tlw->windowHandle()->handle(); | - | ||||||||||||||||||
| 305 | const QPoint topLevelPos = mapTo(tlw, e->pos()); | - | ||||||||||||||||||
| 306 | d->m_platformSizeGrip = platformWindow && platformWindow->startSystemResize(topLevelPos, d->m_corner);
| 0 | ||||||||||||||||||
| 307 | } never executed: end of block | 0 | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | if (d->m_platformSizeGrip)
| 0 | ||||||||||||||||||
| 310 | return; never executed: return; | 0 | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | // Find available desktop/workspace geometry. | - | ||||||||||||||||||
| 313 | QRect availableGeometry; | - | ||||||||||||||||||
| 314 | bool hasVerticalSizeConstraint = true; | - | ||||||||||||||||||
| 315 | bool hasHorizontalSizeConstraint = true; | - | ||||||||||||||||||
| 316 | if (tlw->isWindow())
| 0 | ||||||||||||||||||
| 317 | availableGeometry = QApplication::desktop()->availableGeometry(tlw); never executed: availableGeometry = QApplication::desktop()->availableGeometry(tlw); | 0 | ||||||||||||||||||
| 318 | else { | - | ||||||||||||||||||
| 319 | const QWidget *tlwParent = tlw->parentWidget(); | - | ||||||||||||||||||
| 320 | // Check if tlw is inside QAbstractScrollArea/QScrollArea. | - | ||||||||||||||||||
| 321 | // If that's the case tlw->parentWidget() will return the viewport | - | ||||||||||||||||||
| 322 | // and tlw->parentWidget()->parentWidget() will return the scroll area. | - | ||||||||||||||||||
| 323 | #ifndef QT_NO_SCROLLAREA | - | ||||||||||||||||||
| 324 | QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget()); | - | ||||||||||||||||||
| 325 | if (scrollArea) {
| 0 | ||||||||||||||||||
| 326 | hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; | - | ||||||||||||||||||
| 327 | hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; | - | ||||||||||||||||||
| 328 | } never executed: end of block | 0 | ||||||||||||||||||
| 329 | #endif // QT_NO_SCROLLAREA | - | ||||||||||||||||||
| 330 | availableGeometry = tlwParent->contentsRect(); | - | ||||||||||||||||||
| 331 | } never executed: end of block | 0 | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | // Find frame geometries, title bar height, and decoration sizes. | - | ||||||||||||||||||
| 334 | const QRect frameGeometry = tlw->frameGeometry(); | - | ||||||||||||||||||
| 335 | const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0); | - | ||||||||||||||||||
| 336 | const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0); | - | ||||||||||||||||||
| 337 | const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0); | - | ||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | // Determine dyMax depending on whether the sizegrip is at the bottom | - | ||||||||||||||||||
| 340 | // of the widget or not. | - | ||||||||||||||||||
| 341 | if (d->atBottom()) {
| 0 | ||||||||||||||||||
| 342 | if (hasVerticalSizeConstraint)
| 0 | ||||||||||||||||||
| 343 | d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration; never executed: d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration; | 0 | ||||||||||||||||||
| 344 | else | - | ||||||||||||||||||
| 345 | d->dyMax = INT_MAX; never executed: d->dyMax = 2147483647; | 0 | ||||||||||||||||||
| 346 | } else { | - | ||||||||||||||||||
| 347 | if (hasVerticalSizeConstraint)
| 0 | ||||||||||||||||||
| 348 | d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight; never executed: d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight; | 0 | ||||||||||||||||||
| 349 | else | - | ||||||||||||||||||
| 350 | d->dyMax = -INT_MAX; never executed: d->dyMax = -2147483647; | 0 | ||||||||||||||||||
| 351 | } | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace | - | ||||||||||||||||||
| 354 | // geometry, the size grip geometry and the width of the decoration. | - | ||||||||||||||||||
| 355 | if (d->atLeft()) {
| 0 | ||||||||||||||||||
| 356 | if (hasHorizontalSizeConstraint)
| 0 | ||||||||||||||||||
| 357 | d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration; never executed: d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration; | 0 | ||||||||||||||||||
| 358 | else | - | ||||||||||||||||||
| 359 | d->dxMax = -INT_MAX; never executed: d->dxMax = -2147483647; | 0 | ||||||||||||||||||
| 360 | } else { | - | ||||||||||||||||||
| 361 | if (hasHorizontalSizeConstraint)
| 0 | ||||||||||||||||||
| 362 | d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration; never executed: d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration; | 0 | ||||||||||||||||||
| 363 | else | - | ||||||||||||||||||
| 364 | d->dxMax = INT_MAX; never executed: d->dxMax = 2147483647; | 0 | ||||||||||||||||||
| 365 | } | - | ||||||||||||||||||
| 366 | } | - | ||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | /*! | - | ||||||||||||||||||
| 370 | \fn void QSizeGrip::mouseMoveEvent(QMouseEvent * event) | - | ||||||||||||||||||
| 371 | Resizes the top-level widget containing this widget. The mouse | - | ||||||||||||||||||
| 372 | move event is passed in the \a event parameter. | - | ||||||||||||||||||
| 373 | */ | - | ||||||||||||||||||
| 374 | void QSizeGrip::mouseMoveEvent(QMouseEvent * e) | - | ||||||||||||||||||
| 375 | { | - | ||||||||||||||||||
| 376 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 377 | if (e->buttons() != Qt::LeftButton || d->m_platformSizeGrip) {
| 0 | ||||||||||||||||||
| 378 | QWidget::mouseMoveEvent(e); | - | ||||||||||||||||||
| 379 | return; never executed: return; | 0 | ||||||||||||||||||
| 380 | } | - | ||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | QWidget* tlw = qt_sizegrip_topLevelWidget(this); | - | ||||||||||||||||||
| 383 | if (!d->gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending))
| 0 | ||||||||||||||||||
| 384 | return; never executed: return; | 0 | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | QPoint np(e->globalPos()); | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | // Don't extend beyond the available geometry; bound to dyMax and dxMax. | - | ||||||||||||||||||
| 389 | QSize ns; | - | ||||||||||||||||||
| 390 | if (d->atBottom())
| 0 | ||||||||||||||||||
| 391 | ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax); never executed: ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax); | 0 | ||||||||||||||||||
| 392 | else | - | ||||||||||||||||||
| 393 | ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax); never executed: ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax); | 0 | ||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | if (d->atLeft())
| 0 | ||||||||||||||||||
| 396 | ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax); never executed: ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax); | 0 | ||||||||||||||||||
| 397 | else | - | ||||||||||||||||||
| 398 | ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax); never executed: ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax); | 0 | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | ns = QLayout::closestAcceptableSize(tlw, ns); | - | ||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | QPoint p; | - | ||||||||||||||||||
| 403 | QRect nr(p, ns); | - | ||||||||||||||||||
| 404 | if (d->atBottom()) {
| 0 | ||||||||||||||||||
| 405 | if (d->atLeft())
| 0 | ||||||||||||||||||
| 406 | nr.moveTopRight(d->r.topRight()); never executed: nr.moveTopRight(d->r.topRight()); | 0 | ||||||||||||||||||
| 407 | else | - | ||||||||||||||||||
| 408 | nr.moveTopLeft(d->r.topLeft()); never executed: nr.moveTopLeft(d->r.topLeft()); | 0 | ||||||||||||||||||
| 409 | } else { | - | ||||||||||||||||||
| 410 | if (d->atLeft())
| 0 | ||||||||||||||||||
| 411 | nr.moveBottomRight(d->r.bottomRight()); never executed: nr.moveBottomRight(d->r.bottomRight()); | 0 | ||||||||||||||||||
| 412 | else | - | ||||||||||||||||||
| 413 | nr.moveBottomLeft(d->r.bottomLeft()); never executed: nr.moveBottomLeft(d->r.bottomLeft()); | 0 | ||||||||||||||||||
| 414 | } | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | tlw->setGeometry(nr); | - | ||||||||||||||||||
| 417 | } never executed: end of block | 0 | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | /*! | - | ||||||||||||||||||
| 420 | \reimp | - | ||||||||||||||||||
| 421 | */ | - | ||||||||||||||||||
| 422 | void QSizeGrip::mouseReleaseEvent(QMouseEvent *mouseEvent) | - | ||||||||||||||||||
| 423 | { | - | ||||||||||||||||||
| 424 | if (mouseEvent->button() == Qt::LeftButton) {
| 0 | ||||||||||||||||||
| 425 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 426 | d->gotMousePress = false; | - | ||||||||||||||||||
| 427 | d->p = QPoint(); | - | ||||||||||||||||||
| 428 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 429 | QWidget::mouseReleaseEvent(mouseEvent); | - | ||||||||||||||||||
| 430 | } never executed: end of block | 0 | ||||||||||||||||||
| 431 | } | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | /*! | - | ||||||||||||||||||
| 434 | \reimp | - | ||||||||||||||||||
| 435 | */ | - | ||||||||||||||||||
| 436 | void QSizeGrip::moveEvent(QMoveEvent * /*moveEvent*/) | - | ||||||||||||||||||
| 437 | { | - | ||||||||||||||||||
| 438 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 439 | // We're inside a resize operation; no update necessary. | - | ||||||||||||||||||
| 440 | if (!d->p.isNull())
| 0 | ||||||||||||||||||
| 441 | return; never executed: return; | 0 | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | d->m_corner = d->corner(); | - | ||||||||||||||||||
| 444 | #if !defined(QT_NO_CURSOR) && !defined(Q_DEAD_CODE_FROM_QT4_MAC) | - | ||||||||||||||||||
| 445 | setCursor(d->m_corner == Qt::TopLeftCorner || d->m_corner == Qt::BottomRightCorner | - | ||||||||||||||||||
| 446 | ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor); | - | ||||||||||||||||||
| 447 | #endif | - | ||||||||||||||||||
| 448 | } never executed: end of block | 0 | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | /*! | - | ||||||||||||||||||
| 451 | \reimp | - | ||||||||||||||||||
| 452 | */ | - | ||||||||||||||||||
| 453 | void QSizeGrip::showEvent(QShowEvent *showEvent) | - | ||||||||||||||||||
| 454 | { | - | ||||||||||||||||||
| 455 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 456 | d_func()->updateMacSizer(false); | - | ||||||||||||||||||
| 457 | #endif | - | ||||||||||||||||||
| 458 | QWidget::showEvent(showEvent); | - | ||||||||||||||||||
| 459 | } never executed: end of block | 0 | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | /*! | - | ||||||||||||||||||
| 462 | \reimp | - | ||||||||||||||||||
| 463 | */ | - | ||||||||||||||||||
| 464 | void QSizeGrip::hideEvent(QHideEvent *hideEvent) | - | ||||||||||||||||||
| 465 | { | - | ||||||||||||||||||
| 466 | #ifdef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 467 | d_func()->updateMacSizer(true); | - | ||||||||||||||||||
| 468 | #endif | - | ||||||||||||||||||
| 469 | QWidget::hideEvent(hideEvent); | - | ||||||||||||||||||
| 470 | } never executed: end of block | 0 | ||||||||||||||||||
| 471 | - | |||||||||||||||||||
| 472 | /*! | - | ||||||||||||||||||
| 473 | \reimp | - | ||||||||||||||||||
| 474 | */ | - | ||||||||||||||||||
| 475 | void QSizeGrip::setVisible(bool visible) | - | ||||||||||||||||||
| 476 | { | - | ||||||||||||||||||
| 477 | QWidget::setVisible(visible); | - | ||||||||||||||||||
| 478 | } never executed: end of block | 0 | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | /*! \reimp */ | - | ||||||||||||||||||
| 481 | bool QSizeGrip::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||
| 482 | { | - | ||||||||||||||||||
| 483 | Q_D(QSizeGrip); | - | ||||||||||||||||||
| 484 | if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
| 0 | ||||||||||||||||||
| 485 | || e->type() != QEvent::WindowStateChange
| 0 | ||||||||||||||||||
| 486 | || o != d->tlw) {
| 0 | ||||||||||||||||||
| 487 | return QWidget::eventFilter(o, e); never executed: return QWidget::eventFilter(o, e); | 0 | ||||||||||||||||||
| 488 | } | - | ||||||||||||||||||
| 489 | Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; | - | ||||||||||||||||||
| 490 | #ifndef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||
| 491 | sizeGripNotVisibleState |= Qt::WindowMaximized; | - | ||||||||||||||||||
| 492 | #endif | - | ||||||||||||||||||
| 493 | // Don't show the size grip if the tlw is maximized or in full screen mode. | - | ||||||||||||||||||
| 494 | setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState)); | - | ||||||||||||||||||
| 495 | setAttribute(Qt::WA_WState_ExplicitShowHide, false); | - | ||||||||||||||||||
| 496 | return QWidget::eventFilter(o, e); never executed: return QWidget::eventFilter(o, e); | 0 | ||||||||||||||||||
| 497 | } | - | ||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | /*! | - | ||||||||||||||||||
| 500 | \reimp | - | ||||||||||||||||||
| 501 | */ | - | ||||||||||||||||||
| 502 | bool QSizeGrip::event(QEvent *event) | - | ||||||||||||||||||
| 503 | { | - | ||||||||||||||||||
| 504 | return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||||||||
| 505 | } | - | ||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 508 | - | |||||||||||||||||||
| 509 | #include "moc_qsizegrip.cpp" | - | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | #endif //QT_NO_SIZEGRIP | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |