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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
/* This file is part of the KDE project
Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <KoFrame.h>
#include <KoView.h>
#include <tqpainter.h>
#include <kparts/event.h>
#include <kcursor.h>
#include <kdebug.h>
#define TQMAX32767(a,b) TQMAX(TQMAX(32767,a),b)
class KoFramePrivate
{
public:
KoFramePrivate()
{
}
~KoFramePrivate()
{
}
KoView *m_view;
TQPoint m_mousePressPos;
TQPoint m_framePos;
int m_width;
int m_height;
int m_mode;
KoFrame::State m_state;
};
KoFrame::KoFrame( TQWidget *tqparent, const char *name )
: TQWidget( tqparent, name )
{
d = new KoFramePrivate;
d->m_state = Inactive;
d->m_mode = -1;
d->m_view = 0;
setBackgroundColor( white );
setMouseTracking( true );
}
KoFrame::~KoFrame()
{
delete d;
}
void KoFrame::setView( KoView *view )
{
if ( view == d->m_view )
return;
if ( d->m_view )
d->m_view->removeEventFilter( this );
d->m_view = view;
if ( d->m_view )
d->m_view->installEventFilter( this );
resizeEvent( 0L );
}
KoView *KoFrame::view() const
{
return d->m_view;
}
void KoFrame::setState( State s )
{
if ( d->m_state == s )
return;
State old = d->m_state;
d->m_state = s;
if ( d->m_view )
{
/*
kdDebug(30003) << "KoFrame::setView setMaximumSize "
<< "TQMAX32767(" << d->m_view->maximumWidth() + 2 * border() << "," << d->m_view->maximumWidth() << "), "
<< "TQMAX32767(" << d->m_view->maximumHeight() + 2 * border() << "," << d->m_view->maximumHeight() << ")"
<< endl;
*/
setMaximumSize( TQMAX32767( d->m_view->maximumWidth() + 2 * border(), d->m_view->maximumWidth() ),
TQMAX32767( d->m_view->maximumHeight() + 2 * border(), d->m_view->maximumHeight() ) );
setMinimumSize( d->m_view->minimumWidth() + leftBorder() + rightBorder(),
d->m_view->minimumHeight() + topBorder() + bottomBorder() );
}
if ( d->m_state == Inactive )
{
d->m_state = old;
int l = leftBorder();
int r = rightBorder();
int t = topBorder();
int b = bottomBorder();
d->m_state = Inactive;
setGeometry( x() + l, y() + t, width() - l - r, height() - t - b );
}
else if ( ( d->m_state == Active || d->m_state == Selected ) && old == Inactive )
setGeometry( x() - leftBorder(), y() - topBorder(),
width() + leftBorder() + rightBorder(),
height() + topBorder() + bottomBorder() );
else if ( d->m_state == Active && old == Selected )
{
setGeometry( x() - leftBorder() + border(), y() - topBorder() + border(),
width() + leftBorder() + rightBorder() - 2 * border(),
height() + topBorder() + bottomBorder() - 2 * border() );
}
update();
}
KoFrame::State KoFrame::state() const
{
return d->m_state;
}
int KoFrame::leftBorder() const
{
if ( d->m_state == Inactive )
return 0;
if ( d->m_state == Selected || !d->m_view )
return border();
return d->m_view->leftBorder() + border();
}
int KoFrame::rightBorder() const
{
if ( d->m_state == Inactive )
return 0;
if ( d->m_state == Selected || !d->m_view )
return border();
return d->m_view->rightBorder() + border();
}
int KoFrame::topBorder() const
{
if ( d->m_state == Inactive )
return 0;
if ( d->m_state == Selected || !d->m_view )
return border();
return d->m_view->topBorder() + border();
}
int KoFrame::bottomBorder() const
{
if ( d->m_state == Inactive )
return 0;
if ( d->m_state == Selected || !d->m_view )
return border();
return d->m_view->bottomBorder() + border();
}
int KoFrame::border() const
{
if ( d->m_state == Inactive )
return 0;
return 5;
}
void KoFrame::paintEvent( TQPaintEvent* )
{
TQPainter painter;
painter.begin( this );
painter.setPen( black );
painter.fillRect( 0, 0, width(), height(), BDiagPattern );
if ( d->m_state == Selected )
{
painter.fillRect( 0, 0, 5, 5, black );
painter.fillRect( 0, height() - 5, 5, 5, black );
painter.fillRect( width() - 5, height() - 5, 5, 5, black );
painter.fillRect( width() - 5, 0, 5, 5, black );
painter.fillRect( width() / 2 - 3, 0, 5, 5, black );
painter.fillRect( width() / 2 - 3, height() - 5, 5, 5, black );
painter.fillRect( 0, height() / 2 - 3, 5, 5, black );
painter.fillRect( width() - 5, height() / 2 - 3, 5, 5, black );
}
painter.end();
}
void KoFrame::mousePressEvent( TQMouseEvent* ev )
{
TQRect r1( 0, 0, 5, 5 );
TQRect r2( 0, height() - 5, 5, 5 );
TQRect r3( width() - 5, height() - 5, 5, 5 );
TQRect r4( width() - 5, 0, 5, 5 );
TQRect r5( width() / 2 - 3, 0, 5, 5 );
TQRect r6( width() / 2 - 3, height() - 5, 5, 5 );
TQRect r7( 0, height() / 2 - 3, 5, 5 );
TQRect r8( width()- 5, height() / 2 - 3, 5, 5 );
if ( r1.tqcontains( ev->pos() ) )
d->m_mode = 1;
else if ( r2.tqcontains( ev->pos() ) )
d->m_mode = 2;
else if ( r3.tqcontains( ev->pos() ) )
d->m_mode = 3;
else if ( r4.tqcontains( ev->pos() ) )
d->m_mode = 4;
else if ( r5.tqcontains( ev->pos() ) )
d->m_mode = 5;
else if ( r6.tqcontains( ev->pos() ) )
d->m_mode = 6;
else if ( r7.tqcontains( ev->pos() ) )
d->m_mode = 7;
else if ( r8.tqcontains( ev->pos() ) )
d->m_mode = 8;
else
d->m_mode = 0;
// if ( d->m_state == Active )
// d->m_mode = 0;
kdDebug(30003) << "---- MODE=" << d->m_mode << endl;
d->m_mousePressPos = mapToParent( ev->pos() );
d->m_framePos = mapToParent( TQPoint( 0, 0 ) );
d->m_width = width();
d->m_height = height();
}
void KoFrame::mouseMoveEvent( TQMouseEvent* ev )
{
if ( d->m_mode == 0 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
move( TQPoint( p.x() + d->m_framePos.x() - d->m_mousePressPos.x(),
p.y() + d->m_framePos.y() - d->m_mousePressPos.y() ) );
// The other modes change the tqgeometry so they call resizeEvent.
// This one doesn't, so it has to emit tqgeometryChangedby itself.
emit tqgeometryChanged();
//kdDebug() << "KoFrame::mouseMoveEvent koFrame position is " << x() << "," << y() << endl;
}
else if ( d->m_mode == 1 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int w = TQMIN( TQMAX( d->m_width + d->m_mousePressPos.x() - p.x(), minimumWidth() ), maximumWidth() );
int h = TQMIN( TQMAX( d->m_height + d->m_mousePressPos.y() - p.y(), minimumHeight() ), maximumHeight() );
setGeometry( d->m_framePos.x() - w + d->m_width,
d->m_framePos.y() - h + d->m_height, w, h );
}
else if ( d->m_mode == 2 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int w = TQMIN( TQMAX( d->m_width + d->m_mousePressPos.x() - p.x(), minimumWidth() ), maximumWidth() );
int h = TQMIN( TQMAX( d->m_height - d->m_mousePressPos.y() + p.y(), minimumHeight() ), maximumHeight() );
setGeometry( d->m_framePos.x() - w + d->m_width,
d->m_framePos.y(), w, h );
}
else if ( d->m_mode == 3 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int w = TQMIN( TQMAX( d->m_width - d->m_mousePressPos.x() + p.x(), minimumWidth() ), maximumWidth() );
int h = TQMIN( TQMAX( d->m_height - d->m_mousePressPos.y() + p.y(), minimumHeight() ), maximumHeight() );
resize( w, h );
}
else if ( d->m_mode == 4 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int w = TQMIN( TQMAX( d->m_width - d->m_mousePressPos.x() + p.x(), minimumWidth() ), maximumWidth() );
int h = TQMIN( TQMAX( d->m_height + d->m_mousePressPos.y() - p.y(), minimumHeight() ), maximumHeight() );
setGeometry( d->m_framePos.x(),
d->m_framePos.y() - h + d->m_height, w, h );
}
else if ( d->m_mode == 5 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int h = TQMIN( TQMAX( d->m_height + d->m_mousePressPos.y() - p.y(), minimumHeight() ), maximumHeight() );
setGeometry( d->m_framePos.x(),
d->m_framePos.y() - h + d->m_height, d->m_width, h );
}
else if ( d->m_mode == 6 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int h = TQMIN( TQMAX( d->m_height - d->m_mousePressPos.y() + p.y(), minimumHeight() ), maximumHeight() );
resize( d->m_width, h );
}
else if ( d->m_mode == 7 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int w = TQMIN( TQMAX( d->m_width + d->m_mousePressPos.x() - p.x(), minimumWidth() ), maximumWidth() );
setGeometry( d->m_framePos.x() - w + d->m_width,
d->m_framePos.y(), w, d->m_height );
}
else if ( d->m_mode == 8 )
{
TQPoint p = tqparentWidget()->mapFromGlobal( ev->globalPos() );
int w = TQMIN( TQMAX( d->m_width - d->m_mousePressPos.x() + p.x(), minimumWidth() ), maximumWidth() );
resize( w, d->m_height );
}
else if ( d->m_state == Selected || d->m_state == Active )
{
TQRect r1( 0, 0, 5, 5 );
TQRect r2( 0, height() - 5, 5, 5 );
TQRect r3( width() - 5, height() - 5, 5, 5 );
TQRect r4( width() - 5, 0, 5, 5 );
TQRect r5( width() / 2 - 3, 0, 5, 5 );
TQRect r6( width() / 2 - 3, height() - 5, 5, 5 );
TQRect r7( 0, height() / 2 - 3, 5, 5 );
TQRect r8( width()- 5, height() / 2 - 3, 5, 5 );
if ( r1.tqcontains( ev->pos() ) || r3.tqcontains( ev->pos() ) )
setCursor( sizeFDiagCursor );
else if ( r2.tqcontains( ev->pos() ) || r4.tqcontains( ev->pos() ) )
setCursor( sizeBDiagCursor );
else if ( r5.tqcontains( ev->pos() ) || r6.tqcontains( ev->pos() ) )
setCursor( sizeVerCursor );
else if ( r7.tqcontains( ev->pos() ) || r8.tqcontains( ev->pos() ) )
setCursor( sizeHorCursor );
else
setCursor( KCursor::handCursor() );
}
else
setCursor( KCursor::handCursor() );
}
void KoFrame::mouseReleaseEvent( TQMouseEvent* )
{
d->m_mode = -1;
}
void KoFrame::resizeEvent( TQResizeEvent* )
{
if ( !d->m_view )
return;
if ( d->m_state == Active || d->m_state == Selected )
d->m_view->setGeometry( 5, 5, width() - 10, height() - 10 );
else
d->m_view->setGeometry( 0, 0, width(), height() );
emit tqgeometryChanged();
}
bool KoFrame::eventFilter( TQObject* obj, TQEvent* ev )
{
if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(d->m_view) && KParts::PartActivateEvent::test( ev ) )
{
kdDebug(30003) << "Activate event"<< endl;
KParts::PartActivateEvent* e = (KParts::PartActivateEvent*)ev;
if ( e->part() == (KParts::Part *)d->m_view->koDocument() )
{
if ( e->activated() )
setState( Active );
else
setState( Inactive );
}
}
else if ( TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(d->m_view) && KParts::PartSelectEvent::test( ev ) )
{
kdDebug(30003) << "Selected event" << endl;
KParts::PartSelectEvent* e = (KParts::PartSelectEvent*)ev;
if ( e->part() == (KParts::Part *)d->m_view->koDocument() )
{
if ( e->selected() )
setState( Selected );
else
setState( Inactive );
}
}
return false;
}
#include <KoFrame.moc>
|