summaryrefslogtreecommitdiffstats
path: root/kolourpaint/patches/doc_resize_no_flicker.diff
blob: ae5f9aba29372cc47a1d97add1aa1289ac461999 (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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
Eliminates flicker when moving document resize lines / dragging resize
handles by:

1. Not erasing areas that will be subsequently painted over with resize
   lines.
2. Erasing the old areas and painting the new ones atomicly by using
   clever NOT'ing of pixels.

Additionally, recover the resize lines after a window pops up momentarily
over KolourPaint (kpViewScrollableContainer::windowActivationChange()).

Critical bugs with this code and scrollbars:

1. Drag scrolling leaves trails of resize lines.
2. Moving the mouse cursor above the start of the document does not result
   in a resize line at document y = 1.

Because I'm still debugging, there are a few hacks in the code such as
"m_resizeLinesDontPaintClever".

Index: kpviewscrollablecontainer.cpp
===================================================================
RCS file: /home/kde/kdegraphics/kolourpaint/kpviewscrollablecontainer.cpp,v
retrieving revision 1.7
diff -u -p -r1.7 kpviewscrollablecontainer.cpp
--- kpviewscrollablecontainer.cpp	29 Jul 2004 12:47:15 -0000	1.7
+++ kpviewscrollablecontainer.cpp	30 Jul 2004 11:37:20 -0000
@@ -1,4 +1,4 @@
-
+static bool inScroll = false;
 /*
    Copyright (c) 2003-2004 Clarence Dang <dang@kde.org>
    All rights reserved.
@@ -33,6 +33,7 @@
 #include <qpainter.h>
 #include <qpen.h>
 #include <qpixmap.h>
+#include <qregion.h>
 #include <qtimer.h>
 
 #include <kdebug.h>
@@ -240,7 +241,7 @@ void kpGrip::mousePressEvent (QMouseEven
         m_startPoint = e->pos ();
         m_currentPoint = e->pos ();
         emit beganDraw ();
-        grabKeyboard ();
+        //grabKeyboard ();  HACK
 
         setUserMessage (i18n ("Resize Image: Right click to cancel."));
         setCursor (cursorForType (m_type));
@@ -387,6 +388,7 @@ kpViewScrollableContainer::kpViewScrolla
       m_scrollTimerRunOnce (false),
       m_resizeRoundedLastViewX (-1), m_resizeRoundedLastViewY (-1),
       m_resizeRoundedLastViewDX (0), m_resizeRoundedLastViewDY (0),
+      m_resizeLinesDontPaintClever (0),
       m_haveMovedFromOriginalDocSize (false)
 
 {
@@ -561,6 +563,18 @@ QRect kpViewScrollableContainer::bottomR
                           m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1));
 }
 
+// protected
+QRegion kpViewScrollableContainer::resizeLinesRegion () const
+{
+    QRegion ret;
+
+    ret += rightResizeLineRect ();
+    ret += bottomResizeLineRect ();
+    ret += bottomRightResizeLineRect ();
+
+    return ret;
+}
+
 
 // TODO: are these 2 correct?  Remember that viewport()->x() == 1, viewport()->y() == 1
 
@@ -581,6 +595,17 @@ QRect kpViewScrollableContainer::mapView
     return ret;
 }
 
+// protected
+QRegion kpViewScrollableContainer::mapViewToViewport (const QRegion &viewRegion)
+{
+    if (viewRegion.isEmpty ())
+        return viewRegion;
+
+    QRegion ret = viewRegion;
+    ret.translate (-contentsX (), -contentsY ());
+    return ret;
+}
+
 
 // protected
 QRect kpViewScrollableContainer::mapViewportToGlobal (const QRect &viewportRect)
@@ -589,89 +614,108 @@ QRect kpViewScrollableContainer::mapView
 }
 
 // protected
+QRegion kpViewScrollableContainer::mapViewportToGlobal (const QRegion &viewportRegion)
+{
+    return kpWidgetMapper::toGlobal (viewport (), viewportRegion);
+}
+
+
+// protected
 QRect kpViewScrollableContainer::mapViewToGlobal (const QRect &viewRect)
 {
     return mapViewportToGlobal (mapViewToViewport (viewRect));
 }
 
+// protected
+QRegion kpViewScrollableContainer::mapViewToGlobal (const QRegion &viewRegion)
+{
+    return mapViewportToGlobal (mapViewToViewport (viewRegion));
+}
+
 
 // protected
-void kpViewScrollableContainer::repaintWidgetAtResizeLineViewRect (
-    QWidget *widget, const QRect &resizeLineViewRect)
+void kpViewScrollableContainer::repaintWidgetRegion (
+    QWidget *widget,
+    const QRegion &viewRegion)
 {
-    const QRect resizeLineGlobalRect = mapViewToGlobal (resizeLineViewRect);
+    const QRegion globalRegion = mapViewToGlobal (viewRegion);
+
     const QRect widgetGlobalRect = kpWidgetMapper::toGlobal (widget,
                                                              widget->rect ());
 
-    const QRect redrawGlobalRect =
-        resizeLineGlobalRect.intersect (widgetGlobalRect);
 
-    const QRect redrawWidgetRect =
-        kpWidgetMapper::fromGlobal (widget, redrawGlobalRect);
+    const QRegion redrawGlobalRegion =
+        globalRegion.intersect (widgetGlobalRect);
 
+    const QRegion redrawWidgetRegion =
+        kpWidgetMapper::fromGlobal (widget, redrawGlobalRegion);
 
-    if (redrawWidgetRect.isValid ())
+
+    if (!redrawWidgetRegion.isEmpty ())
     {
         // TODO: should be "!widget->testWFlags (Qt::WRepaintNoErase)"
         //       but for some reason, doesn't work for viewport().
         const bool erase = !dynamic_cast <kpView *> (widget);
-        widget->repaint (redrawWidgetRect, erase);
+        widget->repaint (redrawWidgetRegion, erase);
     }
 }
 
 // protected
-void kpViewScrollableContainer::repaintWidgetAtResizeLines (QWidget *widget)
+void kpViewScrollableContainer::eraseResizeLines (const QRegion &viewRegion)
 {
-    repaintWidgetAtResizeLineViewRect (widget, rightResizeLineRect ());
-    repaintWidgetAtResizeLineViewRect (widget, bottomResizeLineRect ());
-    repaintWidgetAtResizeLineViewRect (widget, bottomRightResizeLineRect ());
-}
+    if (viewRegion.isEmpty ())
+        return;
 
-// protected
-void kpViewScrollableContainer::eraseResizeLines ()
-{
-    if (m_resizeRoundedLastViewX >= 0 && m_resizeRoundedLastViewY >= 0)
-    {
-        repaintWidgetAtResizeLines (viewport ());
-        repaintWidgetAtResizeLines (m_view);
 
-        repaintWidgetAtResizeLines (m_bottomGrip);
-        repaintWidgetAtResizeLines (m_rightGrip);
-        repaintWidgetAtResizeLines (m_bottomRightGrip);
-    }
+    repaintWidgetRegion (viewport (), viewRegion);
+    repaintWidgetRegion (m_view, viewRegion);
+
+    repaintWidgetRegion (m_bottomGrip, viewRegion);
+    repaintWidgetRegion (m_rightGrip, viewRegion);
+    repaintWidgetRegion (m_bottomRightGrip, viewRegion);
 }
 
 
 // protected
-void kpViewScrollableContainer::drawResizeLines ()
+void kpViewScrollableContainer::drawResizeLines (const QRegion &viewRegion)
 {
 #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
-    kdDebug () << "kpViewScrollableContainer::drawResizeLines()"
+    kdDebug () << "kpViewScrollableContainer::drawResizeLines("
+               << viewRegion <<")"
                << " lastViewX=" << m_resizeRoundedLastViewX
                << " lastViewY=" << m_resizeRoundedLastViewY
                << endl;
 #endif
 
+    if (viewRegion.isEmpty ())
+        return;
+
 
     QPainter p (viewport (), true/*unclipped*/);
     p.setRasterOp (Qt::NotROP);
 
-    const QRect rightRect = rightResizeLineRect ();
-    if (rightRect.isValid ())
-        p.fillRect (mapViewToViewport (rightRect), Qt::white);
-
-    const QRect bottomRect = bottomResizeLineRect ();
-    if (bottomRect.isValid ())
-        p.fillRect (mapViewToViewport (bottomRect), Qt::white);
-
-    const QRect bottomRightRect = bottomRightResizeLineRect ();
-    if (bottomRightRect.isValid ())
-        p.fillRect (mapViewToViewport (bottomRightRect), Qt::white);
+    const QMemArray <QRect> rects = mapViewToViewport (viewRegion).rects ();
+    for (QMemArray <QRect>::ConstIterator it = rects.begin ();
+         it != rects.end ();
+         it++)
+    {
+        p.fillRect (*it, Qt::white);
+    }
 
     p.end ();
 }
 
 
+template <typename T>
+static inline void swap (T &a, T &b)
+{
+    T temp = a;
+
+    a = b;
+    b = temp;
+}
+
+
 // protected
 void kpViewScrollableContainer::updateResizeLines (int viewX, int viewY,
                                                    int viewDX, int viewDY)
@@ -686,36 +730,71 @@ void kpViewScrollableContainer::updateRe
                << endl;
 #endif
 
-    eraseResizeLines ();
-
+    int newResizeRoundedLastViewX = -1,
+        newResizeRoundedLastViewY = -1;
+    int newResizeRoundedLastViewDX = 0,
+        newResizeRoundedLastViewDY = 0;
 
     if (viewX >= 0 && viewY >= 0)
     {
-        m_resizeRoundedLastViewX = m_view->zoomDocToViewX (m_view->zoomViewToDocX (viewX));
-        m_resizeRoundedLastViewY = m_view->zoomDocToViewY (m_view->zoomViewToDocY (viewY));
+        newResizeRoundedLastViewX = m_view->zoomDocToViewX (m_view->zoomViewToDocX (viewX));
+        newResizeRoundedLastViewY = m_view->zoomDocToViewY (m_view->zoomViewToDocY (viewY));
 
-        m_resizeRoundedLastViewDX = viewDX;
-        m_resizeRoundedLastViewDY = viewDY;
+        newResizeRoundedLastViewDX = viewDX;
+        newResizeRoundedLastViewDY = viewDY;
     }
-    else
-    {
-        m_resizeRoundedLastViewX = -1;
-        m_resizeRoundedLastViewY = -1;
 
-        m_resizeRoundedLastViewDX = 0;
-        m_resizeRoundedLastViewDY = 0;
-    }
 
-    // TODO: This is suboptimal since if another window pops up on top of
-    //       KolourPaint then disappears, the lines are not redrawn
-    //       (although this doesn't happen very frequently since we grab the
-    //       keyboard and mouse when resizing):
-    //
-    //         e.g. sleep 5 && gedit & sleep 10 && killall gedit
+    QRegion oldLinesRegion = resizeLinesRegion ();
+#if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
+    kdDebug () << "\toldLinesRegion=" << oldLinesRegion << endl;
+#endif
+
+
+// (macro instead of writing out code to permit experimentation)
+#define SWAP_LAST_VIEW_STATS()                                     \
+{                                                                  \
+    swap (m_resizeRoundedLastViewX, newResizeRoundedLastViewX);    \
+    swap (m_resizeRoundedLastViewY, newResizeRoundedLastViewY);    \
+                                                                   \
+    swap (m_resizeRoundedLastViewDX, newResizeRoundedLastViewDX);  \
+    swap (m_resizeRoundedLastViewDY, newResizeRoundedLastViewDY);  \
+}
+    SWAP_LAST_VIEW_STATS ();
+#undef SWAP_LAST_VIEW_STATS
+
+
+    QRegion newLinesRegion = resizeLinesRegion ();
+#if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
+    kdDebug () << "\tnewLinesRegion=" << newLinesRegion << endl;
+#endif
+
+
+    // TODO: This is suboptimal - we will get redraw errors sooner or later.
+    //       But I've tried hard to avoid them (e.g. windowActivationChange()).
     //
     //       Should be done in the paintEvent's of every child of the
     //       scrollview.
-    drawResizeLines ();
+
+    if (m_resizeLinesDontPaintClever)
+    {
+        // (drawResizeLines() NOT's the pixels - so we can erase old and draw
+        //  new at the same time)
+        drawResizeLines (newLinesRegion.eor (oldLinesRegion));
+    #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
+        kdDebug () << "\tNOTRregion="
+                   << newLinesRegion.eor (oldLinesRegion) << endl;
+    #endif
+    }
+    else
+    {
+        eraseResizeLines (oldLinesRegion);
+        drawResizeLines (newLinesRegion);
+    #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
+        kdDebug () << "\tnot erasing old lines; NOTRregion="
+                   << newLinesRegion << endl;
+    #endif
+    }
 }
 
 
@@ -729,6 +808,8 @@ void kpViewScrollableContainer::slotGrip
 
     m_haveMovedFromOriginalDocSize = false;
 
+    m_resizeLinesDontPaintClever = true;
+
     updateResizeLines (m_view->width (), m_view->height (),
                        0/*viewDX*/, 0/*viewDY*/);
 
@@ -750,12 +831,28 @@ void kpViewScrollableContainer::slotGrip
 
     m_haveMovedFromOriginalDocSize = true;
 
+#if 0
+    if (inScroll != !m_resizeLinesNeedErase)
+    {
+        kdError () << "slotGripContDraw EXCEPTION 0: inScroll=" << inScroll << endl;
+        memset (0, 42, 1048576);
+    }
+#endif
+
     updateResizeLines (QMAX (1, QMAX (m_view->width () + viewDX, m_view->zoomDocToViewX (1))),
                        QMAX (1, QMAX (m_view->height () + viewDY, m_view->zoomDocToViewY (1))),
                        viewDX, viewDY);
 
     emit continuedDocResize (newDocSize ());
 
+#if 0
+    if (!m_resizeLinesNeedErase)
+    {
+        kdError () << "slotGripContDraw EXCEPTION 1" << endl;
+        memset (0, 42, 1048576);
+    }
+#endif
+
     beginDragScroll (QPoint (), QPoint (), m_view->zoomLevelX ());
 }
 
@@ -859,8 +956,19 @@ void kpViewScrollableContainer::slotCont
                << x << "," << y << ")" << endl;
 #endif
 
+    m_resizeLinesDontPaintClever++;
+
+    if (inScroll && 0)
+    {
+        kdError () << "slotContentsMovING EXCEPTION" << endl;
+        memset (0, 42, 1048576);
+    }
+
+    inScroll = true;
     // Reduce flicker - don't let QScrollView scroll to-be-erased lines
-    eraseResizeLines ();
+    //eraseResizeLines (resizeLinesRegion ());
+    //m_resizeLinesNeedErase = false;
+
 
     QTimer::singleShot (0, this, SLOT (slotContentsMoved ()));
 }
@@ -874,9 +982,27 @@ void kpViewScrollableContainer::slotCont
                << " grip=" << grip << endl;
 #endif
     if (!grip)
+    {
+        inScroll = false;
         return;
+    }
 
+    if (!inScroll && 0)
+    {
+        kdError () << "slotContentsMoved EXCEPTION" << endl;
+        memset (0, 42, 1048576);
+    }
     grip->mouseMovedTo (grip->mapFromGlobal (QCursor::pos ()));
+#if 0
+    if (!m_resizeLinesNeedErase)
+    {
+        kdError () << "slotContentsMoved EXCEPTION 2" << endl;
+        memset (0, 42, 1048576);
+    }
+#endif
+    inScroll = false;
+
+    m_resizeLinesDontPaintClever--;
 }
 
 
@@ -1191,7 +1317,7 @@ bool kpViewScrollableContainer::eventFil
 // protected virtual [base QScrollView]
 void kpViewScrollableContainer::viewportPaintEvent (QPaintEvent *e)
 {
-#if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
+#if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0
     kdDebug () << "kpViewScrollableContainer::viewportPaintEvent("
                << e->rect ()
                << ")" << endl;
@@ -1213,4 +1339,42 @@ void kpViewScrollableContainer::paintEve
 }
 
 
+// protected slot
+void kpViewScrollableContainer::windowActivationChanged ()
+{
+    if (isActiveWindow () &&
+        m_resizeRoundedLastViewX >= 0 && m_resizeRoundedLastViewY >= 0)
+    {
+        // We were obscured by a window that popped up monmentarily and
+        // this clobbered the resize lines (since the scrollView's child
+        // widgets don't draw them).  This doesn't happen very frequently
+        // since we grab the keyboard and mouse when resizing but:
+        //
+        //     e.g. sleep 5 && gedit & sleep 10 && killall gedit
+        //
+
+        // Repaint child widgets at the resize lines to make sure any
+        // remains of the resize lines are gone.
+        eraseResizeLines (resizeLinesRegion ());
+
+        // Draw the resize lines by NOT-ing the child widget pixels.
+        drawResizeLines (resizeLinesRegion ());
+    }
+}
+
+// protected virtual [base QWidget]
+void kpViewScrollableContainer::windowActivationChange (bool wasActive)
+{
+#if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 1
+    kdDebug () << "kpViewScrollableContainer::windowActivationChange("
+               << wasActive << ")" << endl;
+#endif
+
+    QScrollView::windowActivationChange (wasActive);
+
+    // Wait for m_view to update
+    QTimer::singleShot (0, this, SLOT (windowActivationChanged ()));
+}
+
+
 #include <kpviewscrollablecontainer.moc>
Index: kpviewscrollablecontainer.h
===================================================================
RCS file: /home/kde/kdegraphics/kolourpaint/kpviewscrollablecontainer.h,v
retrieving revision 1.3
diff -u -p -r1.3 kpviewscrollablecontainer.h
--- kpviewscrollablecontainer.h	19 Jul 2004 05:00:47 -0000	1.3
+++ kpviewscrollablecontainer.h	30 Jul 2004 11:37:21 -0000
@@ -31,6 +31,7 @@
 
 
 #include <qpoint.h>
+#include <qregion.h>
 #include <qscrollview.h>
 #include <qsize.h>
 
@@ -147,19 +148,23 @@ protected:
     QRect bottomResizeLineRect () const;
     QRect rightResizeLineRect () const;
     QRect bottomRightResizeLineRect () const;
+    QRegion resizeLinesRegion () const;
 
     QPoint mapViewToViewport (const QPoint &viewPoint);
     QRect mapViewToViewport (const QRect &viewRect);
+    QRegion mapViewToViewport (const QRegion &viewRegion);
 
     QRect mapViewportToGlobal (const QRect &viewportRect);
+    QRegion mapViewportToGlobal (const QRegion &viewportRegion);
+
     QRect mapViewToGlobal (const QRect &viewRect);
+    QRegion mapViewToGlobal (const QRegion &viewRegion);
 
-    void repaintWidgetAtResizeLineViewRect (QWidget *widget,
-                                            const QRect &resizeLineViewRect);
-    void repaintWidgetAtResizeLines (QWidget *widget);
-    void eraseResizeLines ();
+    void repaintWidgetRegion (QWidget *widget,
+        const QRegion &viewRegion);
+    void eraseResizeLines (const QRegion &viewRegion);
 
-    void drawResizeLines ();
+    void drawResizeLines (const QRegion &viewRegion);
 
     void updateResizeLines (int viewX, int viewY,
                             int viewDX, int viewDY);
@@ -213,6 +218,12 @@ protected:
     virtual void viewportPaintEvent (QPaintEvent *e);
     virtual void paintEvent (QPaintEvent *e);
 
+protected slots:
+    void windowActivationChanged ();
+protected:
+    virtual void windowActivationChange (bool wasActive);
+
+
 protected:
     kpMainWindow *m_mainWindow;
     kpView *m_view;
@@ -223,6 +234,7 @@ protected:
     bool m_scrollTimerRunOnce;
     int m_resizeRoundedLastViewX, m_resizeRoundedLastViewY;
     int m_resizeRoundedLastViewDX, m_resizeRoundedLastViewDY;
+    int m_resizeLinesDontPaintClever;
     bool m_haveMovedFromOriginalDocSize;
     QString m_gripStatusMessage;
 };
Index: kpwidgetmapper.cpp
===================================================================
RCS file: /home/kde/kdegraphics/kolourpaint/kpwidgetmapper.cpp,v
retrieving revision 1.1
diff -u -p -r1.1 kpwidgetmapper.cpp
--- kpwidgetmapper.cpp	10 Jul 2004 11:38:09 -0000	1.1
+++ kpwidgetmapper.cpp	30 Jul 2004 11:37:21 -0000
@@ -30,6 +30,7 @@
 
 #include <qpoint.h>
 #include <qrect.h>
+#include <qregion.h>
 #include <qwidget.h>
 
 
@@ -54,6 +55,17 @@ QRect fromGlobal (const QWidget *widget,
     return QRect (topLeft.x (), topLeft.y (), rect.width (), rect.height ());
 }
 
+QRegion fromGlobal (const QWidget *widget, const QRegion &region)
+{
+    if (!widget || region.isEmpty ())
+        return region;
+
+    const QPoint widgetGlobalTopLeft = toGlobal (widget, QPoint (0, 0));
+    QRegion ret = region;
+    ret.translate (-widgetGlobalTopLeft.x (), -widgetGlobalTopLeft.y ());
+    return ret;
+}
+
 
 QPoint toGlobal (const QWidget *widget, const QPoint &point)
 {
@@ -72,5 +84,16 @@ QRect toGlobal (const QWidget *widget, c
     return QRect (topLeft.x (), topLeft.y (), rect.width (), rect.height ());
 }
 
+QRegion toGlobal (const QWidget *widget, const QRegion &region)
+{
+    if (!widget || region.isEmpty ())
+        return region;
+
+    const QPoint widgetGlobalTopLeft = toGlobal (widget, QPoint (0, 0));
+    QRegion ret = region;
+    ret.translate (widgetGlobalTopLeft.x (), widgetGlobalTopLeft.y ());
+    return ret;
+}
+
 
 }  // namespace kpWidgetMapper {
Index: kpwidgetmapper.h
===================================================================
RCS file: /home/kde/kdegraphics/kolourpaint/kpwidgetmapper.h,v
retrieving revision 1.1
diff -u -p -r1.1 kpwidgetmapper.h
--- kpwidgetmapper.h	10 Jul 2004 11:38:09 -0000	1.1
+++ kpwidgetmapper.h	30 Jul 2004 11:37:21 -0000
@@ -32,15 +32,18 @@
 class QWidget;
 class QPoint;
 class QRect;
+class QRegion;
 
 
 namespace kpWidgetMapper
 {
     QPoint fromGlobal (const QWidget *widget, const QPoint &point);
     QRect fromGlobal (const QWidget *widget, const QRect &rect);
+    QRegion fromGlobal (const QWidget *widget, const QRegion &region);
 
     QPoint toGlobal (const QWidget *widget, const QPoint &point);
     QRect toGlobal (const QWidget *widget, const QRect &rect);
+    QRegion toGlobal (const QWidget *widget, const QRegion &region);
 }