Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qlabel.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5454#include "qlabel_p.h"
    5555#include "private/qstylesheetstyle_p.h"
     56#include <qmath.h>
    5657
    5758QT_BEGIN_NAMESPACE
     
    635636#endif
    636637    else if (isTextLabel) {
    637         int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align));
     638        int align = QStyle::visualAlignment(textDirection(), QFlag(this->align));
    638639        // Add indentation
    639640        int m = indent;
     
    662663                control->setTextWidth(-1);
    663664            }
    664             br = QRect(QPoint(0, 0), control->size().toSize());
     665
     666            QSizeF controlSize = control->size();
     667            br = QRect(QPoint(0, 0), QSize(qCeil(controlSize.width()), qCeil(controlSize.height())));
    665668
    666669            // restore state
     
    680683            bool tryWidth = (w < 0) && (align & Qt::TextWordWrap);
    681684            if (tryWidth)
    682                 w = fm.averageCharWidth() * 80;
     685                w = qMin(fm.averageCharWidth() * 80, q->maximumSize().width());
    683686            else if (w < 0)
    684687                w = 2000;
     
    782785}
    783786
     787/*!
     788    Selects text from position \a start and for \a length characters.
     789
     790    \sa selectedText()
     791
     792    \bold{Note:} The textInteractionFlags set on the label need to include
     793    either TextSelectableByMouse or TextSelectableByKeyboard.
     794
     795    \since 4.7
     796*/
     797void QLabel::setSelection(int start, int length)
     798{
     799    Q_D(QLabel);
     800    if (d->control) {
     801        d->ensureTextPopulated();
     802        QTextCursor cursor = d->control->textCursor();
     803        cursor.setPosition(start);
     804        cursor.setPosition(start + length, QTextCursor::KeepAnchor);
     805        d->control->setTextCursor(cursor);
     806    }
     807}
     808
     809/*!
     810    \property QLabel::hasSelectedText
     811    \brief whether there is any text selected
     812
     813    hasSelectedText() returns true if some or all of the text has been
     814    selected by the user; otherwise returns false.
     815
     816    By default, this property is false.
     817
     818    \sa selectedText()
     819
     820    \bold{Note:} The textInteractionFlags set on the label need to include
     821    either TextSelectableByMouse or TextSelectableByKeyboard.
     822
     823    \since 4.7
     824*/
     825bool QLabel::hasSelectedText() const
     826{
     827    Q_D(const QLabel);
     828    if (d->control)
     829        return d->control->textCursor().hasSelection();
     830    return false;
     831}
     832
     833/*!
     834    \property QLabel::selectedText
     835    \brief the selected text
     836
     837    If there is no selected text this property's value is
     838    an empty string.
     839
     840    By default, this property contains an empty string.
     841
     842    \sa hasSelectedText()
     843
     844    \bold{Note:} The textInteractionFlags set on the label need to include
     845    either TextSelectableByMouse or TextSelectableByKeyboard.
     846
     847    \since 4.7
     848*/
     849QString QLabel::selectedText() const
     850{
     851    Q_D(const QLabel);
     852    if (d->control)
     853        return d->control->textCursor().selectedText();
     854    return QString();
     855}
     856
     857/*!
     858    selectionStart() returns the index of the first selected character in the
     859    label or -1 if no text is selected.
     860
     861    \sa selectedText()
     862
     863    \bold{Note:} The textInteractionFlags set on the label need to include
     864    either TextSelectableByMouse or TextSelectableByKeyboard.
     865
     866    \since 4.7
     867*/
     868int QLabel::selectionStart() const
     869{
     870    Q_D(const QLabel);
     871    if (d->control && d->control->textCursor().hasSelection())
     872        return d->control->textCursor().selectionStart();
     873    return -1;
     874}
     875
    784876/*!\reimp
    785877*/
     
    863955    }
    864956    ev->accept();
    865     menu->exec(ev->globalPos());
    866     delete menu;
     957    menu->setAttribute(Qt::WA_DeleteOnClose);
     958    menu->popup(ev->globalPos());
    867959#endif
    868960}
     
    9681060    QRect cr = contentsRect();
    9691061    cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
    970     int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align));
     1062    int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection()
     1063                                                       : layoutDirection(), QFlag(d->align));
    9711064
    9721065#ifndef QT_NO_MOVIE
     
    10281121            painter.restore();
    10291122        } else {
    1030             int flags = align;
     1123            int flags = align | (d->textDirection() == Qt::LeftToRight ? Qt::TextForceLeftToRight
     1124                                                                       : Qt::TextForceRightToLeft);
    10311125            if (d->hasShortcut) {
    10321126                flags |= Qt::TextShowMnemonic;
     
    13561450    } else if (ev->type() == QEvent::ContentsRectChange) {
    13571451        d->updateLabel();
    1358     } else if (ev->type() == QEvent::LayoutDirectionChange) {
    1359         if (d->isTextLabel && d->control) {
    1360             d->sendControlEvent(ev);
    1361         }
    13621452    }
    13631453    QFrame::changeEvent(ev);
     
    13951485}
    13961486
     1487Qt::LayoutDirection QLabelPrivate::textDirection() const
     1488{
     1489    if (control) {
     1490        QTextOption opt = control->document()->defaultTextOption();
     1491        return opt.textDirection();
     1492    }
     1493
     1494    return text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
     1495}
    13971496
    13981497/*!
     
    14121511    QRect cr = q->contentsRect();
    14131512    cr.adjust(margin, margin, -margin, -margin);
    1414     const int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align));
     1513    const int align = QStyle::visualAlignment(isTextLabel ? textDirection()
     1514                                                          : q->layoutDirection(), QFlag(this->align));
    14151515    int m = indent;
    14161516    if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
     
    14731573        return;
    14741574    ensureTextPopulated();
    1475     Q_Q(const QLabel);
    14761575    if (control) {
    14771576        QTextDocument *doc = control->document();
     
    14841583        else
    14851584            opt.setWrapMode(QTextOption::ManualWrap);
    1486 
    1487         opt.setTextDirection(q->layoutDirection());
    14881585
    14891586        doc->setDefaultTextOption(opt);
Note: See TracChangeset for help on using the changeset viewer.