예제 #1
0
QPixmap StylePainterMobile::findComboButton(const QSize& size, bool multiple, bool enabled) const
{
    if (size.isNull())
        return QPixmap();
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::ComboButton;
    id.width = size.width();
    id.height = size.height();
    id.trait1 = multiple;
    id.trait2 = enabled;

    if (!findCachedControl(id, &result)) {
        result = QPixmap(size);
        const qreal border = painterScale(painter);
        const QSizeF padding(2 * border, 2 * border);
        const QSizeF innerSize = size - padding;
        ASSERT(innerSize.isValid());
        result.fill(Qt::transparent);
        QPainter cachePainter(&result);
        cachePainter.translate(border, border);
        if (multiple)
            drawMultipleComboButton(&cachePainter, innerSize, enabled ? darkColor : Qt::lightGray);
        else
            drawSimpleComboButton(&cachePainter, innerSize, enabled ? darkColor : Qt::lightGray);
        insertIntoCache(id, result);
    }
    return result;
}
예제 #2
0
파일: renderer.cpp 프로젝트: KDE/ksudoku
QPixmap Renderer::renderSpecial(SpecialType type, int size) const {
	if(!m_renderer->isValid() || size == 0) return QPixmap();
	
	//only show the errors if the option has been set
	if(!Settings::showErrors() && type == SpecialCellMistake ) type = SpecialCell;
	
	QString cacheName = QString("special_%1_%2").arg(m_specialNames[type]).arg(size);
	QPixmap pix;
	if(!m_cache->find(cacheName, pix)) {
		pix = QPixmap(size, size);
		pix.fill(Qt::transparent);
		QPainter p(&pix);
		
		// NOTE fix for Qt's QSvgRenderer size reporting bug
		QRectF r(m_renderer->boundsOnElement(m_specialNames[type]));
		QRectF from(r.adjusted(+0.5,+0.5,-0.5,-0.5));
		QRectF to(QRectF(0,0,size,size));
		r.setTopLeft(fromRectToRect(r.topLeft(), from, to));
		r.setBottomRight(fromRectToRect(r.bottomRight(), from, to));
		
		m_renderer->render(&p, m_specialNames[type], r);
		p.end();
		m_cache->insert(cacheName, pix);
	}

	return pix;
}
예제 #3
0
QPixmap NumberChoiceLive::outlineText(QString text) {
	QPixmap *canvas = new QPixmap(200,200);
	canvas->fill(Qt::transparent);
	
	QFont font;
	font.setPointSize(60);
	font.setBold(true);
	
	QPen pen; // Give a nice black outline
	pen.setWidth(5);
	
	QPainterPath path; // Have to use path to get an outline
	path.addText(0,90, font, text);
	
	QPainter painter(canvas); // Make the outlines text
	painter.setBrush(QBrush(Qt::yellow));
	painter.setPen(pen);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.drawPath(path);
	
	painter.setFont(font); // Remove the rubbish from the image so we only have the text
	QRect textBounds = painter.boundingRect(canvas->rect(), 0, text);
	
	return canvas->copy(textBounds);
}
예제 #4
0
파일: treeitem.cpp 프로젝트: RankoR/mqutim
void TreeItem::setImage(const QIcon &icon, int column)
{
  if (column<13&&column>-1)
  {
    if (column==1)
    {
      int size=24;
      QSize ava_size(size,size);
      QPixmap pixmap = icon.pixmap(icon.actualSize(QSize(65535,65535)),QIcon::Normal,QIcon::On);
      if (!pixmap.isNull())
      {
        QPixmap alpha (ava_size);
        alpha.fill(QColor(0,0,0));
        QPainter painter(&alpha);
        QPen pen(QColor(127,127,127));
        painter.setRenderHint(QPainter::Antialiasing);
        pen.setWidth(0);
        painter.setPen(pen);
        painter.setBrush(QBrush(QColor(255,255,255)));
        painter.drawRoundRect(QRectF(QPointF(0,0),QSize(size-1,size-1)),5,5);
        painter.end();
        pixmap = pixmap.scaled(ava_size,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
        pixmap.setAlphaChannel(alpha);
        m_item_icons[column] = QIcon(pixmap);
      }
      return;
    }
    if (column==0)
      m_current_status_icon=icon;
    m_item_icons[column] = icon;
  }
}
예제 #5
0
Thumbnail::Thumbnail(const QPixmap &originalPixmap)
{
	QPixmap pixmap = originalPixmap.scaled(PixmapSize, PixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
	QPixmap shadow;
	QRect pixmapRect(Margin + PixmapSize / 2 - pixmap.size().width() / 2, Margin + PixmapSize / 2 - pixmap.size().height() / 2, pixmap.size().width(), pixmap.size().height());
	
	if (_shadowCache.contains(pixmap.size()))
	{
		shadow = _shadowCache.value(pixmap.size());
	}
	else
	{
		shadow = QPixmap(thumbnailSize());
		shadow.fill(Qt::transparent);
		
		QGraphicsScene scene(shadow.rect());
		auto rectItem = scene.addRect(pixmapRect, Qt::NoPen, Qt::white);
		QGraphicsDropShadowEffect effect(0);
		effect.setBlurRadius(6);
		effect.setOffset(0);
		rectItem->setGraphicsEffect(&effect);
		
		QPainter painter(&shadow);
		scene.render(&painter);
		painter.end();
		
		_shadowCache.insert(pixmap.size(), shadow);
	}
	
	_thumbnail = shadow;
	QPainter painter(&_thumbnail);
	painter.drawPixmap(pixmapRect.topLeft(), pixmap);
}
예제 #6
0
void Cmap_button::scale_icon_to_128()
{
    //drawing a beautiful this->zoomlevel * 64 -10 pixmap/icon
    //drawing the scaled image
    QPixmap face = QPixmap( 118, 118 );
    face.fill( Qt::transparent );
    QImage img = this->icon.scaled( QSize( 118,118 ), Qt::KeepAspectRatio );
    QPainter p( &face );
    p.drawImage( QPoint( (118 - img.width()) / 2, (118 -img.height() )) / 2, img );
    //drawing the framed text
    p.setPen( QColor( 42, 42, 42, 200 ) );
    //l shadow
    p.drawText( QRect( -1, 59, 117, 59 ), Qt::AlignCenter, this->text );
    //r shaodw
    p.drawText( QRect( 1, 59, 119, 59 ), Qt::AlignCenter, this->text );
    //u shadow
    p.drawText( QRect( 0, 58, 118, 58 ), Qt::AlignCenter, this->text );
    //d shadow
    p.drawText( QRect( 0, 60, 118, 60 ), Qt::AlignCenter, this->text );

    p.setPen( Qt::white );
    p.drawText( QRect( 0, 59, 118, 59 ), Qt::AlignCenter, this->text );
    p.end();
    this->rendered_face = face;
    this->setIconSize( QSize( 118, 118 ) );
    this->setFixedSize( 128,128 );
    this->setIcon( QIcon( face ) );
}
예제 #7
0
파일: utils.cpp 프로젝트: Daniel1892/tora
    QPixmap connectionColorPixmap(const QString & name)
    {
        QPixmap pm;
        if (name.isNull() || name.isEmpty())
            return pm;
        if (!QPixmapCache::find(name, pm))
        {
            // draw a "cool 3d" bullet here
            pm = QPixmap(16, 16);
            pm.fill(Qt::transparent);
            QColor col(name);

            QPainter painter(&pm);
            painter.setRenderHints(QPainter::HighQualityAntialiasing);
            QRadialGradient brush(16 / 2, 16 / 2, 16 * 1.5, 16 / 2, 16 / 4);
            brush.setColorAt(0, col.lighter());
            brush.setColorAt(0.2, col);
            brush.setColorAt(0.6, col.darker());
            brush.setColorAt(1, Qt::black);
            painter.setBrush(brush);

            QPen pen(Qt::black);
            pen.setWidth(1);
            pen.setCosmetic(true);
            painter.setPen(pen);

            painter.drawEllipse(1, 1, 14, 14);
            painter.end();

            QPixmapCache::insert(name, pm);
        }
        return pm;
    }
예제 #8
0
파일: preffont.cpp 프로젝트: VicHao/kkscope
	/**
	 * Changes the font associated with this item.
	 * The function a sample text on a pixmap using this font, and then
	 * assigns the pixmap to the list item.
	 * The font set by this function is returned by getFont().
	 * @param	font	The font to set
	 */
	void setFont(QFont font) {
		QPixmap pix;
		QFontMetrics fm(font);
		QPainter painter;
		QRect rc;
		
		// Remember the font
		m_font = font;
		
		// Set the pixmap's size so it can contain the sample text
		rc = fm.boundingRect(i18n("Sample"));
		rc.moveTopLeft(QPoint(0, 0));
		pix.resize(rc.width(), rc.height());
		
		// Draw on the pixmap
		pix.fill();
		painter.begin(&pix);
		painter.setFont(font);
		painter.setPen(black);
		painter.drawText(rc, Qt::AlignHCenter | Qt::AlignVCenter,
			i18n("Sample"));
		painter.end();
		
		// Set the pixmap to the item
		setPixmap(1, pix);
	}
예제 #9
0
void CSVWidget::SceneToolToggle::adjustIcon()
{
    unsigned int selection = getSelectionMask();
    if (!selection)
        setIcon (QIcon (QString::fromUtf8 (mEmptyIcon.c_str())));
    else
    {
        QPixmap pixmap (48, 48);
        pixmap.fill (QColor (0, 0, 0, 0));

        {
            QPainter painter (&pixmap);

            for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
                iter!=mButtons.end(); ++iter)
                if (iter->first->isChecked())
                {
                    painter.drawImage (getIconBox (iter->second.mIndex),
                        QImage (QString::fromUtf8 (iter->second.mSmallIcon.c_str())));
                }
        }

        setIcon (pixmap);
    }
}
예제 #10
0
static QIcon drawCheckBox(bool value)
{
	QStyleOptionButton opt;
	opt.state |= value ? QStyle::State_On : QStyle::State_Off;
	opt.state |= QStyle::State_Enabled;
	const QStyle *style = QApplication::style();
	// Figure out size of an indicator and make sure it is not scaled down in a list view item
	// by making the pixmap as big as a list view icon and centering the indicator in it.
	// (if it is smaller, it can't be helped)
	const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
	const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
	const int listViewIconSize = indicatorWidth;
	const int pixmapWidth = indicatorWidth;
	const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);

	opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
	QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
	pixmap.fill(Qt::transparent);
	{
		// Center?
		const int xoff = (pixmapWidth  > indicatorWidth)  ? (pixmapWidth  - indicatorWidth)  / 2 : 0;
		const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
		QPainter painter(&pixmap);
		painter.translate(xoff, yoff);
		style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
	}
	return QIcon(pixmap);
}
/*!
    \reimp
 */
void QxtItemDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QString& text) const
{
    if (!Qt::mightBeRichText(text))
    {
        QItemDelegate::drawDisplay(painter, option, rect, text);
        return;
    }

    QString key = QString(QLatin1String("QxtItemDelegate:%1")).arg(text);
    QPixmap pixmap;
    if (!QPixmapCache::find(key, pixmap))
    {
        if (!qxt_d().document)
            qxt_d().document = new QTextDocument(const_cast<QxtItemDelegate*>(this));
        qxt_d().document->setHtml(text);
        qxt_d().document->adjustSize();

        pixmap = QPixmap(qxt_d().document->size().toSize());
        pixmap.fill(Qt::transparent);
        QPainter painter(&pixmap);
        qxt_d().document->drawContents(&painter);
        painter.end();
        QPixmapCache::insert(key, pixmap);
    }
    painter->drawPixmap(option.rect.topLeft(), pixmap);
}
예제 #12
0
void djvFileBrowserItem::setImageInfo(
    const djvImageIoInfo &  imageInfo,
    const djvVector2i &     thumbnailSize,
    djvPixelDataInfo::PROXY thumbnailProxy)
{
    //DJV_DEBUG("djvFileBrowserItem::setImageInfo");
    //DJV_DEBUG_PRINT("image info = " << imageInfo);
    //DJV_DEBUG_PRINT("thumbnail size = " << thumbnailSize);
    //DJV_DEBUG_PRINT("thumbnail proxy = " << thumbnailProxy);
        
    _imageInfo      = imageInfo;
    _thumbnailSize  = thumbnailSize;
    _thumbnailProxy = thumbnailProxy;
    
    _displayRole[djvFileBrowserModel::NAME] =
        QString("%1\n%2x%3:%4 %5\n%6@%7").
            arg(_fileInfo.name()).
            arg(_imageInfo.size.x).
            arg(_imageInfo.size.y).
            arg(djvVectorUtil::aspect(_imageInfo.size), 0, 'f', 2).
            arg(djvStringUtil::label(_imageInfo.pixel).join(", ")).
            arg(djvTime::frameToString(
                _imageInfo.sequence.frames.count(),
                _imageInfo.sequence.speed)).
            arg(djvSpeed::speedToFloat(_imageInfo.sequence.speed));

    _thumbnail = QPixmap(_thumbnailSize.x, _thumbnailSize.y);
    _thumbnail.fill(Qt::transparent);
}
예제 #13
0
    //________________________________________________
    void TransitionWidget::fade( const QPixmap& source, QPixmap& target, qreal opacity, const QRect& rect ) const
    {

        if( target.isNull() || target.size() != size() )
        { target = QPixmap( size() ); }

        // erase target
        target.fill( Qt::transparent );

        // check opacity
        if( opacity*255 < 1 ) return;

        QPainter p( &target );
        p.setClipRect( rect );

        // draw pixmap
        p.drawPixmap( QPoint(0,0), source );

        // opacity mask (0.996 corresponds to 254/255)
        if( opacity <= 0.996 )
        {
            p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
            QColor color( Qt::black );
            color.setAlphaF( opacity );
            p.fillRect(rect, color );
        }

        p.end();
        return;
    }
예제 #14
0
QPixmap StylePainterMobile::findLineEdit(const QSize & size, bool focused) const
{
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::LineEdit;
    id.width = size.width();
    id.height = size.height();
    id.trait1 = focused;

    if (!findCachedControl(id, &result)) {
        const int focusFrame = painterScale(painter);
        result = QPixmap(size);
        result.fill(Qt::transparent);
        const QRect rect = result.rect().adjusted(focusFrame, focusFrame, -focusFrame, -focusFrame);
        QPainter cachePainter(&result);
        drawControlBackground(&cachePainter, borderPen(painter), rect, Qt::white);

        if (focused) {
            QPen focusPen(highlightColor, 1.2 * painterScale(painter), Qt::SolidLine);
            drawControlBackground(&cachePainter, focusPen, rect, Qt::NoBrush);
        }
        insertIntoCache(id, result);
    }
    return result;
}
예제 #15
0
void PolygonWidget::UpdatePreView()
{
	double roundness = CurvatureSpin->value() / 100.0;
	QPixmap pm = QPixmap(Preview->width() - 5, Preview->height() - 5);
	pm.fill(Qt::white);
	QPainter p;
	p.begin(&pm);
	p.setBrush(Qt::NoBrush);
	p.setPen(Qt::black);
	QPainterPath pp = RegularPolygon(Preview->width() - 6, Preview->height() - 6, Ecken->value(), Konvex->isChecked(), GetFaktor(), Slider2->value(), roundness);
	QRectF br = pp.boundingRect();
	if (br.x() < 0)
	{
		QMatrix m;
		m.translate(-br.x(), 0);
		pp = pp * m;
	}
	if (br.y() < 0)
	{
		QMatrix m;
		m.translate(0, -br.y());
		pp = pp * m;
	}
	br = pp.boundingRect();
	if ((br.height() > Preview->height() - 6) || (br.width() > Preview->width() - 6))
	{
		QMatrix ma;
		double sca = static_cast<double>(qMax(Preview->height() - 6, Preview->width() - 6)) / static_cast<double>(qMax(br.width(), br.height()));
		ma.scale(sca, sca);
		pp = pp * ma;
	}
	p.strokePath(pp, p.pen());
	p.end();
	Preview->setPixmap(pm);
}
예제 #16
0
void RSButtonOnText::updateImage()
{
	if (_textEdit){
		adjustSize();
		QPixmap pixmap;

// Can't get Qt's grab functionality to draw a transparent background so we use our own drawing on a pixmap
//#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
//		pixmap = this->grab();//QT5
//#else
//		pixmap = QPixmap::grabWidget(this);
//#endif

		// get a transparent pixmap
		pixmap = QPixmap(size());
		pixmap.fill(Qt::transparent);

		// init options
		QStyleOptionButton option;
		initStyleOption(&option);

		// draw the button onto the pixmap
		QStylePainter painter(&pixmap, this);
		painter.drawControl(QStyle::CE_PushButton, option);
		painter.end();

		_textEdit->setUpdatesEnabled(false);
		_textEdit->document()->addResource(QTextDocument::ImageResource,QUrl(_uuid),QVariant(pixmap));
		_textEdit->setUpdatesEnabled(true);
	}
}
예제 #17
0
void Cmap_button::scale_icon_to_64()
{
    //drawing a beautiful this->zoomlevel * 64 -10 pixmap/icon
    QPixmap face = QPixmap( 54, 54 );
    face.fill( Qt::transparent );
    QImage img = this->icon.scaled( QSize( 118,118 ), Qt::KeepAspectRatio );
    QPainter p( &face );
    p.drawImage( QPoint( (54 - img.width()) / 2, (54 -img.height() )) / 2, img );
    //drawing the framed text
    p.setPen( QColor( 0, 0, 0, 125 ) );
    //l shadow
    p.drawText( QRect( -1, 27, 53, 27 ), Qt::AlignCenter, this->text );
    //r shaodw
    p.drawText( QRect( 1, 27, 55, 27 ), Qt::AlignCenter, this->text );
    //u shadow
    p.drawText( QRect( 0, 26, 54, 26 ), Qt::AlignCenter, this->text );
    //d shadow
    p.drawText( QRect( 0, 28, 54, 28 ), Qt::AlignCenter, this->text );

    p.setPen( Qt::white );
    p.drawText( QRect( 0, 27, 54, 27 ), Qt::AlignCenter, this->text );
    p.end();
    this->rendered_face = face;
    this->setIconSize( QSize( 54, 54 ) );
    this->setFixedSize( 64,64 );
    this->setIcon( QIcon( face ) );
}
예제 #18
0
void PixServer::draw(int pos, PixMap pix, int i)
{
    QPixmap p;
    p.resize(BRICKSIZE, BRICKSIZE);

    QRect rect = board->rect(pos);

    if (! plainColor)
	bitBlt( &p, 0, 0, &backPix,
		rect.x(), rect.y(), rect.width(), rect.height());
    else
	p.fill(backgroundColor);

    switch (pix) {
    case SamyPix:        bitBlt(&p ,0,0, &samyPix[i]);
	break;
    case CompuSnakePix:  bitBlt(&p ,0,0, &compuSnakePix[i]);
	break;
    case ApplePix:       bitBlt(&p ,0,0, &applePix[i]);
	break;
    case BallPix:        bitBlt(&p ,0,0, &ballPix[i]);
	break;
    default:
	break;
    }

    bitBlt(&cachePix, rect.x(), rect.y(), &p);
}
예제 #19
0
void Cmap_button::scale_icon_to_256()
{
    //drawing a beautiful this->zoomlevel * 64 -10 pixmap/icon
    QPixmap face = QPixmap( 246, 246 );
    face.fill( Qt::transparent );
    QImage img = this->icon.scaled( QSize( 246,246 ), Qt::KeepAspectRatio );
    QPainter p( &face );
    p.drawImage( QPoint( (246 - img.width()) / 2, (246 -img.height() )) / 2, img );
    //drawing the framed text
    p.setPen( QColor( 0, 0, 0, 222 ) );
    //l shadow
    p.drawText( QRect( -1, 123, 245, 123 ), Qt::AlignCenter, this->text );
    //r shaodw
    p.drawText( QRect( 1, 123, 247, 123 ), Qt::AlignCenter, this->text );
    //u shadow
    p.drawText( QRect( 0, 122, 246, 122 ), Qt::AlignCenter, this->text );
    //d shadow
    p.drawText( QRect( 0, 124, 246, 124 ), Qt::AlignCenter, this->text );

    p.setPen( Qt::white );
    p.drawText( QRect( 0, 123, 246, 123 ), Qt::AlignCenter, this->text );
    p.end();
    this->rendered_face = face;
    this->setIconSize( QSize( 246, 246 ) );
    this->setFixedSize( 256,256  );
    this->setIcon( QIcon( face ) );
}
예제 #20
0
void ResetWidget::makeBasicPixmap(
#ifdef USE_PIXMAP
      QPixmap& pixmap,
#else
      QPainter* painter,
#endif
                                   int width,
                                   int height)
{
#ifdef USE_PIXMAP
  pixmap = QPixmap(width, height);

  // Fill the pixmap with black background
  pixmap.fill(Qt::black);

  // Get the painter
  QPainter *painter = new QPainter(&pixmap);
#else
  painter->fillRect(0,0,width,height,QColor(0,0,0));
#endif

  // Paint the items
  BasicPainter::paintItems(painter,
                           myItems,
                           width,
                           height,
                           0);

#ifdef USE_PIXMAP
  // End the paint and release the space
  painter->end();
  delete painter;
#endif
}
예제 #21
0
/*!
    Reimplement this function to draw the \a pixmap in the given \a
    rect, starting at the given \a p. The pixmap will be
    drawn repeatedly until the \a rect is filled.
*/
void QPaintEngine::drawTiledPixmap(const QRectF &rect, const QPixmap &pixmap, const QPointF &p)
{
    int sw = pixmap.width();
    int sh = pixmap.height();

    if (sw*sh < 8192 && sw*sh < 16*rect.width()*rect.height()) {
        int tw = sw, th = sh;
        while (tw*th < 32678 && tw < rect.width()/2)
            tw *= 2;
        while (tw*th < 32678 && th < rect.height()/2)
            th *= 2;
        QPixmap tile;
        if (pixmap.depth() == 1) {
            tile = QBitmap(tw, th);
        } else {
            tile = QPixmap(tw, th);
            if (pixmap.hasAlphaChannel())
                tile.fill(Qt::transparent);
        }
        qt_fill_tile(&tile, pixmap);
        qt_draw_tile(this, rect.x(), rect.y(), rect.width(), rect.height(), tile, p.x(), p.y());
    } else {
        qt_draw_tile(this, rect.x(), rect.y(), rect.width(), rect.height(), pixmap, p.x(), p.y());
    }
}
예제 #22
0
void EditorSpashScreen::construct()
{
    _label_val=0.0;
    _label_max=100.0;
    _percents=0;

    _parts_max=1.0;
    _parts_val=0.0;

    buffer=this->pixmap();

    #ifdef Q_OS_ANDROID
    QDesktopWidget* desktopWidget = qApp->desktop();
    QRect screenGeometry = desktopWidget->screenGeometry();
    int screenWidth = screenGeometry.width();
    int screenHeight = screenGeometry.height();
    qreal oldHeight = buffer.height();
    qreal oldWidth = buffer.width();
    buffer = buffer.scaled(screenWidth, screenHeight, Qt::KeepAspectRatio);
    height_ratio = qreal(buffer.height()) / oldHeight;
    width_ratio =  qreal(buffer.width()) / oldWidth;
    #endif

    QPixmap t = QPixmap(buffer.width(), buffer.height());
    t.fill(Qt::transparent);
    this->setPixmap(t);

    opacity=0.0;
    scaler.setTimerType(Qt::PreciseTimer);
    scaler.setInterval(64);
    connect(&scaler, SIGNAL(timeout()), this, SLOT(opacityUP()));
}
void ListItemCache::draw(QPainter * painter) 
{
    QRectF irect = sourceBoundingRect(Qt::LogicalCoordinates);
    QRectF vrect = painter->clipPath().boundingRect();

    if (vrect.intersects(irect)) {
        QRectF newVisibleRect = irect.intersected(vrect);
        QPixmap pixmap;

        if (!QPixmapCache::find(m_cacheKey, &pixmap) ||
            m_visibleRect.toRect() != newVisibleRect.toRect()) {
            //qDebug() << "ListItemCache: caching" << m_visibleRect
            //    << "->" << newVisibleRect;

            pixmap = QPixmap(sourceBoundingRect().toRect().size());
            pixmap.fill(Qt::transparent);

            QPainter pixmapPainter(&pixmap);
            drawSource(&pixmapPainter);
            pixmapPainter.end();
            m_cacheKey = QPixmapCache::insert(pixmap);

            m_visibleRect = newVisibleRect;
        }

        //qDebug() << "ListItemCache: blitting" << m_visibleRect;
        painter->drawPixmap(0, 0, pixmap);
    } 
}
예제 #24
0
void SpecWidget::resizeEvent(QResizeEvent *e)
{
	// prevent resize glitch when the widget is created,
	// the fist resizeEvent() is bogus
	if(!resizeGlitch)
	{
		resizeGlitch = true;
		return;
	}

	QPixmap tmp = Canvas;
	Canvas = QPixmap(e->size());
	image = QImage(e->size().width(), 1, QImage::Format_RGB32);

	// first time ever - initialise to black
	if(tmp.size().width()==0)
	{
		tmp = QPixmap(e->size());
		// always use a black background
		tmp.fill(QColor::fromRgb(0, 0, 0));
	}
	// vertical stretch - fill below old with black
	if(Canvas.height()>tmp.height())
		Canvas.fill(QColor::fromRgb(0, 0, 0));

	// copy old data, scaling to fit horizontally but making space below
	// TODO - the width scaling is slightly off.
	QPainter p(&Canvas);
	QPoint origin(0,0);
	QSize top(Canvas.width(), tmp.height());
	p.drawPixmap(QRect(origin, top), tmp);
}
예제 #25
0
파일: agente.cpp 프로젝트: Dariasteam/I.A.
void agente::pintarRastro(){
    /*Añade un pixmap a mapa con el color asociado
     * a cada agente*/
    QPixmap* pix = new QPixmap(gPix_->pixmap());
    if(regresando_){
        pix->fill(QColor(255,255,255));
        QGraphicsPixmapItem* aux = ((mapa*)mapaReal_)->pintarPixmap(yAnimacion_,xAnimacion_,pix);
        aux->setZValue(2);
        aux->setOpacity(1);
    }else if(checkRastro_->isChecked()){
        pix->fill(color_);
        QGraphicsPixmapItem* aux = ((mapa*)mapaReal_)->pintarPixmap(yAnimacion_,xAnimacion_,pix);
        aux->setZValue(1);
        aux->setOpacity(0.2);
    }
}
예제 #26
0
bool
FX::blend(const QPixmap &upper, QPixmap &lower, double opacity, int x, int y)
{
    if (opacity == 0.0)
        return false; // haha...

    {
        QPixmap tmp;
        if ( useRaster ) // raster engine is broken... :-(
        {
            tmp = QPixmap(upper.size());
            tmp.fill(Qt::transparent);
            QPainter p(&tmp);
            p.drawPixmap(0,0, upper);
            p.end();
        }
        else
            tmp = upper;

        QPainter p;
        if (opacity < 1.0)
        {
            p.begin(&tmp);
            p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
            p.fillRect(tmp.rect(), QColor(0,0,0, opacity*255.0));
            p.end();
        }
        p.begin(&lower);
        p.setCompositionMode(QPainter::CompositionMode_SourceOver);
        p.drawPixmap(x, y, tmp);
        p.end();
    }
   return true;
}
예제 #27
0
void IndicatorLight::createLabel(int w, int h) {
    if(_glowEnabled && this->scene()) {

        // Draw label glow
        QPixmap pixmap = QPixmap(w,h);
        pixmap.fill(Qt::transparent);
        QPainter painter;
        painter.begin(&pixmap); {
            setupPainter(&painter);
            painter.setBrush(_labelColor);
            painter.setPen(Qt::NoPen);
            painter.drawRoundedRect(0,0,w,h,20,20);
        } painter.end();

        // Setup the graphics item for glow
        // This has a special z-value ontop of other graphics items so that it can glow above the panel cover...
        if(_labelGlowItem) {
            this->scene()->removeItem(_labelGlowItem);
        }
        _labelGlowItem = new QGraphicsPixmapItem(NULL);
        _labelGlowItem->setPixmap(pixmap);
        _labelGlowItem->setOpacity(_glowStrength/100.0);
        _labelGlowItem->setX(this->x());
        _labelGlowItem->setY(this->y());
        _labelGlowItem->setZValue(PANEL_PANELITEM_GLOW_ZVALUE);
        QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(this);
        effect->setBlurRadius(40);
        _labelGlowItem->setGraphicsEffect(effect);
        this->scene()->addItem(_labelGlowItem);
    }
}
예제 #28
0
QPixmap
FX::applyAlpha(const QPixmap &toThisPix, const QPixmap &fromThisPix, const QRect &rect, const QRect &alphaRect)
{
    QPixmap pix;
    int sx,sy,ax,ay,w,h;
    if (rect.isNull())
        { sx = sy = 0; w = toThisPix.width(); h = toThisPix.height(); }
    else
        rect.getRect(&sx,&sy,&w,&h);
    if (alphaRect.isNull())
        { ax = ay = 0; }
    else
    {
        ax = alphaRect.x(); ay = alphaRect.y();
        w = qMin(alphaRect.width(),w); h = qMin(alphaRect.height(),h);
    }

    if (w > fromThisPix.width() || h > fromThisPix.height())
        pix = QPixmap(w, h);
    else
        pix = fromThisPix.copy(0,0,w,h); // cause slow depth conversion...
    pix.fill(Qt::transparent);
    QPainter p(&pix);
    p.drawPixmap(0, 0, toThisPix, sx, sy, w, h);
    p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    p.drawPixmap(0, 0, fromThisPix, ax, ay, w, h);
    p.end();
    return pix;
}
예제 #29
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    this->showMaximized();
    setFocusPolicy(Qt::StrongFocus);
    ui->setupUi(this);
    createActions();
    createToolBars();

    QPixmap *pixmap = new QPixmap(100, 100);
    pixmap->fill(Qt::black);
    QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem();

    QGraphicsScene *scene = new QGraphicsScene(0,0,100,100);



   // ui->viewport->setScene(scene);

    QPainter painter;
    painter.begin(pixmap);
    painter.setPen(QColor(0,255,0));
    painter.drawLine(20,20,30,30);
    painter.setPen(QColor(255,0,0));
    painter.drawEllipse(30,30,30,30);
    painter.end();
    pixmapItem->setPixmap(*pixmap);
     scene->addItem(pixmapItem);
     ui->viewport->setScene(scene);
    ui->viewport->update();
}
예제 #30
0
void Vruler::drawNumber(QString num, int starty, QPainter *p)
{
	int textY = starty;
	for (int a = 0; a < num.length(); ++a)
	{
		QString txt = num.mid(a, 1);
#ifndef Q_WS_MAC
		p->drawText(1, textY, txt);
#else
		static const int SCALE = 16;
		QFontMetrics fm = p->fontMetrics();
		QRect bbox = fm.boundingRect(txt);
		static QPixmap pix;
		if (pix.width() < bbox.width()*SCALE || pix.height() < bbox.height()*SCALE)
			pix = QPixmap(bbox.width()*SCALE, bbox.height()*SCALE);
		QFont fnt = p->font();
		QPainter p2;
		pix.fill();
		p2.begin( &pix );
		if (fnt.pointSize() > 0)
			fnt.setPointSize(SCALE*fnt.pointSize()-SCALE/2);
		else if (fnt.pixelSize() > 0)
			fnt.setPixelSize(SCALE*fnt.pixelSize()-SCALE/2);
		else
			fnt.setPixelSize(SCALE);
		p2.setFont(fnt);
		p2.drawText(-bbox.x()*SCALE, -bbox.y()*SCALE, txt);
		p2.end();
		p->scale(1.0/SCALE,1.0/SCALE);
		p->drawPixmap(1*SCALE, (textY+bbox.top())*SCALE, pix, 0, 0, bbox.width()*SCALE, bbox.height()*SCALE);
		p->scale(SCALE,SCALE);
#endif
		textY += 11;
	}
}