⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlabel.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            paint.drawPixmap(cr.x(), cr.y(), mov->currentPixmap().scaled(cr.size()));        } else {            paint.drawPixmap(r.x(), r.y(), mov->currentPixmap());        }    }    else#endif    if (d->doc) {        QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(d->doc->documentLayout());        Q_ASSERT(layout);        d->doc->setPageSize(QSize(cr.width(), INT_MAX));        int rh = qRound(layout->documentSize().height());        int yo = 0;        if (align & Qt::AlignVCenter)            yo = (cr.height()-rh)/2;        else if (align & Qt::AlignBottom)            yo = cr.height()-rh;        QAbstractTextDocumentLayout::PaintContext context;        QStyleOption opt(0);        opt.init(this);        if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {            context.palette = palette();            context.palette.setColor(QPalette::Text, context.palette.light().color());            QRect r = cr;            r.translate(-cr.x()-1, -cr.y()-yo-1);            paint.save();            paint.translate(cr.x()+1, cr.y()+yo+1);            paint.setClipRect(r);            layout->draw(&paint, context);            paint.restore();        }        // QSimpleRichText always draws with QPalette::Text as with        // background mode Qt::PaletteBase. QLabel typically has        // background mode Qt::PaletteBackground, so we create a temporary        // color group with the text color adjusted.        context.palette = palette();        if (foregroundRole() != QPalette::Text && isEnabled())            context.palette.setColor(QPalette::Foreground, context.palette.color(foregroundRole()));        QRect r = cr;        r.translate(-cr.x(), -cr.y()-yo);        paint.save();        paint.translate(cr.x(), cr.y()+yo);        paint.setClipRect(r);        layout->draw(&paint, context);        paint.restore();    } else#ifndef QT_NO_PICTURE    if (pic) {        QRect br = pic->boundingRect();        int rw = br.width();        int rh = br.height();        if (d->scaledcontents) {            paint.save();            paint.translate(cr.x(), cr.y());            paint.scale((double)cr.width()/rw, (double)cr.height()/rh);            paint.drawPicture(-br.x(), -br.y(), *pic);            paint.restore();        } else {            int xo = 0;            int yo = 0;            if (align & Qt::AlignVCenter)                yo = (cr.height()-rh)/2;            else if (align & Qt::AlignBottom)                yo = cr.height()-rh;            if (align & Qt::AlignRight)                xo = cr.width()-rw;            else if (align & Qt::AlignHCenter)                xo = (cr.width()-rw)/2;            paint.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *pic);        }    } else#endif    {        if (d->scaledcontents && !pix.isNull()) {            if (!d->img)                d->img = new QImage(d->lpixmap->toImage());            if (!d->pix)                d->pix = new QPixmap;            if (d->pix->size() != cr.size())                *d->pix = QPixmap::fromImage(d->img->scaled(cr.width(), cr.height()));            pix = *d->pix;        }        QStyleOption opt(0);        opt.init(this);        if ((align & Qt::TextShowMnemonic) && !style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))            align |= Qt::TextHideMnemonic;        // ordinary text or pixmap label        if (!pix.isNull()) {            if (!isEnabled() )                pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt);            style->drawItemPixmap(&paint, cr, align, pix);        } else {            style->drawItemText(&paint, cr, align, palette(), isEnabled(), d->ltext, foregroundRole());        }    }}/*!    Updates the label, but not the frame.*/void QLabelPrivate::updateLabel(){    Q_Q(QLabel);    valid_hints = false;    QSizePolicy policy = q->sizePolicy();    bool wordWrap = align & Qt::TextWordWrap;    policy.setHeightForWidth(wordWrap);    if (policy != q->sizePolicy())        q->setSizePolicy(policy);#ifndef QT_NO_SHORTCUT    q->releaseShortcut(shortcutId);    if (lbuddy && !doc)        shortcutId = q->grabShortcut(QKeySequence::mnemonic(ltext));#endif    if (doc) {        int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align));        int flags = (wordWrap? 0 : Qt::TextSingleLine) | align;        flags |= (q->layoutDirection() == Qt::RightToLeft) ? QTextDocumentLayout::RTL : QTextDocumentLayout::LTR;        qobject_cast<QTextDocumentLayout *>(doc->documentLayout())->setBlockTextFlags(flags);    }    q->updateGeometry();    q->update(q->contentsRect());}#ifndef QT_NO_SHORTCUT/*!    Sets this label's buddy to \a buddy.    When the user presses the shortcut key indicated by this label,    the keyboard focus is transferred to the label's buddy widget.    The buddy mechanism is only available for QLabels that contain    plain text in which one letter is prefixed with an ampersand, \&.    This letter is set as the shortcut key. The letter is displayed    underlined, and the '\&' is not displayed (i.e. the Qt::TextShowMnemonic    alignment flag is turned on; see setAlignment()).    In a dialog, you might create two data entry widgets and a label    for each, and set up the geometry layout so each label is just to    the left of its data entry widget (its "buddy"), for example:    \code    QLineEdit *nameEd  = new QLineEdit(this);    QLabel    *nameLb  = new QLabel("&Name:", this);    nameLb->setBuddy(nameEd);    QLineEdit *phoneEd = new QLineEdit(this);    QLabel    *phoneLb = new QLabel("&Phone:", this);    phoneLb->setBuddy(phoneEd);    // (layout setup not shown)    \endcode    With the code above, the focus jumps to the Name field when the    user presses Alt+N, and to the Phone field when the user presses    Alt+P.    To unset a previously set buddy, call this function with \a buddy    set to 0.    \sa buddy(), setText(), QShortcut, setAlignment()*/void QLabel::setBuddy(QWidget *buddy){    Q_D(QLabel);    if (buddy)        d->align |= Qt::TextShowMnemonic;    else        d->align &= ~Qt::TextShowMnemonic;    d->lbuddy = buddy;    d->updateLabel();}/*!    Returns this label's buddy, or 0 if no buddy is currently set.    \sa setBuddy()*/QWidget * QLabel::buddy() const{    Q_D(const QLabel);    return d->lbuddy;}#endif // QT_NO_SHORTCUT#ifndef QT_NO_MOVIEvoid QLabelPrivate::_q_movieUpdated(const QRect& rect){    Q_Q(QLabel);    if (lmovie && lmovie->isValid()) {        QRect r;        if (scaledcontents) {            QRect cr = q->contentsRect();            QRect pixmapRect(cr.topLeft(), lmovie->currentPixmap().size());            if (pixmapRect.isEmpty())                return;            r.setRect(cr.left(), cr.top(),                      (rect.width() * cr.width()) / pixmapRect.width(),                      (rect.height() * cr.height()) / pixmapRect.height());        } else {            r = q->style()->itemPixmapRect(q->contentsRect(), align, lmovie->currentPixmap());            r.translate(rect.x(), rect.y());            r.setWidth(qMin(r.width(), rect.width()));            r.setHeight(qMin(r.height(), rect.height()));        }        q->update(r);    }}void QLabelPrivate::_q_movieResized(const QSize& size){    Q_Q(QLabel);    valid_hints = false;    _q_movieUpdated(QRect(QPoint(0,0), size));    q->updateGeometry();}/*!    Sets the label contents to \a movie. Any previous content is    cleared.    The buddy shortcut, if any, is disabled.    The label resizes itself if auto-resizing is enabled.    \sa movie(), setBuddy()*/void QLabel::setMovie(QMovie *movie){    Q_D(QLabel);    d->clearContents();    d->lmovie = movie;    connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize)));    connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect)));    // Assume that if the movie is running,    // resize/update signals will come soon enough    if (movie->state() != QMovie::Running)        d->updateLabel();}#endif // QT_NO_MOVIE/*!  \internal  Clears any contents, without updating/repainting the label.*/void QLabelPrivate::clearContents(){    delete doc;    doc = 0;    delete lpixmap;    lpixmap = 0;#ifndef QT_NO_PICTURE    delete lpicture;    lpicture = 0;#endif    delete img;    img = 0;    delete pix;    pix = 0;    ltext.clear();#ifndef QT_NO_SHORTCUT    Q_Q(QLabel);    q->releaseShortcut(shortcutId);    shortcutId = 0;#endif#ifndef QT_NO_MOVIE    lmovie = 0;#endif}#ifndef QT_NO_MOVIE/*!    Returns a pointer to the label's movie, or 0 if no movie has been    set.    \sa setMovie()*/QMovie *QLabel::movie() const{    Q_D(const QLabel);    return d->lmovie;}#endif  // QT_NO_MOVIE/*!    \property QLabel::textFormat    \brief the label's text format    See the Qt::TextFormat enum for an explanation of the possible    options.    The default format is Qt::AutoText.    \sa text()*/Qt::TextFormat QLabel::textFormat() const{    Q_D(const QLabel);    return d->textformat;}void QLabel::setTextFormat(Qt::TextFormat format){    Q_D(QLabel);    if (format != d->textformat) {        d->textformat = format;        QString t = d->ltext;        if (!t.isNull()) {            d->ltext.clear();            setText(t);        }    }}/*!  \reimp*/void QLabel::changeEvent(QEvent *ev){    Q_D(QLabel);    if(ev->type() == QEvent::FontChange) {        if (!d->ltext.isEmpty()) {            if (d->doc)                d->doc->setDefaultFont(font());            d->updateLabel();        }    }    QFrame::changeEvent(ev);}/*!    \property QLabel::scaledContents    \brief whether the label will scale its contents to fill all    available space.    When enabled and the label shows a pixmap, it will scale the    pixmap to fill the available space.    This property's default is false.*/bool QLabel::hasScaledContents() const{    Q_D(const QLabel);    return d->scaledcontents;}void QLabel::setScaledContents(bool enable){    Q_D(QLabel);    if ((bool)d->scaledcontents == enable)        return;    d->scaledcontents = enable;    if (!enable) {        delete d->img;        d->img = 0;        delete d->pix;        d->pix = 0;    }    update(contentsRect());}/*!    \fn void QLabel::setAlignment(Qt::AlignmentFlag flag)    \internal    Without this function, a call to e.g. setAlignment(Qt::AlignTop)    results in the \c QT3_SUPPORT function setAlignment(int) being called,    rather than setAlignment(Qt::Alignment).*/#include "moc_qlabel.cpp"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -