head 1.3; access; symbols; locks; strict; comment @// @; 1.3 date 2005.08.24.23.13.50; author behdad; state Exp; branches; next 1.2; commitid 5379430cff294567; 1.2 date 2005.08.19.20.37.33; author behdad; state Exp; branches; next 1.1; commitid 68a54306430a4567; 1.1 date 2005.07.01.19.49.07; author cworth; state Exp; branches; next ; commitid 3eec42c59e334567; desc @@ 1.3 log @2005-08-24 Behdad Esfahbod * qcairowidget.cpp: Use Qt platform-specific wrappers instead of Xlib. Patch from Mauricio Piacentini. @ text @#include "qcairowidget.h" QCairoWidget::QCairoWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) { setDoubleBuffered( true ); m_surf = cairo_xlib_surface_create ((Display *) x11AppDisplay(), (Drawable) handle(), (Visual *) x11Visual(), width(), height() ); m_cr = cairo_create(m_surf); cairo_surface_destroy(m_surf); } QCairoWidget::~QCairoWidget() { cairo_destroy( m_cr ); m_cr = 0; } void QCairoWidget::setDoubleBuffered( bool db ) { m_doubleBuffer = db; if ( m_doubleBuffer ) setBackgroundMode( Qt::NoBackground ); } void QCairoWidget::cairoPaint( cairo_t *, const QRect & ) { } void QCairoWidget::paintEvent( QPaintEvent *e ) { //the save/restore is a little silly... cairo_save( m_cr ); Display *dpy = x11AppDisplay(); Drawable drw = handle(); if ( m_doubleBuffer ) { m_buffer = QPixmap( size() ); m_buffer.fill( this, 0, 0 ); dpy = m_buffer.x11AppDisplay(); drw = m_buffer.handle(); } m_surf = cairo_get_target (m_cr); cairo_xlib_surface_set_drawable (m_surf, drw, width(), height()); cairoPaint( m_cr, e->rect() ); if ( cairo_status( m_cr ) != CAIRO_STATUS_SUCCESS ) { qDebug("Cairo is unhappy: %s\n", cairo_status_to_string( cairo_status( m_cr ) ) ); } if ( m_doubleBuffer ) bitBlt( this, 0, 0, &m_buffer ); cairo_restore( m_cr ); } @ 1.2 log @2005-08-19 Behdad Esfahbod * Updated to latest Cairo interface. Patch from Mauricio Piacentini. @ text @d7 1 a7 5 Display *dpy = x11AppDisplay(); Drawable drw = handle(); m_surf = cairo_xlib_surface_create (dpy, drw, DefaultVisual (dpy, DefaultScreen (dpy)), width(), height() ); @ 1.1 log @ From 2005-01-25 Zack Rusin : * .cvsignore: * controlwidgetbase.ui: * mainwindow.cpp: * mainwindow.h: * qcairo.cpp: * qcairo.h: * qcairo.pro: * qcairowidget.cpp: * qcairowidget.h: * qkapow.cpp: * qkapow.h: 1) I created a QCairoWidget which has a virtual void cairoPaint(cairo_t *) method which essentially replaces the QWidget::paintEvent. It's done essentially to enable people to just take the widget, stick it in their app and just use Cairo (either duble-buffered or not). 2) Instead of the old demo code it uses now kapow. It's a little bit more attractive and nicely shows how to use QCairoWidget. @ text @d7 7 a13 1 m_cr = cairo_create(); d49 2 a50 1 cairo_set_target_drawable( m_cr, dpy, drw ); d54 2 a55 3 if ( cairo_status( m_cr ) ) { qDebug("Cairo is unhappy: %s\n", cairo_status_string( m_cr ) ); exit(0); @