summaryrefslogtreecommitdiffstats
path: root/tqtinterface/qt4/src/kernel/tqsizegrip.cpp
blob: f47665133f006fbcfbf7a517f98e7a86c50ba381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/****************************************************************************
**
** Implementation of TQSizeGrip class
**
** Created : 980119
**
** Copyright (C) 2010 Timothy Pearson and (C) 1992-2008 Trolltech ASA.
**
** This file is part of the kernel module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "sizegrip.h"

#ifndef TQT_NO_SIZEGRIP

#include "tqpainter.h"
#include "tqapplication.h"
#include "tqstyle.h"

#if defined(TQ_WS_X11)
#include "tqt_x11_p.h"
extern Atom qt_sizegrip;			// defined in qapplication_x11.cpp
#elif defined (TQ_WS_WIN )
#include "tqobjectlist.h"
#include "tqt_windows.h"
#elif defined(TQ_WS_MAC)
bool qt_mac_update_sizer(TQWidget *, int); //qwidget_mac.cpp
#endif


static TQWidget *qt_sizegrip_tqtopLevelWidget( TQWidget* w)
{
    TQWidget *p = w->parentWidget();
    while ( !w->isTopLevel() && p && !p->inherits("TQWorkspace") ) {
	w = p;
	p = p->parentWidget();
    }
    return w;
}

static TQWidget* qt_sizegrip_workspace( TQWidget* w )
{
    while ( w && !w->inherits("TQWorkspace" ) ) {
	if ( w->isTopLevel() )
	    return 0;
	w = w->parentWidget();
    }
    return w;
}


/*!
    \class TQSizeGrip sizegrip.h

    \brief The TQSizeGrip class provides a corner-grip for resizing a top-level window.

    \ingroup application
    \ingroup basic
    \ingroup appearance

    This widget works like the standard Windows resize handle. In the
    X11 version this resize handle generally works differently from
    the one provided by the system; we hope to reduce this difference
    in the future.

    Put this widget anywhere in a widget tree and the user can use it
    to resize the top-level window. Generally, this should be in the
    lower right-hand corner. Note that TQStatusBar already uses this
    widget, so if you have a status bar (e.g. you are using
    TQMainWindow), then you don't need to use this widget explicitly.

    <img src=qsizegrip-m.png> <img src=qsizegrip-w.png>

    \sa TQStatusBar
*/


/*!
    Constructs a resize corner called \a name, as a child widget of \a
    tqparent.
*/
TQSizeGrip::TQSizeGrip( TQWidget * tqparent, const char* name )
    : TQWidget( tqparent, name )
{
#ifndef TQT_NO_CURSOR
#ifndef TQ_WS_MAC
    if ( TQApplication::reverseLayout() )
	setCursor( Qt::SizeBDiagCursor );
    else
	setCursor( Qt::SizeFDiagCursor );
#endif
#endif
    tqsetSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) );
#if defined(TQ_WS_X11)
    if ( !qt_sizegrip_workspace( this ) ) {
	WId id = winId();
	XChangeProperty(qt_xdisplay(), tqtopLevelWidget()->winId(),
			qt_sizegrip, XA_WINDOW, 32, PropModeReplace,
			(unsigned char *)&id, 1);
    }
#endif
    tlw = qt_sizegrip_tqtopLevelWidget( this );
    if ( tlw )
	tlw->installEventFilter( this );
    installEventFilter( this ); //for binary compatibility fix in 4.0 with an event() ###
}


/*!
    Destroys the size grip.
*/
TQSizeGrip::~TQSizeGrip()
{
#if defined(TQ_WS_X11)
    if ( !TQApplication::closingDown() && parentWidget() ) {
	WId id = None;
 	XChangeProperty(qt_xdisplay(), tqtopLevelWidget()->winId(),
 			qt_sizegrip, XA_WINDOW, 32, PropModeReplace,
 			(unsigned char *)&id, 1);
    }
#endif
}

/*!
    Returns the size grip's size hint; this is a small size.
*/
TQSize TQSizeGrip::sizeHint() const
{
    return (tqstyle().sizeFromContents(TQStyle::CT_SizeGrip, this, TQSize(13, 13)).
	    expandedTo(TQApplication::globalStrut()));
}

/*!
    Paints the resize grip. Resize grips are usually rendered as small
    diagonal textured lines in the lower-right corner. The event is in
    \a e.
*/
void TQSizeGrip::paintEvent( TQPaintEvent *e )
{
    TQPainter painter( this );
    painter.setClipRegion(e->region());
    tqstyle().tqdrawPrimitive(TQStyle::PE_SizeGrip, &painter, rect(), tqcolorGroup());
}

/*!
    Primes the resize operation. The event is in \a e.
*/
void TQSizeGrip::mousePressEvent( TQMouseEvent * e )
{
    p = e->globalPos();
    s = qt_sizegrip_tqtopLevelWidget(this)->size();
}


/*!
    Resizes the top-level widget containing this widget. The event is
    in \a e.
*/
void TQSizeGrip::mouseMoveEvent( TQMouseEvent * e )
{
    if ( e->state() != Qt::LeftButton )
	return;

    TQWidget* tlw = qt_sizegrip_tqtopLevelWidget(this);
    if ( tlw->testWState((WState)TQt::WState_ConfigPending) )
	return;

    TQPoint np( e->globalPos() );

    TQWidget* ws = qt_sizegrip_workspace( this );
    if ( ws ) {
	TQPoint tmp( ws->mapFromGlobal( np ) );
	if ( tmp.x() > ws->width() )
	    tmp.setX( ws->width() );
	if ( tmp.y() > ws->height() )
	    tmp.setY( ws->height() );
	np = ws->mapToGlobal( tmp );
    }

    int w;
    int h = np.y() - p.y() + s.height();

    if ( TQApplication::reverseLayout() )
	w = s.width() - ( np.x() - p.x() );
    else
	w = np.x() - p.x() + s.width();

    if ( w < 1 )
	w = 1;
    if ( h < 1 )
	h = 1;
    TQSize ms( tlw->tqminimumSizeHint() );
    ms = ms.expandedTo( tqminimumSize() );
    if ( w < ms.width() )
	w = ms.width();
    if ( h < ms.height() )
	h = ms.height();

    if (TQApplication::reverseLayout()) {
	tlw->resize( w, h );
	if (tlw->size() == TQSize(w,h))
	    tlw->move( tlw->x() + ( np.x()-p.x() ), tlw->y() );
    } else {
	tlw->resize( w, h );
    }
#ifdef TQ_WS_WIN
    MSG msg;
    while( PeekMessage( &msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE ) )
      ;
#endif
    TQApplication::syncX();

    if ( TQApplication::reverseLayout() && tlw->size() == TQSize(w,h) ) {
	s.rwidth() = tlw->size().width();
	p.rx() = np.x();
    }
}

/*! \reimp */
bool TQSizeGrip::eventFilter( TQObject *o, TQEvent *e )
{
    if ( static_cast<TQT_BASE_OBJECT_NAME*>(o) == tlw ) {
	switch ( e->type() ) {
#ifndef TQ_WS_MAC
	/* The size grip goes no where on Mac OS X when you maximize!  --Sam */
	case TQEvent::ShowMaximized:
#endif
	case TQEvent::ShowFullScreen:
	    hide();
	    break;
	case TQEvent::ShowNormal:
	    show();
	    break;
	default:
	    break;
	}
    } else if(static_cast<TQT_BASE_OBJECT_NAME*>(o) == this) {
#if defined(TQ_WS_MAC)
	switch(e->type()) {
	case TQEvent::Hide:
	case TQEvent::Show:
	    if(!TQApplication::closingDown() && parentWidget() && !qt_sizegrip_workspace(this)) {
		if(TQWidget *w = qt_sizegrip_tqtopLevelWidget(this)) {
		    if(w->isTopLevel())
			qt_mac_update_sizer(w, e->type() == TQEvent::Hide ? -1 : 1);
		}
	    }
	    break;
	default:
	    break;
	}
 #endif
    }
    return FALSE;
}

#endif //TQT_NO_SIZEGRIP