예제 #1
0
void MediaPlayerPrivateQt::nativeSizeChanged(const QSizeF& size)
{
    LOG(Media, "MediaPlayerPrivateQt::naturalSizeChanged(%dx%d)",
            size.toSize().width(), size.toSize().height());

    if (!size.isValid())
        return;

    m_naturalSize = size.toSize();
    m_webCorePlayer->sizeChanged();
}
예제 #2
0
//-----------------------------------------------------------
void VisaoGeralWidget::redimensionarVisaoGeral(void)
{
 if(viewp)
 {
  QSizeF tam;

  //Redimensiona o widget conforme as dimensões da cena
  tam=cena->sceneRect().size();
  tam.setWidth(tam.width() * FATOR_REDIM);
  tam.setHeight(tam.height() * FATOR_REDIM);
  this->resize(tam.toSize());
  this->setMaximumSize(tam.toSize());
  this->setMinimumSize(tam.toSize());
 }
}
예제 #3
0
파일: main.cpp 프로젝트: EQ4/guido-engine
int main(int argc , char* argv[])
{
	QApplication app( argc , argv );

	//Guido Engine initialization
	QGuidoPainter::startGuidoEngine();

	//Create a QGuidoPainter...
	QGuidoPainter * p = QGuidoPainter::createGuidoPainter();
	//...and give it some Guido Music Notation
	p->setGMNCode( "[c/8 d e g e d c]" );

	//Get the size of the score's first and only page
	int pageIndex = 1;
	QSizeF s = p->pageSizeMM( pageIndex );

	//Create a blank image, using the size of the score
	QImage image( s.toSize() * 10 , 
				  QImage::Format_ARGB32 );
	image.fill( QColor(Qt::white).rgb() );
	
	//Draw on the QImage with the QGuidoPainter, via a QPainter
	QPainter painter( &image );
	p->draw( &painter , pageIndex , image.rect() );
	
	QGuidoPainter::destroyGuidoPainter( p );

	//Destroy the Guido Engine resources 
	QGuidoPainter::stopGuidoEngine();

	//Save the score
	image.save( "myScore.png" );

	return 0;
}
SuperButton::SuperButton(const QString &label, const QSizeF &size, const QString file_name, Qt::AlignmentFlag flag)
    : label(label), size(size), mute(true), font(Config.SmallFont)
{
    title = QPixmap(size.toSize());
    outimg = QImage(size.toSize(), QImage::Format_ARGB32);
    init(file_name, flag);
}
예제 #5
0
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
{
    qreal scaleFactor = translatedSize.width() / boundingRect().width();
    
    CardInfo *imageSource = facedown ? db->getCard() : info;
    QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize());
    painter->save();
    QColor bgColor = Qt::transparent;
    if (translatedPixmap) {
        painter->save();
        transformPainter(painter, translatedSize, angle);
        painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
        painter->restore();
    } else {
        QString colorStr;
        if (!color.isEmpty())
            colorStr = color;
        else if (info->getColors().size() > 1)
            colorStr = "m";
        else if (!info->getColors().isEmpty())
            colorStr = info->getColors().first().toLower();
        
        if (colorStr == "b")
            bgColor = QColor(0, 0, 0);
        else if (colorStr == "u")
            bgColor = QColor(0, 140, 180);
        else if (colorStr == "w")
            bgColor = QColor(255, 250, 140);
        else if (colorStr == "r")
            bgColor = QColor(230, 0, 0);
        else if (colorStr == "g")
            bgColor = QColor(0, 160, 0);
        else if (colorStr == "m")
            bgColor = QColor(250, 190, 30);
        else
            bgColor = QColor(230, 230, 230);
    }
    painter->setBrush(bgColor);
    QPen pen(Qt::black);
    pen.setWidth(2);
    painter->setPen(pen);
    painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
    
    if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) {
        painter->save();
        transformPainter(painter, translatedSize, angle);
        painter->setPen(Qt::white);
        painter->setBackground(Qt::black);
        painter->setBackgroundMode(Qt::OpaqueMode);
        QString nameStr;
        if (facedown)
            nameStr = "# " + QString::number(id);
        else
            nameStr = name;
        painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, nameStr);
        painter->restore();
    }
    
    painter->restore();
}
예제 #6
0
void PosteRazorCore::paintPaperOnCanvas(PaintCanvasInterface *paintCanvas, bool paintOverlapping) const
{
    const QSizeF canvasSize = paintCanvas->size();
    const QSizeF paperSize = this->paperSize();
    const QSizeF boxSize = previewSize(paperSize, canvasSize.toSize(), true);
    const QPointF offset((canvasSize.width() - boxSize.width()) / 2.0, (canvasSize.height() - boxSize.height()) / 2.0);
    const qreal UnitOfLengthToPixelfactor = boxSize.width()/paperSize.width();
    const qreal borderTop = paperBorderTop() * UnitOfLengthToPixelfactor;
    const qreal borderRight = paperBorderRight() * UnitOfLengthToPixelfactor;
    const qreal borderBottom = paperBorderBottom() * UnitOfLengthToPixelfactor;
    const qreal borderLeft = paperBorderLeft() * UnitOfLengthToPixelfactor;
    const QSizeF printableAreaSize(boxSize.width() - borderLeft - borderRight, boxSize.height() - borderTop - borderBottom);

    paintCanvas->drawFilledRect(QRectF(offset, boxSize), QColor(128, 128, 128));
    paintCanvas->drawFilledRect(QRectF(QPointF(borderLeft, borderTop) + offset, printableAreaSize), QColor(230, 230, 230));

    if (paintOverlapping) {
        const qreal overlappingWidth = this->overlappingWidth() * UnitOfLengthToPixelfactor;
        const qreal overlappingHeight = this->overlappingHeight() * UnitOfLengthToPixelfactor;
        const Qt::Alignment overlappingPosition = this->overlappingPosition();
        const qreal overlappingTop = (overlappingPosition & Qt::AlignTop)?
            borderTop:boxSize.height() - borderBottom - overlappingHeight;
        const qreal overlappingLeft = (overlappingPosition & Qt::AlignLeft)?
            borderLeft:boxSize.width() - borderRight - overlappingWidth;

        const QColor overlappingBrush(255, 128, 128);
        paintCanvas->drawFilledRect(QRectF(QPointF(borderLeft, overlappingTop) + offset, QSizeF(printableAreaSize.width(), overlappingHeight)), overlappingBrush);
        paintCanvas->drawFilledRect(QRectF(QPointF(overlappingLeft, borderTop) + offset, QSizeF(overlappingWidth, printableAreaSize.height())), overlappingBrush);
    }
}
예제 #7
0
QImage SvgPatternHelper::generateImage( const QRectF &objectBound, const QList<KoShape*> content )
{
    KoZoomHandler zoomHandler;
    
    QSizeF patternSize = size( objectBound );
    QSizeF tileSize = zoomHandler.documentToView( patternSize );

    QMatrix viewMatrix;

    if( ! m_patternContentViewbox.isNull() )
    {
        viewMatrix.translate( -m_patternContentViewbox.x(), -m_patternContentViewbox.y() );
        const qreal xScale = patternSize.width() / m_patternContentViewbox.width();
        const qreal yScale = patternSize.height() / m_patternContentViewbox.height();
        viewMatrix.scale( xScale, yScale );
    }

    // setup the tile image
    QImage tile( tileSize.toSize(), QImage::Format_ARGB32 );
    tile.fill( QColor( Qt::transparent ).rgba() );
    
    // setup the painter to paint the tile content
    QPainter tilePainter( &tile );
    tilePainter.setClipRect( tile.rect() );
    tilePainter.setWorldMatrix( viewMatrix );
    //tilePainter.setRenderHint(QPainter::Antialiasing);

    // paint the content into the tile image
    KoShapePainter shapePainter;
    shapePainter.setShapes( content );
    shapePainter.paintShapes( tilePainter, zoomHandler );

    return tile;
}
예제 #8
0
QImage GLImageDrawable::applyBorder(const QImage& sourceImg)
{
	if(renderBorder() && 
	   m_borderWidth > 0.001)
	{
		QSizeF originalSizeWithBorder = sourceImg.size();

		double x = m_borderWidth * 2;
		originalSizeWithBorder.rwidth()  += x;
		originalSizeWithBorder.rheight() += x;
		
		QImage cache(originalSizeWithBorder.toSize(),QImage::Format_ARGB32_Premultiplied);
		memset(cache.scanLine(0),0,cache.byteCount());
		QPainter p(&cache);
		
		int bw = (int)(m_borderWidth / 2);
		p.drawImage(bw,bw,sourceImg); //drawImage(bw,bw,sourceImg);
		p.setPen(QPen(m_borderColor,m_borderWidth));
		p.drawRect(sourceImg.rect().adjusted(bw,bw,bw,bw)); //QRectF(sourceImg.rect()).adjusted(-bw,-bw,bw,bw));
		
		m_imageWithBorder = cache;
		return cache;
	}
	
	if(!m_imageWithBorder.isNull())
		m_imageWithBorder = QImage();
	
	return sourceImg;
}
SuperButton::SuperButton(const QString &label, const QSizeF &size)
    : label(label), size(size), mute(true), font(Config.SmallFont)
{
    title = QPixmap(size.toSize());
    outimg = QImage(size.toSize(), QImage::Format_ARGB32);
    init();
}
예제 #10
0
void CDiaryEdit::slotPrintPreview()
{
    CDiaryEditLock lock(this);
    collectData();

    QPrinter printer;
    QPrintDialog dialog(&printer, this);
    dialog.setWindowTitle(tr("Print Diary"));
    if (dialog.exec() != QDialog::Accepted)
        return;

    QTextDocument doc;
    QSizeF pageSize = printer.pageRect(QPrinter::DevicePixel).size();
    doc.setPageSize(pageSize);
    draw(doc);

    if(checkAddMap->isChecked())
    {
        QImage img;
        theMainWindow->getCanvas()->print(img, pageSize.toSize() - QSize(10,10));
        doc.rootFrame()->lastCursorPosition().insertImage(img);
    }
    doc.print(&printer);

    textEdit->clear();
    textEdit->document()->setTextWidth(textEdit->size().width() - 20);
    draw(*textEdit->document());
}
void KStandardItemListWidget::updateTextsCache()
{
    QTextOption textOption;
    switch (m_layout) {
    case IconsLayout:
        textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
        textOption.setAlignment(Qt::AlignHCenter);
        break;
    case CompactLayout:
    case DetailsLayout:
        textOption.setAlignment(Qt::AlignLeft);
        textOption.setWrapMode(QTextOption::NoWrap);
        break;
    default:
        Q_ASSERT(false);
        break;
    }

    qDeleteAll(m_textInfo);
    m_textInfo.clear();
    for (int i = 0; i < m_sortedVisibleRoles.count(); ++i) {
        TextInfo* textInfo = new TextInfo();
        textInfo->staticText.setTextFormat(Qt::PlainText);
        textInfo->staticText.setPerformanceHint(QStaticText::AggressiveCaching);
        textInfo->staticText.setTextOption(textOption);
        m_textInfo.insert(m_sortedVisibleRoles[i], textInfo);
    }

    switch (m_layout) {
    case IconsLayout:   updateIconsLayoutTextCache(); break;
    case CompactLayout: updateCompactLayoutTextCache(); break;
    case DetailsLayout: updateDetailsLayoutTextCache(); break;
    default: Q_ASSERT(false); break;
    }

    const TextInfo* ratingTextInfo = m_textInfo.value("rating");
    if (ratingTextInfo) {
        // The text of the rating-role has been set to empty to get
        // replaced by a rating-image showing the rating as stars.
        const KItemListStyleOption& option = styleOption();
        QSizeF ratingSize = preferredRatingSize(option);

        const qreal availableWidth = (m_layout == DetailsLayout)
                                     ? columnWidth("rating") - columnPadding(option)
                                     : size().width();
        if (ratingSize.width() > availableWidth) {
            ratingSize.rwidth() = availableWidth;
        }
        m_rating = QPixmap(ratingSize.toSize());
        m_rating.fill(Qt::transparent);

        QPainter painter(&m_rating);
        const QRect rect(0, 0, m_rating.width(), m_rating.height());
        const int rating = data().value("rating").toInt();
        KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating);
    } else if (!m_rating.isNull()) {
        m_rating = QPixmap();
    }
}
예제 #12
0
void QgsHtmlAnnotation::renderAnnotation( QgsRenderContext &context, QSizeF size ) const
{
  if ( !context.painter() )
  {
    return;
  }

  mWebPage->setViewportSize( size.toSize() );
  mWebPage->mainFrame()->render( context.painter() );
}
    void paintEvent(QPaintEvent *)
    {
        QSize pageSize = m_pageLayout.fullRectPoints().size();
        QSizeF scaledSize = pageSize.scaled(width() - 10, height() - 10, Qt::KeepAspectRatio);
        QRect pageRect = QRect(QPoint(0,0), scaledSize.toSize());
        pageRect.moveCenter(rect().center());
        qreal width_factor = scaledSize.width() / pageSize.width();
        qreal height_factor = scaledSize.height() / pageSize.height();
        QMarginsF margins = m_pageLayout.margins(QPageLayout::Point);
        int left = qRound(margins.left() * width_factor);
        int top = qRound(margins.top() * height_factor);
        int right = qRound(margins.right() * width_factor);
        int bottom = qRound(margins.bottom() * height_factor);
        QRect marginRect(pageRect.x() + left, pageRect.y() + top,
                         pageRect.width() - (left + right + 1), pageRect.height() - (top + bottom + 1));

        QPainter p(this);
        QColor shadow(palette().mid().color());
        for (int i=1; i<6; ++i) {
            shadow.setAlpha(180-i*30);
            QRect offset(pageRect.adjusted(i, i, i, i));
            p.setPen(shadow);
            p.drawLine(offset.left(), offset.bottom(), offset.right(), offset.bottom());
            p.drawLine(offset.right(), offset.top(), offset.right(), offset.bottom()-1);
        }
        p.fillRect(pageRect, palette().light());

        if (marginRect.isValid()) {
            p.setPen(QPen(palette().color(QPalette::Dark), 0, Qt::DotLine));
            p.drawRect(marginRect);

            marginRect.adjust(2, 2, -1, -1);
            p.setClipRect(marginRect);
            QFont font;
            font.setPointSizeF(font.pointSizeF()*0.25);
            p.setFont(font);
            p.setPen(palette().color(QPalette::Dark));
            QString text(QLatin1String("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."));
            for (int i=0; i<3; ++i)
                text += text;

            const int spacing = pageRect.width() * 0.1;
            const int textWidth = (marginRect.width() - (spacing * (m_pagePreviewColumns-1))) / m_pagePreviewColumns;
            const int textHeight = (marginRect.height() - (spacing * (m_pagePreviewRows-1))) / m_pagePreviewRows;

            for (int x = 0 ; x < m_pagePreviewColumns; ++x) {
                for (int y = 0 ; y < m_pagePreviewRows; ++y) {
                    QRect textRect(marginRect.left() + x * (textWidth + spacing),
                                   marginRect.top() + y * (textHeight + spacing),
                                   textWidth, textHeight);
                    p.drawText(textRect, Qt::TextWordWrap|Qt::AlignVCenter, text);
                }
            }
        }
    }
void WlanLoginView::adjustViewSize()
{
    OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_ENTRY );
    
    //Store current screen size
    QSizeF screenSize = mMainWindow->layoutRect().size();
    
    //Store current content size
    QSize contentSize = mWebView->page()->mainFrame()->contentsSize();
    
    //Set viewPortSize to biggest values of content size or current screen size 
    QSize newViewPortSize;
    if (screenSize.toSize().width() > contentSize.width()) {
        newViewPortSize.setWidth(screenSize.toSize().width());
    } else {    
        newViewPortSize.setWidth(contentSize.width());
    }
    
    if (screenSize.toSize().height() > contentSize.height()) {
        newViewPortSize.setHeight(screenSize.toSize().height());
    } else {    
        newViewPortSize.setHeight(contentSize.height());
    }
    mWebView->page()->setViewportSize(newViewPortSize);
    
    
    //Set Web View size to same size as viewport
    mWebView->setMinimumWidth((qreal)newViewPortSize.width());
    mWebView->setMaximumWidth((qreal)newViewPortSize.width());
    mWebView->setPreferredWidth((qreal)newViewPortSize.width());
    
    mWebView->setMinimumHeight((qreal)newViewPortSize.height());
    mWebView->setMaximumHeight((qreal)newViewPortSize.height());
    mWebView->setPreferredHeight((qreal)newViewPortSize.height());
    
    
    //Set preferred content size to current screen size
    mWebView->page()->setPreferredContentsSize(mMainWindow->layoutRect().size().toSize());
      
    OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_EXIT );
}
예제 #15
0
Window::Window(const QString &title, const QSizeF &size, const QString &path)
    : size(size), keep_when_disappear(false)
{
    setFlags(ItemIsMovable);

    QPixmap *bg;
    if (!path.isEmpty())
        bg = new QPixmap(path);
    else
        bg = size.width() > size.height() ? new QPixmap("image/system/tip.png") : new QPixmap("image/system/about.png");
    QImage bgimg = bg->toImage();
    outimg = new QImage(size.toSize(), QImage::Format_ARGB32);

    qreal pad = 10;

    int w = bgimg.width(), h = bgimg.height();
    int tw = outimg->width(), th = outimg->height();

    qreal xc = (w - 2 * pad) / (tw - 2 * pad), yc = (h - 2 * pad) / (th - 2 * pad);

    for (int i = 0; i < tw; i++) {
        for (int j = 0; j < th; j++) {
            int x = i, y = j;

            if (x >= pad && x <= (tw - pad))
                x = pad + (x - pad) * xc;
            else if (x >= (tw - pad))
                x = w - (tw - x);

            if (y >= pad && y <= (th - pad))
                y = pad + (y - pad) * yc;
            else if (y >= (th - pad))
                y = h - (th - y);

            QRgb rgb = bgimg.pixel(x, y);
            outimg->setPixel(i, j, rgb);
        }
    }

    scaleTransform = new QGraphicsScale(this);
    scaleTransform->setXScale(1.05);
    scaleTransform->setYScale(0.95);
    scaleTransform->setOrigin(QVector3D(boundingRect().width() / 2, boundingRect().height() / 2, 0));

    QList<QGraphicsTransform *> transforms;
    transforms << scaleTransform;
    setTransformations(transforms);

    setOpacity(0.0);

    titleItem = new QGraphicsTextItem(this);
    setTitle(title);
}
예제 #16
0
/*!
  Find the bounding rect for the label. The coordinates of
  the rect are absolute coordinates ( calculated from pos() ).
  in direction of the tick.

  \param font Font used for painting
  \param value Value

  \sa labelRect()
*/
QRect QwtScaleDraw::boundingLabelRect( const QFont &font, double value ) const
{
    QwtText lbl = tickLabel( font, value );
    if ( lbl.isEmpty() )
        return QRect();

    const QPointF pos = labelPosition( value );
    QSizeF labelSize = lbl.textSize( font );

    const QTransform transform = labelTransformation( pos, labelSize );
    return transform.mapRect( QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
}
예제 #17
0
int Icon::addFile(lua_State * L) // ( const QString &, const QSize &, Mode, State )  
{
    QIcon* obj = QtValue<QIcon>::check( L, 1 );
	QIcon::Mode mode = QIcon::Normal;
	QIcon::State state = QIcon::Off; 
	if( Util::top(L) > 3 )
		mode = (QIcon::Mode)Util::toInt( L, 4 );
	if( Util::top(L) > 4 )
		state = (QIcon::State)Util::toInt( L, 5 );
    QSizeF* s = QtValue<QSizeF>::check( L, 3 );
    obj->addFile( QtValueBase::toString(L,2), s->toSize(), mode, state );
	return 0;
}
예제 #18
0
void KoPatternBackground::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
{
    Q_D(const KoPatternBackground);
    if (! d->imageData)
        return;

    painter.save();

    if (d->repeat == Tiled) {
        // calculate scaling of pixmap
        QSizeF targetSize = d->targetSize();
        QSizeF imageSize = d->imageData->imageSize();
        qreal scaleX = targetSize.width() / imageSize.width();
        qreal scaleY = targetSize.height() / imageSize.height();

        QRectF targetRect = fillPath.boundingRect();
        // undo scaling on target rectangle
        targetRect.setWidth(targetRect.width() / scaleX);
        targetRect.setHeight(targetRect.height() / scaleY);

        // determine pattern offset
        QPointF offset = d->offsetFromRect(targetRect, imageSize);

        // create matrix for pixmap scaling
        QTransform matrix;
        matrix.scale(scaleX, scaleY);

        painter.setClipPath(fillPath);
        painter.setWorldTransform(matrix, true);
        painter.drawTiledPixmap(targetRect, d->imageData->pixmap(imageSize.toSize()), -offset);
    } else if (d->repeat == Original) {
        QRectF sourceRect(QPointF(0, 0), d->imageData->imageSize());
        QRectF targetRect(QPoint(0, 0), d->targetSize());
        targetRect.moveCenter(fillPath.boundingRect().center());
        painter.setClipPath(fillPath);
        painter.drawPixmap(targetRect, d->imageData->pixmap(sourceRect.size().toSize()), sourceRect);
    } else if (d->repeat == Stretched) {
        painter.setClipPath(fillPath);
        // undo conversion of the scaling so that we can use a nicely scaled image of the correct size
        qreal zoomX, zoomY;
        converter.zoom(&zoomX, &zoomY);
        zoomX = zoomX ? 1 / zoomX : zoomX;
        zoomY = zoomY ? 1 / zoomY : zoomY;
        painter.scale(zoomX, zoomY);

        QRectF targetRect = converter.documentToView(fillPath.boundingRect());
        painter.drawPixmap(targetRect.topLeft(), d->imageData->pixmap(targetRect.size().toSize()));
    }

    painter.restore();
}
예제 #19
0
int Icon::actualSize(lua_State * L) // ( const QSize &, Mode, State ) const : QSize 
{
    QIcon* obj = QtValue<QIcon>::check( L, 1 );
	QIcon::Mode mode = QIcon::Normal;
	QIcon::State state = QIcon::Off; 
	if( Util::top(L) > 2 )
		mode = (QIcon::Mode)Util::toInt( L, 3 );
	if( Util::top(L) > 3 )
		state = (QIcon::State)Util::toInt( L, 4 );
    QSizeF* res = QtValue<QSizeF>::create( L );
    QSizeF* s = QtValue<QSizeF>::check( L, 2 );
	*res = obj->actualSize( s->toSize(), mode, state );
	return 1;
}
void QQuickTextNodeEngine::addTextObject(const QPointF &position, const QTextCharFormat &format,
                                         SelectionState selectionState,
                                         QTextDocument *textDocument, int pos,
                                         QTextFrameFormat::Position layoutPosition)
{
    QTextObjectInterface *handler = textDocument->documentLayout()->handlerForObject(format.objectType());
    if (handler != 0) {
        QImage image;
        QSizeF size = handler->intrinsicSize(textDocument, pos, format);

        if (format.objectType() == QTextFormat::ImageObject) {
            QTextImageFormat imageFormat = format.toImageFormat();
            if (QQuickTextDocumentWithImageResources *imageDoc = qobject_cast<QQuickTextDocumentWithImageResources *>(textDocument)) {
                image = imageDoc->image(imageFormat);

                if (image.isNull())
                    return;
            } else {
                QTextImageHandler *imageHandler = static_cast<QTextImageHandler *>(handler);
                image = imageHandler->image(textDocument, imageFormat);
            }
        }

        if (image.isNull()) {
            image = QImage(size.toSize(), QImage::Format_ARGB32_Premultiplied);
            image.fill(Qt::transparent);
            {
                QPainter painter(&image);
                handler->drawObject(&painter, image.rect(), textDocument, pos, format);
            }
        }

        qreal ascent;
        QFontMetrics m(format.font());
        switch (format.verticalAlignment())
        {
        case QTextCharFormat::AlignMiddle:
            ascent = size.height() / 2 - 1;
            break;
        case QTextCharFormat::AlignBaseline:
            ascent = size.height() - m.descent() - 1;
            break;
        default:
            ascent = size.height() - 1;
        }

        addImage(QRectF(position, size), image, ascent, selectionState, layoutPosition);
    }
}
예제 #21
0
//-----------------------------------------------------------
void VisaoGeralWidget::redimensionarFrameJanela(void)
{
 if(viewp)
 {
  QSizeF tam;

  //Redimensiona o frame da janela conforme as dimensões do viewport
  tam=viewp->geometry().size();
  tam.setWidth(tam.width() * FATOR_REDIM * 1/fator_zoom);
  tam.setHeight(tam.height() * FATOR_REDIM * 1/fator_zoom);
  janela_frm->resize(tam.toSize());

  //Posiciona a janela conforme os valores das barras de rolagem
  janela_frm->move(QPoint(viewp->horizontalScrollBar()->value() * FATOR_REDIM,
                          viewp->verticalScrollBar()->value() * FATOR_REDIM));
 }
}
예제 #22
0
void PosteRazorCore::paintImageOnCanvas(PaintCanvasInterface *paintCanvas) const
{
    if (isImageLoaded()) {
        const QSizeF canvasSize = paintCanvas->size();
        const QSize inputImageSize = inputImageSizePixels();
        const QSizeF boxSize = previewSize(inputImageSize, canvasSize.toSize(), false);
        QPointF offset((canvasSize.width() - boxSize.width()) / 2, (canvasSize.height() - boxSize.height()) / 2);

        // If the image is not downscaled, make sure that the coordinates are integers in order
        // to prevent unneeded blurring
        if (canvasSize.width() >= inputImageSize.width() && canvasSize.height() >= inputImageSize.height()) {
            offset.setX(floor(offset.x()));
            offset.setY(floor(offset.y()));
        }

        paintCanvas->drawImage(QRectF(offset, boxSize));
    }
}
예제 #23
0
void QgsFormAnnotation::renderAnnotation( QgsRenderContext &context, QSizeF size ) const
{
  if ( !mDesignerWidget )
    return;

  // scale painter back to 96 dpi, so that forms look good even in layout prints
  context.painter()->save();
  const double scaleFactor = context.painter()->device()->logicalDpiX() / 96.0;
  context.painter()->scale( scaleFactor, scaleFactor );
  size /= scaleFactor;

  mDesignerWidget->setFixedSize( size.toSize() );
  context.painter()->setBrush( Qt::NoBrush );
  context.painter()->setPen( Qt::NoPen );
  mDesignerWidget->render( context.painter(), QPoint( 0, 0 ) );

  context.painter()->restore();
}
예제 #24
0
/*!
   Draws the label for a major scale tick

   \param painter Painter
   \param value Value

   \sa drawTick(), drawBackbone(), boundingLabelRect()
*/
void QwtScaleDraw::drawLabel( QPainter *painter, double value ) const
{
    QwtText lbl = tickLabel( painter->font(), value );
    if ( lbl.isEmpty() )
        return;

    QPointF pos = labelPosition( value );

    QSizeF labelSize = lbl.textSize( painter->font() );

    const QTransform transform = labelTransformation( pos, labelSize );

    painter->save();
    painter->setWorldTransform( transform, true );

    lbl.draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );

    painter->restore();
}
예제 #25
0
QSize FancyToolButton::sizeHint() const
{
    QSizeF buttonSize = iconSize().expandedTo(QSize(64, 38));
    if (defaultAction()->property("titledAction").toBool()) {
        QFont boldFont(font());
        boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
        boldFont.setBold(true);
        QFontMetrics fm(boldFont);
        qreal lineHeight = fm.height();
        const QString projectName = defaultAction()->property("heading").toString();
        buttonSize += QSizeF(0, 10);
        if (!projectName.isEmpty())
            buttonSize += QSizeF(0, lineHeight + 2);

        const QString buildConfiguration = defaultAction()->property("subtitle").toString();
        if (!buildConfiguration.isEmpty())
            buttonSize += QSizeF(0, lineHeight + 2);
    }
    return buttonSize.toSize();
}
예제 #26
0
void TextBoxContent::updateTextConstraints(int w)
{
	DEBUG_TSTART();
	if(!m_text)
		return;

	int textWidth = w;
	if(w < 0)
		textWidth = contentsRect().width();

	if(DEBUG_LAYOUT)
		qDebug("updateTextConstraints() BEGIN (width: %d)",textWidth);


	m_text->setTextWidth(textWidth);
	m_shadowText->setTextWidth(textWidth);

	QSizeF sz = m_text->documentLayout()->documentSize();
      	m_textRect = QRect(QPoint(0,0),sz.toSize());

	// Adjust the bounding rect *height* to our document wrapped height, but leave
	// the width alone.
	bool changed = false;
	QRect newRect = contentsRect();
	if(m_textRect.height() > newRect.height())
	{
		// Changed from "!=" comparrison to ">" inorder to not mess up song slide templates
		// - JB 20091011
		newRect.setHeight(m_textRect.height());
		changed = true;
	}

	if(changed)
	{
		AbstractContent::resizeContents(newRect);
	}
	
	//qDebug() << "TextBoxContent::updateTextConstraints(): \t \t Elapsed:"<<(((double)total.elapsed())/1000.0)<<" sec";

}
예제 #27
0
//virtual
bool PageTabBar::resize(const QSize& s)
{
	m_geom = DimensionsGlobal::realRectAroundRealPoint(QSizeF(s));
	m_boundingRect = m_geom.adjusted(-0.5,-0.5,0.5,0.5);

	m_backgroundGeom = m_geom;
	m_backgroundShadowGeom = m_geom.adjusted(0.0,0.0,
												0.0,2.0);
	if (m_qp_backgroundPmo)
	{
		m_qp_backgroundPmo->resize(m_backgroundGeom.size().toSize());
	}
	if (m_qp_backgroundShadowPmo)
	{
		m_qp_backgroundShadowPmo->resize(m_backgroundShadowGeom.size().toSize());
	}

	if (m_pageTabs.size() == 0)
		return true;		//nothing to do

	resetTabSpaces();

	QSizeF tabMaxSize = QSizeF(newTabMaxSize());

	//TODO: TEMP - equal sized tabs, all left compressed (aligned left, no space between)
	for (PageTabConstIterator it = m_pageTabs.constBegin(); it != m_pageTabs.constEnd();++it)
	{
		if (!(*it))
		{
			continue;
		}
		(*it)->resize(tabMaxSize.toSize());
	}
	relayoutExistingTabs();
	//WARN: this should be the greatest of m_geom, m_backgroundShadowGeom, and m_backgroundGeom
	ThingPaintable::recomputeBoundingRect(m_backgroundShadowGeom);
	update();
	return true;
}
예제 #28
0
void QOpenGLWebPage::setSize(const QSizeF &size)
{
    if (d->mSize == size) {
        return;
    }

    bool widthWillChanged = d->mSize.width() != size.width();
    bool heightWillChanged = d->mSize.height() != size.height();

    d->mSize = size;
    d->mGLSurfaceSize = size.toSize();
    d->UpdateViewSize();

    if (widthWillChanged) {
        Q_EMIT widthChanged();
    }

    if (heightWillChanged) {
        Q_EMIT heightChanged();
    }

    Q_EMIT sizeChanged();
}
예제 #29
0
void MusicShape::saveOdf( KoShapeSavingContext & context ) const
{
    KoXmlWriter& writer = context.xmlWriter();
    writer.startElement("draw:frame");
    saveOdfAttributes(context, OdfAllAttributes);

    writer.startElement("music:shape");
    writer.addAttribute("xmlns:music", "http://www.koffice.org/music");
    MusicXmlWriter().writeSheet(writer, m_sheet, false);
    writer.endElement(); // music:shape

    // Save a preview image
    qreal previewDPI = 150;
    QSizeF imgSize = size(); // in points
    imgSize *= previewDPI / 72;
    QImage img(imgSize.toSize(), QImage::Format_ARGB32);
    QPainter painter(&img);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::TextAntialiasing);
    KoZoomHandler converter;
    converter.setZoomAndResolution(100, previewDPI, previewDPI);
    constPaint(painter, converter);
    writer.startElement("draw:image");
    // In the spec, only the xlink:href attribute is marked as mandatory, cool :)
    QString name = context.imageHref(img);
    writer.addAttribute("xlink:type", "simple" );
    writer.addAttribute("xlink:show", "embed" );
    writer.addAttribute("xlink:actuate", "onLoad");
    writer.addAttribute("xlink:href", name);
    writer.endElement(); // draw:image

    // TODO: Save a preview svg

    saveOdfCommonChildElements(context);
    writer.endElement(); // draw:frame
}
예제 #30
0
void MusicShape::saveOdf( KoShapeSavingContext & context ) const
{
    // The name of this object in the ODF file.
    KoEmbeddedDocumentSaver &fileSaver = context.embeddedSaver();
    QString objectName = fileSaver.getFilename("Object");

    KoXmlWriter& writer = context.xmlWriter();
    writer.startElement("draw:frame");
    saveOdfAttributes(context, OdfAllAttributes);

    writer.startElement("music:shape");
    writer.addAttribute("xmlns:music", "http://www.calligra.org/music");
    MusicXmlWriter().writeSheet(writer, m_sheet, false);
    writer.endElement(); // music:shape

    const qreal previewZoom = 150 / 72.; // 150 DPI
    QSizeF imgSize = size(); // in points
    imgSize *= previewZoom;
    KoViewConverter converter;
    
    // Save a preview SVG image.
    // -------------------------

    // 1. Set up the svg renderer.
    QByteArray svgContents;           // The contents
    QBuffer svgBuffer(&svgContents);  // The corresponding QIODevice
    QSvgGenerator svg;
    svg.setOutputDevice(&svgBuffer);  // Write to the buffer
    svg.setSize(imgSize.toSize());
    svg.setViewBox(QRect(0, 0, boundingRect().width(), boundingRect().height()));
        
    // 2. Paint the svg preview image.
    //
    // We need to create all text as paths, because otherwise it
    // will be difficult for most people to preview the SVG
    // image. Not many people have music fonts installed.
    QPainter svgPainter;
    svgPainter.begin(&svg);
    svgPainter.setRenderHint(QPainter::Antialiasing);
    svgPainter.setRenderHint(QPainter::TextAntialiasing);
    m_style->setTextAsPath(true);
    constPaint(svgPainter, converter);
    m_style->setTextAsPath(false);
    svgPainter.end();

    // 3. Create the xml to embed the svg image and the contents to the file.
    writer.startElement("draw:image");
    QString name = QString("ObjectReplacements/") + objectName + ".svg";
    writer.addAttribute("xlink:type", "simple" );
    writer.addAttribute("xlink:show", "embed" );
    writer.addAttribute("xlink:actuate", "onLoad");
    writer.addAttribute("xlink:href", name);
    writer.endElement(); // draw:image
    fileSaver.saveFile(name, "image/svg+xml", svgContents);

    // Save a preview bitmap image.
    // ----------------------------

    // 1. Create the image.
    QImage img(imgSize.toSize(), QImage::Format_ARGB32);
    QPainter painter(&img);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::TextAntialiasing);
    converter.setZoom(previewZoom);
    constPaint(painter, converter);

    // 2. Create the xml to embed the svg image and the contents to the file.
    writer.startElement("draw:image");
    name = context.imageHref(img);
    // FIXME: Find out how to save a picture using the embeddedSaver and saveFile()
    //name = QString("ObjectReplacements/") + objectName + ".png";
    writer.addAttribute("xlink:type", "simple" );
    writer.addAttribute("xlink:show", "embed" );
    writer.addAttribute("xlink:actuate", "onLoad");
    writer.addAttribute("xlink:href", name);
    writer.endElement(); // draw:image

    saveOdfCommonChildElements(context);
    writer.endElement(); // draw:frame
}