source: trunk/src/kernel/qsizegrip.cpp

Last change on this file was 8, checked in by dmik, 20 years ago

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1/****************************************************************************
2** $Id: qsizegrip.cpp 8 2005-11-16 19:36:46Z dmik $
3**
4** Implementation of QSizeGrip class
5**
6** Created : 980119
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qsizegrip.h"
39
40#ifndef QT_NO_SIZEGRIP
41
42#include "qpainter.h"
43#include "qapplication.h"
44#include "qstyle.h"
45
46#if defined(Q_WS_X11)
47#include "qt_x11_p.h"
48extern Atom qt_sizegrip; // defined in qapplication_x11.cpp
49#elif defined (Q_WS_WIN )
50#include "qobjectlist.h"
51#include "qt_windows.h"
52#elif defined (Q_WS_PM)
53#include "qobjectlist.h"
54#include "qt_os2.h"
55#elif defined(Q_WS_MAC)
56bool qt_mac_update_sizer(QWidget *, int); //qwidget_mac.cpp
57#endif
58
59
60static QWidget *qt_sizegrip_topLevelWidget( QWidget* w)
61{
62 QWidget *p = w->parentWidget();
63 while ( !w->isTopLevel() && p && !p->inherits("QWorkspace") ) {
64 w = p;
65 p = p->parentWidget();
66 }
67 return w;
68}
69
70static QWidget* qt_sizegrip_workspace( QWidget* w )
71{
72 while ( w && !w->inherits("QWorkspace" ) ) {
73 if ( w->isTopLevel() )
74 return 0;
75 w = w->parentWidget();
76 }
77 return w;
78}
79
80
81/*!
82 \class QSizeGrip qsizegrip.h
83
84 \brief The QSizeGrip class provides a corner-grip for resizing a top-level window.
85
86 \ingroup application
87 \ingroup basic
88 \ingroup appearance
89
90 This widget works like the standard Windows resize handle. In the
91 X11 version this resize handle generally works differently from
92 the one provided by the system; we hope to reduce this difference
93 in the future.
94
95 Put this widget anywhere in a widget tree and the user can use it
96 to resize the top-level window. Generally, this should be in the
97 lower right-hand corner. Note that QStatusBar already uses this
98 widget, so if you have a status bar (e.g. you are using
99 QMainWindow), then you don't need to use this widget explicitly.
100
101 <img src=qsizegrip-m.png> <img src=qsizegrip-w.png>
102
103 \sa QStatusBar
104*/
105
106
107/*!
108 Constructs a resize corner called \a name, as a child widget of \a
109 parent.
110*/
111QSizeGrip::QSizeGrip( QWidget * parent, const char* name )
112 : QWidget( parent, name )
113{
114#ifndef QT_NO_CURSOR
115#ifndef Q_WS_MAC
116 if ( QApplication::reverseLayout() )
117 setCursor( sizeBDiagCursor );
118 else
119 setCursor( sizeFDiagCursor );
120#endif
121#endif
122 setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
123#if defined(Q_WS_X11)
124 if ( !qt_sizegrip_workspace( this ) ) {
125 WId id = winId();
126 XChangeProperty(qt_xdisplay(), topLevelWidget()->winId(),
127 qt_sizegrip, XA_WINDOW, 32, PropModeReplace,
128 (unsigned char *)&id, 1);
129 }
130#endif
131 tlw = qt_sizegrip_topLevelWidget( this );
132 if ( tlw )
133 tlw->installEventFilter( this );
134 installEventFilter( this ); //for binary compatibility fix in 4.0 with an event() ###
135}
136
137
138/*!
139 Destroys the size grip.
140*/
141QSizeGrip::~QSizeGrip()
142{
143#if defined(Q_WS_X11)
144 if ( !QApplication::closingDown() && parentWidget() ) {
145 WId id = None;
146 XChangeProperty(qt_xdisplay(), topLevelWidget()->winId(),
147 qt_sizegrip, XA_WINDOW, 32, PropModeReplace,
148 (unsigned char *)&id, 1);
149 }
150#endif
151}
152
153/*!
154 Returns the size grip's size hint; this is a small size.
155*/
156QSize QSizeGrip::sizeHint() const
157{
158 return (style().sizeFromContents(QStyle::CT_SizeGrip, this, QSize(13, 13)).
159 expandedTo(QApplication::globalStrut()));
160}
161
162/*!
163 Paints the resize grip. Resize grips are usually rendered as small
164 diagonal textured lines in the lower-right corner. The event is in
165 \a e.
166*/
167void QSizeGrip::paintEvent( QPaintEvent *e )
168{
169 QPainter painter( this );
170 painter.setClipRegion(e->region());
171 style().drawPrimitive(QStyle::PE_SizeGrip, &painter, rect(), colorGroup());
172}
173
174/*!
175 Primes the resize operation. The event is in \a e.
176*/
177void QSizeGrip::mousePressEvent( QMouseEvent * e )
178{
179 p = e->globalPos();
180 s = qt_sizegrip_topLevelWidget(this)->size();
181}
182
183
184/*!
185 Resizes the top-level widget containing this widget. The event is
186 in \a e.
187*/
188void QSizeGrip::mouseMoveEvent( QMouseEvent * e )
189{
190 if ( e->state() != LeftButton )
191 return;
192
193 QWidget* tlw = qt_sizegrip_topLevelWidget(this);
194 if ( tlw->testWState(WState_ConfigPending) )
195 return;
196
197 QPoint np( e->globalPos() );
198
199 QWidget* ws = qt_sizegrip_workspace( this );
200 if ( ws ) {
201 QPoint tmp( ws->mapFromGlobal( np ) );
202 if ( tmp.x() > ws->width() )
203 tmp.setX( ws->width() );
204 if ( tmp.y() > ws->height() )
205 tmp.setY( ws->height() );
206 np = ws->mapToGlobal( tmp );
207 }
208
209 int w;
210 int h = np.y() - p.y() + s.height();
211
212 if ( QApplication::reverseLayout() )
213 w = s.width() - ( np.x() - p.x() );
214 else
215 w = np.x() - p.x() + s.width();
216
217 if ( w < 1 )
218 w = 1;
219 if ( h < 1 )
220 h = 1;
221 QSize ms( tlw->minimumSizeHint() );
222 ms = ms.expandedTo( minimumSize() );
223 if ( w < ms.width() )
224 w = ms.width();
225 if ( h < ms.height() )
226 h = ms.height();
227
228 if (QApplication::reverseLayout()) {
229 if (tlw->isTopLevel()) {
230 int x = tlw->geometry().x() + ( np.x()-p.x() );
231 int y = tlw->geometry().y();
232 tlw->setGeometry(x,y,w,h);
233 } else {
234 tlw->resize( w, h );
235 if (tlw->size() == QSize(w,h))
236 tlw->move( tlw->x() + ( np.x()-p.x() ), tlw->y() );
237 }
238 } else {
239 tlw->resize( w, h );
240 }
241#if defined (Q_WS_WIN)
242 MSG msg;
243 while( PeekMessage( &msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE ) )
244 ;
245#elif defined (Q_WS_PM)
246//@@TODO (dmik): is the code below really necessary?
247 QMSG qmsg;
248 while( WinPeekMsg( 0, &qmsg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE ) )
249 ;
250#endif
251 QApplication::syncX();
252
253 if ( QApplication::reverseLayout() && tlw->size() == QSize(w,h) ) {
254 s.rwidth() = tlw->size().width();
255 p.rx() = np.x();
256 }
257}
258
259/*! \reimp */
260bool QSizeGrip::eventFilter( QObject *o, QEvent *e )
261{
262 if ( o == tlw ) {
263 switch ( e->type() ) {
264#ifndef Q_WS_MAC
265 /* The size grip goes no where on Mac OS X when you maximize! --Sam */
266 case QEvent::ShowMaximized:
267#endif
268 case QEvent::ShowFullScreen:
269 hide();
270 break;
271 case QEvent::ShowNormal:
272 show();
273 break;
274 default:
275 break;
276 }
277 } else if(o == this) {
278#if defined(Q_WS_MAC)
279 switch(e->type()) {
280 case QEvent::Hide:
281 case QEvent::Show:
282 if(!QApplication::closingDown() && parentWidget() && !qt_sizegrip_workspace(this)) {
283 if(QWidget *w = qt_sizegrip_topLevelWidget(this)) {
284 if(w->isTopLevel())
285 qt_mac_update_sizer(w, e->type() == QEvent::Hide ? -1 : 1);
286 }
287 }
288 break;
289 default:
290 break;
291 }
292 #endif
293 }
294 return FALSE;
295}
296
297#endif //QT_NO_SIZEGRIP
Note: See TracBrowser for help on using the repository browser.