void TestRender::renderToImage() { int py=0; int ew = part->view()->viewport()->width(); int eh = part->view()->viewport()->height(); QPixmap paintBuffer(800,600); while (py < eh) { QPainter* tp = new QPainter; tp->begin( &paintBuffer ); int ph = eh-py<PAINT_BUFFER_HEIGHT ? eh-py : PAINT_BUFFER_HEIGHT; tp->fillRect(0, py, ew, ph, palette().active().brush(QColorGroup::Background)); part->docImpl()->renderer()->print(tp, 0, py, ew, ph, 0, 0); tp->end(); delete tp; py += PAINT_BUFFER_HEIGHT; } if (!paintBuffer.save(destDir+"/"+filenames.at(fileno)+".png","PNG")) *logStream << "Error writing to file "+destDir+"/"+filenames.at(fileno)+".png" << endl; }
/*! \brief Repaint the knob */ void QwtKnob::paintEvent(QPaintEvent *e) { const QRect &ur = e->rect(); if ( ur.isValid() ) { QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter(), ur); } }
/*! \brief paintEvent */ void QwtScaleWidget::paintEvent(QPaintEvent *e) { const QRect &ur = e->rect(); if ( ur.isValid() ) { #if QT_VERSION < 0x040000 QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter()); #else QPainter painter(this); draw(&painter); #endif } }
/*! Qt paint event \param event Paint event */ void QwtSlider::paintEvent(QPaintEvent *event) { const QRect &ur = event->rect(); if ( ur.isValid() ) { #if QT_VERSION < 0x040000 QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter(), ur); #else QPainter painter(this); draw(&painter, ur); #endif } }
//! Qt paint event. void QwtThermo::paintEvent(QPaintEvent *e) { // Use double-buffering const QRect &ur = e->rect(); if ( ur.isValid() ) { #if QT_VERSION < 0x040000 QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter(), ur); #else QPainter painter(this); draw(&painter, ur); #endif } }
/*! Repaint the knob \param e Paint event */ void QwtKnob::paintEvent(QPaintEvent *e) { const QRect &ur = e->rect(); if ( ur.isValid() ) { #if QT_VERSION < 0x040000 QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter(), ur); #else QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); draw(&painter, ur); #endif } }
//! Repaint the dial void QwtDial::paintEvent(QPaintEvent *e) { const QRect &ur = e->rect(); if ( ur.isValid() ) { QwtPaintBuffer paintBuffer(this, ur); QPainter *painter = paintBuffer.painter(); drawContents(painter); drawFrame(painter); if ( hasFocus() ) drawFocusIndicator(painter); } }
void QwtPlotCanvas::drawCanvas(QPainter *painter) { if ( !contentsRect().isValid() ) return; QRect clipRect = contentsRect(); if ( !cacheMode() || !QwtPaintBuffer::isEnabled() ) { // If we don´t need the paint buffer as cache we can // use the clip for painting to the buffer too. if ( painter && !painter->clipRegion().isNull() ) clipRect = painter->clipRegion().boundingRect(); } QwtPaintBuffer paintBuffer(this, clipRect, painter); ((QwtPlot *)parent())->drawCanvas(paintBuffer.painter()); if ( cacheMode() ) { if ( d_cache == NULL ) { d_cache = new QPixmap(contentsRect().size()); #if QT_VERSION >= 300 #ifdef Q_WS_X11 if ( d_cache->x11Screen() != x11Screen() ) d_cache->x11SetScreen(x11Screen()); #endif #endif } else d_cache->resize(contentsRect().size()); if ( QwtPaintBuffer::isEnabled() ) *d_cache = paintBuffer.buffer(); else { d_cache->fill(this, 0, 0); QPainter cachePainter(d_cache); cachePainter.translate(-contentsRect().x(), -contentsRect().y()); ((QwtPlot *)parent())->drawCanvas(&cachePainter); } } }
// ============================================================================ // DrawBox::draw() // convert particles from 3D space to 2D screen coordinates // compute blending values for particles and texture void DrawBox::draw( GLBox * glbox, const ParticlesData * part_data, const ParticlesSelectVector * _psv, const GlobalOptions * _store_options, QString shot_name) { const double * mProj = glbox->getProjMatrix(); double * mMod = const_cast<double*> (glbox->getModelMatrix()); // get data pointers viewport = glbox->getViewPort(); store_options = _store_options; psv = _psv; #define MP(row,col) mProj[col*4+row] #define MM(row,col) mMod[col*4+row] // get windows size width = viewport[2]; height= viewport[3]; // set windows size setGeometry(viewport[0],viewport[1],viewport[2],viewport[3]); //QPainter paint(this); //paint.eraseRect(viewport[0],viewport[1],viewport[2],viewport[3]); clearBuffer(); if (psv->size()) { // Zoom is located in ModelView matrix at coordinates MM(2,3) // loop on all object for (int i=0; i< (int ) psv->size(); i++ ) { // loop on all visible object selected particles //std::cerr << "----------\n"; if ((*psv)[i].vps->is_visible ) { for (int j = 0; j < (*psv)[i].vps->ni_index; j ++) { int jndex= (*psv)[i].vps->index_tab[j]; float x=part_data->pos[jndex*3 ], y=part_data->pos[jndex*3+1], z=part_data->pos[jndex*3+2], w=1; // do the product Mmodel X point = mxyzw float myzw0 = MM(0,1)*y + MM(0,2)*z + MM(0,3)*w; float mx = MM(0,0)*x + myzw0; float mx1= mx + store_options->texture_size/2.; // move X from half a texture float myzw1 = MM(1,1)*y + MM(1,2)*z + MM(1,3)*w; float my = MM(1,0)*x + myzw1; float MmzG = MM(2,1)*y + MM(2,2)*z; float Mmz = MM(2,0)*x + MmzG; float mz = Mmz + MM(2,3)*w; float mwG= MM(3,1)*y + MM(3,2)*z + MM(3,3)*w; float mw = MM(3,0)*x + mwG; // do the product Mproj X mxyzw = pxyzw float Ppx = MP(0,0)*mx + MP(0,1)*my + MP(0,3)*mw; float px = Ppx + MP(0,2)*mz; float px1 = MP(0,0)*mx1 + MP(0,1)*my + MP(0,3)*mw + MP(0,2)*mz; float Ppy= MP(1,0)*mx + MP(1,1)*my + MP(1,3)*mw; float py = Ppy + MP(1,2)*mz; float Ppz= MP(2,0)*mx + MP(2,1)*my + MP(2,3)*mw; float pz = Ppz + MP(2,2)*mz; float Ppw= MP(3,0)*mx + MP(3,1)*my + MP(3,3)*mw; float pw = Ppw + MP(3,2)*mz; float pw1 = MP(3,0)*mx1 + MP(3,1)*my + MP(3,3)*mw + MP(3,2)*mz; // normalyze //std::cerr << px << " " << py << " " << pz << "\n"; px /= pw; px1/= pw1; py /= pw; pz /= pw; //std::cerr << px << " " << py << " " << pz << "\n"; // compute screen coordinates float winx =viewport[0] + (1 + px) * viewport[2] / 2; float winx1=viewport[0] + (1 + px1) * viewport[2] / 2; float winy =viewport[1] + (1 + py) * viewport[3] / 2; // paint particles //paint.setPen(red); //paint.drawPoint((int) (winx), viewport[3]-(int) (winy)); #define MMAX(A,B) ((A)>(B)?(A):(B)) #define MMIN(A,B) ((A)<(B)?(A):(B)) //if (winx >= 0. && winy >= 0 && winx < 1024 && winy < 1024) { if (winx >= 0. && winy >= 0 && winx < width && winy < height && pz<1.0) { float size_texture = (int) fabs(winx1-winx); //std::cerr << "x=" << winx << " x1=" << winx1 << " size="<<size_texture<< "\n"; //color_rgba[(int) (winx)][(int) (winy)].blend(psv[i].vps->col,(float) (alpha)/255.); if (store_options->show_part) { //color_rgba[(int) (winx)][viewport[3]-1-(int) (winy)].blend((*psv)[i].vps->col, //(float) (store_options->particles_alpha)/255.); filterPoint( winx,winy,(*psv)[i].vps->col,(float) (store_options->particles_alpha)/255.); } //paint.drawPoint((int) (winx), (int) (winy)); if (store_options->show_poly) { float s4 = size_texture*4.; float ratio_texture = s4 - floor(s4); float ceil_texture = ceil(s4); texture->draw(this,psv,i,winx,winy,(int)(ceil_texture), ratio_texture); } } } } } } paintBuffer(shot_name); }