void PanelRadar::paintEvent(QPaintEvent* event) { const qreal scale0 = 0.14644660940672623779957781894758; const qreal scale1 = (1.0 - scale0); PanelWidget::paintEvent(event); QPainter p; p.begin(this); setMargins(&p); p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHint(QPainter::TextAntialiasing, true); QPen pen = p.pen(); pen.setWidth(1); p.setPen(QColor("black")); QPainterPath path; qreal rx = p.device()->width(); qreal ry = p.device()->height(); QPointF point(0.5 * rx, 0.5 * ry); path.addEllipse(point, 0.50 * rx, 0.50 * ry); p.fillPath(path, QColor("white")); path.addEllipse(point, 0.25 * rx, 0.25 * ry); p.drawPath(path); p.drawLine(0, 0.5 * ry, rx, 0.5 * ry); p.drawLine(0.5 * rx, 0, 0.5 * rx, ry); p.drawLine(rx * scale0 + 1, ry * scale0 + 1, rx * scale1 - 1, ry * scale1 - 1); p.drawLine(rx * scale0 + 1, ry * scale1 - 1, rx * scale1 - 1, ry * scale0 + 1); drawItems(&p); p.end(); }
void KoPictureEps::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode) { if ( !width || !height ) return; QSize screenSize( width, height ); //kdDebug() << "KoPictureEps::draw screenSize=" << screenSize.width() << "x" << screenSize.height() << endl; QPaintDeviceMetrics metrics (painter.device()); kdDebug(30003) << "Metrics: X: " << metrics.logicalDpiX() << " x Y: " << metrics.logicalDpiX() << " (in KoPictureEps::draw)" << endl; if ( painter.device()->isExtDev() ) // Is it an external device (i.e. printer) { kdDebug(30003) << "Drawing for a printer (in KoPictureEps::draw)" << endl; // For printing, always re-sample the image, as a printer has never the same resolution than a display. QImage image( scaleWithGhostScript( screenSize, metrics.logicalDpiX(), metrics.logicalDpiY() ) ); // sx,sy,sw,sh is meant to be used as a cliprect on the pixmap, but drawImage // translates it to the (x,y) point -> we need (x+sx, y+sy). painter.drawImage( x + sx, y + sy, image, sx, sy, sw, sh ); } else // No, it is simply a display { scaleAndCreatePixmap(screenSize, fastMode, metrics.logicalDpiX(), metrics.logicalDpiY() ); // sx,sy,sw,sh is meant to be used as a cliprect on the pixmap, but drawPixmap // translates it to the (x,y) point -> we need (x+sx, y+sy). painter.drawPixmap( x + sx, y + sy, m_cachedPixmap, sx, sy, sw, sh ); } }
void paint(QPainter &painter){ painter.setRenderHint(QPainter::Antialiasing,true); const T w=painter.device()->width(); const T h=painter.device()->height(); QPen base(QBrush(Qt::NoBrush),2); QPen brown(base); brown.setWidthF(0.01); brown.setStyle(Qt::SolidLine); brown.setColor(QColor("brown")); QPen green(base); green.setWidthF(0.04); green.setColor(QColor("green")); QPen purple(base); purple.setWidthF(0.01); purple.setColor(QColor("purple").darker()); painter.translate(w/2,h/2); qreal s=qMin(w,h); painter.scale(s,s); T step=0.02; T gx=cx/step; gx-=floor(gx); gx*=-step; T gy=cy/step; gy-=floor(gy); gy*=-step; painter.setPen(brown); for(T y=gy-h;y<h;y+=step){ painter.drawLine(QPointF(0,y-1),QPointF(w,y+1)); } for(T x=gx-w;x<w;x+=step){ painter.drawLine(QPointF(x-1,0),QPointF(x+1,h)); } if(singleLimbMode){ limbs[0]->paint(painter); } else{ for(quint32 i=0;i<limbCount;++i){ limbs[i]->paint(painter); } const T r=0.01; QPointF cob(cobx,coby); painter.setPen(green); painter.drawEllipse(cob,r,r); QPointF cog(cogx,cogy); painter.setPen(purple); painter.drawEllipse(cog,r,r); } }
void ImageDisplayer::drawImage(QPainter &painter) { if(img.data != NULL) { //QRectF target(0.0f, 0.0f, this->width()*2*(1+zoomFactor/10.0), this->height()*2*(1+zoomFactor/10.0)); //cout << painter.device()->width() << endl; //cout << painter.device()->height() << endl; QRectF source(0.0f, 0.0f, painter.device()->width(), painter.device()->height()); QRectF target(source); //painter.drawImage(target, temImage, source); painter.drawImage(source, qimg); } }
extern "C" VIS_SPECTSHARED_EXPORT void Draw(QPainter &paint, float *fft ){ paint.fillRect(0, 0, paint.device()->width(), paint.device()->height(), QColor(0x00, 0x00, 0x00)); paint.setPen(QColor(0x00, 0xff, 0x00)); float c = 0; int h = 0; int j1 = 0; for(int i = 0, j = 0; i < 1024; i+=8, j++){ for(int l = 0; l < 8; l+=2){ c += fft[i+l]; } c = c / 4; //вычисление среднего из 4х "соседних частот" h = (int)(paint.device()->height() - (c * 10 * paint.device()->height() * 3)); if(h < (paint.device()->height() / 2)){ h = (int)((paint.device()->height() / 2) + (h / 10)); //"урезание" } if(h <= pik[j]){ pik[j] = h - 2; } j1 = j * 2; paint.drawLine(j1, paint.device()->height(), j1, h); j1++; paint.drawLine(j1, paint.device()->height(), j1, h); c = 0; } for(int k = 0; k < 128; k++){ pik[k]+=2; } paint.setPen(QColor(0xff, 0x00, 0x00)); for(int k = 0; k < 128; k++){ paint.drawLine(k * 2 + 1, pik[k], k * 2 + 2, pik[k+1]); } }
//void Object::paintImage(QPainter &painter, int frameNumber, const QRectF &source, const QRectF &target, bool background, qreal curveOpacity, bool antialiasing, bool niceGradients) { void Object::paintImage(QPainter& painter, int frameNumber, bool background, qreal curveOpacity, bool antialiasing, int gradients) { painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); //painter.setWorldMatrix(matrix); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); // paints the background if (background) { painter.setPen(Qt::NoPen); painter.setBrush(Qt::white); painter.setWorldMatrixEnabled(false); painter.drawRect( QRect(0,0, painter.device()->width(), painter.device()->height() ) ); painter.setWorldMatrixEnabled(true); } for(int i=0; i < getLayerCount(); i++) { Layer* layer = getLayer(i); if (layer->visible) { painter.setOpacity(1.0); // paints the bitmap images if (layer->type == Layer::BITMAP) { LayerBitmap* layerBitmap = (LayerBitmap*)layer; /*BitmapImage* bitmapImage = layerBitmap->getLastBitmapImageAtFrame(frameNumber, 0); // TO BE FIXED if (bitmapImage != NULL) { if ( mirror) { painter.drawImage(target, (*(bitmapImage->image)).mirrored(true, false), source); } else { painter.drawImage(target, *(bitmapImage->image), source); } }*/ layerBitmap->getLastBitmapImageAtFrame(frameNumber, 0)->paintImage(painter); } // paints the vector images if (layer->type == Layer::VECTOR) { LayerVector* layerVector = (LayerVector*)layer; layerVector->getLastVectorImageAtFrame(frameNumber, 0)->paintImage(painter, false, false, curveOpacity, antialiasing, gradients); } } } }
/*! * \en * Print browser content. * \_en * \ru * Печатает содержимое браузера. * \_ru */ void aReportBrowser::print() { QPrinter printer; QPainter p; if (!printer.setup()) return; if ( p.begin( &printer ) ){ QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QSimpleRichText richText( textBrowser->text(), QFont(), textBrowser->context(), textBrowser->styleSheet(), textBrowser->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() >= richText.height() ) break; printer.newPage(); page++; } while (TRUE); } }
void GraphicsContext::beginTransparencyLayer(float opacity) { if (paintingDisabled()) return; int x, y, w, h; x = y = 0; QPainter *p = m_data->p(); const QPaintDevice *device = p->device(); w = device->width(); h = device->height(); QRectF clip = p->clipPath().boundingRect(); bool ok; QTransform transform = p->transform().inverted(&ok); if (ok) { QRectF deviceClip = transform.mapRect(clip); x = int(qBound(qreal(0), deviceClip.x(), (qreal)w)); y = int(qBound(qreal(0), deviceClip.y(), (qreal)h)); w = int(qBound(qreal(0), deviceClip.width(), (qreal)w) + 2); h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2); } TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h)); layer->opacity = opacity; m_data->layers.push(layer); }
void PictureImage::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode) { //kDebug(30508) <<"KoImage::draw currentSize:" << currentSize.width() <<"x" << currentSize.height(); if (!width || !height) return; QSize origSize = getOriginalSize(); const bool scaleImage = dynamic_cast<QPrinter*>(painter.device()) != 0 // we are printing && ((width <= origSize.width()) || (height <= origSize.height())); if (scaleImage) { // use full resolution of image qreal xScale = qreal(width) / qreal(origSize.width()); qreal yScale = qreal(height) / qreal(origSize.height()); painter.save(); painter.translate(x, y); painter.scale(xScale, yScale); // Note that sx, sy, sw and sh are unused in this case. Not a problem, since it's about printing. // Note 2: we do not cache the QPixmap. As we are printing, the next time we will probably // need again the screen version. painter.drawImage(0, 0, m_originalImage); painter.restore(); } else { QSize screenSize(width, height); //kDebug(30508) <<"PictureImage::draw screenSize=" << screenSize.width() <<"x" << screenSize.height(); scaleAndCreatePixmap(screenSize, fastMode); // sx,sy,sw,sh is meant to be used as a cliprect on the pixmap, but drawPixmap // translates it to the (x,y) point -> we need (x+sx, y+sy). painter.drawPixmap(x + sx, y + sy, m_cachedPixmap, sx, sy, sw, sh); } }
void PaintHistoryInScreen( QPainter& painter, const OverlayHistoryWindow& wnd, const QPoint& pos ) { int padding = 10; QRect rect( pos.x() + 20, pos.y(), wnd.Width(), wnd.Height() ); rect.translate( -qMax( rect.right() - painter.device()->width() + padding, 0 ), -qMax( rect.bottom() - painter.device()->height() + padding, 0 ) ); // fit to window wnd.Paint( painter, rect.x(), rect.y() ); }
void Plot2D::reCalcGui(QPainter &dc) { dm_dirty = false; // calc the off set stuff dm_offset.rx() = border*2; dm_offset.ry() = border; dm_area = QSize(dc.device()->width(), dc.device()->height()); dm_area.rwidth() += -3 * border; dm_area.rheight() += -2 * border; // calc the min max bool clean_slate = true; for (int i=0; i<dm_data.size(); ++i) { double d; if (dm_data[i].xvalues.empty()) continue; scopira::basekit::min(dm_data[i].xvalues, d); if (clean_slate || d < dm_data_xmin) dm_data_xmin = d; scopira::basekit::max(dm_data[i].xvalues, d); if (clean_slate || d > dm_data_xmax) dm_data_xmax = d; scopira::basekit::min(dm_data[i].yvalues, d); if (clean_slate || d < dm_data_ymin) dm_data_ymin = d; scopira::basekit::max(dm_data[i].yvalues, d); if (clean_slate || d > dm_data_ymax) dm_data_ymax = d; clean_slate = false; } dm_emptydata = clean_slate || dm_data_xmin >= dm_data_xmax || dm_data_ymin >= dm_data_ymax; if (dm_xrange_auto) { dm_view_xmin = dm_data_xmin; dm_view_xmax = dm_data_xmax; } if (dm_yrange_auto) { dm_view_ymin = dm_data_ymin; dm_view_ymax = dm_data_ymax; } }
void Object::paintImage( QPainter& painter, int frameNumber, bool background, bool antialiasing ) { painter.setRenderHint( QPainter::Antialiasing, true ); painter.setRenderHint( QPainter::SmoothPixmapTransform, true ); //painter.setTransform(matrix); painter.setCompositionMode( QPainter::CompositionMode_SourceOver ); // paints the background if ( background ) { painter.setPen( Qt::NoPen ); painter.setBrush( Qt::white ); painter.setWorldMatrixEnabled( false ); painter.drawRect( QRect( 0, 0, painter.device()->width(), painter.device()->height() ) ); painter.setWorldMatrixEnabled( true ); } for ( int i = 0; i < getLayerCount(); i++ ) { Layer* layer = getLayer( i ); if ( layer->visible ) { painter.setOpacity( 1.0 ); // paints the bitmap images if ( layer->type() == Layer::BITMAP ) { LayerBitmap* layerBitmap = ( LayerBitmap* )layer; layerBitmap->getLastBitmapImageAtFrame( frameNumber, 0 )->paintImage( painter ); } // paints the vector images if ( layer->type() == Layer::VECTOR ) { LayerVector* layerVector = ( LayerVector* )layer; layerVector->getLastVectorImageAtFrame( frameNumber, 0 )->paintImage( painter, false, false, antialiasing ); } } } }
void Stickman::render(QPainter &painter) const { // Draw the stickman at the bottom of the screen int yPos = painter.device()->height() - getHeight(); // Find how much to scale the sprite image by to match the bounding box of the stickman // If x velocity is negative, we flip the image as well. float scaleX = getWidth() / getSprite().width() * (m_xVelocity < 0 ? -1 : 1); float scaleY = getHeight() / getSprite().height(); painter.drawPixmap(m_xOffset, yPos, getSprite().transformed(QTransform().scale(scaleX, scaleY))); }
void SurfaceImpl::Init(SurfaceID sid, WindowID) { Release(); // This method, and the SurfaceID type, is only used when printing. As it // is actually a void * we pass (when using SCI_FORMATRANGE) a pointer to a // QPainter rather than a pointer to a SurfaceImpl as might be expected. QPainter *p = reinterpret_cast<QPainter *>(sid); pd = p->device(); painter = p; }
static void draw_measure(const vmd_measure_t *measure, void *_painter) { QPainter *painter = static_cast<QPainter *>(_painter); WPiano *piano = static_cast<WPiano *>(painter->device()); vmd_time_t cell_size = piano->grid_size() > 0 ? piano->grid_size() : measure->part_size; painter->setPen(piano->palette().windowText().color()); for (vmd_time_t t = measure->beg; t < measure->end; t += cell_size) { int x = piano->time2x(t); painter->drawLine(x, 0, x, piano->height()); painter->setPen(piano->palette().mid().color()); } }
static void drawVertCmRuler(QPainter &painter, int x, int y1, int y2) { painter.drawLine(x, y1, x, y2); const int dpI = painter.device()->logicalDpiY(); const int dpCm = qRound(double(dpI) / 2.54); const int h = dpCm / 2; const QFontMetrics fm(painter.font()); for (int cm = 0, y = y1; y < y2; y += dpCm, ++cm) { painter.drawLine(x, y, x + h, y); if (cm) { const QString n = QString::number(cm); const QRect br = fm.boundingRect(n); painter.drawText(x + h + 10, y + br.height() / 2, n); } } }
static void drawHorizCmRuler(QPainter &painter, int x1, int x2, int y) { painter.drawLine(x1, y, x2, y); const int dpI = painter.device()->logicalDpiX(); const int dpCm = qRound(double(dpI) / 2.54); const int h = dpCm / 2; const QFontMetrics fm(painter.font()); for (int cm = 0, x = x1; x < x2; x += dpCm, ++cm) { painter.drawLine(x, y, x, y - h); if (cm) { const QString n = QString::number(cm); const QRect br = fm.boundingRect(n); painter.drawText(x - br.width() / 2, y - h - 10, n); } } }
void SeafileTabBar::paintEvent(QPaintEvent *event) { QStylePainter p(this); QPainter painter; painter.begin(this); for (int index = 0, total = count(); index < total; index++) { const QRect rect = tabRect(index); // QStyleOptionTabV3 tab; // initStyleOption(&tab, index); // Draw the tab background painter.fillRect(rect, QColor(kTabsBackgroundColor)); // Draw the tab icon in the center QPoint top_left; top_left.setX(rect.topLeft().x() + ((rect.width() - kTabIconSize) / 2)); top_left.setY(rect.topLeft().y() + ((rect.height() - kTabIconSize) / 2)); QIcon icon(currentIndex() == index ? highlighted_icons_[index] : icons_[index]); QRect icon_rect(top_left, QSize(kTabIconSize, kTabIconSize)); // get the device pixel radio from current painter device int scale_factor = 1; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) scale_factor = painter.device()->devicePixelRatio(); #endif // QT5 QPixmap icon_pixmap(icon.pixmap(QSize(kTabIconSize, kTabIconSize) * scale_factor)); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) icon_pixmap.setDevicePixelRatio(scale_factor); #endif // QT5 painter.drawPixmap(icon_rect, icon_pixmap); int indicator_width = count() * rect.width() / 8; // Draw the selected tab indicator if (currentIndex() == index) { top_left.setX(rect.bottomLeft().x() + (rect.width() / 2) - (indicator_width / 2)); top_left.setY(rect.bottomLeft().y() - kSelectedTabBorderBottomWidth + 1); QRect border_bottom_rect(top_left, QSize(indicator_width, kSelectedTabBorderBottomWidth)); painter.fillRect(border_bottom_rect, QColor(kSelectedTabBorderBottomColor)); } } }
void ApplicationWindow::print() { #ifndef QT_NO_PRINTER printer->setFullPage( TRUE ); if ( printer->setup(this) ) { // printer dialog statusBar()->message( "Printing..." ); QPainter p; if( !p.begin( printer ) ) { // paint on printer statusBar()->message( "Printing aborted", 2000 ); return; } QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin ); QSimpleRichText richText( QStyleSheet::convertFromPlainText(e->text()), QFont(), e->context(), e->styleSheet(), e->mimeSourceFactory(), body.height() ); richText.setWidth( &p, body.width() ); QRect view( body ); int page = 1; do { richText.draw( &p, body.left(), body.top(), view, colorGroup() ); view.moveBy( 0, body.height() ); p.translate( 0 , -body.height() ); p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ), view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) ); if ( view.top() >= richText.height() ) break; printer->newPage(); page++; } while (TRUE); statusBar()->message( "Printing completed", 2000 ); } else { statusBar()->message( "Printing aborted", 2000 ); } #endif }
/* *Function: Print *Inputs:none *Outputs:none *Returns:none */ void GraphPaneData::Print() { IT_IT("GraphPaneData::Print"); QPrinter prt; prt.setDocName(tr("Pen Trace")); prt.setCreator(tr(SYSTEM_NAME)); prt.setOrientation(QPrinter::Landscape); prt.setOutputFileName("~out.ps"); prt.setOutputToFile(false); // if(prt.setup(this)) { // // Handle the case of no printer being selected // if(!prt.printerName().isEmpty()) { QPainter p; p.begin(&prt); QPaintDeviceMetrics metrics(p.device()); // int dpix = metrics.logicalDpiX() ; // inch border int dpiy = metrics.logicalDpiY() ; // QRect body(dpix, dpiy, metrics.width() - dpix*6, metrics.height() - dpiy*2); TheGraph.Plot(p,body,Qt::white); // QFont font("times", 8); p.setFont(font); // p.drawText( body.left() ,body.top(), Title); // p.end(); // } else { QMessageBox::information(this,tr("Print Graph Error"),tr("No Printer Selected!")); }; }; };
static void * draw_note(vmd_note_t *note, void *_painter) { QPainter *painter = static_cast<QPainter *>(_painter); WPiano *piano = static_cast<WPiano *>(painter->device()); QPen pen; pen.setWidth(level_height - 1); pen.setCapStyle(Qt::FlatCap); if (note->mark) pen.setColor(Qt::blue); painter->setPen(pen); int level = pitch2level(piano->track(), note->pitch); int y = piano->level2y(level); int x1 = piano->time2x(note->on_time); int x2 = piano->time2x(note->off_time); painter->drawLine(x1, y, x2 - 1, y); return NULL; }
/*! Flush the internal pixmap buffer to the device. */ void QwtPaintBuffer::flush() { if ( d_enabled && d_device != 0 && d_rect.isValid()) { // We need a painter to find out if // there is a painter redirection for d_device. QPainter *p; if ( d_devicePainter == 0 ) p = new QPainter(d_device); else p = d_devicePainter; QPaintDevice *device = p->device(); if ( device->isExtDev() ) d_devicePainter->drawPixmap(d_rect.topLeft(), d_pixBuffer); else bitBlt(device, d_rect.topLeft(), &d_pixBuffer ); if ( d_devicePainter == 0 ) delete p; } }
void TopLevel::printIt( KPrinter &printer, QPainter &painter ) { QPaintDeviceMetrics dm(painter.device()); QApplication::setOverrideCursor( waitCursor ); kapp->processEvents(); const bool fullpage = printer.option(APP_KFAX_SCALE_FULLPAGE) == "true"; const bool center_h = printer.option(APP_KFAX_CENTER_HORZ) == "true"; const bool center_v = printer.option(APP_KFAX_CENTER_VERT) == "true"; int currentpage = 0; bool first_page_printed = false; struct pagenode *pn; for(pn = firstpage; pn; pn = pn->next) { ++currentpage; // should this page be printed ? if (printer.pageList().findIndex(currentpage) < 0) continue; XImage *Image = Pimage(pn); if (!Image) continue; // byte-swapping the image QByteArray bytes( Image->height*Image->bytes_per_line ); for (int y=Image->height-1; y>=0; --y) { Q_UINT32 offset = y*Image->bytes_per_line; Q_UINT32 *source = (Q_UINT32 *) (Image->data + offset); Q_UINT32 *dest = (Q_UINT32 *) (bytes.data() + offset); for (int x=(Image->bytes_per_line/4)-1; x>=0; --x) { Q_UINT32 dv = 0, sv = *source; for (int bit=32; bit>0; --bit) { dv <<= 1; dv |= sv&1; sv >>= 1; } *dest = dv; ++dest; ++source; } } QImage image( (uchar *)bytes.data(), Image->bytes_per_line*8, Image->height, 1, NULL, 2, QImage::LittleEndian); if (first_page_printed) printer.newPage(); first_page_printed = true; const QSize printersize( dm.width(), dm.height() ); kdDebug() << "Printersize = " << printersize << endl; // print Image in original size if possible, else scale it. const QSize size( // logical size of the image Image->width * dm.logicalDpiX() / pn->dpiX, Image->height * dm.logicalDpiY() / pn->dpiY ); kdDebug() << "Org image size = " << Image->width << "x" << Image->height << " logical picture res = " << pn->dpiX << "x" << pn->dpiY << endl; kdDebug() << "New image size = " << size << " logical printer res = " << dm.logicalDpiX() << "x" << dm.logicalDpiY() << endl; uint top, left, bottom, right; if (fullpage) top = left = bottom = right = 0; else printer.margins( &top, &left, &bottom, &right ); kdDebug() << "Margins = " << top << " " << left << " " << bottom << " " << right << endl; const QSize maxSize( printersize.width()-left-right, printersize.height()-top-bottom ); QSize scaledImageSize = size; if (size.width() > maxSize.width() || size.height() > maxSize.height() ) { // Image does not fit - scale it and print centered scaledImageSize.scale( maxSize, QSize::ScaleMin ); kdDebug() << "Image does not fit - scaling to " << maxSize << endl; } else { // Image does fit - print it in original size, but centered scaledImageSize.scale( size, QSize::ScaleMin ); kdDebug() << "Image does fit - scaling to " << size << endl; } kdDebug() << "Final image size " << scaledImageSize << endl; int x,y; if (center_h) x = (maxSize.width()-scaledImageSize.width())/2 + left; else x = left; if (center_v) y = (maxSize.height()-scaledImageSize.height())/2 + top; else y = top; painter.drawImage( QRect(x,y,scaledImageSize.width(), scaledImageSize.height()), image ); } QApplication::restoreOverrideCursor(); }
void PluginView::paint(GraphicsContext* context, const IntRect& rect) { if (!m_isStarted) { paintMissingPluginIcon(context, rect); return; } if (context->paintingDisabled()) return; setNPWindowIfNeeded(); if (m_isWindowed || !m_drawable) return; const bool syncX = m_pluginDisplay && m_pluginDisplay != QX11Info::display(); QPainter* painter = context->platformContext(); IntRect exposedRect(rect); exposedRect.intersect(frameRect()); exposedRect.move(-frameRect().x(), -frameRect().y()); QPixmap qtDrawable = QPixmap::fromX11Pixmap(m_drawable, QPixmap::ExplicitlyShared); const int drawableDepth = ((NPSetWindowCallbackStruct*)m_npWindow.ws_info)->depth; ASSERT(drawableDepth == qtDrawable.depth()); // When printing, Qt uses a QPicture to capture the output in preview mode. The // QPicture holds a reference to the X Pixmap. As a result, the print preview would // update itself when the X Pixmap changes. To prevent this, we create a copy. if (m_element->document()->printing()) qtDrawable = qtDrawable.copy(); if (m_isTransparent && drawableDepth != 32) { // Attempt content propagation for drawable with no alpha by copying over from the backing store QPoint offset; QPaintDevice* backingStoreDevice = QPainter::redirected(painter->device(), &offset); offset = -offset; // negating the offset gives us the offset of the view within the backing store pixmap const bool hasValidBackingStore = backingStoreDevice && backingStoreDevice->devType() == QInternal::Pixmap; QPixmap* backingStorePixmap = static_cast<QPixmap*>(backingStoreDevice); // We cannot grab contents from the backing store when painting on QGraphicsView items // (because backing store contents are already transformed). What we really mean to do // here is to check if we are painting on QWebView, but let's be a little permissive :) QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient(); const bool backingStoreHasUntransformedContents = client && qobject_cast<QWidget*>(client->pluginParent()); if (hasValidBackingStore && backingStorePixmap->depth() == drawableDepth && backingStoreHasUntransformedContents) { GC gc = XDefaultGC(QX11Info::display(), QX11Info::appScreen()); XCopyArea(QX11Info::display(), backingStorePixmap->handle(), m_drawable, gc, offset.x() + m_windowRect.x() + exposedRect.x(), offset.y() + m_windowRect.y() + exposedRect.y(), exposedRect.width(), exposedRect.height(), exposedRect.x(), exposedRect.y()); } else { // no backing store, clean the pixmap because the plugin thinks its transparent QPainter painter(&qtDrawable); painter.fillRect(exposedRect, Qt::white); } if (syncX) QApplication::syncX(); } XEvent xevent; memset(&xevent, 0, sizeof(XEvent)); XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose; exposeEvent.type = GraphicsExpose; exposeEvent.display = QX11Info::display(); exposeEvent.drawable = qtDrawable.handle(); exposeEvent.x = exposedRect.x(); exposeEvent.y = exposedRect.y(); exposeEvent.width = exposedRect.x() + exposedRect.width(); // flash bug? it thinks width is the right in transparent mode exposeEvent.height = exposedRect.y() + exposedRect.height(); // flash bug? it thinks height is the bottom in transparent mode dispatchNPEvent(xevent); if (syncX) XSync(m_pluginDisplay, False); // sync changes by plugin painter->drawPixmap(QPoint(frameRect().x() + exposedRect.x(), frameRect().y() + exposedRect.y()), qtDrawable, exposedRect); }
void Plot2D::drawFrame(QPainter &dc) { LocalPainter p(dc); dc.setBrush(QColor(0xFFFFFF)); dc.drawRect(dm_offset.x(), dm_offset.y(), dm_area.width(), dm_area.height()); int x, y, i, ticknum; int last_font; double axis_min, axis_max, tick_spacing; // draw x axis last_font = -1; ticknum = calcTickMarks(dm_view_xmin, dm_view_xmax, axis_min, axis_max, tick_spacing); for (i=0; i<=ticknum; ++i) { x = xToPixel(axis_min + i*tick_spacing); if (x == -1) continue; y = dm_offset.y()+dm_area.height(); dc.drawLine(x, y, x, y+6); QString label; QTextStream s(&label); s << handleXLabel(axis_min + i*tick_spacing); QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, label); if (last_font == -1 || x-ext.width()/2 > last_font) { dc.drawLine(x, y, x, y+12); // draw a longer line dc.drawText(x-ext.width()/2, y+12+ext.height(), label); last_font = x+ext.width()/2; last_font += 10; // add some buffer space } } // draw y axis last_font = -1; ticknum = calcTickMarks(dm_view_ymin, dm_view_ymax, axis_min, axis_max, tick_spacing); for (i=0; i<=ticknum; ++i) { y = yToPixel(axis_min + i*tick_spacing); if (y == -1) continue; x = dm_offset.x(); dc.drawLine(x, y, x-4, y); QString label; QTextStream s(&label); s << handleYLabel(axis_min + i*tick_spacing); QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, label); if (last_font == -1 || y+ext.height()/2 < last_font) { dc.drawLine(x, y, x-10, y); //draw a longer line dc.drawText(x-10-4-ext.width(), y+ext.height()/2-4, label); last_font = y+ext.height()/2; last_font -= 20; // add some buffer space } } if (!dm_title.isEmpty()) { QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, dm_title); dc.drawText((dc.device()->width()-ext.width())/2, 10, dm_title); } if (!dm_xlabel.isEmpty()) { QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, dm_xlabel); //dc.DrawRotatedText(dm_xlabel, (dm_area.width()-ext.width())/2+dm_offset.x(), dc.device()->height()-20, 0); dc.drawText((dm_area.width()-ext.width())/2+dm_offset.x(), dc.device()->height(), dm_xlabel); } if (!dm_ylabel.isEmpty()) { QSize ext = QFontMetrics(dc.font()).size(Qt::TextSingleLine, dm_ylabel); LocalPainter rotatedcontext(dc); // cuz we'redoing a rotate dc.translate(4+ext.height(), dm_offset.y()+dm_area.height()-(dm_area.height()-ext.width())/2); dc.rotate(-90); //dc.DrawRotatedText(dm_ylabel, 4, dm_offset.y()+dm_area.height()-(dm_area.height()-ext.width())/2, 90); //dc.drawText(4, dm_offset.y()+dm_area.height()-(dm_area.height()-ext.width())/2, dm_ylabel); dc.drawText(0, 0, dm_ylabel); } }
bool QgsVectorLayerRenderer::render() { if ( mGeometryType == QGis::NoGeometry || mGeometryType == QGis::UnknownGeometry ) return true; if ( !mRendererV2 ) { mErrors.append( "No renderer for drawing." ); return false; } // Per feature blending mode if ( mContext.useAdvancedEffects() && mFeatureBlendMode != QPainter::CompositionMode_SourceOver ) { // set the painter to the feature blend mode, so that features drawn // on this layer will interact and blend with each other mContext.painter()->setCompositionMode( mFeatureBlendMode ); } mRendererV2->startRender( mContext, mFields ); QgsFeatureRequest featureRequest = QgsFeatureRequest() .setFilterRect( mContext.extent() ) .setSubsetOfAttributes( mAttrNames, mFields ); // enable the simplification of the geometries (Using the current map2pixel context) before send it to renderer engine. if ( mSimplifyGeometry ) { QPainter* p = mContext.painter(); double dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2; double map2pixelTol = mSimplifyMethod.threshold() * 96.0f / dpi; const QgsMapToPixel& mtp = mContext.mapToPixel(); map2pixelTol *= mtp.mapUnitsPerPixel(); const QgsCoordinateTransform* ct = mContext.coordinateTransform(); // resize the tolerance using the change of size of an 1-BBOX from the source CoordinateSystem to the target CoordinateSystem if ( ct && !(( QgsCoordinateTransform* )ct )->isShortCircuited() ) { try { QgsPoint center = mContext.extent().center(); double rectSize = ct->sourceCrs().geographicFlag() ? 0.0008983 /* ~100/(40075014/360=111319.4833) */ : 100; QgsRectangle sourceRect = QgsRectangle( center.x(), center.y(), center.x() + rectSize, center.y() + rectSize ); QgsRectangle targetRect = ct->transform( sourceRect ); QgsDebugMsg( QString( "Simplify - SourceTransformRect=%1" ).arg( sourceRect.toString( 16 ) ) ); QgsDebugMsg( QString( "Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ) ); if ( !sourceRect.isEmpty() && sourceRect.isFinite() && !targetRect.isEmpty() && targetRect.isFinite() ) { QgsPoint minimumSrcPoint( sourceRect.xMinimum(), sourceRect.yMinimum() ); QgsPoint maximumSrcPoint( sourceRect.xMaximum(), sourceRect.yMaximum() ); QgsPoint minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() ); QgsPoint maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() ); double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) ); double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) ); QgsDebugMsg( QString( "Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ) ); QgsDebugMsg( QString( "Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ) ); if ( targetHypothenuse != 0 ) map2pixelTol *= ( sourceHypothenuse / targetHypothenuse ); } } catch ( QgsCsException &cse ) { QgsMessageLog::logMessage( QObject::tr( "Simplify transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) ); } } QgsSimplifyMethod simplifyMethod; simplifyMethod.setMethodType( QgsSimplifyMethod::OptimizeForRendering ); simplifyMethod.setTolerance( map2pixelTol ); simplifyMethod.setForceLocalOptimization( mSimplifyMethod.forceLocalOptimization() ); featureRequest.setSimplifyMethod( simplifyMethod ); } QgsFeatureIterator fit = mSource->getFeatures( featureRequest ); if (( mRendererV2->capabilities() & QgsFeatureRendererV2::SymbolLevels ) && mRendererV2->usingSymbolLevels() ) drawRendererV2Levels( fit ); else drawRendererV2( fit ); //apply layer transparency for vector layers if ( mContext.useAdvancedEffects() && mLayerTransparency != 0 ) { // a layer transparency has been set, so update the alpha for the flattened layer // by combining it with the layer transparency QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * mLayerTransparency / 100 ) ); // use destination in composition mode to merge source's alpha with destination mContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn ); mContext.painter()->fillRect( 0, 0, mContext.painter()->device()->width(), mContext.painter()->device()->height(), transparentFillColor ); } return true; }
void renderGraph(QPainter & paint, const QRect & rect, ORGraphData & gData, XSqlQuery * query, const QMap<QString, QColor> & _colorMap) { QPaintDeviceMetrics dpm(paint.device()); int dpi = dpm.logicalDpiX(); QFont fnt; tGraph graph(rect); fnt = gData.font; fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize()); graph.setFont(fnt); if(gData.title.string.length() > 0) { graph.setTitle(gData.title.string); if(gData.title.font_defined) { fnt = gData.title.font; fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize()); graph.setTitleFont(&fnt); } } QString lbl_clmn = gData.dataaxis.column; if(lbl_clmn.length() > 0 && gData.dataaxis.font_defined) { fnt = gData.dataaxis.font; fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize()); graph.setDataFont(&fnt); } if(gData.dataaxis.title.string.length() > 0) { graph.setDataLabel(gData.dataaxis.title.string); if(gData.dataaxis.title.font_defined) { fnt = gData.dataaxis.title.font; fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize()); graph.setDataLabelFont(&fnt); } } graph.setAutoMinMax(gData.valueaxis.autominmax); graph.setMinValue(gData.valueaxis.min); graph.setMaxValue(gData.valueaxis.max); if(gData.valueaxis.font_defined) { fnt = gData.valueaxis.font; fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize()); graph.setValueFont(&fnt); } if(gData.valueaxis.title.string.length() > 0) { graph.setValueLabel(gData.valueaxis.title.string); if(gData.valueaxis.title.font_defined) { fnt = gData.valueaxis.title.font; fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize()); graph.setValueLabelFont(&fnt); } } // setup the sets/series unsigned int snum = 0; ORSeriesData * sd = 0; for(snum = 0; snum < gData.series.count(); snum++) { sd = gData.series.at(snum); if(sd) { graph.setSetColor(snum, &_colorMap[sd->color]); graph.setSetStyle(snum, sd->style); } } // populate the data if(query->first()) { do { if(lbl_clmn.length() > 0) { graph.setReferenceLabel(query->at(), query->value(lbl_clmn).toString()); } for(snum = 0; snum < gData.series.count(); snum++) { sd = gData.series.at(snum); if(sd) { graph.setSetValue(query->at(), snum, query->value(sd->column).toDouble()); } } } while(query->next()); } // draw the graph graph.draw(paint); }
void PixmapRenderer::drawPixmap( QPainter& painter, QPixmap const& pixmap) { #if !defined(Q_WS_X11) drawPixmapNoXRender(painter, pixmap); #else QPaintDevice* const dev = painter.device(); QPoint offset; // Both x and y will be either zero or negative. QPaintDevice* const redir_dev = QPainter::redirected(painter.device(), &offset); QPaintDevice* const paint_dev = redir_dev ? redir_dev : dev; #if defined(ENABLE_OPENGL) if (dynamic_cast<QGLWidget*>(paint_dev)) { drawPixmapNoXRender(painter, pixmap); return; } #endif QRect const device_rect( QRect(0, 0, dev->width(), dev->height()).translated(-offset) ); QRectF const src_rect(pixmap.rect()); Display* const dpy = QX11Info::display(); Picture const src_pict = pixmap.x11PictureHandle(); Picture dst_pict = 0; if (QWidget* widget = dynamic_cast<QWidget*>(paint_dev)) { dst_pict = widget->x11PictureHandle(); } else if (QPixmap* pixmap = dynamic_cast<QPixmap*>(paint_dev)) { dst_pict = pixmap->x11PictureHandle(); } if (!dst_pict) { drawPixmapNoXRender(painter, pixmap); return; } // Note that device transform already accounts for offset // within a destination surface. QTransform const src_to_dst(painter.deviceTransform()); QTransform const dst_to_src(src_to_dst.inverted()); QPolygonF const dst_poly(src_to_dst.map(src_rect)); XTransform xform = {{ { XDoubleToFixed(dst_to_src.m11()), XDoubleToFixed(dst_to_src.m21()), XDoubleToFixed(dst_to_src.m31()) }, { XDoubleToFixed(dst_to_src.m12()), XDoubleToFixed(dst_to_src.m22()), XDoubleToFixed(dst_to_src.m32()) }, { XDoubleToFixed(dst_to_src.m13()), XDoubleToFixed(dst_to_src.m23()), XDoubleToFixed(dst_to_src.m33()) } }}; XRenderSetPictureTransform(dpy, src_pict, &xform); char const* filter = "fast"; if (painter.testRenderHint(QPainter::SmoothPixmapTransform)) { filter = "good"; } XRenderSetPictureFilter(dpy, src_pict, filter, 0, 0); QRectF const dst_rect_precise(dst_poly.boundingRect()); QRect const dst_rect_fitting( QPoint( int(ceil(dst_rect_precise.left())), int(ceil(dst_rect_precise.top())) ), QPoint( int(floor(dst_rect_precise.right())) - 1, int(floor(dst_rect_precise.bottom())) - 1 ) ); QRect dst_bounding_rect(device_rect); if (painter.hasClipping()) { QRect const clip_rect( src_to_dst.map(painter.clipPath()).boundingRect().toRect() ); dst_bounding_rect = dst_bounding_rect.intersected(clip_rect); } QRect const dst_rect(dst_rect_fitting.intersect(dst_bounding_rect)); // Note that XRenderComposite() expects destination coordinates // everywhere, even for source picture origin. XRenderComposite( dpy, PictOpSrc, src_pict, 0, dst_pict, dst_rect.left(), dst_rect.top(), 0, 0, dst_rect.left(), dst_rect.top(), dst_rect.width(), dst_rect.height() ); #endif }
void Theme::drawBackground(QPainter& painter) const { painter.fillRect(0, 0, painter.device()->width(), painter.device()->height(), m_pixmap[Background]); }
void Matrix::print() { QPrinter printer; printer.setColorMode (QPrinter::GrayScale); if (printer.setup()) { printer.setFullPage( TRUE ); QPainter p; if ( !p.begin(&printer ) ) return; // paint on printer QPaintDeviceMetrics metrics( p.device() ); int dpiy = metrics.logicalDpiY(); const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins QHeader *hHeader = d_table->horizontalHeader(); QHeader *vHeader = d_table->verticalHeader(); int rows=d_table->numRows(); int cols=d_table->numCols(); int height=margin; int i,vertHeaderWidth=vHeader->width(); int right = margin + vertHeaderWidth; // print header p.setFont(QFont()); QRect br=p.boundingRect(br,Qt::AlignCenter, hHeader->label(0),-1,0); p.drawLine(right,height,right,height+br.height()); QRect tr(br); for (i=0;i<cols;i++) { int w=d_table->columnWidth (i); tr.setTopLeft(QPoint(right,height)); tr.setWidth(w); tr.setHeight(br.height()); p.drawText(tr,Qt::AlignCenter,hHeader->label(i),-1); right+=w; p.drawLine(right,height,right,height+tr.height()); if (right >= metrics.width()-2*margin ) break; } p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line height+=tr.height(); p.drawLine(margin,height,right-1,height); // print d_table values for (i=0;i<rows;i++) { right=margin; QString text=vHeader->label(i)+"\t"; tr=p.boundingRect(tr,Qt::AlignCenter,text,-1,0); p.drawLine(right,height,right,height+tr.height()); br.setTopLeft(QPoint(right,height)); br.setWidth(vertHeaderWidth); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,text,-1); right+=vertHeaderWidth; p.drawLine(right,height,right,height+tr.height()); for (int j=0;j<cols;j++) { int w=d_table->columnWidth (j); text=d_table->text(i,j)+"\t"; tr=p.boundingRect(tr,Qt::AlignCenter,text,-1,0); br.setTopLeft(QPoint(right,height)); br.setWidth(w); br.setHeight(tr.height()); p.drawText(br,Qt::AlignCenter,text,-1); right+=w; p.drawLine(right,height,right,height+tr.height()); if (right >= metrics.width()-2*margin ) break; } height+=br.height(); p.drawLine(margin,height,right-1,height); if (height >= metrics.height()-margin ) { printer.newPage(); height=margin; p.drawLine(margin,height,right,height); } } } }