Esempio n. 1
0
bool Board::loadTiles(float scale) {
  int i, j, x, y;

  // delete old tiles
  for(i = 0; i < 45; i++)
    if(pm_tile[i] != 0) {
      delete pm_tile[i];
      pm_tile[i] = 0;
    }

  QPixmap pm((PICDIR + "/kshisen.xpm").data());
  if(pm.width() == 0 || pm.height() == 0) {
    KMsgBox::message(0, klocale->translate("Shisen-Sho"), 
		     klocale->translate("Cannot load pixmaps!"));
    exit(1);
  }
  
  if(pm.width() == 0 || pm.height() == 0)
    return FALSE;

  x = pm.width() / 9;
  y = pm.height() / 5;
  for(i = 0; i < 9; i++)
    for(j = 0; j < 5; j++) {
	pm_tile[i + j*9] = new QPixmap(x,y);
	bitBlt(pm_tile[i + j*9], 0, 0, &pm, x * i, y * j, x, y, CopyROP);
	if(scale != 1.0) {
	  QWMatrix wm;
	  wm.scale(scale, scale);
	  *pm_tile[i + j*9] = pm_tile[i + j*9]->xForm(wm);
	}
    }
  
  return TRUE;
}
Esempio n. 2
0
void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
    MimeType type( info->absFilePath() );
    if (!compliesMime( type.id() ) )
        return;

    QPixmap pix = type.pixmap();
    QString dir, name;
    bool locked;
    if ( pix.isNull() ) {
        QWMatrix matrix;
        QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
        matrix.scale( .4, .4 );
        pix = pixer.xForm( matrix );
    }
    dir = info->dirPath( true );
    locked = false;
    if ( symlink )
        name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
    else {
        name = info->fileName();
        if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
                ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
            locked = true;
            pix = Resource::loadPixmap("locked");
        }
    }
    (void)new OFileSelectorItem( m_view, pix, name,
                                 info->lastModified().toString(), QString::number( info->size() ),
                                 dir, locked );
}
Esempio n. 3
0
QPixmap fastScalePixmap(const QPixmap &pixmap, int width, int height)
{
  QWMatrix m;
  m.scale(width/(double)pixmap.width(),
      height/(double)pixmap.height());
  return pixmap.xForm(m);
}
Esempio n. 4
0
void ImageLabel::applyTransformations(bool useSmoothScale)
{
    pixmap = realpixmap;
    if (doRotate)
    {
        // KDE and QT seem to miss a high quality image rotation
        QWMatrix rotMat;
        rotMat.rotate(rot_angle);
        pixmap = pixmap.xForm(rotMat);
    }
    if (doScale)
    {
        if (m_karamba -> useSmoothTransforms() || useSmoothScale)
        {
            pixmap.convertFromImage(
              pixmap.convertToImage().smoothScale(scale_w, scale_h));
        }
        else
        {
            double widthFactor = ((double)scale_w) / ((double)pixmap.width());
            double heightFactor = ((double)scale_h) / ((double)pixmap.height());
            QWMatrix scaleMat;
            scaleMat.scale(widthFactor, heightFactor);
            pixmap = pixmap.xForm(scaleMat);
        }
    }
    if (imageEffect != 0)
    {
        pixmap = imageEffect -> apply(pixmap);
    }
    setWidth(pixmap.width());
    setHeight(pixmap.height());
}
Esempio n. 5
0
void ClsQSAList::insertSA(QPixmap qpm, string, vector <vector<double> > v, bool bReplace) {
//    cout << "ClsQSAList::insertSA(QPixmap qpm, string, vector <vector<double> > v)" << endl;
    double fFactor = (double)iListViewVisibleWidth / (double) qpm.width();
    
    QWMatrix m;
    m.scale(fFactor, fFactor );
    QPixmap pmS = qpm.xForm( m ); 

    ClsListBoxSA* clsListBoxSA = new ClsListBoxSA(qlbox, pmS);
    clsListBoxSA->setMatrix(v);


    if(bReplace){
	int iCurrent = qlbox->currentItem();
	if(iCurrent>=0) {
	    qlbox->removeItem(iCurrent);
	}
	qlbox->insertItem(clsListBoxSA, iCurrent);
    } else {
	qlbox->insertItem(clsListBoxSA);
    }

    qlbox->setCurrentItem(clsListBoxSA);
    qlbox->clearSelection ();
    qlbox->setSelected(clsListBoxSA, true);
}
Esempio n. 6
0
QWMatrix KoView::matrix() const
{
  QWMatrix m;
  m.scale( zoom(), zoom() );
  //m.translate(  canvasXOffset() ,  canvasYOffset() );
  return m;
}
Esempio n. 7
0
void k9MenuEditor::resizeEvent ( QResizeEvent * e ) {
    QWMatrix m;
    double scalex=(e->size().width()-4.0)/720.0;
    double scaley=(e->size().height()-4.0)/576.0;
    m.scale(QMIN(scalex,scaley),QMIN(scalex,scaley));
    this->setWorldMatrix(m);

}
Esempio n. 8
0
void SymbolItem::setKind( int kind_ )
{
    kind = kind_;

    QWMatrix m;
    if ( kind == FOLDER )
    {
        m.scale( 0.6, 0.6 );
        QPixmap small = i_folder.xForm( m );
        setPixmap( 0, small );
    }
    else if ( kind == GRAPHIC )
    {
        m.scale( 0.55, 0.55 );
        QPixmap small = i_graphic.xForm( m );
        setPixmap( 0, small );
    }
}
Esempio n. 9
0
void KoChild::transform( QPainter &painter )
{
    setClipRegion( painter, true );

    QWMatrix m = painter.worldMatrix();
    m = d->m_matrix * m;
    m.scale( d->m_scaleX, d->m_scaleY );
    painter.setWorldMatrix( m );
}
Esempio n. 10
0
void CVBEditor::updateWorldMatrix() {
	double z = p_itemView->zoomLevel();
	QRect r = m_pCanvas->rect();
// 	QWMatrix m( z, 0.0, 0.0, z, -r.left(), -r.top() );
// 	QWMatrix m( z, 0.0, 0.0, z, 0.0, 0.0 );
	QWMatrix m;
	m.scale(z, z);
	m.translate(-r.left(), -r.top());
	setWorldMatrix(m);
}
Esempio n. 11
0
void StartRoom::loadLevel(int level)
{
	if(level < 1 || level > leV->max())
		return;

	QPixmap pixmap = leV->getPixmap(level);
	QWMatrix m;
	m.scale( (double)7, (double)7 );
	pixmap = pixmap.xForm( m );
	picture->setPixmap(pixmap);
}
Esempio n. 12
0
void ClsQDiagramView::zoomOut() {
#ifdef DEBUG_CLSQDIAGRAMVIEW
    cout << "ClsQDiagramView::zoomOut()" << endl;
#endif
    QWMatrix m = clsQDiagramCanvasView->worldMatrix();
    m.scale( 0.9, 0.9 );
    clsQDiagramCanvasView->setWorldMatrix( m );
#ifdef USEPANNER
    clsqcanvaspanner->canvasResized();
#endif
};
Esempio n. 13
0
void KBBGraphic::scalePixmaps( int w, int h )
{
    int i, w0, h0;
    QWMatrix wm;

    w0 = pix[0]->width();
    h0 = pix[0]->height();
    wm.scale( (float) w / (float) w0, (float) h / (float) h0 );
    for (i = 0; i < NROFTYPES; i++) {
        *pixScaled[i] = pix[i]->xForm( wm );
    }
}
Esempio n. 14
0
/**
 * Draws the graph on the canvas using the graphviz engine.
 * A new canvas is created, so all items need to be regenerated.
 * TODO: Can we use the same canvas and only reposition existing items?
 */
void GraphWidget::draw()
{
	QWMatrix mtx;
	char szTempFile[TMP_TMPL_SIZE];
	int nFd;
	FILE* pFile;
	
	// Do nothing if drawing process has already started
	if (m_dot.isRunning())
		return;
	
	// Apply the zoom factor
	mtx.scale(m_dZoom, m_dZoom);
	setWorldMatrix(mtx);

	// Do not draw until the Dot process finishes
	setUpdatesEnabled(false);

	// Open a temporary file
	strcpy(szTempFile, TMP_TMPL);
	nFd = mkstemp(szTempFile);
	if ((pFile = fdopen(nFd, "w")) == NULL)
		return;
	
	// Remember the file name (so it can be deleted later)
	m_sDrawFilePath = szTempFile;
	
	// Write the graph contents to the temporary file
	{
		QTextStream str(pFile, IO_WriteOnly);
		write(str, "graph", "--", false);
	}
	
	// Close the file
	fclose(pFile);
	
	// Draw the graph
	if (m_dot.run(szTempFile)) {
		// Create the progress dialogue
		m_pProgressDlg = new ProgressDlg(i18n("KScope"), 
			i18n("Generating graph, please wait"), this);
		m_pProgressDlg->setMinimumDuration(1000);
		m_pProgressDlg->setValue(0);
		
		// TODO:
		// Implement cancel (what do we do when the drawing process is 
		// terminated, even though the nodes and edges were already added by
		// Cscope?)
		// m_pProgressDlg->setAllowCancel(true);
	}
}
Esempio n. 15
0
void MyPaint(NBioBSPRollDemo_Widget* pWidget)
{
   QPixmap Spm;
   Spm = pWidget->m_RollImage;
   Spm.setOptimization(QPixmap::BestOptim);
   
   QWMatrix Sm;
   Sm.scale((double)IMAGE_FRAME_WIDTH/(double)pWidget->m_DeviceInfo0.ImageWidth,
      (double)IMAGE_FRAME_HEIGHT/(double)pWidget->m_DeviceInfo0.ImageHeight);
   
   QPixmap Srpm = Spm.xForm(Sm);
        
   bitBlt(pWidget->m_frmRoll, 0, 0, &Srpm);
}
Esempio n. 16
0
/**
 * Changes the zoom factor.
 * @param	bIn	true to zoom in, false to zoom out
 */
void GraphWidget::zoom(bool bIn)
{
	QWMatrix mtx;
	
	// Set the new zoom factor
	if (bIn)
		m_dZoom *= 2.0;
	else
		m_dZoom /= 2.0;
		
	// Apply the transformation matrix
	mtx.scale(m_dZoom, m_dZoom);
	setWorldMatrix(mtx);
}
Esempio n. 17
0
bool KGrCanvas::changeSize (int d)
{
#ifdef QT3
    if ((d < 0) && (scaleStep <= STEP)) {
	// Note: Smaller scales lose detail (e.g. the joints in brickwork).
	KGrMessage::information (this, i18n("Change Size"),
	i18n("Sorry, you cannot make the play area any smaller."));
	return FALSE;
    }

    if ((d >= 0) && (scaleStep >= 2 * STEP)) {
	// Note: Larger scales go off the edge of the monitor.
	KGrMessage::information (this, i18n("Change Size"),
	i18n("Sorry, you cannot make the play area any larger."));
	return FALSE;
    }

    QWMatrix wm = worldMatrix();
    double   wmScale = 1.0;

    // Set the scale back to 1:1 and calculate the new scale factor.
    wm.reset();
    scaleStep = (d < 0) ? (scaleStep - 1) : (scaleStep + 1);

    // If scale > 1:1, scale up to the new factor (e.g. 1.25:1, 1.5:1, etc.)
    if (scaleStep > STEP) {
	wmScale = (wmScale * scaleStep) / STEP;
	wm.scale (wmScale, wmScale);
    }
    setWorldMatrix (wm);

    // Force the title size and position to be re-calculated.
    QString t = title->text();
    makeTitle ();
    setTitle (t);

    // Fit the QCanvasView and its frame to the canvas.
    int frame = frameWidth()*2;
    setFixedSize ((FIELDWIDTH  + 4) * 4 * scaleStep + frame,
		  (FIELDHEIGHT + 4) * 4 * scaleStep + frame);
    return TRUE;

#else
    KGrMessage::information (this, i18n( "Change Size" ),
    i18n( "Sorry, you cannot change the size of the playing area. "
    "That function requires Qt Library version 3 or later." ));
    return FALSE;
#endif
}
Esempio n. 18
0
void Pen::mousePressEvent(QMouseEvent *e)
{
  int x,y;
  QPainter painter1;
  QPainter painter2;
  QWMatrix m;

  KDEBUG(KDEBUG_INFO, 3000, "Pen::mousePressEvent() handler called\n");
  
  if (isActive()) {
    if (drawing) {
      KDEBUG(KDEBUG_INFO, 3000, "Pen: Warning button press received while drawing\n");
    }
    x= (e->pos()).x();
    y= (e->pos()).y();
    activeButton= e->button();

    m.scale((float) 100/(canvas->zoom()), (float) 100/(canvas->zoom()));

    painter1.begin(canvas->pixmap());

    if (activeButton == LeftButton)
      painter1.setPen(leftpen);
    else
      painter1.setPen(rightpen);
    painter1.setWorldMatrix(m);

    painter2.begin(canvas->zoomedPixmap());

    if (activeButton == LeftButton)
      painter2.setPen(leftpen);
    else
      painter2.setPen(rightpen);

    painter1.drawPoint(x, y);
    painter2.drawPoint(x, y);

    painter1.end();
    painter2.end();

    canvas->repaint(0);
    lastx= x;
    lasty= y;
    drawing= TRUE;
  } 
  if (!isActive()) {
    KDEBUG(KDEBUG_WARN, 3000, "Warning event received when inactive (ignoring)\n");
  }
}
Esempio n. 19
0
void AudioBrowserScreen::displayAlbumArt(const QString& key) {
    QPixmap image = dbHandler->loadAlbumArt(key);
    if (image.isNull()) {
        cover->hide();
    }
    else {
        double scalew = cover->width()/(double)image.width();
        double scaleh = cover->height()/(double)image.height();
        QWMatrix m;
        m.scale(scalew,scaleh);
        QPixmap scaled = image.xForm(m);
        cover->setPixmap(scaled);
        cover->show();
    }
}
Esempio n. 20
0
void Pen::mouseMoveEvent(QMouseEvent *e)
{
  int x,y;
  QPainter painter1;
  QPainter painter2;
  QWMatrix m;

  if (isActive()) {
    x= (e->pos()).x();
    y= (e->pos()).y();

    if (drawing) {
      if ((x != lastx) || (y != lasty)) {
	emit modified();
	m.scale((float) 100/(canvas->zoom()), (float) 100/(canvas->zoom()));

	painter1.begin(canvas->pixmap());

	if (activeButton == LeftButton)
	  painter1.setPen(leftpen);
	else
	  painter1.setPen(rightpen);

	painter1.setWorldMatrix(m);

	painter2.begin(canvas->zoomedPixmap());

	if (activeButton == LeftButton)
	  painter2.setPen(leftpen);
	else
	  painter2.setPen(rightpen);

	painter1.drawLine(lastx, lasty, x, y);
	painter2.drawLine(lastx, lasty, x, y);

	lastx= x;
	lasty= y;

	painter1.end();
	painter2.end();
	canvas->repaint(0);
      }
    }
  }
  else {
    KDEBUG(KDEBUG_WARN, 3000, "Warning event received when inactive (ignoring)\n");
  }
}
Esempio n. 21
0
int main( int argc, char **argv )
{
    QApplication a(argc,argv);			
    
    QTable v( numRows, numCols );
    QWMatrix wm;
    wm.scale( 0.5, 0.5 );
    QPixmap pix( qtlogo_xpm );
    pix = pix.xForm( wm );
    v.setPixmap( 3, 3, pix );
    v.setText( 3, 3, "A Pixmap" );
    
    a.setMainWidget( &v );
    v.show();
    return a.exec();
}
Esempio n. 22
0
QtFileIconView::QtFileIconView( const QString &dir, QWidget *parent, const char *name )
    : QIconView( parent, name ), viewDir( dir ), newFolderNum( 0 )
{
    if ( !iconFolderLockedLarge ) {
        qAddPostRoutine( cleanup );
        QWMatrix m;
        m.scale( 0.6, 0.6 );
        QPixmap iconpix( folder_locked_icon );
        iconFolderLockedLarge = new QPixmap( folder_locked_icon );
        iconpix = iconpix.xForm( m );
        iconFolderLockedSmall = new QPixmap( iconpix );
        iconpix = QPixmap( folder_icon );
        iconFolderLarge = new QPixmap( folder_icon );
        iconpix = iconpix.xForm( m );
        iconFolderSmall = new QPixmap( iconpix );
        iconpix = QPixmap( file_icon );
        iconFileLarge = new QPixmap( file_icon );
        iconpix = iconpix.xForm( m );
        iconFileSmall = new QPixmap( iconpix );
        iconpix = QPixmap( link_icon );
        iconLinkLarge = new QPixmap( link_icon );
        iconpix = iconpix.xForm( m );
        iconLinkSmall = new QPixmap( iconpix );
    }

    vm = Large;

    setGridX( 75 );
    setResizeMode( Adjust );
    setWordWrapIconText( FALSE );

    connect( this, SIGNAL( doubleClicked( QIconViewItem * ) ),
             this, SLOT( itemDoubleClicked( QIconViewItem * ) ) );
    connect( this, SIGNAL( returnPressed( QIconViewItem * ) ),
             this, SLOT( itemDoubleClicked( QIconViewItem * ) ) );
    connect( this, SIGNAL( dropped( QDropEvent *, const QValueList<QIconDragItem> & ) ),
             this, SLOT( slotDropped( QDropEvent *, const QValueList<QIconDragItem> & ) ) );
    connect( this, SIGNAL( contextMenuRequested( QIconViewItem *, const QPoint & ) ),
             this, SLOT( slotRightPressed( QIconViewItem * ) ) );

    setHScrollBarMode( AlwaysOff );
    setVScrollBarMode( Auto );

    setAutoArrange( TRUE );
    setSorting( TRUE );
    openItem = 0;
}
Esempio n. 23
0
void Line::mouseReleaseEvent(QMouseEvent *e)
{
  int x,y;
  QPainter paint;
  QWMatrix m;

KDEBUG(KDEBUG_INFO, 3000, "Line::mouseReleaseEvent() handler called\n");

  if (isActive() && drawing && (e->button() == activeButton)) {
    emit modified();
    x= (e->pos()).x();
    y= (e->pos()).y();

    // Erase old line
    paint.begin(canvas->zoomedPixmap());
    if (activeButton == LeftButton)
      paint.setPen(leftpen);
    else
      paint.setPen(rightpen);
    paint.setRasterOp(DEFAULT_RASTER_OP);
    paint.drawLine(startx, starty, lastx, lasty);

    paint.end();

    m.scale((float) 100/(canvas->zoom()), (float) 100/(canvas->zoom()));
    paint.begin(canvas->pixmap());
    if (activeButton == LeftButton)
      paint.setPen(leftpen);
    else
      paint.setPen(rightpen);
    paint.setWorldMatrix(m);

    paint.setRasterOp(CopyROP);
    // Draw new line
    paint.drawLine(startx, starty, lastx, lasty);
    paint.end();
    drawing= FALSE;
    canvas->updateZoomed();
    canvas->repaint(0);
  }
  else {
KDEBUG(KDEBUG_WARN, 3000, "Warning event received when inactive (ignoring)\n");
  }
}
Esempio n. 24
0
void QVFbView::drawScreen()
{
    QPainter p( viewport() );

    p.translate( -contentsX(), -contentsY() );

    lock();
    QRect r( hdr->update );
    hdr->dirty = FALSE;
    hdr->update = QRect();
    // qDebug( "update %d, %d, %dx%d", r.y(), r.x(), r.width(), r.height() );
    r = r.intersect( QRect(0, 0, hdr->width, hdr->height ) );
    if ( !r.isEmpty() )  {
	if ( int(zm) != zm ) {
	    r.rLeft() = int(int(r.left()*zm)/zm);
	    r.rTop() = int(int(r.top()*zm)/zm);
	    r.rRight() = int(int(r.right()*zm+zm+0.0000001)/zm+1.9999);
	    r.rBottom() = int(int(r.bottom()*zm+zm+0.0000001)/zm+1.9999);
	    r.rRight() = QMIN(r.right(),hdr->width-1);
	    r.rBottom() = QMIN(r.bottom(),hdr->height-1);
	}
	int leading;
	QImage img( getBuffer( r, leading ) );
	QPixmap pm;
	if ( zm == 1 ) {
	    pm.convertFromImage( img );
	} else if ( int(zm) == zm ) {
	    QWMatrix m;
	    m.scale(zm,zm);
	    pm.convertFromImage( img );
	    pm = pm.xForm(m);
	} else {
	    pm.convertFromImage( img.smoothScale(int(img.width()*zm),int(img.height()*zm)) );
	}
	unlock();
	p.setPen( black );
	p.setBrush( white );
	p.drawPixmap( int(r.x()*zm), int(r.y()*zm), pm,
			int(leading*zm), 0, pm.width(), pm.height() );
    } else {
	unlock();
    }
}
LapsusPanelDefault::LapsusPanelDefault(Qt::Orientation orientation,
			QWidget *parent):
		LapsusPanelWidget(orientation, parent, 0), _label(0)
{
	if ( orientation == Qt::Horizontal )
		_layout = new QVBoxLayout( this );
	else
		_layout = new QHBoxLayout( this );

	_layout->addStretch();

	_label = new QLabel(this);
	_label->setBackgroundMode(X11ParentRelative);

	QPixmap pic = UserIcon("laptop");

	if (!pic.isNull() )
	{
		// scale icon
		QWMatrix t;
		t = t.scale( 20.0/pic.width(), 20.0/pic.height() );
		pic = pic.xForm( t );

		_label->setPixmap( pic );
		_label->resize( 20, 20 );
	}
	else
	{
		// Desperate fallback... ;)
		_label->setText("Lapsus\nApplet");
	}

	_layout->add(_label);
	_layout->addStretch();

	_label->show();

	QToolTip::add( _label, "Lapsus Panel Applet" );

	_label->show();
}
Esempio n. 26
0
QPixmap KIconLoader::loadInternal ( const QString &name, int w,  int h ){

  QPixmap *pix;
  KPixmap new_xpm;

  int index;

  if ( (index = name_list.find(name)) < 0){
    
    pix = new QPixmap;
    new_xpm.load( getIconPath(name), 0L, KPixmap::LowColor );
    *pix = new_xpm;
    
    if( !(pix->isNull()) ){
      
      name_list.append(name);
      pixmap_list.append(pix);

    } 
    else {
      delete pix;
      return new_xpm;
    }
  }
  else{
    pix = pixmap_list.at(index);
  }
  

  if (pix && !pix->isNull() && w > 0 && h > 0 &&  
      (pix->width() > w || pix->height() > h)){

    QWMatrix m;
    m.scale(w/(float)pix->width(), h/(float)pix->height());

    return pix->xForm(m);

  }

  return *pix;
}
Esempio n. 27
0
void AreaSelect::mouseReleaseEvent(QMouseEvent *e)
{
  int x,y;
  QPainter paint;
  QWMatrix m;

KDEBUG(KDEBUG_INFO, 3000, "AreaSelect::mouseReleaseEvent() handler called\n");

  if (isActive() && (e->button() == LeftButton)) {
    x= (e->pos()).x();
    y= (e->pos()).y();

    // Erase old line
    paint.begin(canvas->zoomedPixmap());
    paint.setPen(QPen(green, 0, DashLine));
    paint.setRasterOp(DEFAULT_RASTER_OP);
    paint.drawRect(startx, starty, lastx-startx, lasty-starty);

    paint.end();

    m.scale((float) 100/(canvas->zoom()), (float) 100/(canvas->zoom()));
    paint.begin(canvas->pixmap());
    //    paint.setPen(pen);
    paint.setWorldMatrix(m);
    paint.setRasterOp(CopyROP);
    canvas->setSelection(QRect(startx, starty, x-startx, y-starty));
    paint.end();
    drawing= FALSE;
    canvas->updateZoomed();
    canvas->repaint(0);

    startTimer(TIMER_INTERVALL);
    showedSF= false;
  }
  else {
KDEBUG(KDEBUG_WARN, 3000, "Warning event received when inactive (ignoring)\n");
  }
}
Esempio n. 28
0
File: main.C Progetto: 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;
  }
}
Esempio n. 29
0
void AnalogClock::paintEvent( QPaintEvent * )	// paint clock
{
    if ( !isVisible() )				// is is invisible
	return;
    time = QTime::currentTime();		// save current time

    QPointArray pts;
    QPainter paint( this );
    paint.setBrush( foregroundColor() );	// fill with foreground color

    QPoint cp = rect().center();		// widget center point
    int d = QMIN(width(),height());		// we want a circular clock

    QWMatrix matrix;				// setup transformation matrix
    matrix.translate( cp.x(), cp.y() );		// origin at widget center
    matrix.scale( d/1000.0F, d/1000.0F );	// scale coordinate system

    float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
    matrix.rotate( h_angle );			// rotate to draw hour hand
    paint.setWorldMatrix( matrix );
    pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
    paint.drawPolygon( pts );			// draw hour hand
    matrix.rotate( -h_angle );			// rotate back to zero

    float m_angle = (time.minute()-15)*6;
    matrix.rotate( m_angle );			// rotate to draw minute hand
    paint.setWorldMatrix( matrix );
    pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
    paint.drawPolygon( pts );			// draw minute hand
    matrix.rotate( -m_angle );			// rotate back to zero

    for ( int i=0; i<12; i++ ) {		// draw hour lines
	paint.setWorldMatrix( matrix );
	paint.drawLine( 450,0, 500,0 );
	matrix.rotate( 30 );
    }
}
Esempio n. 30
0
void KdmClock::paintEvent( QPaintEvent * )
{
	if (!isVisible())
		return;

	QPainter p( this );
	drawFrame( &p );

	QPixmap pm( contentsRect().size() );
	QPainter paint;
	paint.begin( &pm );
	paint.fillRect( contentsRect(), mBackgroundBrush );

	// get current time
	QTime time = QTime::currentTime();

/*
	if (mDigital) {
		QString buf;
		if (mSecond)
			buf.sprintf( "%02d:%02d:%02d", time.hour(), time.minute(),
			             time.second() );
		else
			buf.sprintf( "%02d:%02d", time.hour(), time.minute() );
		mFont.setPointSize( QMIN( (int)(width()/buf.length()*1.5),height() ) );
		paint.setFont( mFont );
		paint.setPen( backgroundColor() );
		paint.drawText( contentsRect(),AlignHCenter|AlignVCenter, buf,-1,0,0 );
	} else {
*/
		QPointArray pts;
		QPoint cp = contentsRect().center() - QPoint( 2,2 );
		int d = QMIN( contentsRect().width()-15,contentsRect().height()-15 );
		paint.setPen( foregroundColor() );
		paint.setBrush( foregroundColor() );

		QWMatrix matrix;
		matrix.translate( cp.x(), cp.y() );
		matrix.scale( d/1000.0F, d/1000.0F );

		// Hour
		float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
		matrix.rotate( h_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
		paint.drawPolygon( pts );
		matrix.rotate( -h_angle );

		// Minute
		float m_angle = (time.minute()-15)*6;
		matrix.rotate( m_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
		paint.drawPolygon( pts );
		matrix.rotate( -m_angle );

		// Second
		float s_angle = (time.second()-15)*6;
		matrix.rotate( s_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4,0,0,0,0,400,0,0,0 );
		if (mSecond)
			paint.drawPolygon( pts );
		matrix.rotate( -s_angle );

		// quadrante
		for (int i=0 ; i < 60 ; i++) {
			paint.setWorldMatrix( matrix );
			if ((i % 5) == 0)
				paint.drawLine( 450,0, 500,0 ); // draw hour lines
			else
				paint.drawPoint( 480,0 ); // draw second lines
			matrix.rotate( 6 );
		}

//	} // if (mDigital)
	paint.end();

	// flicker free code by Remi Guyomarch <*****@*****.**>
	bitBlt( this, contentsRect().topLeft(), &pm );
}