| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWIDGETRESIZEHANDLER_P_H |
| 5 | #define QWIDGETRESIZEHANDLER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. This header file may |
| 12 | // change from version to version without notice, or even be |
| 13 | // removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
| 19 | #include "QtCore/qobject.h" |
| 20 | #include "QtCore/qpoint.h" |
| 21 | |
| 22 | QT_REQUIRE_CONFIG(resizehandler); |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QMouseEvent; |
| 27 | class QKeyEvent; |
| 28 | |
| 29 | class QWidgetResizeHandler : public QObject |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | |
| 33 | public: |
| 34 | explicit QWidgetResizeHandler(QWidget *parent, QWidget *cw = nullptr); |
| 35 | void setEnabled(bool b); |
| 36 | bool isEnabled() const; |
| 37 | |
| 38 | bool isButtonDown() const { return buttonDown; } |
| 39 | |
| 40 | void setExtraHeight(int h) { extrahei = h; } |
| 41 | |
| 42 | void setFrameWidth(int w) { fw = w; } |
| 43 | |
| 44 | void doResize(); |
| 45 | |
| 46 | Q_SIGNALS: |
| 47 | void activate(); |
| 48 | |
| 49 | protected: |
| 50 | bool eventFilter(QObject *o, QEvent *e) override; |
| 51 | void mouseMoveEvent(QMouseEvent *e); |
| 52 | void keyPressEvent(QKeyEvent *e); |
| 53 | |
| 54 | private: |
| 55 | Q_DISABLE_COPY_MOVE(QWidgetResizeHandler) |
| 56 | |
| 57 | enum MousePosition { |
| 58 | Nowhere, |
| 59 | TopLeft, BottomRight, BottomLeft, TopRight, |
| 60 | Top, Bottom, Left, Right, |
| 61 | Center |
| 62 | }; |
| 63 | |
| 64 | QWidget *widget; |
| 65 | QWidget *childWidget; |
| 66 | QPoint moveOffset; |
| 67 | QPoint invertedMoveOffset; |
| 68 | MousePosition mode; |
| 69 | int fw; |
| 70 | int extrahei; |
| 71 | int range; |
| 72 | uint buttonDown :1; |
| 73 | uint active :1; |
| 74 | uint enabled :1; |
| 75 | |
| 76 | void setMouseCursor(MousePosition m); |
| 77 | bool isResizing() const { |
| 78 | return active && mode != Center; |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | QT_END_NAMESPACE |
| 83 | |
| 84 | #endif // QWIDGETRESIZEHANDLER_P_H |
| 85 | |