0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "qsizegrip.h"
|
|
43 |
|
|
44 |
#ifndef QT_NO_SIZEGRIP
|
|
45 |
|
|
46 |
#include "qapplication.h"
|
|
47 |
#include "qevent.h"
|
|
48 |
#include "qpainter.h"
|
|
49 |
#include "qstyle.h"
|
|
50 |
#include "qstyleoption.h"
|
|
51 |
#include "qlayout.h"
|
|
52 |
#include "qdebug.h"
|
|
53 |
#include <QDesktopWidget>
|
|
54 |
|
|
55 |
#if defined(Q_WS_X11)
|
|
56 |
#include <private/qt_x11_p.h>
|
|
57 |
#elif defined (Q_WS_WIN)
|
|
58 |
#include "qt_windows.h"
|
|
59 |
#endif
|
|
60 |
#ifdef Q_WS_MAC
|
|
61 |
#include <private/qt_mac_p.h>
|
|
62 |
#endif
|
|
63 |
|
|
64 |
#include <private/qwidget_p.h>
|
|
65 |
#include <QtGui/qabstractscrollarea.h>
|
|
66 |
|
|
67 |
#define SZ_SIZEBOTTOMRIGHT 0xf008
|
|
68 |
#define SZ_SIZEBOTTOMLEFT 0xf007
|
|
69 |
#define SZ_SIZETOPLEFT 0xf004
|
|
70 |
#define SZ_SIZETOPRIGHT 0xf005
|
|
71 |
|
|
72 |
QT_BEGIN_NAMESPACE
|
|
73 |
|
|
74 |
static QWidget *qt_sizegrip_topLevelWidget(QWidget* w)
|
|
75 |
{
|
|
76 |
while (w && !w->isWindow() && w->windowType() != Qt::SubWindow)
|
|
77 |
w = w->parentWidget();
|
|
78 |
return w;
|
|
79 |
}
|
|
80 |
|
|
81 |
static inline bool hasHeightForWidth(QWidget *widget)
|
|
82 |
{
|
|
83 |
if (!widget)
|
|
84 |
return false;
|
|
85 |
if (QLayout *layout = widget->layout())
|
|
86 |
return layout->hasHeightForWidth();
|
|
87 |
return widget->sizePolicy().hasHeightForWidth();
|
|
88 |
}
|
|
89 |
|
|
90 |
class QSizeGripPrivate : public QWidgetPrivate
|
|
91 |
{
|
|
92 |
Q_DECLARE_PUBLIC(QSizeGrip)
|
|
93 |
public:
|
|
94 |
void init();
|
|
95 |
QPoint p;
|
|
96 |
QRect r;
|
|
97 |
int d;
|
|
98 |
int dxMax;
|
|
99 |
int dyMax;
|
|
100 |
Qt::Corner m_corner;
|
|
101 |
bool gotMousePress;
|
|
102 |
#ifdef Q_WS_MAC
|
|
103 |
void updateMacSizer(bool hide) const;
|
|
104 |
#endif
|
|
105 |
Qt::Corner corner() const;
|
|
106 |
inline bool atBottom() const
|
|
107 |
{
|
|
108 |
return m_corner == Qt::BottomRightCorner || m_corner == Qt::BottomLeftCorner;
|
|
109 |
}
|
|
110 |
|
|
111 |
inline bool atLeft() const
|
|
112 |
{
|
|
113 |
return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner;
|
|
114 |
}
|
|
115 |
|
|
116 |
// This slot is invoked by QLayout when the size grip is added to
|
|
117 |
// a layout or reparented after the tlw is shown. This re-implementation is basically
|
|
118 |
// the same as QWidgetPrivate::_q_showIfNotHidden except that it checks
|
|
119 |
// for Qt::WindowFullScreen and Qt::WindowMaximized as well.
|
|
120 |
void _q_showIfNotHidden()
|
|
121 |
{
|
|
122 |
Q_Q(QSizeGrip);
|
|
123 |
bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
|
|
124 |
QWidget *tlw = qt_sizegrip_topLevelWidget(q);
|
|
125 |
if (tlw && showSizeGrip) {
|
|
126 |
Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
|
|
127 |
#ifndef Q_WS_MAC
|
|
128 |
sizeGripNotVisibleState |= Qt::WindowMaximized;
|
|
129 |
#endif
|
|
130 |
// Don't show the size grip if the tlw is maximized or in full screen mode.
|
|
131 |
showSizeGrip = !(tlw->windowState() & sizeGripNotVisibleState);
|
|
132 |
}
|
|
133 |
if (showSizeGrip)
|
|
134 |
q->setVisible(true);
|
|
135 |
}
|
|
136 |
};
|
|
137 |
|
|
138 |
#ifdef Q_WS_MAC
|
|
139 |
void QSizeGripPrivate::updateMacSizer(bool hide) const
|
|
140 |
{
|
|
141 |
Q_Q(const QSizeGrip);
|
|
142 |
if (QApplication::closingDown() || !parent)
|
|
143 |
return;
|
|
144 |
QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q));
|
|
145 |
if(topLevelWindow && topLevelWindow->isWindow())
|
|
146 |
QWidgetPrivate::qt_mac_update_sizer(topLevelWindow, hide ? -1 : 1);
|
|
147 |
}
|
|
148 |
#endif
|
|
149 |
|
|
150 |
Qt::Corner QSizeGripPrivate::corner() const
|
|
151 |
{
|
|
152 |
Q_Q(const QSizeGrip);
|
|
153 |
QWidget *tlw = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q));
|
|
154 |
const QPoint sizeGripPos = q->mapTo(tlw, QPoint(0, 0));
|
|
155 |
bool isAtBottom = sizeGripPos.y() >= tlw->height() / 2;
|
|
156 |
bool isAtLeft = sizeGripPos.x() <= tlw->width() / 2;
|
|
157 |
if (isAtLeft)
|
|
158 |
return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
|
|
159 |
else
|
|
160 |
return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner;
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
\class QSizeGrip
|
|
165 |
|
|
166 |
\brief The QSizeGrip class provides a resize handle for resizing top-level windows.
|
|
167 |
|
|
168 |
\ingroup mainwindow-classes
|
|
169 |
\ingroup basicwidgets
|
|
170 |
|
|
171 |
This widget works like the standard Windows resize handle. In the
|
|
172 |
X11 version this resize handle generally works differently from
|
|
173 |
the one provided by the system if the X11 window manager does not
|
|
174 |
support necessary modern post-ICCCM specifications.
|
|
175 |
|
|
176 |
Put this widget anywhere in a widget tree and the user can use it
|
|
177 |
to resize the top-level window or any widget with the Qt::SubWindow
|
|
178 |
flag set. Generally, this should be in the lower right-hand corner.
|
|
179 |
Note that QStatusBar already uses this widget, so if you have a
|
|
180 |
status bar (e.g., you are using QMainWindow), then you don't need
|
|
181 |
to use this widget explicitly.
|
|
182 |
|
|
183 |
On some platforms the size grip automatically hides itself when the
|
|
184 |
window is shown full screen or maximised.
|
|
185 |
|
|
186 |
\table 50%
|
|
187 |
\row \o \inlineimage plastique-sizegrip.png Screenshot of a Plastique style size grip
|
|
188 |
\o A size grip widget at the bottom-right corner of a main window, shown in the
|
|
189 |
\l{Plastique Style Widget Gallery}{Plastique widget style}.
|
|
190 |
\endtable
|
|
191 |
|
|
192 |
The QSizeGrip class inherits QWidget and reimplements the \l
|
|
193 |
{QWidget::mousePressEvent()}{mousePressEvent()} and \l
|
|
194 |
{QWidget::mouseMoveEvent()}{mouseMoveEvent()} functions to feature
|
|
195 |
the resize functionality, and the \l
|
|
196 |
{QWidget::paintEvent()}{paintEvent()} function to render the
|
|
197 |
size grip widget.
|
|
198 |
|
|
199 |
\sa QStatusBar QWidget::windowState()
|
|
200 |
*/
|
|
201 |
|
|
202 |
|
|
203 |
/*!
|
|
204 |
Constructs a resize corner as a child widget of the given \a
|
|
205 |
parent.
|
|
206 |
*/
|
|
207 |
QSizeGrip::QSizeGrip(QWidget * parent)
|
|
208 |
: QWidget(*new QSizeGripPrivate, parent, 0)
|
|
209 |
{
|
|
210 |
Q_D(QSizeGrip);
|
|
211 |
d->init();
|
|
212 |
}
|
|
213 |
|
|
214 |
#ifdef QT3_SUPPORT
|
|
215 |
/*!
|
|
216 |
\obsolete
|
|
217 |
|
|
218 |
Constructs a resize corner with the given \a name, as a child
|
|
219 |
widget of the given \a parent.
|
|
220 |
*/
|
|
221 |
QSizeGrip::QSizeGrip(QWidget * parent, const char* name)
|
|
222 |
: QWidget(*new QSizeGripPrivate, parent, 0)
|
|
223 |
{
|
|
224 |
Q_D(QSizeGrip);
|
|
225 |
setObjectName(QString::fromAscii(name));
|
|
226 |
d->init();
|
|
227 |
}
|
|
228 |
#endif
|
|
229 |
|
|
230 |
void QSizeGripPrivate::init()
|
|
231 |
{
|
|
232 |
Q_Q(QSizeGrip);
|
|
233 |
dxMax = 0;
|
|
234 |
dyMax = 0;
|
|
235 |
m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
|
|
236 |
gotMousePress = false;
|
|
237 |
|
|
238 |
#if !defined(QT_NO_CURSOR) && !defined(Q_WS_MAC)
|
|
239 |
q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner
|
|
240 |
? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
|
|
241 |
#endif
|
|
242 |
q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
|
|
243 |
QWidget *tlw = qt_sizegrip_topLevelWidget(q);
|
|
244 |
tlw->installEventFilter(q);
|
|
245 |
}
|
|
246 |
|
|
247 |
|
|
248 |
/*!
|
|
249 |
Destroys this size grip.
|
|
250 |
*/
|
|
251 |
QSizeGrip::~QSizeGrip()
|
|
252 |
{
|
|
253 |
}
|
|
254 |
|
|
255 |
/*!
|
|
256 |
\reimp
|
|
257 |
*/
|
|
258 |
QSize QSizeGrip::sizeHint() const
|
|
259 |
{
|
|
260 |
QStyleOption opt(0);
|
|
261 |
opt.init(this);
|
|
262 |
return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this).
|
|
263 |
expandedTo(QApplication::globalStrut()));
|
|
264 |
}
|
|
265 |
|
|
266 |
/*!
|
|
267 |
Paints the resize grip.
|
|
268 |
|
|
269 |
Resize grips are usually rendered as small diagonal textured lines
|
|
270 |
in the lower-right corner. The paint event is passed in the \a
|
|
271 |
event parameter.
|
|
272 |
*/
|
|
273 |
void QSizeGrip::paintEvent(QPaintEvent *event)
|
|
274 |
{
|
|
275 |
Q_UNUSED(event);
|
|
276 |
Q_D(QSizeGrip);
|
|
277 |
QPainter painter(this);
|
|
278 |
QStyleOptionSizeGrip opt;
|
|
279 |
opt.init(this);
|
|
280 |
opt.corner = d->m_corner;
|
|
281 |
style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this);
|
|
282 |
}
|
|
283 |
|
|
284 |
/*!
|
|
285 |
\fn void QSizeGrip::mousePressEvent(QMouseEvent * event)
|
|
286 |
|
|
287 |
Receives the mouse press events for the widget, and primes the
|
|
288 |
resize operation. The mouse press event is passed in the \a event
|
|
289 |
parameter.
|
|
290 |
*/
|
|
291 |
void QSizeGrip::mousePressEvent(QMouseEvent * e)
|
|
292 |
{
|
|
293 |
if (e->button() != Qt::LeftButton) {
|
|
294 |
QWidget::mousePressEvent(e);
|
|
295 |
return;
|
|
296 |
}
|
|
297 |
|
|
298 |
Q_D(QSizeGrip);
|
|
299 |
QWidget *tlw = qt_sizegrip_topLevelWidget(this);
|
|
300 |
d->p = e->globalPos();
|
|
301 |
d->gotMousePress = true;
|
|
302 |
d->r = tlw->geometry();
|
|
303 |
|
|
304 |
#ifdef Q_WS_X11
|
|
305 |
// Use a native X11 sizegrip for "real" top-level windows if supported.
|
|
306 |
if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE))
|
|
307 |
&& !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) {
|
|
308 |
XEvent xev;
|
|
309 |
xev.xclient.type = ClientMessage;
|
|
310 |
xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE);
|
|
311 |
xev.xclient.display = X11->display;
|
|
312 |
xev.xclient.window = tlw->winId();
|
|
313 |
xev.xclient.format = 32;
|
|
314 |
xev.xclient.data.l[0] = e->globalPos().x();
|
|
315 |
xev.xclient.data.l[1] = e->globalPos().y();
|
|
316 |
if (d->atBottom())
|
|
317 |
xev.xclient.data.l[2] = d->atLeft() ? 6 : 4; // bottomleft/bottomright
|
|
318 |
else
|
|
319 |
xev.xclient.data.l[2] = d->atLeft() ? 0 : 2; // topleft/topright
|
|
320 |
xev.xclient.data.l[3] = Button1;
|
|
321 |
xev.xclient.data.l[4] = 0;
|
|
322 |
XUngrabPointer(X11->display, X11->time);
|
|
323 |
XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False,
|
|
324 |
SubstructureRedirectMask | SubstructureNotifyMask, &xev);
|
|
325 |
return;
|
|
326 |
}
|
|
327 |
#endif // Q_WS_X11
|
|
328 |
#ifdef Q_WS_WIN
|
|
329 |
if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) {
|
|
330 |
uint orientation = 0;
|
|
331 |
if (d->atBottom())
|
|
332 |
orientation = d->atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT;
|
|
333 |
else
|
|
334 |
orientation = d->atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT;
|
|
335 |
|
|
336 |
ReleaseCapture();
|
|
337 |
PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0);
|
|
338 |
return;
|
|
339 |
}
|
|
340 |
#endif // Q_WS_WIN
|
|
341 |
|
|
342 |
// Find available desktop/workspace geometry.
|
|
343 |
QRect availableGeometry;
|
|
344 |
bool hasVerticalSizeConstraint = true;
|
|
345 |
bool hasHorizontalSizeConstraint = true;
|
|
346 |
if (tlw->isWindow())
|
|
347 |
availableGeometry = QApplication::desktop()->availableGeometry(tlw);
|
|
348 |
else {
|
|
349 |
const QWidget *tlwParent = tlw->parentWidget();
|
|
350 |
// Check if tlw is inside QAbstractScrollArea/QScrollArea.
|
|
351 |
// If that's the case tlw->parentWidget() will return the viewport
|
|
352 |
// and tlw->parentWidget()->parentWidget() will return the scroll area.
|
|
353 |
#ifndef QT_NO_SCROLLAREA
|
|
354 |
QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget());
|
|
355 |
if (scrollArea) {
|
|
356 |
hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
|
|
357 |
hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
|
|
358 |
}
|
|
359 |
#endif // QT_NO_SCROLLAREA
|
|
360 |
availableGeometry = tlwParent->contentsRect();
|
|
361 |
}
|
|
362 |
|
|
363 |
// Find frame geometries, title bar height, and decoration sizes.
|
|
364 |
const QRect frameGeometry = tlw->frameGeometry();
|
|
365 |
const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0);
|
|
366 |
const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0);
|
|
367 |
const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0);
|
|
368 |
|
|
369 |
// Determine dyMax depending on whether the sizegrip is at the bottom
|
|
370 |
// of the widget or not.
|
|
371 |
if (d->atBottom()) {
|
|
372 |
if (hasVerticalSizeConstraint)
|
|
373 |
d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration;
|
|
374 |
else
|
|
375 |
d->dyMax = INT_MAX;
|
|
376 |
} else {
|
|
377 |
if (hasVerticalSizeConstraint)
|
|
378 |
d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight;
|
|
379 |
else
|
|
380 |
d->dyMax = -INT_MAX;
|
|
381 |
}
|
|
382 |
|
|
383 |
// In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace
|
|
384 |
// geometry, the size grip geometry and the width of the decoration.
|
|
385 |
if (d->atLeft()) {
|
|
386 |
if (hasHorizontalSizeConstraint)
|
|
387 |
d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration;
|
|
388 |
else
|
|
389 |
d->dxMax = -INT_MAX;
|
|
390 |
} else {
|
|
391 |
if (hasHorizontalSizeConstraint)
|
|
392 |
d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration;
|
|
393 |
else
|
|
394 |
d->dxMax = INT_MAX;
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
|
|
399 |
/*!
|
|
400 |
\fn void QSizeGrip::mouseMoveEvent(QMouseEvent * event)
|
|
401 |
Resizes the top-level widget containing this widget. The mouse
|
|
402 |
move event is passed in the \a event parameter.
|
|
403 |
*/
|
|
404 |
void QSizeGrip::mouseMoveEvent(QMouseEvent * e)
|
|
405 |
{
|
|
406 |
if (e->buttons() != Qt::LeftButton) {
|
|
407 |
QWidget::mouseMoveEvent(e);
|
|
408 |
return;
|
|
409 |
}
|
|
410 |
|
|
411 |
Q_D(QSizeGrip);
|
|
412 |
QWidget* tlw = qt_sizegrip_topLevelWidget(this);
|
|
413 |
if (!d->gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending))
|
|
414 |
return;
|
|
415 |
|
|
416 |
#ifdef Q_WS_X11
|
|
417 |
if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE))
|
|
418 |
&& tlw->isTopLevel() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw))
|
|
419 |
return;
|
|
420 |
#endif
|
|
421 |
#ifdef Q_WS_WIN
|
|
422 |
if (tlw->isWindow() && GetSystemMenu(tlw->winId(), FALSE) != 0 && internalWinId()
|
|
423 |
&& !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !hasHeightForWidth(tlw)) {
|
|
424 |
MSG msg;
|
|
425 |
while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
|
|
426 |
return;
|
|
427 |
}
|
|
428 |
#endif
|
|
429 |
|
|
430 |
QPoint np(e->globalPos());
|
|
431 |
|
|
432 |
// Don't extend beyond the available geometry; bound to dyMax and dxMax.
|
|
433 |
QSize ns;
|
|
434 |
if (d->atBottom())
|
|
435 |
ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax);
|
|
436 |
else
|
|
437 |
ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax);
|
|
438 |
|
|
439 |
if (d->atLeft())
|
|
440 |
ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax);
|
|
441 |
else
|
|
442 |
ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax);
|
|
443 |
|
|
444 |
ns = QLayout::closestAcceptableSize(tlw, ns);
|
|
445 |
|
|
446 |
QPoint p;
|
|
447 |
QRect nr(p, ns);
|
|
448 |
if (d->atBottom()) {
|
|
449 |
if (d->atLeft())
|
|
450 |
nr.moveTopRight(d->r.topRight());
|
|
451 |
else
|
|
452 |
nr.moveTopLeft(d->r.topLeft());
|
|
453 |
} else {
|
|
454 |
if (d->atLeft())
|
|
455 |
nr.moveBottomRight(d->r.bottomRight());
|
|
456 |
else
|
|
457 |
nr.moveBottomLeft(d->r.bottomLeft());
|
|
458 |
}
|
|
459 |
|
|
460 |
tlw->setGeometry(nr);
|
|
461 |
}
|
|
462 |
|
|
463 |
/*!
|
|
464 |
\reimp
|
|
465 |
*/
|
|
466 |
void QSizeGrip::mouseReleaseEvent(QMouseEvent *mouseEvent)
|
|
467 |
{
|
|
468 |
if (mouseEvent->button() == Qt::LeftButton) {
|
|
469 |
Q_D(QSizeGrip);
|
|
470 |
d->gotMousePress = false;
|
|
471 |
d->p = QPoint();
|
|
472 |
} else {
|
|
473 |
QWidget::mouseReleaseEvent(mouseEvent);
|
|
474 |
}
|
|
475 |
}
|
|
476 |
|
|
477 |
/*!
|
|
478 |
\reimp
|
|
479 |
*/
|
|
480 |
void QSizeGrip::moveEvent(QMoveEvent * /*moveEvent*/)
|
|
481 |
{
|
|
482 |
Q_D(QSizeGrip);
|
|
483 |
// We're inside a resize operation; no update necessary.
|
|
484 |
if (!d->p.isNull())
|
|
485 |
return;
|
|
486 |
|
|
487 |
d->m_corner = d->corner();
|
|
488 |
#if !defined(QT_NO_CURSOR) && !defined(Q_WS_MAC)
|
|
489 |
setCursor(d->m_corner == Qt::TopLeftCorner || d->m_corner == Qt::BottomRightCorner
|
|
490 |
? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
|
|
491 |
#endif
|
|
492 |
}
|
|
493 |
|
|
494 |
/*!
|
|
495 |
\reimp
|
|
496 |
*/
|
|
497 |
void QSizeGrip::showEvent(QShowEvent *showEvent)
|
|
498 |
{
|
|
499 |
#ifdef Q_WS_MAC
|
|
500 |
d_func()->updateMacSizer(false);
|
|
501 |
#endif
|
|
502 |
QWidget::showEvent(showEvent);
|
|
503 |
}
|
|
504 |
|
|
505 |
/*!
|
|
506 |
\reimp
|
|
507 |
*/
|
|
508 |
void QSizeGrip::hideEvent(QHideEvent *hideEvent)
|
|
509 |
{
|
|
510 |
#ifdef Q_WS_MAC
|
|
511 |
d_func()->updateMacSizer(true);
|
|
512 |
#endif
|
|
513 |
QWidget::hideEvent(hideEvent);
|
|
514 |
}
|
|
515 |
|
|
516 |
/*!
|
|
517 |
\reimp
|
|
518 |
*/
|
|
519 |
void QSizeGrip::setVisible(bool visible)
|
|
520 |
{
|
|
521 |
QWidget::setVisible(visible);
|
|
522 |
}
|
|
523 |
|
|
524 |
/*! \reimp */
|
|
525 |
bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
|
|
526 |
{
|
|
527 |
if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
|
|
528 |
|| e->type() != QEvent::WindowStateChange) {
|
|
529 |
return QWidget::eventFilter(o, e);
|
|
530 |
}
|
|
531 |
QWidget *tlw = qt_sizegrip_topLevelWidget(this);
|
|
532 |
if (o != tlw)
|
|
533 |
return QWidget::eventFilter(o, e);
|
|
534 |
Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
|
|
535 |
#ifndef Q_WS_MAC
|
|
536 |
sizeGripNotVisibleState |= Qt::WindowMaximized;
|
|
537 |
#endif
|
|
538 |
// Don't show the size grip if the tlw is maximized or in full screen mode.
|
|
539 |
setVisible(!(tlw->windowState() & sizeGripNotVisibleState));
|
|
540 |
setAttribute(Qt::WA_WState_ExplicitShowHide, false);
|
|
541 |
return QWidget::eventFilter(o, e);
|
|
542 |
}
|
|
543 |
|
|
544 |
/*!
|
|
545 |
\reimp
|
|
546 |
*/
|
|
547 |
bool QSizeGrip::event(QEvent *event)
|
|
548 |
{
|
|
549 |
return QWidget::event(event);
|
|
550 |
}
|
|
551 |
|
|
552 |
#ifdef Q_WS_WIN
|
|
553 |
/*! \reimp */
|
|
554 |
bool QSizeGrip::winEvent( MSG *m, long *result )
|
|
555 |
{
|
|
556 |
return QWidget::winEvent(m, result);
|
|
557 |
}
|
|
558 |
#endif
|
|
559 |
|
|
560 |
QT_END_NAMESPACE
|
|
561 |
|
|
562 |
#include "moc_qsizegrip.cpp"
|
|
563 |
|
|
564 |
#endif //QT_NO_SIZEGRIP
|