1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the widgets module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qsizegrip.h"
31
#ifndef QT_NO_SIZEGRIP
33
#include "qapplication.h"
37
#include "qstyleoption.h"
40
#include <private/qt_x11_p.h>
41
#elif defined (Q_WS_WIN)
42
#include "qt_windows.h"
45
#include <private/qwidget_p.h>
47
class QSizeGripPrivate : public QWidgetPrivate
49
Q_DECLARE_PUBLIC(QSizeGrip)
59
static QWidget *qt_sizegrip_topLevelWidget(QWidget* w)
61
QWidget *p = w->parentWidget();
62
while (!w->isWindow() && p && !p->inherits("QWorkspace")) {
64
p = p->parentWidget();
69
static QWidget* qt_sizegrip_workspace(QWidget* w)
71
while (w && !w->inherits("QWorkspace")) {
74
w = w->parentWidget();
81
\class QSizeGrip qsizegrip.h
83
\brief The QSizeGrip class provides a corner-grip for resizing a top-level window.
89
This widget works like the standard Windows resize handle. In the
90
X11 version this resize handle generally works differently from
91
the one provided by the system; we hope to reduce this difference
94
Put this widget anywhere in a widget tree and the user can use it
95
to resize the top-level window. Generally, this should be in the
96
lower right-hand corner. Note that QStatusBar already uses this
97
widget, so if you have a status bar (e.g. you are using
98
QMainWindow), then you don't need to use this widget explicitly.
100
On some platforms the sizegrip automatically hides itself when the
101
window is shown full screen or maximised.
103
\inlineimage qsizegrip-m.png Screenshot in Motif style
104
\inlineimage qsizegrip-w.png Screenshot in Windows style
106
\sa QStatusBar QWidget::windowState()
111
Constructs a resize corner as a child widget of \a
114
QSizeGrip::QSizeGrip(QWidget * parent)
115
: QWidget(*new QSizeGripPrivate, parent, 0)
125
Constructs a resize corner called \a name, as a child widget of \a
128
QSizeGrip::QSizeGrip(QWidget * parent, const char* name)
129
: QWidget(*new QSizeGripPrivate, parent, 0)
137
void QSizeGripPrivate::init()
140
hiddenByUser = false;
143
q->setCursor(q->isRightToLeft() ? Qt::SizeBDiagCursor : Qt::SizeFDiagCursor);
146
q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
147
#if defined(Q_WS_X11)
148
if (!qt_sizegrip_workspace(q)) {
150
XChangeProperty(X11->display, q->window()->winId(),
151
ATOM(_QT_SIZEGRIP), XA_WINDOW, 32, PropModeReplace,
152
(unsigned char *)&id, 1);
155
tlw = qt_sizegrip_topLevelWidget(q);
157
tlw->installEventFilter(q);
162
Destroys the size grip.
164
QSizeGrip::~QSizeGrip()
166
#if defined(Q_WS_X11)
167
if (!QApplication::closingDown() && parentWidget()) {
169
XChangeProperty(X11->display, window()->winId(),
170
ATOM(_QT_SIZEGRIP), XA_WINDOW, 32, PropModeReplace,
171
(unsigned char *)&id, 1);
177
Returns the size grip's size hint; this is a small size.
179
QSize QSizeGrip::sizeHint() const
183
return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this).
184
expandedTo(QApplication::globalStrut()));
188
Paints the resize grip. Resize grips are usually rendered as small
189
diagonal textured lines in the lower-right corner. The event is in
192
void QSizeGrip::paintEvent(QPaintEvent *event)
195
QPainter painter(this);
198
style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this);
202
Primes the resize operation. The event is in \a e.
204
void QSizeGrip::mousePressEvent(QMouseEvent * e)
207
d->p = e->globalPos();
208
d->s = qt_sizegrip_topLevelWidget(this)->size();
213
Resizes the top-level widget containing this widget. The event is
216
void QSizeGrip::mouseMoveEvent(QMouseEvent * e)
218
if (e->buttons() != Qt::LeftButton)
222
QWidget* tlw = qt_sizegrip_topLevelWidget(this);
223
if (tlw->testAttribute(Qt::WA_WState_ConfigPending))
226
QPoint np(e->globalPos());
228
QWidget* ws = qt_sizegrip_workspace(this);
230
QPoint tmp(ws->mapFromGlobal(np));
231
if (tmp.x() > ws->width())
232
tmp.setX(ws->width());
233
if (tmp.y() > ws->height())
234
tmp.setY(ws->height());
235
np = ws->mapToGlobal(tmp);
239
int h = np.y() - d->p.y() + d->s.height();
242
w = d->s.width() - (np.x() - d->p.x());
244
w = np.x() - d->p.x() + d->s.width();
250
QSize ms(tlw->minimumSize());
251
ms = ms.expandedTo(minimumSize());
257
if (isRightToLeft()) {
258
d->tlw->resize(w, h);
259
if (d->tlw->size() == QSize(w, h))
260
d->tlw->move(tlw->x() + (np.x() - d->p.x()), tlw->y());
262
d->tlw->resize(w, h);
266
while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
269
QApplication::syncX();
271
if (isRightToLeft() && d->tlw->size() == QSize(w,h)) {
272
d->s.rwidth() = tlw->size().width();
278
void QSizeGrip::setVisible(bool visible)
281
d->hiddenByUser = !visible;
282
QWidget::setVisible(visible);
287
bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
290
if (!d->hiddenByUser && e->type() == QEvent::WindowStateChange && o == d->tlw) {
291
QWidget::setVisible((d->tlw->windowState() &
292
(Qt::WindowFullScreen
294
| Qt::WindowMaximized
302
bool QSizeGrip::event(QEvent *e)
305
#if defined(Q_WS_MAC)
308
if(!QApplication::closingDown() && parentWidget() && !qt_sizegrip_workspace(this)) {
309
if(QWidget *w = qt_sizegrip_topLevelWidget(this)) {
311
QWidgetPrivate::qt_mac_update_sizer(w, e->type() == QEvent::Hide ? -1 : 1);
319
return QWidget::event(e);
322
#endif //QT_NO_SIZEGRIP