コード例 #1
0
void QSPixmapClass::resize( QSEnv *env )
{
    if ( env->numArgs() < 1 || env->numArgs() > 2 ) {
	env->throwError( QString::fromLatin1( "Pixmap.resize() called with %1 arguments. 1 or 2 arguments expected." ).
			 arg( env->numArgs() ) );
	return;
    }

    QSObject t = env->thisValue();
    QSPixmapClass *pac = (QSPixmapClass*)t.objectType();
    QPixmap *pix = pac->pixmap( &t );
    if ( env->numArgs() == 1 ) {
	QSObject a0 = env->arg( 0 );
	if ( !a0.isA( "Size" ) ) {
	    env->throwError( QString::fromLatin1( "Pixmap.resize() called with an argument of type %1. "
				  "Type Size is expeced" ).
			     arg( a0.typeName() ) );
	    return;
	}
	pix->resize( *( (QSSizeClass*)a0.objectType() )->size( &a0 ) );
    } else {
	if ( !env->arg( 0 ).isA( "Number" ) || !env->arg( 1 ).isA( "Number" ) ) {
	    env->throwError( QString::fromLatin1( "Pixmap.resize() called with arguments of type %1 and %2. "
				  "Type Number and Number is expeced" ).
			     arg( env->arg( 0 ).typeName() ).arg( env->arg( 1 ).typeName() ) );
	    return;
	}
	pix->resize( env->arg( 0 ).toInteger(), env->arg( 1 ).toInteger() );
    }

    return;
}
コード例 #2
0
ファイル: Plot3DDialog.cpp プロジェクト: kuzavas/qtiplot
void Plot3DDialog::setColorMapPreview(const QString& fileName)
{
    if (fileName.isEmpty()) {
        colorMapPreviewLabel->setText(tr("None"));
        return;
    }

    ColorVector cv;
    if (!Graph3D::openColorMapFile(cv, fileName)) {
        colorMapPreviewLabel->setText(tr("None"));
        return;
    }

    int height = 20;
    QPixmap pix;
    pix.resize(cv.size(), height);
    QPainter p(&pix);
    for (unsigned i = 0; i != cv.size(); ++i) {
        RGBA rgb = cv[i];
        p.setPen(GL2Qt(rgb.r, rgb.g, rgb.b));
        p.drawLine(QPoint(0, 0), QPoint(0, height));
        p.translate(1, 0);
    }
    p.end();
    colorMapPreviewLabel->setPixmap(pix);
}
コード例 #3
0
QPixmap loadRenderingPixmap( KTNEFPropertySet *pSet, const QColor& bgColor )
{
	QPixmap pix;
	QVariant rendData = pSet->attribute( attATTACHRENDDATA ), wmf = pSet->attribute( attATTACHMETAFILE );
	if ( !rendData.isNull() && !wmf.isNull() )
	{
		// Get rendering size
		QBuffer rendBuffer( rendData.asByteArray() );
		rendBuffer.open( IO_ReadOnly );
		QDataStream rendStream( &rendBuffer );
		rendStream.setByteOrder( QDataStream::LittleEndian );
		Q_UINT16 type, w, h;
		rendStream >> type >> w >> w; // read type and skip 4 bytes
		rendStream >> w >> h;
		rendBuffer.close();

		if ( type == 1 && w > 0 && h > 0 )
		{
			// Load WMF data
			QWinMetaFile wmfLoader;
			QBuffer wmfBuffer( wmf.asByteArray() );
			wmfBuffer.open( IO_ReadOnly );
			wmfLoader.setBbox( QRect( 0, 0, w, h ) );
			if ( wmfLoader.load( wmfBuffer ) )
			{
				pix.resize( w, h );
				pix.fill( bgColor );
				wmfLoader.paint( &pix );
			}
			wmfBuffer.close();
		}
	}
コード例 #4
0
ファイル: textoptionsimp.cpp プロジェクト: icefox/kinkatta
/**
 * Helper Function.  Gets a color and fulls button 'l' with it.
 * @param c initial color;
 * @param l button to fill.
 */
void TextOptionsImp::getNewColor(QColor &c, QPushButton *l){
  KColorDialog::getColor ( c, this );
  QPixmap color;
  color.resize(40,20);
  color.fill(c);
  l->setPixmap(color);
}
コード例 #5
0
QPixmap QPixmap::grabWidget( QWidget * widget, int x, int y, int w, int h )
{
    QPixmap res;
    if ( !widget )
	return res;

    if ( w < 0 )
	w = widget->width() - x;
    if ( h < 0 )
	h = widget->height() - y;

    QRect wr( x, y, w, h );
    if ( wr == widget->rect() )
	return grabChildWidgets( widget );
    if ( !wr.intersects( widget->rect() ) )
	return res;

    res.resize( w, h );
    if( res.isNull() )
	return res;
    res.fill( widget, QPoint( w,h ) );
    QPixmap tmp( grabChildWidgets( widget ) );
    if( tmp.isNull() )
	return tmp;
    ::bitBlt( &res, 0, 0, &tmp, x, y, w, h );
    return res;
}
コード例 #6
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);
	}
コード例 #7
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);
}
コード例 #8
0
ファイル: ClsBaseQStateArrayView.cpp プロジェクト: jeez/iqr
QPixmap ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight, int _iColorMode ) {
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
    cout << "ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight)" << endl;
#endif

//    int iColorMode = ClsBaseQStateArrayView::GRAY;
//    int iColorMode = ClsBaseQStateArrayView::BLUE2RED;
//    int iColorMode = ClsBaseQStateArrayView::HSV;

    QPixmap pmGradient;
    QPainter* paintGradient = new QPainter();
    QWMatrix mxRot;
    int iDiag = (int)(sqrt(double(iImgWidth * iImgWidth + iImgHeight * iImgHeight))/2.);

    pmGradient.resize(2 * iDiag, 2 * iDiag);
    paintGradient->begin(&pmGradient);

    paintGradient->setWindow( 0, 0, 2 * iDiag, 2 * iDiag );

    int iNrSices = 50;
    for ( int i=0; i<iNrSices; i++ ) {
	paintGradient->setWorldMatrix( mxRot );
	QColor c;
	if(_iColorMode == ClsBaseQStateArrayView::GRAY){
	    c.setRgb( i* 255 / iNrSices,  i* 255 / iNrSices,  i* 255 / iNrSices );
	}
	else if(_iColorMode == ClsBaseQStateArrayView::BLUE2RED){
	    if(i<iNrSices/2){
		/* BLUE */
		c.setRgb(0, 0,  255 - i * 510/iNrSices);
	    }
	    else {
		/* RED */
		c.setRgb( (i - iNrSices/2) * 255/(iNrSices/2),  0,0);
	    }
	}
	else {
	    c.setHsv( i* 360 / iNrSices, 255, 255 );
	}
	paintGradient->setBrush( c );
	paintGradient->setPen( c );
//zzz	QPointArray a;
	QPolygon a;

	a.setPoints( 4,
		     0, 0,
		     iDiag * 2 / iNrSices, 0,
		     iDiag * 2 / iNrSices, iDiag * 2,
		     0, iDiag * 2 );
	paintGradient->drawPolygon( a );
	mxRot.translate( (double)iDiag * 2.0 / (double)iNrSices, 0.0  );
    }

    paintGradient->end();
    return pmGradient;

}
コード例 #9
0
void PColorButton::changeColor()
{
#ifdef PURE_QT
   m_color = QColorDialog::getColor(m_color,this);
   updateProperty(m_color);
   m_edit->setText(m_color.name());
   QPixmap px;
   px.resize(14,14);
   px.fill(m_color);
   m_edit->setIconSet(px);

#endif
}
コード例 #10
0
void Editor::paintEvent( QPaintEvent*  ) {


    // first we layer on a background grid
    QPixmap buff;
    QPixmap *dest=drawFrame->getPreviewPixmap();
    buff.resize(dest->width(), dest->height());
    drawBackground(&buff);
    drawTiles(&buff);
    bitBlt(dest, 0,0,&buff, 0,0,buff.width(), buff.height(), CopyROP);

    drawFrame->repaint(false);
}
コード例 #11
0
ファイル: ptank.cpp プロジェクト: jiajw0426/easyscada
/*!
  \brief Repaint the widget
*/
void PTank::paintEvent(QPaintEvent *event)
{

    static QPixmap  pixmap;
    QRect rect = event->rect();

    QSize newSize = rect.size().expandedTo(pixmap.size());
    pixmap.resize(newSize);
    pixmap.fill(this,rect.topLeft());
    QPainter painter(&pixmap,this);
    painter.translate(-rect.x(),-rect.y());
    drawTank(&painter);
    bitBlt(this,rect.x(),rect.y(),&pixmap,0,0,rect.width(),rect.height());
}
コード例 #12
0
ファイル: textoptionsimp.cpp プロジェクト: icefox/kinkatta
/**
 * Sets up the default buddy colors.
 */
void TextOptionsImp::setDefaultBuddyColors(){
  chat_contactText_color.setRgb(0,0,0);
  chat_contactName_color.setRgb(128,0,0);
  chat_contactbg_color.setRgb(255,255,255);
  
  QPixmap color;
  color.resize(40,20);
  color.fill(chat_contactText_color);
  chat_color_btext->setPixmap(color);  
  color.fill(chat_contactName_color);
  chat_color_bname->setPixmap(color);
  color.fill(chat_contactbg_color);
  chat_color_bbcolor->setPixmap(color);
}
コード例 #13
0
ファイル: textoptionsimp.cpp プロジェクト: icefox/kinkatta
/**
 * Sets up the default user colors.
 */
void TextOptionsImp::setDefaultUserColors(){
  chat_yourText_color.setRgb(0,0,0);
  chat_yourName_color.setRgb(0,60,128);
  chat_yourbg_color.setRgb(255,255,255);
  
  QPixmap color;
  color.resize(40,20);
  color.fill(chat_yourText_color);
  chat_color_ytext->setPixmap(color);  
  color.fill(chat_yourName_color);
  chat_color_yname->setPixmap(color);
  color.fill(chat_yourbg_color);
  chat_color_ybcolor->setPixmap(color);
}
コード例 #14
0
void KWMThemeClient::drawTitle(QPainter &dest)
{
    QRect titleRect = titlebar->geometry();
    QRect r(0, 0, titleRect.width(), titleRect.height());
    QPixmap buffer;

    if(buffer.width() == r.width())
        return;

    buffer.resize(r.size());
    QPainter p;
    p.begin(&buffer);

    if(titleSunken){
        qDrawShadeRect(&p, r, options()->colorGroup(KDecorationOptions::ColorFrame, isActive()),
                       true, 1, 0);
        r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);
    }
    
    KPixmap *fill = isActive() ? aTitlePix : iTitlePix;
    if(fill)
        p.drawTiledPixmap(r, *fill);
    else if(titleGradient){
        fill = isActive() ? aGradient : iGradient;
        if(fill->width() != r.width()){
            fill->resize(r.width(), 20);
            KPixmapEffect::gradient(*fill,
                                    options()->color(KDecorationOptions::ColorTitleBar, isActive()),
                                    options()->color(KDecorationOptions::ColorTitleBlend, isActive()),
                                    grType);
        }
        p.drawTiledPixmap(r, *fill);
    }
    else{
        p.fillRect(r, options()->colorGroup(KDecorationOptions::ColorTitleBar, isActive()).
                   brush(QColorGroup::Button));
    }
    p.setFont(options()->font(isActive()));
    p.setPen(options()->color(KDecorationOptions::ColorFont, isActive()));
    // Add left & right margin
    r.setLeft(r.left()+5);
    r.setRight(r.right()-5);
    p.drawText(r, titleAlign, caption());
    p.end();

    dest.drawPixmap(titleRect.x(), titleRect.y(), buffer);
}
コード例 #15
0
void ThumbView::slSetBackGround( )
{
   QPixmap bgPix;
   if( m_bgImg.isEmpty())
   {
      bgPix.resize( QSize(16, 16));
      bgPix.fill( QPixmap::blue );
   }
   else
   {
      bgPix.load( m_bgImg );
   }

   m_iconView->setPaletteBackgroundPixmap ( bgPix );
   setPaletteBackgroundPixmap ( bgPix );

}
コード例 #16
0
const QPixmap *QWindowsXPStylePrivate::tabBody( QWidget *widget )
{
    if ( !tabbody ) {
        tabbody = new QPixmap( 1, 1 );
        QPainter painter( tabbody );
        XPThemeData theme( widget, &painter, "TAB", TABP_BODY, 0 );
        SIZE sz;
        GetThemePartSize( theme.handle(), painter.handle(), TABP_BODY, 0, 0, TS_TRUE, &sz );
        painter.end();
        tabbody->resize( sz.cx, sz.cy );
        painter.begin( tabbody );
        theme.rec = QRect( 0, 0, sz.cx, sz.cy );
        theme.drawBackground();
        painter.end();
    }
    return tabbody;
}
コード例 #17
0
bool AppPage::setPicture( const QString &pictureFile,
        const QString &pictureTip )
{
    // If no picture label in the AppPage, simply return.
    if ( ! m_pictureLabel )
    {
        return( false );
    }
    // Check if the picture is in the pixmap cache.
    QPixmap picturePixmap;
    if ( ! QPixmapCache::find( pictureFile, picturePixmap ) )
    {
        //qDebug( QString( "%1 pixmap loaded by AppPage::setPicture()." )
        //    .arg( pictureFile ) );
        picturePixmap = QPixmap( appFileSystem()->imagePath( pictureFile ) );
        QPixmapCache::insert( pictureFile, picturePixmap );
    }
    // Display a white space if the picture can't be created.
    if ( picturePixmap.isNull() )
    // This code block should never be executed!
    {
        int wd = 185;
        int ht = 300;
        picturePixmap.resize( wd, ht );
        QPainter paint( &picturePixmap );
        paint.fillRect( 0, 0, wd, ht, QBrush( "white", SolidPattern ) );
        paint.end();
        return( false );
    }
    // Apply the pixmap to the picture label.
    m_pictureLabel->setPixmap( picturePixmap );

    // Don't let the dialog get any shorter than the picture.
    m_pictureLabel->setMinimumHeight( m_pictureLabel->sizeHint().height() );

    // Don't let the picture get any wider than necessary.
    m_pictureLabel->setMaximumWidth( m_pictureLabel->sizeHint().width() );

    // Add a tool tip to the picture.
    if ( ! pictureTip.isNull() && ! pictureTip.isEmpty() )
    {
        QToolTip::add( m_pictureLabel, pictureTip );
    }
    return( true );
}
コード例 #18
0
void PColorButton::setValue(const QVariant& value, bool emitChange)
{
#ifndef PURE_QT
    disconnect(m_edit, SIGNAL(changed(const QColor&)), this, SLOT(updateProperty(const QColor&)));
    m_edit->setColor(value.toColor());
    connect(m_edit, SIGNAL(changed(const QColor&)), this, SLOT(updateProperty(const QColor&)));
#else
    m_color = value.toColor();
    m_edit->setText(m_color.name());
    QPixmap px;
    px.resize(14,14);
    px.fill(m_color);
    m_edit->setIconSet(px);
#endif
    if (emitChange)
        emit propertyChanged(m_property, value);

}
コード例 #19
0
extern "C" void
gxpport_create_mutable(gxpport_mutableimage_native_handle *newImagePtr,
		       int width, int height,
		       gxutl_native_image_error_codes* creationErrorPtr) {
  /* set optimization for all QPixmaps
     move this to startup/initialization code. */
  QPixmap::setDefaultOptimization(QPixmap::BestOptim);

  /*
   * Populate Java data pointer before calling checkResourceLimit
   * because it might trigger GC and makes the Java pointer invalid.
   */  
  QPixmap* qpixmap = new QPixmap(); /* Start with a NULL image object */
  if (NULL == qpixmap) {
     *creationErrorPtr = GXUTL_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR;
     return;
  }

  /* Check resource limit before really creating image memory */
  if (midpCheckResourceLimit(RSC_TYPE_IMAGE_MUT,
                             ImgRegionRscSize(width, height)) == 0) {
     *creationErrorPtr = GXUTL_NATIVE_IMAGE_RESOURCE_LIMIT;
     delete qpixmap;
     return;
  }

  /* ALLOCATE MEMORY FOR QT IMAGE DATA */
  qpixmap->resize(width, height);

  /* INITIALIZE CONTENTS TO WHITE */
  qpixmap->fill();

  /* Update the resource count */
  if (midpIncResourceCount(RSC_TYPE_IMAGE_MUT, ImgRscSize(qpixmap)) == 0) {
      REPORT_INFO(LC_LOWUI,"Error in updating resource"
                  " limit for Mutable image");
  }

  /* return the qpixmap pointer */
  *newImagePtr = qpixmap;

  *creationErrorPtr = GXUTL_NATIVE_IMAGE_NO_ERROR;
}
コード例 #20
0
ファイル: prefcolor.cpp プロジェクト: VicHao/kkscope
	/**
	 * Changes the colour associated with this item.
	 * The function assigns a pixmap to the item which shows a rectangle
	 * filled with the requested colour.
	 * The colour set by this function is returned by getColor().
	 * @param	clr		The colour to set
	 */
	void setColor(QColor clr) {
		QPixmap pix;
		QPainter painter;
		int nWidth, nHeight;
		
		// Remember the colour
		m_clr = clr;
		
		// Set the pixmap's size to fit into the list field
		nWidth = listView()->columnWidth(1) - 1;
		nHeight = height();
		pix.resize(nWidth, nHeight);
		
		// Draw on the pixmap
		painter.begin(&pix);
		painter.setBrush(clr);
		painter.drawRect(0, 0, nWidth, nHeight);
		painter.end();
		
		// Set the pixmap to the item
		setPixmap(1, pix);
	}
コード例 #21
0
ファイル: textoptionsimp.cpp プロジェクト: icefox/kinkatta
/**
 * Copy the settings from the structs to the widgets.
 */
void TextOptionsImp::updateData(){
  // Get settings.
  KConfig &config = *KGlobal::config();
  config.setGroup("chatwindow");
  i_aimSettings = setup::settings();

  QColor c;
  c.setRgb(0,0,0);
  chat_yourText_color = config.readColorEntry( "chat_yourText_color", &c );
  c.setRgb(0,60,128);
  chat_yourName_color = config.readColorEntry( "chat_yourName_color", &c );
  c.setRgb(0,0,0);
  chat_contactText_color = config.readColorEntry( "chat_contactText_color", &c );
  c.setRgb(128,0,0);
  chat_contactName_color = config.readColorEntry( "chat_contactName_color", &c );
  c.setRgb(255,255,255);
  chat_yourbg_color = config.readColorEntry( "chat_yourbg_color", &c );
  chat_contactbg_color = config.readColorEntry( "chat_contactbg_color", &c );


  QPixmap color;
  color.resize(40,20);
  
  color.fill(chat_yourText_color);
  chat_color_ytext->setPixmap(color);  
  color.fill(chat_yourName_color);
  chat_color_yname->setPixmap(color);
  color.fill(chat_yourbg_color);  // Get settings.
  
  chat_color_ybcolor->setPixmap(color);

  color.fill(chat_contactText_color);
  chat_color_btext->setPixmap(color);  
  color.fill(chat_contactName_color);
  chat_color_bname->setPixmap(color);
  color.fill(chat_contactbg_color);
  chat_color_bbcolor->setPixmap(color);

}
コード例 #22
0
ファイル: marklist.cpp プロジェクト: kthxbyte/KDE1-Linaro
QPixmap MarkList::flagPixmap() {
	QColorGroup cg = QApplication::palette()->normal();
	
	QPixmap pm;
	pm.resize(16,16);
	pm.fill( cg.background() );
		
	int xOffset = 4;
	int yOffset = 3;

	QPainter p;
	p.begin( &pm);
	p.setPen( cg.text() );
	p.drawLine( xOffset+4, yOffset, xOffset+4, yOffset+9 );
	p.setPen( red );
	p.drawLine( xOffset+3, yOffset+1, xOffset, yOffset+4 );
	p.drawLine( xOffset+3, yOffset+1, xOffset+3, yOffset+4 );
	p.drawLine( xOffset, yOffset+4, xOffset+3, yOffset+4 );
	p.end();
	
	return pm;
}
コード例 #23
0
ファイル: main.C プロジェクト: xwizard/kde1
void TEDemo::pixmap_menu_activated(int item)
{
  if (item <= 1) pmPath = "";
  QPixmap pm(pmPath.data());
  if (pm.isNull()) { pmPath = ""; item = 1; }
  // FIXME: respect scrollbar (instead of te->size)
  n_render = item;
  switch (item)
  {
    case 1: // none
    case 2: // tile
            te->setBackgroundPixmap(pm);
    break;
    case 3: // center
            { QPixmap bgPixmap;
              bgPixmap.resize(te->size());
              bgPixmap.fill(te->getDefaultBackColor());
              bitBlt( &bgPixmap, ( te->size().width() - pm.width() ) / 2,
                                ( te->size().height() - pm.height() ) / 2,
                      &pm, 0, 0,
                      pm.width(), pm.height() );
              te->setBackgroundPixmap(bgPixmap);
            }
    break;
    case 4: // full
            {
              float sx = (float)te->size().width() / pm.width();
              float sy = (float)te->size().height() / pm.height();
              QWMatrix matrix;
              matrix.scale( sx, sy );
              te->setBackgroundPixmap(pm.xForm( matrix ));
            }
    break;
    default: // oops
             n_render = 1;
  }
}
コード例 #24
0
//-----------------------------------------------------------
void VisaoGeralWidget::atualizarVisaoGeral(void)
{
 if(viewp && this->isVisible())
 {
  QSize tam;
  QPixmap pix;

  //Cria um pixmap com o tamanho da cena
  pix.resize(cena->sceneRect().size().toSize());

  //Cria um QSize com 20% do tamanho da cena
  tam=cena->sceneRect().size().toSize();
  tam.setWidth(tam.width() * FATOR_REDIM);
  tam.setHeight(tam.height() * FATOR_REDIM);

  ///Desenha a cena no pixmap
  QPainter p(&pix);
  cena->render(&p, pix.rect(), cena->sceneRect().toRect());

  //Exibe o pixmap no label redimensionado com o QSize criado anteriormente
  label->setPixmap(pix.scaled(tam, Qt::KeepAspectRatio, Qt::SmoothTransformation));
  label->resize(tam);
 }
}
コード例 #25
0
ファイル: notedrag.cpp プロジェクト: tytycoon/basket
void NoteDrag::serializeImage(NoteSelection *noteList, K3MultipleDrag *multipleDrag)
{
	Q3ValueList<QPixmap> pixmaps;
	QPixmap pixmap;
	for (NoteSelection *node = noteList->firstStacked(); node; node = node->nextStacked()) {
		pixmap = node->note->content()->toPixmap();
		if (!pixmap.isNull())
			pixmaps.append(pixmap);
	}
	if (!pixmaps.isEmpty()) {
		QPixmap pixmapEquivalent;
		if (pixmaps.count() == 1)
			pixmapEquivalent = pixmaps[0];
		else {
			// Search the total size:
			int height = 0;
			int width  = 0;
			for (Q3ValueList<QPixmap>::iterator it = pixmaps.begin(); it != pixmaps.end(); ++it) {
				height += (*it).height();
				if ((*it).width() > width)
					width = (*it).width();
			}
			// Create the image by painting all image into one big image:
			pixmapEquivalent.resize(width, height);
			pixmapEquivalent.fill(Qt::white);
			QPainter painter(&pixmapEquivalent);
			height = 0;
			for (Q3ValueList<QPixmap>::iterator it = pixmaps.begin(); it != pixmaps.end(); ++it) {
				painter.drawPixmap(0, height, *it);
				height += (*it).height();
			}
		}
		Q3ImageDrag *imageDrag = new Q3ImageDrag(pixmapEquivalent.convertToImage());
		multipleDrag->addDragObject(imageDrag);
	}
}
コード例 #26
0
QByteArray KstViewObjectImageDrag::encodedData(const char *mimeType) const {
  if (!_mimeTypes.contains(QString::fromLatin1(mimeType))) {
    return QByteArray();
  }

  QRect geom(0, 0, 0, 0);
  for (KstViewObjectList::ConstIterator i = _objects.begin(); i != _objects.end(); ++i) {
    geom = geom.unite((*i)->geometry());
  }

  QPixmap pm;
  pm.resize(geom.size());
  pm.fill();

  int prog = 0;
  bool cancelled = false;
  KstPainter p(KstPainter::P_EXPORT);
  p.begin(&pm);
  p.setClipping(true);
  KProgressDialog *dlg = new KProgressDialog(0, 0, QString::null, i18n("Generating and storing images of objects..."), true);
  dlg->setAllowCancel(true);
  dlg->progressBar()->setTotalSteps(_objects.count());
  dlg->progressBar()->setValue(prog);
  dlg->show();

  for (KstViewObjectList::Iterator i = _objects.begin(); i != _objects.end(); ++i) {
    p.setClipRect((*i)->geometry());
    p.setViewport((*i)->geometry());
    (*i)->paint(p, QRegion());
    if (dlg->wasCancelled()) {
      cancelled = true;
      break;
    }
    dlg->progressBar()->setValue(++prog);
    kapp->eventLoop()->processEvents(QEventLoop::ExcludeSocketNotifiers);
  }
  p.end();

  delete dlg;

  if (cancelled) {
    return QByteArray();
  }

  QByteArray rc;
#if QT_VERSION < 0x030200
  KTempFile tf;
  pm.save(tf.name(), KImageIO::typeForMime(mimeType).latin1());
  tf.close();
  QFile f(tf.name());
  if (f.open(IO_ReadOnly)) {
    rc = f.readAll();
    f.close();
  }
  QFile::remove(tf.name());
#else
  QDataStream ds(rc, IO_WriteOnly);
  pm.save(ds.device(), KImageIO::typeForMime(mimeType).latin1());
#endif

  return rc;
}
コード例 #27
0
ファイル: regularData2DWidget.C プロジェクト: HeyJJ/ball
		// creates a polygon from a given vector RegularData1D * data
		void RegularData2DWidget::createPlot()
		{
			// no data => no polygon
			if (data_ == 0 ||
					data_->size() == 0) 
			{
				return;
			}

			// set up the ColorMap... TODO: This should be done by a dialog or something similar
			
			ColorRGBA colorList[3];
			ColorMap color_table_;  
			colorList[0] = ColorRGBA(1.,0.,0.,1.);
			colorList[1] = ColorRGBA(0.,1.,0.,1.);
			colorList[2] = ColorRGBA(0.,0.,1.,1.);

			color_table_.setBaseColors(colorList, 3);
			color_table_.setNumberOfColors(100);
			
			// determine the minimal and maximal values in data_
			float min = (*data_)[0];
			float max = (*data_)[0];

			for (Position i=1; i < (*data_).size(); i++)
			{
				if      ((*data_)[i] < min) min = (*data_)[i];
				else if ((*data_)[i] > max) max = (*data_)[i];
			}			
			color_table_.setRange(min, max);
			color_table_.createMap();
			
			//maximal number of Lines and Columns
			Size max_x = (*data_).getSize().x;
			Size max_y = (*data_).getSize().y;

			// Draw the points
			QPixmap pixmap;								
			pixmap.resize(max_x, max_y);
			pixmap.fill();           			// delete the old picture
			QPainter paint;     
			paint.begin(&pixmap);         // set the Painter 

			try
			{
				QColor pCol;        
				for (Position y=0; y< max_y; y++) 
				{
					for (Position x=0; x< max_x; x++) 
					{
						ColorRGBA mapcolor = color_table_.map(data_->getData(x + y * max_x));
						pCol = QColor(mapcolor.getRed(), mapcolor.getGreen(), mapcolor.getBlue());
						paint.setPen(pCol);
						paint.drawPoint(x, y);
					}
				}
			}
			catch(...)
			{
				setStatusbarText("Error: Point in dataset out of grid!");
				Log.error() << "Error: Point in dataset out of grid!" << std::endl;
				return;
			}

			paint.end();

			//put the pixmapItem into objects
			PixmapItem* pixItem = new PixmapItem(&canvas_, pixmap);
			pixItem->show();
			objects_.push_back(dynamic_cast<Q3CanvasItem*> (pixItem)); 

			// resize the canvas to fit the data
			canvas_.resize(max_x, max_y);
		}
コード例 #28
0
void CrystalButton::drawButton(QPainter *painter)
{
	if (!CrystalFactory::initialized()) return;

	QColorGroup group;
	float dx, dy;
	int dm=0;

	QPixmap pufferPixmap;
	pufferPixmap.resize(width(), height());
	QPainter pufferPainter(&pufferPixmap);
	
	CrystalFactory *f=((CrystalFactory*)client_->factory());
	QPixmap *background;
	if (f->transparency)background=f->image_holder->image(client_->isActive());
		else background=NULL;
	WND_CONFIG *wndcfg=client_->isActive()?&f->active:&f->inactive;

	if (background && !background->isNull())
	{
		QRect r=rect();
		QPoint p=mapToGlobal(QPoint(0,0));
		r.moveBy(p.x(),p.y());
	
		pufferPainter.drawPixmap(QPoint(0,0),*background,r);
	}else{
		group = client_->options()->colorGroup(KDecoration::ColorTitleBar, client_->isActive());
		pufferPainter.fillRect(rect(), group.background());
	}

	if (!wndcfg->overlay.isNull())
	{
		pufferPainter.drawTiledPixmap(rect(),wndcfg->overlay,QPoint(x(),y()));
	}

	dm=0;
	if (image && (image->drawMode==1))dm=1;
	if (wndcfg->outlineMode)
	{
		// outline the frame
		pufferPainter.setPen(wndcfg->frameColor);

		if (wndcfg->outlineMode==2)pufferPainter.setPen(wndcfg->frameColor.dark(150));
		if (wndcfg->outlineMode==3)pufferPainter.setPen(wndcfg->frameColor.light(150));
		// top
		if ((client_->FullMax && client_->isShade() && (dm==0)) ||
			((dm==1)&&(!client_->FullMax || client_->isShade()))) pufferPainter.drawLine(0,0,width(),0);
		// left
		if (first && client_->FullMax && client_->isShade())pufferPainter.drawLine(0,0,0,height());

		if (wndcfg->outlineMode==2)pufferPainter.setPen(wndcfg->frameColor.light(150));
		if (wndcfg->outlineMode==3)pufferPainter.setPen(wndcfg->frameColor.dark(150));
		// bottom
		if (client_->isShade() && ((dm==1)||(client_->FullMax)))pufferPainter.drawLine(0,height()-1,width(),height()-1);
		
		// right
		if (last && client_->FullMax && client_->isShade())pufferPainter.drawLine(width()-1,0,width()-1,height());
	}
	if (wndcfg->inlineMode && (client_->FullMax||dm==1) && !client_->isShade())
	{
		// inline the frame
		if (wndcfg->inlineMode==1)pufferPainter.setPen(wndcfg->inlineColor);
		if (wndcfg->inlineMode==2)pufferPainter.setPen(wndcfg->inlineColor.dark(150));
		if (wndcfg->inlineMode==3)pufferPainter.setPen(wndcfg->inlineColor.light(150));
		// buttons just need to draw the bottom line
		pufferPainter.drawLine(0,height()-1,width(),height()-1);
	}


	if (type_ == ButtonMenu && (!::factory->menuImage || image==NULL || (image!=NULL && !image->initialized()))) {
		// we paint the mini icon (which is 16 pixels high)
		dx = float(width() - 16) / 2.0;
		dy = float(height() - 16) / 2.0;

		if (dx<1 || dy<=1)
		{
			int m=(rect().width()-2<rect().height())?rect().width()-2:rect().height();
			QRect r((rect().width()-m)/2,(rect().height()-m)/2,m,m);
// 			if (isDown()) { r.moveBy(1,1); }
        		pufferPainter.drawPixmap(r, client_->icon().pixmap(QIconSet::Small,
                                                           QIconSet::Normal));
		}else{
//         	if (isDown()) { dx++; dy++; }
			pufferPainter.drawPixmap((int)dx, (int)dy, client_->icon().pixmap(QIconSet::Small,
                                                           QIconSet::Normal));
		}
	} else if (image && image->initialized()) {
		// otherwise we paint the deco
		dx = float(width() - image->image_width) / 2.0;
		dy = float(height() - image->image_height) / 2.0;
		
		QImage *img=image->normal;

		if (::factory->hovereffect)
		{
			if (hover)
			{
				img=image->hovered; 
			}
			if (::factory->animateHover)
			{
				img=image->getAnimated(animation);
			}
		}
		if (isDown())
		{
			img=image->pressed;
		}
	
		if (img)
		if (dx<image->hSpace/2 || dy<0)
		{	// Deco size is smaller than image, we need to stretch it
			int w,h;

			if (rect().width()-image->hSpace<rect().height())
			{
				w=rect().width()-image->hSpace;
				h=(int)((float)w*(float)image->image_height/(float)image->image_width);
			}else{
				h=rect().height();
				w=(int)((float)h*(float)image->image_width/(float)image->image_height);
			}

			QRect r((rect().width()-w)/2,(rect().height()-h)/2,w,h);

			pufferPainter.drawImage(r,*img);
			if (type_ == ButtonMenu) drawMenuImage(&pufferPainter, r);
		}else{
			// Otherwise we just paint it
			if (image->drawMode==1)dy=0;
			pufferPainter.drawImage(QPoint((int)dx,(int)dy),*img);

			if (type_ == ButtonMenu) drawMenuImage(&pufferPainter, 
				QRect((int)dx,(int)dy,image->image_width,image->image_height));
	    }
	}
	
	pufferPainter.end();
	painter->drawPixmap(0,0, pufferPixmap);
}
コード例 #29
0
bool readPixmapNode( const QDomElement& element, QPixmap& pixmap )
{
    bool ok = true;
    int tempLengthi;
    QString tempData;
    QDomNode node = element.firstChild();
    while( !node.isNull() ) {
        QDomElement element = node.toElement();
        if( !element.isNull() ) { // was really an element
            QString tagName = element.tagName();
            if( tagName == "Format" ) {
                QString formatName;
                ok = ok & readStringNode( element, formatName );
#ifndef NDEBUG
                if( formatName != "XPM.GZ" )
                    qDebug( "Unsupported pixmap format in XML file" );
#endif
            } else if( tagName == "Length" ) {
                ok = ok & readIntNode( element, tempLengthi );
            } else if( tagName == "Data" ) {
                ok = ok & readStringNode( element, tempData );
            } else {
                qDebug( "Unknown tag in Pixmap" );
            }
        }
        node = node.nextSibling();
    }

    if( ok ) {
	if( 0 < tempLengthi ) {
            // Decode the image file format in the same way Qt Designer does.
            char *ba = new char[ tempData.length() / 2 ];
            for ( int i = 0; i < (int)tempData.length() / 2; ++i ) {
                char h = tempData[ 2 * i ].latin1();
                char l = tempData[ 2 * i  + 1 ].latin1();
                uchar r = 0;
                if ( h <= '9' )
                    r += h - '0';
                else
                    r += h - 'a' + 10;
                r = r << 4;
                if ( l <= '9' )
                    r += l - '0';
                else
                    r += l - 'a' + 10;
                ba[ i ] = r;
            }

            if( tempLengthi < (int)tempData.length() * 5 )
                tempLengthi = tempData.length() * 5;
            unsigned long tempLength = tempLengthi;
            QByteArray baunzip( tempLength );
            ::uncompress( (uchar*) baunzip.data(), &tempLength,
                          (uchar*) ba, tempData.length()/2 );
            QImage image;
            image.loadFromData( (const uchar*)baunzip.data(), tempLength, "XPM" );

            if( image.isNull() )
                pixmap.resize( 0, 0 ); // This is _not_ an error, we just read a NULL pixmap!
            else
                ok = ok & pixmap.convertFromImage( image, 0 );
        } else
            pixmap.resize( 0, 0 ); // This is _not_ an error, we just read a empty pixmap!
    }

    return ok;
}
コード例 #30
-1
ファイル: pmenu.cpp プロジェクト: kthxbyte/KDE1-Linaro
void PMenu::create_pixmap( QPixmap &buf, PMenuItem *item, QPopupMenu *menu)
{
  int w, h;
  QPainter p;
  QFontMetrics fm = menu->fontMetrics();   // size of font set for this widget

  w  = 2 + item->pixmap.width() + 4 + fm.width( item->text_name ) + 2;
  h = ( item->pixmap.height() > fm.height() ? item->pixmap.height() : fm.height() ) + 4; 
  
  buf.resize( w, h );                    // resize pixmap
  buf.fill( menu->backgroundColor() );   // clear it
  
  p.begin( &buf );
  p.drawPixmap( 2, 2, item->pixmap );              // use 2x2 border
  p.setFont( menu->font() );
  p.drawText( 2 + item->pixmap.width() + 4,        // center text in item
	      0, w, h,
	      AlignVCenter | ShowPrefix | DontClip | SingleLine,
	      item->text_name );
  p.end();
}