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/text/qtextdocumentlayout.cpp

    r2 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**
     
    199199            return cellPadding;
    200200        } else {
    201             Q_ASSERT(v.type() == QVariant::Double);
    202             return QFixed::fromReal(v.toDouble() * deviceScale);
     201            Q_ASSERT(v.userType() == QVariant::Double || v.userType() == QMetaType::Float);
     202            return QFixed::fromReal(v.toReal() * deviceScale);
    203203        }
    204204    }
     
    856856void QTextDocumentLayoutPrivate::drawFrameDecoration(QPainter *painter, QTextFrame *frame, QTextFrameData *fd, const QRectF &clip, const QRectF &rect) const
    857857{
     858
     859    const QBrush bg = frame->frameFormat().background();
     860    if (bg != Qt::NoBrush) {
     861        QRectF bgRect = rect;
     862        bgRect.adjust((fd->leftMargin + fd->border).toReal(),
     863                      (fd->topMargin + fd->border).toReal(),
     864                      - (fd->rightMargin + fd->border).toReal(),
     865                      - (fd->bottomMargin + fd->border).toReal());
     866
     867        QRectF gradientRect; // invalid makes it default to bgRect
     868        QPointF origin = bgRect.topLeft();
     869        if (!frame->parentFrame()) {
     870            bgRect = clip;
     871            gradientRect.setWidth(painter->device()->width());
     872            gradientRect.setHeight(painter->device()->height());
     873        }
     874        fillBackground(painter, bgRect, bg, origin, gradientRect);
     875    }
    858876    if (fd->border != 0) {
    859877        painter->save();
     
    875893
    876894        painter->restore();
    877     }
    878 
    879     const QBrush bg = frame->frameFormat().background();
    880     if (bg != Qt::NoBrush) {
    881         QRectF bgRect = rect;
    882         bgRect.adjust((fd->leftMargin + fd->border).toReal(),
    883                       (fd->topMargin + fd->border).toReal(),
    884                       - (fd->rightMargin + fd->border).toReal(),
    885                       - (fd->bottomMargin + fd->border).toReal());
    886 
    887         QRectF gradientRect; // invalid makes it default to bgRect
    888         QPointF origin = bgRect.topLeft();
    889         if (!frame->parentFrame()) {
    890             bgRect = clip;
    891             gradientRect.setWidth(painter->device()->width());
    892             gradientRect.setHeight(painter->device()->height());
    893         }
    894         fillBackground(painter, bgRect, bg, origin, gradientRect);
    895895    }
    896896}
     
    13841384    case QTextListFormat::ListLowerAlpha:
    13851385    case QTextListFormat::ListUpperAlpha:
     1386    case QTextListFormat::ListLowerRoman:
     1387    case QTextListFormat::ListUpperRoman:
    13861388        itemText = static_cast<QTextList *>(object)->itemText(bl);
    13871389        size.setWidth(fontMetrics.width(itemText));
     
    14271429    case QTextListFormat::ListDecimal:
    14281430    case QTextListFormat::ListLowerAlpha:
    1429     case QTextListFormat::ListUpperAlpha: {
     1431    case QTextListFormat::ListUpperAlpha:
     1432    case QTextListFormat::ListLowerRoman:
     1433    case QTextListFormat::ListUpperRoman: {
    14301434        QTextLayout layout(itemText, font, q->paintDevice());
    14311435        layout.setCacheEnabled(true);
     
    14341438        layout.setTextOption(option);
    14351439        layout.beginLayout();
    1436         layout.createLine();
     1440        QTextLine line = layout.createLine();
     1441        if (line.isValid())
     1442            line.setLeadingIncluded(true);
    14371443        layout.endLayout();
    14381444        layout.draw(painter, QPointF(r.left(), pos.y()));
     
    14431449        break;
    14441450    case QTextListFormat::ListCircle:
    1445         painter->drawEllipse(r);
     1451        painter->setPen(QPen(brush, 0));
     1452        painter->drawEllipse(r.translated(0.5, 0.5)); // pixel align for sharper rendering
    14461453        break;
    14471454    case QTextListFormat::ListDisc:
     
    14491456        painter->setPen(Qt::NoPen);
    14501457        painter->drawEllipse(r);
    1451         painter->setBrush(Qt::NoBrush);
    14521458        break;
    14531459    case QTextListFormat::ListStyleUndefined:
     
    19911997    }
    19921998
    1993     if (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom) {
     1999    bool frameSpansIntoNextPage = (y + layoutStruct->frameY + fd->size.height > layoutStruct->pageBottom);
     2000    if (frameSpansIntoNextPage && fd->size.height <= layoutStruct->pageHeight) {
    19942001        layoutStruct->newPage();
    19952002        y = layoutStruct->y;
     2003
     2004        frameSpansIntoNextPage = false;
    19962005    }
    19972006
     
    20142023//     qDebug()<< "float positioned at " << fd->position.x << fd->position.y;
    20152024    fd->layoutDirty = false;
     2025
     2026    // If the frame is a table, then positioning it will affect the size if it covers more than
     2027    // one page, because of page breaks and repeating the header.
     2028    if (qobject_cast<QTextTable *>(frame) != 0)
     2029        fd->sizeDirty = frameSpansIntoNextPage;
    20162030}
    20172031
     
    23452359
    23462360                positionFloat(c);
     2361
     2362                // If the size was made dirty when the position was set, layout again
     2363                if (cd->sizeDirty)
     2364                    updateRect = layoutFrame(c, layoutFrom, layoutTo);
    23472365
    23482366                QRectF frameRect(cd->position.toPointF(), cd->size.toSizeF());
     
    25012519    LDEBUG << "layoutBlock from=" << layoutFrom << "to=" << layoutTo;
    25022520
    2503 //    qDebug() << "layoutBlock; width" << layoutStruct->x_right - layoutStruct->x_left << "(maxWidth is btw" << tl->maximumWidth() << ")";
     2521//    qDebug() << "layoutBlock; width" << layoutStruct->x_right - layoutStruct->x_left << "(maxWidth is btw" << tl->maximumWidth() << ')';
    25042522
    25052523    if (previousBlockFormat) {
     
    25642582            if (!line.isValid())
    25652583                break;
     2584            line.setLeadingIncluded(true);
    25662585
    25672586            QFixed left, right;
     
    25982617                layoutStruct->pendingFloats.clear();
    25992618
    2600                 if (haveWordOrAnyWrapMode) {
    2601                     option.setWrapMode(QTextOption::WrapAnywhere);
    2602                     tl->setTextOption(option);
    2603                 }
    2604 
    26052619                line.setLineWidth((right-left).toReal());
    26062620                if (QFixed::fromReal(line.naturalTextWidth()) > right-left) {
     2621                    if (haveWordOrAnyWrapMode) {
     2622                        option.setWrapMode(QTextOption::WrapAnywhere);
     2623                        tl->setTextOption(option);
     2624                    }
     2625
    26072626                    layoutStruct->pendingFloats.clear();
    26082627                    // lines min width more than what we have
     
    26162635                        right -= text_indent;
    26172636                    line.setLineWidth(qMax<qreal>(line.naturalTextWidth(), (right-left).toReal()));
     2637
     2638                    if (haveWordOrAnyWrapMode) {
     2639                        option.setWrapMode(QTextOption::WordWrap);
     2640                        tl->setTextOption(option);
     2641                    }
    26182642                }
    26192643
    2620                 if (haveWordOrAnyWrapMode) {
    2621                     option.setWrapMode(QTextOption::WordWrap);
    2622                     tl->setTextOption(option);
    2623                 }
    26242644            }
    26252645
     
    32063226qreal QTextDocumentLayoutPrivate::scaleToDevice(qreal value) const
    32073227{
    3208     QPaintDevice *dev = q_func()->paintDevice();
    3209     if (!dev)
     3228    if (!paintDevice)
    32103229        return value;
    3211     return value * dev->logicalDpiY() / qreal(qt_defaultDpi());
     3230    return value * paintDevice->logicalDpiY() / qreal(qt_defaultDpi());
    32123231}
    32133232
    32143233QFixed QTextDocumentLayoutPrivate::scaleToDevice(QFixed value) const
    32153234{
    3216     QPaintDevice *dev = q_func()->paintDevice();
    3217     if (!dev)
     3235    if (!paintDevice)
    32183236        return value;
    3219     return value * QFixed(dev->logicalDpiY()) / QFixed(qt_defaultDpi());
     3237    return value * QFixed(paintDevice->logicalDpiY()) / QFixed(qt_defaultDpi());
    32203238}
    32213239
Note: See TracChangeset for help on using the changeset viewer.