Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/painting/qregion.cpp

    r95 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5050#include <qdebug.h>
    5151
    52 #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE)
     52#if defined(Q_OS_UNIX) || defined(Q_WS_WIN)
    5353#include "qimage.h"
    5454#include "qbitmap.h"
     
    6262    \brief The QRegion class specifies a clip region for a painter.
    6363
    64     \ingroup multimedia
     64    \ingroup painting
    6565    \ingroup shared
    6666
     
    9292    Example of using complex regions:
    9393    \snippet doc/src/snippets/code/src_gui_painting_qregion.cpp 0
    94 
    95     \warning Due to window system limitations, the whole coordinate space for a
    96     region is limited to the points between -32767 and 32767 on Windows
    97     95/98/ME. You can circumvent this limitation by using a QPainterPath.
    9894
    9995    \section1 Additional License Information
     
    451447    QVector<QRect> rects = r.rects();
    452448    s.nospace() << "QRegion(size=" << rects.size() << "), "
    453                 << "bounds = " << r.boundingRect() << "\n";
     449                << "bounds = " << r.boundingRect() << '\n';
    454450    for (int i=0; i<rects.size(); ++i)
    455         s << "- " << i << rects.at(i) << "\n";
     451        s << "- " << i << rects.at(i) << '\n';
    456452    return s;
    457453}
     
    550546    \sa intersected()
    551547*/
    552 #if !defined (Q_OS_UNIX) && !defined (Q_OS_WINCE)
     548#if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN)
    553549QRegion& QRegion::operator+=(const QRect &r)
    554550{
     
    566562  \sa intersected()
    567563*/
    568 #if (!defined(Q_WS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_WS_PM)
    569564QRegion& QRegion::operator&=(const QRegion &r)
    570565    { return *this = *this & r; }
    571 #endif
    572566
    573567/*!
     
    575569   \since 4.4
    576570 */
    577 #if defined (Q_OS_UNIX) || defined (Q_OS_WINCE)
     571#if defined (Q_OS_UNIX) || defined (Q_WS_WIN)
    578572QRegion& QRegion::operator&=(const QRect &r)
    579573{
     
    596590  \sa subtracted()
    597591*/
    598 #if (!defined(Q_WS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_WS_PM)
    599592QRegion& QRegion::operator-=(const QRegion &r)
    600593    { return *this = *this - r; }
    601 #endif
    602594
    603595/*!
     
    699691    if (!rect_intersects(boundingRect(), region.boundingRect()))
    700692        return false;
     693    if (rectCount() == 1 && region.rectCount() == 1)
     694        return true;
    701695
    702696    const QVector<QRect> myRects = rects();
     
    724718    if (!rect_intersects(boundingRect(), r))
    725719        return false;
     720    if (rectCount() == 1)
     721        return true;
    726722
    727723    const QVector<QRect> myRects = rects();
     
    732728}
    733729
    734 #if !defined (Q_OS_UNIX) && !defined (Q_OS_WINCE)
     730#if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN)
    735731/*!
    736732    \overload
     
    744740
    745741/*!
     742    \obsolete
    746743    \fn int QRegion::numRects() const
    747744    \since 4.4
     745
     746    Returns the number of rectangles that will be returned in rects().
     747*/
     748
     749/*!
     750    \fn int QRegion::rectCount() const
     751    \since 4.6
    748752
    749753    Returns the number of rectangles that will be returned in rects().
     
    10321036{
    10331037    QPainterPath result;
    1034     if (region.numRects() == 1) {
     1038    if (region.rectCount() == 1) {
    10351039        result.addRect(region.boundingRect());
    10361040        return result;
     
    10871091}
    10881092
    1089 #if defined(Q_OS_UNIX) || defined(Q_OS_WINCE)
     1093#if defined(Q_OS_UNIX) || defined(Q_WS_WIN)
    10901094
    10911095//#define QT_REGION_DEBUG
     
    16021606        const QRect r = rects.at(i);
    16031607        if ((r.width() * r.height()) > innerArea)
    1604             qDebug() << "selfTest(): innerRect" << innerRect << "<" << r;
     1608            qDebug() << "selfTest(): innerRect" << innerRect << '<' << r;
    16051609    }
    16061610
     
    16281632# include "qregion_mac.cpp"
    16291633QT_END_INCLUDE_NAMESPACE
    1630 #elif defined(Q_OS_WINCE)
     1634#elif defined(Q_WS_WIN)
    16311635QT_BEGIN_INCLUDE_NAMESPACE
    1632 # include "qregion_wince.cpp"
     1636# include "qregion_win.cpp"
    16331637QT_END_INCLUDE_NAMESPACE
    16341638#elif defined(Q_WS_QWS)
     
    31683172            tmpSLLBlock =
    31693173                  (ScanLineListBlock *)malloc(sizeof(ScanLineListBlock));
     3174            Q_CHECK_PTR(tmpSLLBlock);
    31703175            (*SLLBlock)->next = tmpSLLBlock;
    31713176            tmpSLLBlock->next = (ScanLineListBlock *)NULL;
     
    35543559 *     encoding of the resultant bitmap -- the run-length
    35553560 *     encoding is in the form of an array of rectangles.
     3561 *
     3562 *     Can return 0 in case of errors.
    35563563 */
    35573564static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule)
     
    36253632
    36263633
    3627     if (rule == EvenOddRule) {
    3628         /*
    3629          *  for each scanline
    3630          */
    3631         for (y = ET.ymin; y < ET.ymax; ++y) {
    3632 
     3634    QT_TRY {
     3635        if (rule == EvenOddRule) {
    36333636            /*
    3634              *  Add a new edge to the active edge table when we
    3635              *  get to the next edge.
     3637             *  for each scanline
    36363638             */
    3637             if (pSLL && y == pSLL->scanline) {
    3638                 loadAET(&AET, pSLL->edgelist);
    3639                 pSLL = pSLL->next;
    3640             }
    3641             pPrevAET = &AET;
    3642             pAET = AET.next;
    3643 
    3644             /*
    3645              *  for each active edge
    3646              */
    3647             while (pAET) {
    3648                 pts->setX(pAET->bres.minor_axis);
    3649                 pts->setY(y);
    3650                 ++pts;
    3651                 ++iPts;
     3639            for (y = ET.ymin; y < ET.ymax; ++y) {
    36523640
    36533641                /*
    3654                  *  send out the buffer
     3642                 *  Add a new edge to the active edge table when we
     3643                 *  get to the next edge.
    36553644                 */
    3656                 if (iPts == NUMPTSTOBUFFER) {
    3657                     tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK));
    3658                     tmpPtBlock->pts = reinterpret_cast<QPoint *>(tmpPtBlock->data);
    3659                     curPtBlock->next = tmpPtBlock;
    3660                     curPtBlock = tmpPtBlock;
    3661                     pts = curPtBlock->pts;
    3662                     ++numFullPtBlocks;
    3663                     iPts = 0;
     3645                if (pSLL && y == pSLL->scanline) {
     3646                    loadAET(&AET, pSLL->edgelist);
     3647                    pSLL = pSLL->next;
    36643648                }
    3665                 EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
    3666             }
    3667             InsertionSort(&AET);
    3668         }
    3669     } else {
    3670         /*
    3671          *  for each scanline
    3672          */
    3673         for (y = ET.ymin; y < ET.ymax; ++y) {
    3674             /*
    3675              *  Add a new edge to the active edge table when we
    3676              *  get to the next edge.
    3677              */
    3678             if (pSLL && y == pSLL->scanline) {
    3679                 loadAET(&AET, pSLL->edgelist);
    3680                 computeWAET(&AET);
    3681                 pSLL = pSLL->next;
    3682             }
    3683             pPrevAET = &AET;
    3684             pAET = AET.next;
    3685             pWETE = pAET;
    3686 
    3687             /*
    3688              *  for each active edge
    3689              */
    3690             while (pAET) {
     3649                pPrevAET = &AET;
     3650                pAET = AET.next;
     3651
    36913652                /*
    3692                  *  add to the buffer only those edges that
    3693                  *  are in the Winding active edge table.
     3653                 *  for each active edge
    36943654                 */
    3695                 if (pWETE == pAET) {
     3655                while (pAET) {
    36963656                    pts->setX(pAET->bres.minor_axis);
    36973657                    pts->setY(y);
     
    37033663                     */
    37043664                    if (iPts == NUMPTSTOBUFFER) {
    3705                         tmpPtBlock = static_cast<POINTBLOCK *>(malloc(sizeof(POINTBLOCK)));
     3665                        tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK));
     3666                        Q_CHECK_PTR(tmpPtBlock);
    37063667                        tmpPtBlock->pts = reinterpret_cast<QPoint *>(tmpPtBlock->data);
    37073668                        curPtBlock->next = tmpPtBlock;
     
    37113672                        iPts = 0;
    37123673                    }
    3713                     pWETE = pWETE->nextWETE;
     3674                    EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
    37143675                }
    3715                 EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET)
     3676                InsertionSort(&AET);
    37163677            }
    3717 
     3678        } else {
    37183679            /*
    3719              *  recompute the winding active edge table if
    3720              *  we just resorted or have exited an edge.
     3680             *  for each scanline
    37213681             */
    3722             if (InsertionSort(&AET) || fixWAET) {
    3723                 computeWAET(&AET);
    3724                 fixWAET = false;
     3682            for (y = ET.ymin; y < ET.ymax; ++y) {
     3683                /*
     3684                 *  Add a new edge to the active edge table when we
     3685                 *  get to the next edge.
     3686                 */
     3687                if (pSLL && y == pSLL->scanline) {
     3688                    loadAET(&AET, pSLL->edgelist);
     3689                    computeWAET(&AET);
     3690                    pSLL = pSLL->next;
     3691                }
     3692                pPrevAET = &AET;
     3693                pAET = AET.next;
     3694                pWETE = pAET;
     3695
     3696                /*
     3697                 *  for each active edge
     3698                 */
     3699                while (pAET) {
     3700                    /*
     3701                     *  add to the buffer only those edges that
     3702                     *  are in the Winding active edge table.
     3703                     */
     3704                    if (pWETE == pAET) {
     3705                        pts->setX(pAET->bres.minor_axis);
     3706                        pts->setY(y);
     3707                        ++pts;
     3708                        ++iPts;
     3709
     3710                        /*
     3711                         *  send out the buffer
     3712                         */
     3713                        if (iPts == NUMPTSTOBUFFER) {
     3714                            tmpPtBlock = static_cast<POINTBLOCK *>(malloc(sizeof(POINTBLOCK)));
     3715                            tmpPtBlock->pts = reinterpret_cast<QPoint *>(tmpPtBlock->data);
     3716                            curPtBlock->next = tmpPtBlock;
     3717                            curPtBlock = tmpPtBlock;
     3718                            pts = curPtBlock->pts;
     3719                            ++numFullPtBlocks;
     3720                            iPts = 0;
     3721                        }
     3722                        pWETE = pWETE->nextWETE;
     3723                    }
     3724                    EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET)
     3725                }
     3726
     3727                /*
     3728                 *  recompute the winding active edge table if
     3729                 *  we just resorted or have exited an edge.
     3730                 */
     3731                if (InsertionSort(&AET) || fixWAET) {
     3732                    computeWAET(&AET);
     3733                    fixWAET = false;
     3734                }
    37253735            }
    37263736        }
    3727     }
     3737    } QT_CATCH(...) {
     3738        FreeStorage(SLLBlock.next);
     3739        PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region);
     3740        for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) {
     3741            tmpPtBlock = curPtBlock->next;
     3742            free(curPtBlock);
     3743            curPtBlock = tmpPtBlock;
     3744        }
     3745        free(pETEs);
     3746        return 0; // this function returns 0 in case of an error
     3747    }
     3748
    37283749    FreeStorage(SLLBlock.next);
    37293750    PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region);
     
    38303851        d->rgn = 0;
    38313852        d->xrectangles = 0;
    3832 #elif defined(Q_OS_WINCE)
     3853#elif defined(Q_WS_WIN)
    38333854        d->rgn = 0;
    38343855#endif
     
    38473868{
    38483869    if (a.count() > 2) {
    3849         d =  new QRegionData;
    3850         d->ref = 1;
     3870        QRegionPrivate *qt_rgn = PolygonRegion(a.constData(), a.size(),
     3871                                               fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
     3872        if (qt_rgn) {
     3873            d =  new QRegionData;
     3874            d->ref = 1;
    38513875#if defined(Q_WS_X11)
    3852         d->rgn = 0;
    3853         d->xrectangles = 0;
    3854 #elif defined(Q_OS_WINCE)
    3855         d->rgn = 0;
     3876            d->rgn = 0;
     3877            d->xrectangles = 0;
     3878#elif defined(Q_WS_WIN)
     3879            d->rgn = 0;
    38563880#endif
    3857         d->qt_rgn = PolygonRegion(a.constData(), a.size(),
    3858                                   fillRule == Qt::WindingFill ? WindingRule : EvenOddRule);
     3881            d->qt_rgn = qt_rgn;
     3882        } else {
     3883            d = &shared_empty;
     3884            d->ref.ref();
     3885        }
    38593886    } else {
    38603887        d = &shared_empty;
     
    38623889    }
    38633890}
    3864 
    38653891
    38663892QRegion::QRegion(const QRegion &r)
     
    38823908        d->rgn = 0;
    38833909        d->xrectangles = 0;
    3884 #elif defined(Q_OS_WINCE)
     3910#elif defined(Q_WS_WIN)
    38853911        d->rgn = 0;
    38863912#endif
     
    38973923    if (x->xrectangles)
    38983924        free(x->xrectangles);
    3899 #elif defined(Q_OS_WINCE)
     3925#elif defined(Q_WS_WIN)
    39003926    if (x->rgn)
    39013927        qt_win_dispose_rgn(x->rgn);
     
    39243950    \internal
    39253951*/
    3926 
    39273952QRegion QRegion::copy() const
    39283953{
    39293954    QRegion r;
    3930     QRegionData *x = new QRegionData;
     3955    QScopedPointer<QRegionData> x(new QRegionData);
    39313956    x->ref = 1;
    39323957#if defined(Q_WS_X11)
    39333958    x->rgn = 0;
    39343959    x->xrectangles = 0;
    3935 #elif defined(Q_OS_WINCE)
     3960#elif defined(Q_WS_WIN)
    39363961    x->rgn = 0;
    39373962#endif
     
    39423967    if (!r.d->ref.deref())
    39433968        cleanUp(r.d);
    3944     r.d = x;
     3969    r.d = x.take();
    39453970    return r;
    39463971}
     
    43064331}
    43074332
     4333int QRegion::rectCount() const
     4334{
     4335    return (d->qt_rgn ? d->qt_rgn->numRects : 0);
     4336}
     4337
     4338
    43084339bool QRegion::operator==(const QRegion &r) const
    43094340{
Note: See TracChangeset for help on using the changeset viewer.