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/widgets/qlabel.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**
     
    6262
    6363    \ingroup basicwidgets
    64     \ingroup text
    65     \mainclass
    6664
    6765    QLabel is used for displaying text or an image. No user
     
    889887{
    890888    Q_D(QLabel);
    891     d->sendControlEvent(ev);
     889    if (d->control) {
     890        d->sendControlEvent(ev);
     891        QTextCursor cursor = d->control->textCursor();
     892        Qt::FocusReason reason = ev->reason();
     893        if (reason != Qt::ActiveWindowFocusReason
     894            && reason != Qt::PopupFocusReason
     895            && cursor.hasSelection()) {
     896            cursor.clearSelection();
     897            d->control->setTextCursor(cursor);
     898        }
     899    }
     900
    892901    QFrame::focusOutEvent(ev);
    893902}
     
    972981    if (d->isTextLabel) {
    973982        QRectF lr = d->layoutRect();
     983        QStyleOption opt;
     984        opt.initFrom(this);
     985#ifndef QT_NO_STYLE_STYLESHEET
     986        if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
     987            cssStyle->styleSheetPalette(this, &opt, &opt.palette);
     988        }
     989#endif
    974990        if (d->control) {
    975991#ifndef QT_NO_SHORTCUT
     
    9851001
    9861002            QAbstractTextDocumentLayout::PaintContext context;
    987             QStyleOption opt(0);
    988             opt.init(this);
    989 
    990             if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
    991                 context.palette = palette();
     1003            if (!isEnabled() && !d->control &&
     1004                // We cannot support etched for rich text controls because custom
     1005                // colors and links will override the light palette
     1006                style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
     1007                context.palette = opt.palette;
    9921008                context.palette.setColor(QPalette::Text, context.palette.light().color());
    9931009                painter.save();
     
    10001016
    10011017            // Adjust the palette
    1002             context.palette = palette();
    1003 #ifndef QT_NO_STYLE_STYLESHEET
    1004             if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
    1005                 cssStyle->focusPalette(this, &opt, &context.palette);
    1006             }
    1007 #endif
     1018            context.palette = opt.palette;
    10081019
    10091020            if (foregroundRole() != QPalette::Text && isEnabled())
     
    10201031            if (d->hasShortcut) {
    10211032                flags |= Qt::TextShowMnemonic;
    1022                 QStyleOption opt;
    1023                 opt.initFrom(this);
    10241033                if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
    10251034                    flags |= Qt::TextHideMnemonic;
    10261035            }
    1027             style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole());
     1036            style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole());
    10281037        }
    10291038    } else
     
    11621171    hasShortcut = false;
    11631172
    1164     if (control) {
    1165         ensureTextPopulated();
    1166         // Underline the first character that follows an ampersand
    1167         shortcutCursor = control->document()->find(QLatin1String("&"));
    1168         if (shortcutCursor.isNull())
    1169             return;
    1170         hasShortcut = true;
    1171         shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
    1172         shortcutCursor.deleteChar(); // remove the ampersand
    1173         shortcutCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
    1174     } else {
    1175         if (!text.contains(QLatin1String("&")))
    1176             return;
    1177         hasShortcut = true;
    1178         shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
    1179     }
     1173    if (!text.contains(QLatin1Char('&')))
     1174        return;
     1175    hasShortcut = true;
     1176    shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
    11801177}
    11811178
     
    14481445#endif
    14491446            doc->setUndoRedoEnabled(false);
     1447
     1448#ifndef QT_NO_SHORTCUT
     1449            if (hasShortcut) {
     1450                // Underline the first character that follows an ampersand (and remove the others ampersands)
     1451                int from = 0;
     1452                bool found = false;
     1453                QTextCursor cursor;
     1454                while (!(cursor = control->document()->find((QLatin1String("&")), from)).isNull()) {
     1455                    cursor.deleteChar(); // remove the ampersand
     1456                    cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
     1457                    from = cursor.position();
     1458                    if (!found && cursor.selectedText() != QLatin1String("&")) { //not a second &
     1459                        found = true;
     1460                        shortcutCursor = cursor;
     1461                    }
     1462                }
     1463            }
     1464#endif
    14501465        }
    14511466    }
Note: See TracChangeset for help on using the changeset viewer.