示例#1
0
void QLabelPrivate::ensureTextLayouted() const
{
    if (!textLayoutDirty)
        return;
    ensureTextPopulated();
    if (control) {
        QTextDocument *doc = control->document();
        QTextOption opt = doc->defaultTextOption();

        opt.setAlignment(QFlag(this->align));

        if (this->align & Qt::TextWordWrap)
            opt.setWrapMode(QTextOption::WordWrap);
        else
            opt.setWrapMode(QTextOption::ManualWrap);

        doc->setDefaultTextOption(opt);

        QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
        fmt.setMargin(0);
        doc->rootFrame()->setFrameFormat(fmt);
        doc->setTextWidth(documentRect().width());
    }
    textLayoutDirty = false;
}
示例#2
0
void QLabelPrivate::updateShortcut()
{
    Q_Q(QLabel);
    Q_ASSERT(shortcutId == 0);
    // Introduce an extra boolean to indicate the presence of a shortcut in the
    // text. We cannot use the shortcutId itself because on the mac mnemonics are
    // off by default, so QKeySequence::mnemonic always returns an empty sequence.
    // But then we do want to hide the ampersands, so we can't use shortcutId.
    hasShortcut = false;

    if (control) {
        ensureTextPopulated();
        // Underline the first character that follows an ampersand
        shortcutCursor = control->document()->find(QLatin1String("&"));
        if (shortcutCursor.isNull())
            return;
        hasShortcut = true;
        shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
        shortcutCursor.deleteChar(); // remove the ampersand
        shortcutCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
    } else {
        if (!text.contains(QLatin1String("&")))
            return;
        hasShortcut = true;
        shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
    }
}