Пример #1
0
void TextLabel::updateImplicitSize()
{
    if (m_elide) {
        setImplicitWidth(0);
        setImplicitHeight(0);
    } else {
        QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::GeneralFont));

        setImplicitWidth(fm.width(m_text));
        setImplicitHeight(fm.height());
    }
}
Пример #2
0
void QDeclarativeImage::updatePaintedGeometry()
{
    Q_D(QDeclarativeImage);

    if (d->fillMode == PreserveAspectFit) {
        if (!d->pix.width() || !d->pix.height()) {
            setImplicitWidth(0);
            setImplicitHeight(0);
            return;
        }
        qreal w = widthValid() ? width() : d->pix.width();
        qreal widthScale = w / qreal(d->pix.width());
        qreal h = heightValid() ? height() : d->pix.height();
        qreal heightScale = h / qreal(d->pix.height());
        if (widthScale <= heightScale) {
            d->paintedWidth = w;
            d->paintedHeight = widthScale * qreal(d->pix.height());
        } else if(heightScale < widthScale) {
            d->paintedWidth = heightScale * qreal(d->pix.width());
            d->paintedHeight = h;
        }
        if (widthValid() && !heightValid()) {
            setImplicitHeight(d->paintedHeight);
        } else {
            setImplicitHeight(d->pix.height());
        }
        if (heightValid() && !widthValid()) {
            setImplicitWidth(d->paintedWidth);
        } else {
            setImplicitWidth(d->pix.width());
        }
    } else if (d->fillMode == PreserveAspectCrop) {
        if (!d->pix.width() || !d->pix.height())
            return;
        qreal widthScale = width() / qreal(d->pix.width());
        qreal heightScale = height() / qreal(d->pix.height());
        if (widthScale < heightScale) {
            widthScale = heightScale;
        } else if(heightScale < widthScale) {
            heightScale = widthScale;
        }

        d->paintedHeight = heightScale * qreal(d->pix.height());
        d->paintedWidth = widthScale * qreal(d->pix.width());
    } else {
        d->paintedWidth = width();
        d->paintedHeight = height();
    }
    emit paintedGeometryChanged();
}
Пример #3
0
void FilteredImage::setSource(const QString &source)
{
    if(m_source != source)
    {
        m_source = source;

        QImageReader ir(m_source);
        QByteArray format(ir.format());

        m_image = ir.read();

        NemoImageMetadata meta(m_source, format);

        if (meta.orientation() != NemoImageMetadata::TopLeft)
        {
            m_image = rotate(m_image, meta.orientation());
        }

        setImplicitWidth((qreal)m_image.width());
        setImplicitHeight((qreal)m_image.height());

        m_imageChanged = true;
        emit sourceChanged(m_source);
        emit imageChanged(m_image);
    }
}
Пример #4
0
void MySvgView::setSource(QUrl arg)
{
    if (m_source != arg) {
        m_source = arg;

        QString str = m_source.toLocalFile();
        if(str == "") {
            str = m_source.toString();
            if(str=="") {
                svg->deleteLater();
                svg = new QSvgRenderer(this);
                return;
            }
        }

        if( str.mid (0, 3) == "qrc")
            str = str.mid (3, str.count ()-3);
        svg->load (str);
        setDefaultSize (svg->defaultSize ());
        int width = svg->defaultSize ().width ();
        int height = svg->defaultSize ().height ();
        setImplicitWidth(width);
        setImplicitHeight(height);
        update ();
        emit sourceChanged(arg);
    }
}
Пример #5
0
void QDeclarativeImageBase::requestFinished()
{
    Q_D(QDeclarativeImageBase);

    QDeclarativeImageBase::Status oldStatus = d->status;
    qreal oldProgress = d->progress;

    if (d->pix.isError()) {
        d->status = Error;
        qmlInfo(this) << d->pix.error();
    } else {
        d->status = Ready;
    }

    d->progress = 1.0;

    setImplicitWidth(d->pix.width());
    setImplicitHeight(d->pix.height());

    if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height())
        emit sourceSizeChanged();

    if (d->status != oldStatus)
        emit statusChanged(d->status);
    if (d->progress != oldProgress)
        emit progressChanged(d->progress);
    pixmapChange();
    update();
}
Пример #6
0
void FrameSvgItem::setPrefix(const QString &prefix)
{
    if (m_prefix == prefix) {
        return;
    }

    m_frameSvg->setElementPrefix(prefix);
    m_prefix = prefix;

    if (implicitWidth() <= 0) {
        setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
    }

    if (implicitHeight() <= 0) {
        setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
    }

    emit prefixChanged();
    m_margins->update();
    m_fixedMargins->update();

    if (isComponentComplete()) {
        m_frameSvg->resizeFrame(QSizeF(width(), height()));
        m_textureChanged = true;
        update();
    }
}
Пример #7
0
void SvgItem::setSvg(Plasma::Svg *svg)
{
    if (m_svg) {
        disconnect(m_svg.data(), 0, this, 0);
    }
    m_svg = svg;
    updateDevicePixelRatio();

    if (svg) {
        connect(svg, SIGNAL(repaintNeeded()), this, SLOT(updateNeeded()));
        connect(svg, SIGNAL(repaintNeeded()), this, SIGNAL(naturalSizeChanged()));
        connect(svg, SIGNAL(sizeChanged()), this, SIGNAL(naturalSizeChanged()));
    }

    if (implicitWidth() <= 0) {
        setImplicitWidth(naturalSize().width());
    }
    if (implicitHeight() <= 0) {
        setImplicitHeight(naturalSize().height());
    }

    scheduleImageUpdate();

    emit svgChanged();
    emit naturalSizeChanged();
}
void QDeclarativeBorderImage::setGridScaledImage(const QDeclarativeGridScaledImage& sci)
{
    Q_D(QDeclarativeBorderImage);
    if (!sci.isValid()) {
        d->status = Error;
        emit statusChanged(d->status);
    } else {
        QDeclarativeScaleGrid *sg = border();
        sg->setTop(sci.gridTop());
        sg->setBottom(sci.gridBottom());
        sg->setLeft(sci.gridLeft());
        sg->setRight(sci.gridRight());
        d->horizontalTileMode = sci.horizontalTileRule();
        d->verticalTileMode = sci.verticalTileRule();

        d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl()));

        QDeclarativePixmap::Options options;
        if (d->async)
            options |= QDeclarativePixmap::Asynchronous;
        if (d->cache)
            options |= QDeclarativePixmap::Cache;
        d->pix.clear(this);
        d->pix.load(qmlEngine(this), d->sciurl, options);

        if (d->pix.isLoading()) {
            static int thisRequestProgress = -1;
            static int thisRequestFinished = -1;
            if (thisRequestProgress == -1) {
                thisRequestProgress =
                    QDeclarativeBorderImage::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
                thisRequestFinished =
                    QDeclarativeBorderImage::staticMetaObject.indexOfSlot("requestFinished()");
            }

            d->pix.connectFinished(this, thisRequestFinished);
            d->pix.connectDownloadProgress(this, thisRequestProgress);

        } else {

            QSize impsize = d->pix.implicitSize();
            setImplicitWidth(impsize.width());
            setImplicitHeight(impsize.height());

            if (d->pix.isReady()) {
                d->status = Ready;
            } else {
                d->status = Error;
                qmlInfo(this) << d->pix.error();
            }

            d->progress = 1.0;
            emit statusChanged(d->status);
            emit progressChanged(1.0);
            update();

        }
    }
}
Пример #9
0
QT_BEGIN_NAMESPACE


void QDeclarativeVideo::_q_nativeSizeChanged(const QSizeF &size)
{
    setImplicitWidth(size.width());
    setImplicitHeight(size.height());
}
void MDeclarativeImplicitSizeItem::setImplicitHeightNotify(const qreal height)
{
    if (implicitHeight() == height)
        return;

    setImplicitHeight(height);
    emit implicitHeightChanged();
}
void QDeclarativeBasePositioner::prePositioning()
{
    Q_D(QDeclarativeBasePositioner);
    if (!isComponentComplete())
        return;

    if (d->doingPositioning)
        return;

    d->queuedPositioning = false;
    d->doingPositioning = true;
    //Need to order children by creation order modified by stacking order
    QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children;
    qSort(children.begin(), children.end(), d->insertionOrder);

    QPODVector<PositionedItem,8> oldItems;
    positionedItems.copyAndClear(oldItems);
    for (int ii = 0; ii < children.count(); ++ii) {
        QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii));
        if (!child)
            continue;
        QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child));
        PositionedItem *item = 0;
        PositionedItem posItem(child);
        int wIdx = oldItems.find(posItem);
        if (wIdx < 0) {
            d->watchChanges(child);
            positionedItems.append(posItem);
            item = &positionedItems[positionedItems.count()-1];
            item->isNew = true;
            if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden)
                item->isVisible = false;
        } else {
            item = &oldItems[wIdx];
            // Items are only omitted from positioning if they are explicitly hidden
            // i.e. their positioning is not affected if an ancestor is hidden.
            if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden) {
                item->isVisible = false;
            } else if (!item->isVisible) {
                item->isVisible = true;
                item->isNew = true;
            } else {
                item->isNew = false;
            }
            positionedItems.append(*item);
        }
    }
    QSizeF contentSize;
    doPositioning(&contentSize);
    if(d->addTransition || d->moveTransition)
        finishApplyTransitions();
    d->doingPositioning = false;
    //Set implicit size to the size of its children
    setImplicitHeight(contentSize.height());
    setImplicitWidth(contentSize.width());
}
Пример #12
0
void QDeclarativeBasePositioner::prePositioning()
{
    Q_D(QDeclarativeBasePositioner);
    if (!isComponentComplete())
        return;

    d->queuedPositioning = false;
    //Need to order children by creation order modified by stacking order
    QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children;
    qSort(children.begin(), children.end(), d->insertionOrder);

    QPODVector<PositionedItem,8> oldItems;
    positionedItems.copyAndClear(oldItems);
    for (int ii = 0; ii < children.count(); ++ii) {
        QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii));
        if (!child)
            continue;
        PositionedItem *item = 0;
        PositionedItem posItem(child);
        int wIdx = oldItems.find(posItem);
        if (wIdx < 0) {
            d->watchChanges(child);
            positionedItems.append(posItem);
            item = &positionedItems[positionedItems.count()-1];
            item->isNew = true;
            if (child->opacity() <= 0.0 || !child->isVisible())
                item->isVisible = false;
        } else {
            item = &oldItems[wIdx];
            if (child->opacity() <= 0.0 || !child->isVisible()) {
                item->isVisible = false;
            } else if (!item->isVisible) {
                item->isVisible = true;
                item->isNew = true;
            } else {
                item->isNew = false;
            }
            positionedItems.append(*item);
        }
    }
    doPositioning();
    if(d->addTransition || d->moveTransition)
        finishApplyTransitions();
    //Set implicit size to the size of its children
    qreal h = 0.0f;
    qreal w = 0.0f;
    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &posItem = positionedItems.at(i);
        if (posItem.isVisible) {
            h = qMax(h, posItem.item->y() + posItem.item->height());
            w = qMax(w, posItem.item->x() + posItem.item->width());
        }
    }
    setImplicitHeight(h);
    setImplicitWidth(w);
}
Пример #13
0
void MyImage::setImage(QImage &image)
{
    setDefaultSize(image.size());

    if(m_cache){
        QPixmap *temp_pixmap = new QPixmap(QPixmap::fromImage(image));
        pixmapCache.insert(m_source.toString(), temp_pixmap);
    }

    QSize temp_size = m_sourceSize;
    if(temp_size==QSize(0,0)){
        temp_size = m_defaultSize;
    }else if(temp_size.width()==0){
        temp_size.setWidth((double)temp_size.height()/m_defaultSize.height()*m_defaultSize.width());
    }else if(temp_size.height()==0){
        temp_size.setHeight((double)temp_size.width()/m_defaultSize.width()*m_defaultSize.height());
    }
    if(m_defaultSize!=temp_size)
        image = image.scaled(temp_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

    if(m_grayscale){//如果为黑白
        chromaticToGrayscale(image);//转换为黑白图
    }

    if(pixmap!=NULL)
        delete pixmap;
    pixmap = new QPixmap(QPixmap::fromImage(image));

    QString str = m_maskSource.toLocalFile();
    if(str==""){
        str = m_maskSource.toString();
    }
    if(str!=""){
        if( str.mid (0, 3) == "qrc")
            str = str.mid (3, str.count ()-3);
        QBitmap bitmap(str);
        if(!bitmap.isNull()){
            int max_width = bitmap.width();
            int max_height = bitmap.height();
            max_width = pixmap->width()>max_width?pixmap->width():max_width;
            max_height = pixmap->height()>max_height?pixmap->height():max_height;

            QPixmap temp_pixmap = pixmap->scaled(max_width, max_height);
            temp_pixmap.setMask (bitmap.scaled(temp_pixmap.size()));
            *pixmap = temp_pixmap.scaled(image.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        }
    }

    setImplicitWidth(image.width());
    setImplicitHeight(image.height());

    update();

    setStatus(Ready);
    emit loadReady();
}
Пример #14
0
void SvgItem::updateNeeded()
{
    if (implicitWidth() <= 0) {
        setImplicitWidth(naturalSize().width());
    }
    if (implicitHeight() <= 0) {
        setImplicitHeight(naturalSize().height());
    }
    scheduleImageUpdate();
}
Пример #15
0
/*!
    Sets the size of the contents to the given \a size.

    \sa contentsSize()
*/
void QDeclarativePaintedItem::setContentsSize(const QSize &size)
{
    Q_D(QDeclarativePaintedItem);
    if (d->contentsSize == size) return;
    d->contentsSize = size;
    setImplicitWidth(size.width()*d->contentsScale);
    setImplicitHeight(size.height()*d->contentsScale);
    clearCache();
    update();
    emit contentsSizeChanged();
}
Пример #16
0
void QDeclarativePaintedItem::setContentsScale(qreal scale)
{
    Q_D(QDeclarativePaintedItem);
    if (d->contentsScale == scale) return;
    d->contentsScale = scale;
    setImplicitWidth(d->contentsSize.width()*scale);
    setImplicitHeight(d->contentsSize.height()*scale);
    clearCache();
    update();
    emit contentsScaleChanged();
}
Пример #17
0
void TextQuickItem::calcPos()
{
    int textWidth = 0;
    int textAscent = 0;
    int textDescent = 0;
    int textXShift = 0;

    bool firstLoop = true;
    for (TextWithFont &textWithFont : m_textParts) {

        // Note: Initial construction of QFontMetrics is expensive (This function takes ~95% of first updatePaintNode
        // call - e.g 48,5 of 51 ms)! Subsequent calls are much faster, so Qt seems to already have a caching mechanism
        // in place. There is no significant difference between using tightBoundingRect, boundingRect or merely
        // height/width.
        // TODO: use already existing font calculation from BBoxDeviceContext (which is currently not stored anywhere)
        // for ascent, descent, height, width
        QFontMetrics fm(textWithFont.font);

        auto boundingRect = fm.boundingRect(textWithFont.text);

        textWithFont.offset = textWidth;
        textWidth += fm.width(textWithFont.text);
        textAscent = std::max(textAscent, boundingRect.top() * -1);
        textDescent = std::max(textDescent, boundingRect.bottom());
        if (firstLoop) {
            // Note that the bounding rect can start at a negative x (e.g. italic font)
            textXShift = boundingRect.left();
            textWidth -= textXShift;
            firstLoop = false;
        }
    }
    qreal newX = x() + textXShift;
    if (m_alignment == Qt::AlignRight) {
        setX(newX - textWidth);
    }
    else if (m_alignment == Qt::AlignHCenter) {
        setX(newX - textWidth / 2);
    }
    else {
        setX(newX);
    }
    setY(y() - textAscent);

    m_paintOffsetY += textAscent;
    m_paintOffsetX += textXShift * -1;

    int textHeight = textDescent + textAscent + 1;

    setImplicitWidth(textWidth);
    setImplicitHeight(textHeight);
}
void QQuickStretchColumnContainer::updatePolish (void) {
    const QList<QQuickItem *> childrenList = childItems ();
    /// find items and stretchers
    qreal tmpW = 0;
    qreal tmpH = 0;
    int nbItems   = 0;
    int nbStretch = 0;
    for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin (); it != childrenList.constEnd (); it++) {
        QQuickItem * child = (* it);
        if (child != Q_NULLPTR && !child->inherits ("QQuickRepeater") && child->isVisible ()) {
            if (child->implicitWidth () > tmpW) {
                tmpW = child->implicitWidth ();
            }
            if (child->implicitHeight () >= 0) {
                tmpH += child->implicitHeight ();
            }
            else {
                nbStretch++;
            }
            nbItems++;
        }
    }
    /// resize layout
    if (nbItems > 1) {
        tmpH += (m_spacing * (nbItems -1));
    }
    setImplicitWidth  (tmpW);
    setImplicitHeight (tmpH);
    const qreal layoutWidth  = width  ();
    const qreal layoutHeight = height ();
    const qreal autoSize = (nbStretch > 0 ? (layoutHeight - tmpH) / qreal (nbStretch) : 0);
    /// position children
    int currY = 0;
    for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin (); it != childrenList.constEnd (); it++) {
        QQuickItem * child = (* it);
        if (child != Q_NULLPTR && !child->inherits ("QQuickRepeater") && child->isVisible ()) {
            if (currY) {
                currY += m_spacing;
            }
            child->setY (currY);
            child->setWidth (layoutWidth);
            child->setHeight (child->implicitHeight () >= 0 ? child->implicitHeight () : autoSize);
            currY += child->height ();
        }
    }
}
Пример #19
0
void QDeclarativeImageBase::load()
{
    Q_D(QDeclarativeImageBase);

    if (d->url.isEmpty()) {
        d->pix.clear();
        d->status = Null;
        d->progress = 0.0;
        setImplicitWidth(0);
        setImplicitHeight(0);
        emit progressChanged(d->progress);
        emit statusChanged(d->status);
        pixmapChange();
        update();
    } else {
        QDeclarativePixmap::Options options;
        if (d->async)
            options |= QDeclarativePixmap::Asynchronous;
        if (d->cache)
            options |= QDeclarativePixmap::Cache;
        d->pix.load(qmlEngine(this), d->url, d->explicitSourceSize ? sourceSize() : QSize(), options);

        if (d->pix.isLoading()) {
            d->progress = 0.0;
            d->status = Loading;
            emit progressChanged(d->progress);
            emit statusChanged(d->status);

            static int thisRequestProgress = -1;
            static int thisRequestFinished = -1;
            if (thisRequestProgress == -1) {
                thisRequestProgress =
                    QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
                thisRequestFinished =
                    QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestFinished()");
            }

            d->pix.connectFinished(this, thisRequestFinished);
            d->pix.connectDownloadProgress(this, thisRequestProgress);

        } else {
            requestFinished();
        }
    }
}
Пример #20
0
void QQuickComponentsLinearLayout::updateLayoutItems()
{
    const QList<QQuickItem *> &children = childItems();
    qreal implicitWidth = 0;
    qreal implicitHeight = 0;
    foreach (QQuickItem *child, children) {
        if (m_orientation == Horizontal) {
            implicitWidth += child->implicitWidth();
            implicitHeight = qMax(implicitHeight, child->implicitHeight());
        } else {
            implicitHeight += child->implicitHeight();
            implicitWidth = qMax(implicitWidth, child->implicitWidth());
        }
        insertLayoutItem(child);
    }
    setImplicitWidth(implicitWidth);
    setImplicitHeight(implicitHeight);
}
Пример #21
0
void SvgItem::setElementId(const QString &elementID)
{
    if (elementID == m_elementID) {
        return;
    }

    if (implicitWidth() <= 0) {
        setImplicitWidth(naturalSize().width());
    }
    if (implicitHeight() <= 0) {
        setImplicitHeight(naturalSize().height());
    }

    m_elementID = elementID;
    emit elementIdChanged();
    emit naturalSizeChanged();

    scheduleImageUpdate();
}
void QDeclarativeImageBase::load()
{
    Q_D(QDeclarativeImageBase);
    if (d->progress != 0.0) {
        d->progress = 0.0;
        emit progressChanged(d->progress);
    }

    if (d->url.isEmpty()) {
        d->pix.clear();
        d->status = Null;
        setImplicitWidth(0);
        setImplicitHeight(0);
        emit statusChanged(d->status);
        pixmapChange();
        update();
    } else {

        d->status = Loading;
        emit statusChanged(d->status);

        d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async);

        if (d->pix.isLoading()) {

            static int thisRequestProgress = -1;
            static int thisRequestFinished = -1;
            if (thisRequestProgress == -1) {
                thisRequestProgress =
                    QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)");
                thisRequestFinished =
                    QDeclarativeImageBase::staticMetaObject.indexOfSlot("requestFinished()");
            }

            d->pix.connectFinished(this, thisRequestFinished);
            d->pix.connectDownloadProgress(this, thisRequestProgress);

        } else {
            requestFinished();
        }
    }
}
void QDeclarativeBorderImage::requestFinished()
{
    Q_D(QDeclarativeBorderImage);

    QSize impsize = d->pix.implicitSize();
    if (d->pix.isError()) {
        d->status = Error;
        qmlInfo(this) << d->pix.error();
    } else {
        d->status = Ready;
    }

    setImplicitWidth(impsize.width());
    setImplicitHeight(impsize.height());

    d->progress = 1.0;
    emit statusChanged(d->status);
    emit progressChanged(1.0);
    update();
}
Пример #24
0
IconItem::IconItem(QQuickItem *parent)
    : QQuickItem(parent),
      m_svgIcon(0),
      m_status(Plasma::Svg::Normal),
      m_smooth(false),
      m_active(false),
      m_animated(true),
      m_usesPlasmaTheme(true),
      m_textureChanged(false),
      m_sizeChanged(false),
      m_allowNextAnimation(false),
      m_colorGroup(Plasma::Theme::NormalColorGroup),
      m_animValue(0)
{
    m_animation = new QPropertyAnimation(this);
    connect(m_animation, SIGNAL(valueChanged(QVariant)),
            this, SLOT(valueChanged(QVariant)));
    connect(m_animation, SIGNAL(finished()),
            this, SLOT(animationFinished()));
    m_animation->setTargetObject(this);
    m_animation->setEasingCurve(QEasingCurve::InOutQuad);
    m_animation->setDuration(250); //FIXME from theme

    setFlag(ItemHasContents, true);

    connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
            this, SIGNAL(implicitWidthChanged()));
    connect(KIconLoader::global(), SIGNAL(iconLoaderSettingsChanged()),
            this, SIGNAL(implicitHeightChanged()));

    connect(this, &QQuickItem::enabledChanged,
            this, &IconItem::enabledChanged);

    connect(this, &QQuickItem::windowChanged,
            this, &IconItem::schedulePixmapUpdate);

    //initialize implicit size to the Dialog size
    setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
    setImplicitHeight(KIconLoader::global()->currentSize(KIconLoader::Dialog));
}
Пример #25
0
//### we should perhaps be a bit smarter here -- depending on what has changed, we shouldn't
//    need to do all the calculations each time
void QDeclarativeTextEdit::updateSize()
{
    Q_D(QDeclarativeTextEdit);
    if (isComponentComplete()) {
        QFontMetrics fm = QFontMetrics(d->font);
        int dy = height();
        // ### assumes that if the width is set, the text will fill to edges
        // ### (unless wrap is false, then clipping will occur)
        if (widthValid())
            d->document->setTextWidth(width());
        dy -= (int)d->document->size().height();

        int yoff = 0;
        if (heightValid()) {
            if (d->vAlign == AlignBottom)
                yoff = dy;
            else if (d->vAlign == AlignVCenter)
                yoff = dy/2;
        }
        setBaselineOffset(fm.ascent() + yoff + d->textMargin);

        //### need to comfirm cost of always setting these
        int newWidth = (int)d->document->idealWidth();
        d->document->setTextWidth(newWidth); // ### QTextDoc> Alignment will not work unless textWidth is set. Does Text need this line as well?
        int cursorWidth = 1;
        if(d->cursor)
            cursorWidth = d->cursor->width();
        newWidth += cursorWidth;
        if(!d->document->isEmpty())
            newWidth += 3;// ### Need a better way of accounting for space between char and cursor
        // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed.
        setImplicitWidth(newWidth);
        setImplicitHeight(d->text.isEmpty() ? fm.height() : (int)d->document->size().height());

        setContentsSize(QSize(width(), height()));
    } else {
        d->dirty = true;
    }
    emit update();
}
Пример #26
0
void FrameSvgItem::doUpdate()
{
    if (implicitWidth() <= 0) {
        setImplicitWidth(m_frameSvg->marginSize(Plasma::Types::LeftMargin) + m_frameSvg->marginSize(Plasma::Types::RightMargin));
    }

    if (implicitHeight() <= 0) {
        setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
    }

    QString prefix = m_frameSvg->actualPrefix();
    bool hasOverlay = !prefix.startsWith(QLatin1String("mask-")) && m_frameSvg->hasElement(prefix % QLatin1String("overlay"));
    bool hasComposeOverBorder = m_frameSvg->hasElement(prefix % QLatin1String("hint-compose-over-border")) &&
                                m_frameSvg->hasElement(QLatin1String("mask-") % prefix % QLatin1String("center"));
    m_fastPath = !hasOverlay && !hasComposeOverBorder;
    m_textureChanged = true;

    update();
    m_margins->update();
    m_fixedMargins->update();
    emit repaintNeeded();
}
void StretchColumn::layoutChildrenWithDefaultSize() {
	//static int count = 0;
	//qDebug() << "Column Default Size" << ++count;
    Q_ASSERT(m_defaultSize != 0);

	const QList<QQuickItem *> childrenList = childItems();
	if (childrenList.isEmpty()) return;

    const int contentWidth = width() - m_leftMargin - m_rightMargin;
    qreal currY = 0;
    for (QList<QQuickItem *>::const_iterator it = childrenList.constBegin(); it != childrenList.constEnd(); ++it) {
		QQuickItem* child = (*it);
		if (child == Q_NULLPTR || !child->isVisible()) {
			continue;
		}

		// add spacing if it is not the first item:
		if (currY > 0) {
			currY += m_spacing;
		}
		if (currY != child->y()) child->setY(currY);
		// check if item has a stretch proportion set:
		if (child->implicitHeight() < 0) {
			// yes -> set it to default size multiplied by relative size:
            qreal newHeight = m_defaultSize * child->implicitHeight() * -1;
            if (newHeight != child->height()) child->setHeight(newHeight);
		}
		// set width of all items to fill the layout:
        if (m_leftMargin != child->x()) child->setX(m_leftMargin);
		if (contentWidth != child->width()) child->setWidth(contentWidth);
		currY += child->height();
	}

	// set implicit size to fit all items:
	if (currY != implicitHeight()) setImplicitHeight(currY);
}
Пример #28
0
void QDeclarativeImageBase::pixmapChange()
{
    Q_D(QDeclarativeImageBase);
    setImplicitWidth(d->pix.width());
    setImplicitHeight(d->pix.height());
}
Пример #29
0
void QDeclarativeMozView::updateDeclarativeMozViewSize()
{
    QSizeF size = d->view->geometry().size();
    setImplicitWidth(size.width());
    setImplicitHeight(size.height());
}
void QDeclarativeBorderImage::load()
{
    Q_D(QDeclarativeBorderImage);
    if (d->progress != 0.0) {
        d->progress = 0.0;
        emit progressChanged(d->progress);
    }

    if (d->url.isEmpty()) {
        d->pix.clear();
        d->status = Null;
        setImplicitWidth(0);
        setImplicitHeight(0);
        emit statusChanged(d->status);
        update();
    } else {
        d->status = Loading;
        if (d->url.path().endsWith(QLatin1String("sci"))) {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
            QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url);
            if (!lf.isEmpty()) {
                QFile file(lf);
                file.open(QIODevice::ReadOnly);
                setGridScaledImage(QDeclarativeGridScaledImage(&file));
            } else
#endif
            {
                QNetworkRequest req(d->url);
                d->sciReply = qmlEngine(this)->networkAccessManager()->get(req);

                static int sciReplyFinished = -1;
                static int thisSciRequestFinished = -1;
                if (sciReplyFinished == -1) {
                    sciReplyFinished =
                        QNetworkReply::staticMetaObject.indexOfSignal("finished()");
                    thisSciRequestFinished =
                        QDeclarativeBorderImage::staticMetaObject.indexOfSlot("sciRequestFinished()");
                }

                QMetaObject::connect(d->sciReply, sciReplyFinished, this,
                                     thisSciRequestFinished, Qt::DirectConnection);
            }
        } else {

            d->pix.load(qmlEngine(this), d->url, d->async);

            if (d->pix.isLoading()) {
                d->pix.connectFinished(this, SLOT(requestFinished()));
                d->pix.connectDownloadProgress(this, SLOT(requestProgress(qint64,qint64)));
            } else {
                QSize impsize = d->pix.implicitSize();
                setImplicitWidth(impsize.width());
                setImplicitHeight(impsize.height());

                if (d->pix.isReady()) {
                    d->status = Ready;
                } else {
                    d->status = Error;
                    qmlInfo(this) << d->pix.error();
                }

                d->progress = 1.0;
                emit statusChanged(d->status);
                emit progressChanged(d->progress);
                update();
            }
        }
    }

    emit statusChanged(d->status);
}