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#ifndef QWIDGETRESIZEHANDLER_P_H
41#define QWIDGETRESIZEHANDLER_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. This header file may
48// change from version to version without notice, or even be
49// removed.
50//
51// We mean it.
52//
53
54#include <QtWidgets/private/qtwidgetsglobal_p.h>
55#include "QtCore/qobject.h"
56#include "QtCore/qpoint.h"
57
58QT_REQUIRE_CONFIG(resizehandler);
59
60QT_BEGIN_NAMESPACE
61
62class QMouseEvent;
63class QKeyEvent;
64
65class Q_WIDGETS_EXPORT QWidgetResizeHandler : public QObject
66{
67 Q_OBJECT
68
69public:
70 enum Action {
71 Move = 0x01,
72 Resize = 0x02,
73 Any = Move|Resize
74 };
75
76 explicit QWidgetResizeHandler(QWidget *parent, QWidget *cw = nullptr);
77 void setActive(bool b) { setActive(Any, b); }
78 void setActive(Action ac, bool b);
79 bool isActive() const { return isActive(Any); }
80 bool isActive(Action ac) const;
81 void setMovingEnabled(bool b) { movingEnabled = b; }
82 bool isMovingEnabled() const { return movingEnabled; }
83
84 bool isButtonDown() const { return buttonDown; }
85
86 void setExtraHeight(int h) { extrahei = h; }
87 void setSizeProtection(bool b) { sizeprotect = b; }
88
89 void setFrameWidth(int w) { fw = w; }
90
91 void doResize();
92 void doMove();
93
94Q_SIGNALS:
95 void activate();
96
97protected:
98 bool eventFilter(QObject *o, QEvent *e) override;
99 void mouseMoveEvent(QMouseEvent *e);
100 void keyPressEvent(QKeyEvent *e);
101
102private:
103 Q_DISABLE_COPY_MOVE(QWidgetResizeHandler)
104
105 enum MousePosition {
106 Nowhere,
107 TopLeft, BottomRight, BottomLeft, TopRight,
108 Top, Bottom, Left, Right,
109 Center
110 };
111
112 QWidget *widget;
113 QWidget *childWidget;
114 QPoint moveOffset;
115 QPoint invertedMoveOffset;
116 MousePosition mode;
117 int fw;
118 int extrahei;
119 int range;
120 uint buttonDown :1;
121 uint moveResizeMode :1;
122 uint activeForResize :1;
123 uint sizeprotect :1;
124 uint movingEnabled :1;
125 uint activeForMove :1;
126
127 void setMouseCursor(MousePosition m);
128 bool isMove() const {
129 return moveResizeMode && mode == Center;
130 }
131 bool isResize() const {
132 return moveResizeMode && !isMove();
133 }
134};
135
136QT_END_NAMESPACE
137
138#endif // QWIDGETRESIZEHANDLER_P_H
139