Ejemplo n.º 1
0
/*!
  Draw the canvas

  Paints all plot items to the canvasRect, using QwtPolarPlot::drawCanvas
  and updates the paint cache.

  \sa QwtPolarPlot::drawCanvas, setPaintAttributes(), testPaintAttributes()
*/
void QwtPolarCanvas::drawCanvas( QPainter *painter,
                                 const QwtDoubleRect& canvasRect )
{
  if ( !canvasRect.isValid() )
    return;

  if ( testPaintAttribute( PaintCached ) && d_data->cache )
  {
    *d_data->cache = QPixmap( contentsRect().size() );

#ifdef Q_WS_X11
#if QT_VERSION >= 0x040000
    if ( d_data->cache->x11Info().screen() != x11Info().screen() )
      d_data->cache->x11SetScreen( x11Info().screen() );
#else
    if ( d_data->cache->x11Screen() != x11Screen() )
      d_data->cache->x11SetScreen( x11Screen() );
#endif
#endif

    d_data->cache->fill( this, d_data->cache->rect().topLeft() );

    QPainter cachePainter( d_data->cache );
    cachePainter.translate( -contentsRect().x(),
                            -contentsRect().y() );

    plot()->drawCanvas( &cachePainter, canvasRect );

    cachePainter.end();

    painter->drawPixmap( canvasRect.topLeft().toPoint(), *d_data->cache );
  }
  else
    plot()->drawCanvas( painter, canvasRect );
}
Ejemplo n.º 2
0
/*!
  \return A pixmap that can be used as backing store

  \param widget Widget, for which the backinstore is intended
  \param size Size of the pixmap
 */
QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
{
    QPixmap pm;

#define QWT_HIGH_DPI 1

#if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
    qreal pixelRatio = 1.0;

    if ( widget && widget->windowHandle() )
    {
        pixelRatio = widget->windowHandle()->devicePixelRatio();
    }
    else
    {
        if ( qApp )
            pixelRatio = qApp->devicePixelRatio();
    }

    pm = QPixmap( size * pixelRatio );
    pm.setDevicePixelRatio( pixelRatio );
#else
    Q_UNUSED( widget )
    pm = QPixmap( size );
#endif

#if 0
#ifdef Q_WS_X11
    if ( pm.x11Info().screen() != x11Info().screen() )
         pm.x11SetScreen( x11Info().screen() );
#endif
#endif

    return pm;
}
Ejemplo n.º 3
0
/*!
  Draw the the canvas

  Paints all plot items to the contentsRect(), using QwtPlot::drawCanvas
  and updates the paint cache.

  \param painter Painter

  \sa QwtPlot::drawCanvas(), setPaintAttributes(), testPaintAttributes()
*/
void QwtPlotCanvas::drawCanvas( QPainter *painter )
{
    if ( !contentsRect().isValid() )
        return;

    QBrush bgBrush = palette().brush( backgroundRole() );

    if ( d_data->paintAttributes & PaintCached && d_data->cache )
    {
        *d_data->cache = QPixmap( contentsRect().size() );

#ifdef Q_WS_X11
        if ( d_data->cache->x11Info().screen() != x11Info().screen() )
            d_data->cache->x11SetScreen( x11Info().screen() );
#endif

        if ( d_data->paintAttributes & PaintPacked )
        {
            QPainter bgPainter( d_data->cache );
            bgPainter.setPen( Qt::NoPen );

            bgPainter.setBrush( bgBrush );
            bgPainter.drawRect( d_data->cache->rect() );
        }
        else
            d_data->cache->fill( this, d_data->cache->rect().topLeft() );

        QPainter cachePainter( d_data->cache );
        cachePainter.translate( -contentsRect().x(),
            -contentsRect().y() );

        ( ( QwtPlot * )parent() )->drawCanvas( &cachePainter );

        cachePainter.end();

        painter->drawPixmap( contentsRect(), *d_data->cache );
    }
    else
    {
        if ( d_data->paintAttributes & PaintPacked )
        {
            painter->save();

            painter->setPen( Qt::NoPen );
            painter->setBrush( bgBrush );
            painter->drawRect( contentsRect() );

            painter->restore();
        }

        ( ( QwtPlot * )parent() )->drawCanvas( painter );
    }
}
Ejemplo n.º 4
0
VdpauWidget::VdpauWidget( QString dataDir, QWidget *parent ) : QWidget( parent )
{
   QPalette palette = this->palette();
   palette.setColor(backgroundRole(), Qt::black);
   setPalette(palette);
   setAttribute(Qt::WA_OpaquePaintEvent, true);
   setAttribute(Qt::WA_PaintOnScreen, true);
   setFixedSize( 1024, 576 );

   vc = new VDPAUContext( x11Info().display(), x11Info().screen() );
   mixer = VDP_INVALID_HANDLE;
   mixerWidth = mixerHeight = 0;
   dataDirectory = dataDir;
}
Ejemplo n.º 5
0
void AppMainWindow::raiseWindow()
{
    setWindowState(windowState() & ~Qt::WindowMinimized);

    raise();

#if defined(Q_WS_X11)
    // Do the same as QWidget::activateWindow(), but with two differences
    // * set newest timestamp (instead of userTime()). See QTBUG-24932
    // * set source to 'pager'. This seems to do the trick e.g. on kwin even if
    //   the app currently having focus is 'active' (but we hit a breakpoint).
    XEvent e;
    e.xclient.type = ClientMessage;
    e.xclient.message_type = XInternAtom(QX11Info::display(), "_NET_ACTIVE_WINDOW", 1);
    e.xclient.display = QX11Info::display();
    e.xclient.window = winId();
    e.xclient.format = 32;
    e.xclient.data.l[0] = 2;     // pager!
    e.xclient.data.l[1] = QX11Info::appTime(); // X11 time!
    e.xclient.data.l[2] = None;
    e.xclient.data.l[3] = 0;
    e.xclient.data.l[4] = 0;
    XSendEvent(QX11Info::display(), QX11Info::appRootWindow(x11Info().screen()),
               false, SubstructureNotifyMask | SubstructureRedirectMask, &e);
#else
    activateWindow();
#endif
}
Ejemplo n.º 6
0
/*!
    This function is a reimplementation of QWidget::showEvent(). The
    reimplemented function handles the given \a event by ensuring that the
    dialog widget is managed and hidden.
*/
void QtMotifDialog::showEvent(QShowEvent *event)
{
    if (!event->spontaneous()) {
        // tell motif about modality
        Arg args[1];
        XtSetArg( args[0], XmNdialogStyle,
                  (testAttribute(Qt::WA_ShowModal)
                   ? XmDIALOG_FULL_APPLICATION_MODAL :
                   XmDIALOG_MODELESS));
        XtSetValues( d->shell, args, 1 );
        XtSetMappedWhenManaged( d->shell, False );
        if ( d->dialog ) {
            XtManageChild( d->dialog );

            XSync(x11Info().display(), FALSE);
            XSync(QtMotif::display(), FALSE);
        } else if ( !parentWidget() ) {
            adjustSize();
            QApplication::sendPostedEvents(this, QEvent::Resize);

            Widget p = XtParent( d->shell ), s = p;
            while ( s != NULL && !XtIsShell( s ) ) // find the shell
                s = XtParent( s );

            if ( p && s ) {
                int offx = ( (  XtWidth( p ) -  width() ) / 2 );
                int offy = ( ( XtHeight( p ) - height() ) / 2 );
                move( XtX ( s ) + offx, XtY( s ) + offy );
            }
        }
        XtSetMappedWhenManaged( d->shell, True );
    }
    QDialog::showEvent(event);

}
Ejemplo n.º 7
0
/*!
    Destroys the QDialog, dialog widget, and \c Shell widget.
*/
QtMotifDialog::~QtMotifDialog()
{
    QtMotif::unregisterWidget( this );
    ( (QtMotifDialogWidget) d->shell )->qmotifdialog.dialog = 0;
    XtDestroyWidget( d->shell );

    // make sure we don't have any pending requests for the window we
    // are about to destroy
    XSync(x11Info().display(), FALSE);
    XSync(QtMotif::display(), FALSE);
    destroy( false );

    // Make sure everything is finished before ~QWidget() runs
    XSync(x11Info().display(), FALSE);
    XSync(QtMotif::display(), FALSE);

    delete d;
}
Ejemplo n.º 8
0
	void OgreWidget::initialise(const Ogre::NameValuePairList *miscParams)
	{
		//These attributes are the same as those use in a QGLWidget
		setAttribute(Qt::WA_PaintOnScreen);
		setAttribute(Qt::WA_NoSystemBackground);

		//Parameters to pass to Ogre::Root::createRenderWindow()
		Ogre::NameValuePairList params;

		//If the user passed in any parameters then be sure to copy them into our own parameter set.
		//NOTE: Many of the parameters the user can supply (left, top, border, etc) will be ignored
		//as they are overridden by Qt. Some are still useful (such as FSAA).
		if(miscParams != 0)
		{
			params.insert(miscParams->begin(), miscParams->end());
		}

		//The external windows handle parameters are platform-specific
		Ogre::String externalWindowHandleParams;

		//Accept input focus
		setFocusPolicy(Qt::StrongFocus);

	#if defined(Q_WS_WIN)
		//positive integer for W32 (HWND handle) - According to Ogre Docs
		externalWindowHandleParams = Ogre::StringConverter::toString((unsigned int)(winId()));
	#endif

	#if defined(Q_WS_X11)
		//poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX - According to Ogre Docs
		QX11Info info = x11Info();
		externalWindowHandleParams  = Ogre::StringConverter::toString((unsigned long)(info.display()));
		externalWindowHandleParams += ":";
		externalWindowHandleParams += Ogre::StringConverter::toString((unsigned int)(info.screen()));
		externalWindowHandleParams += ":";
		externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(winId()));
		//externalWindowHandleParams += ":";
		//externalWindowHandleParams += Ogre::StringConverter::toString((unsigned long)(info.visual()));
	#endif

		//Add the external window handle parameters to the existing params set.
	#if defined(Q_WS_WIN)		
		params["externalWindowHandle"] = externalWindowHandleParams;
	#endif

	#if defined(Q_WS_X11)
		params["parentWindowHandle"] = externalWindowHandleParams;
	#endif

		//Finally create our window.
		m_pOgreRenderWindow = Ogre::Root::getSingletonPtr()->createRenderWindow("OgreWindow", width(), height(), false, &params);

		mIsInitialised = true;
	}
Ejemplo n.º 9
0
/**
 * @brief setup the rendering context
 * @author Kito Berg-Taylor
 */
void OgreWidget::initializeGL()
{
 //== Creating and Acquiring Ogre Window ==//
 
  // Get the parameters of the window QT created
  Ogre::String winHandle;
  #ifdef WIN32
  // Windows code
  winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
  #else
  // Unix code
  QX11Info info = x11Info();
  winHandle  = Ogre::StringConverter::toString((unsigned long)(info.display()));
  winHandle += ":";
  winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
  winHandle += ":";
  winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
  #endif
 
  Ogre::NameValuePairList params;
  params["parentWindowHandle"] = winHandle;
 
  mOgreWindow = mOgreRoot->createRenderWindow( "QOgreWidget_RenderWindow",
                           this->width(),
                           this->height(),
                           false,
                           &params );
 
  mOgreWindow->setActive(true);
  WId ogreWinId = 0x0;
  mOgreWindow->getCustomAttribute( "WINDOW", &ogreWinId );
 
  assert( ogreWinId );
 
  this->create( ogreWinId );
  setAttribute( Qt::WA_PaintOnScreen, true );
  setAttribute( Qt::WA_NoBackground );
 
  //== Ogre Initialization ==//
  Ogre::SceneType scene_manager_type = Ogre::ST_EXTERIOR_CLOSE;
 
  mSceneMgr = mOgreRoot->createSceneManager( scene_manager_type );
  mSceneMgr->setAmbientLight( Ogre::ColourValue(1,1,1) );
 
  mCamera = mSceneMgr->createCamera( "QOgreWidget_Cam" );
  mCamera->setPosition( Ogre::Vector3(0,1,0) );
  mCamera->lookAt( Ogre::Vector3(0,0,0) );
  mCamera->setNearClipDistance( 1.0 );
 
  Ogre::Viewport *mViewport = mOgreWindow->addViewport( mCamera );
  mViewport->setBackgroundColour( Ogre::ColourValue( 0.8,0.8,1 ) );
}
Ejemplo n.º 10
0
/*!
    \internal
    Wraps the Motif dialog by setting the X window for the
    QtMotifDialog to the X window id of the dialog shell.
*/
void QtMotifDialog::realize( Widget w )
{
    // use the winid of the dialog shell, reparent any children we have
    if ( XtWindow( w ) != winId() ) {
	XSync(QtMotif::display(), FALSE);

	XtSetMappedWhenManaged( d->shell, False );

	// save the window title
	QString wtitle = windowTitle();
	if (wtitle.isEmpty()) {
 	    char *t = 0;
 	    XtVaGetValues(w, XtNtitle, &t, NULL);
 	    wtitle = QString::fromLocal8Bit(t);
	}
        setWindowTitle(QString()); // make sure setWindowTitle() works below

        QString icontext = windowIconText();
        if (icontext.isEmpty()) {
 	    char *iconName = 0;
 	    XtVaGetValues(w, XtNiconName, &iconName, NULL);
 	    icontext = QString::fromLocal8Bit(iconName);
        }
        setWindowIconText(QString()); // make sure setWindowTitle() works below

	Window newid = XtWindow(w);
	QObjectList list = children();
	for (int i = 0; i < list.size(); ++i) {
	    QWidget *widget = qobject_cast<QWidget*>(list.at(i));
	    if (!widget || widget->isWindow()) continue;

	    XReparentWindow(widget->x11Info().display(), widget->winId(), newid,
			    widget->x(), widget->y());
	}
	QApplication::syncX();

	create( newid, true, true );

	// restore the window title and icon text
 	if (!wtitle.isEmpty())
 	    setWindowTitle(wtitle);
        if (!icontext.isEmpty())
            setWindowIconText(icontext);

	// if this dialog was created without a QWidget parent, then the transient
	// for will be set to the root window, which is not acceptable.
	// instead, set it to the window id of the shell's parent
	if ( ! parent() && XtParent( d->shell ) )
	    XSetTransientForHint(x11Info().display(), newid, XtWindow(XtParent(d->shell)));
    }
    QtMotif::registerWidget( this );
}
void  OgreWidget::initOgreSystem()
{
  m_ogreRoot = new Ogre::Root();

  Ogre::RenderSystem * renderSystem = m_ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
  m_ogreRoot->setRenderSystem(renderSystem);
  m_ogreRoot->initialise(false);

  m_sceneManager = m_ogreRoot->createSceneManager(Ogre::ST_GENERIC);

  Ogre::NameValuePairList viewConfig;
  Ogre::String widgetHandle;

#ifdef Q_WS_WIN
  widgetHandle = Ogre::StringConverter::toString((size_t)winId());
  viewConfig["externalWindowHandle"] = widgetHandle;
#else
  QX11Info xInfo = x11Info();

  widgetHandle = Ogre::StringConverter::toString(reinterpret_cast<unsigned long>(xInfo.display())) +
      ":" + Ogre::StringConverter::toString(static_cast<unsigned int>(xInfo.screen())) +
      ":" + Ogre::StringConverter::toString(static_cast<unsigned long>(parentWidget()->winId()));
  viewConfig["parentWindowHandle"] = widgetHandle;
#endif

  m_renderWindow = m_ogreRoot->createRenderWindow("Ogre rendering window", width(), height(), false, &viewConfig);

#ifndef Q_WS_WIN
  WId window_id;
  m_renderWindow->getCustomAttribute("WINDOW", &window_id);
  create(window_id);
#endif

  m_camera = new Camera(m_sceneManager->createCamera("myCamera"));

  m_camera->reset();
  m_camera->getCamera()->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height()));
  m_camera->getCamera()->setNearClipDistance(Ogre::Real(0.1));

  m_viewport = m_renderWindow->addViewport(m_camera->getCamera());
  m_viewport->setBackgroundColour(Ogre::ColourValue(0.5, 0.5, 0.5));

  m_selectionBuffer = new SelectionBuffer(m_sceneManager, m_renderWindow);

  initResources();
  initScene();
}
Ejemplo n.º 12
0
Diversia::Util::String OgreWidget::getWidgetHandle()
{
#if DIVERSIA_PLATFORM == DIVERSIA_PLATFORM_WIN32
    return Ogre::StringConverter::toString( (size_t)( (HWND)winId() ) );
#elif DIVERSIA_PLATFORM == DIVERSIA_PLATFORM_LINUX
    QWidget* q_parent = dynamic_cast <QWidget *> ( parent() );
    QX11Info xInfo = x11Info();

    return Ogre::StringConverter::toString( (unsigned long)xInfo.display() ) +
        ":" + Ogre::StringConverter::toString( (unsigned int)xInfo.screen() ) +
        ":" + Ogre::StringConverter::toString( (unsigned long)q_parent->winId() );
#else
    DivAssert( 0, "Cannot get widget handle, unsupported OS" );
#endif

    return "";
}
Ejemplo n.º 13
0
void OgreWidget::initOgreSystem()
{
    ogreRoot = new Ogre::Root();

    Ogre::RenderSystem *renderSystem = ogreRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
    ogreRoot->setRenderSystem(renderSystem);
    ogreRoot->initialise(false);

    ogreSceneManager = ogreRoot->createSceneManager(Ogre::ST_GENERIC);

    Ogre::NameValuePairList viewConfig;
    Ogre::String widgetHandle;
#ifdef Q_WS_WIN
    widgetHandle = Ogre::StringConverter::toString((size_t)((HWND)winId()));
#else
    QWidget *q_parent = dynamic_cast <QWidget *> (parent());
    QX11Info xInfo = x11Info();

    widgetHandle = Ogre::StringConverter::toString ((unsigned long)xInfo.display()) +
        ":" + Ogre::StringConverter::toString ((unsigned int)xInfo.screen()) +
        ":" + Ogre::StringConverter::toString ((unsigned long)q_parent->winId());

#endif
    viewConfig["externalWindowHandle"] = widgetHandle;
    ogreRenderWindow = ogreRoot->createRenderWindow("Ogre rendering window",
                width(), height(), false, &viewConfig);

    ogreCamera = ogreSceneManager->createCamera("myCamera");
    Ogre::Vector3 camPos(0, 50,150);
        ogreCamera->setPosition(camPos);
        ogreCamera->lookAt(0,50,0);
    emit cameraPositionChanged(camPos);

    ogreViewport = ogreRenderWindow->addViewport(ogreCamera);
    ogreViewport->setBackgroundColour(Ogre::ColourValue(0,0,255));
    ogreCamera->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height()));

        setupNLoadResources();
        createScene();
}
Ejemplo n.º 14
0
/*!
    \internal
    Initializes QtMotifDialog by creating the QtMotifDialogPrivate data
    and the Shell widget.
*/
void QtMotifDialog::init( const char *name, Widget parent, ArgList args, Cardinal argcount )
{
    d = new QtMotifDialogPrivate;

    Arg *realargs = new Arg[ argcount + 3 ];
    memcpy( realargs, args, argcount * sizeof(Arg) );
    int screen = x11Info().screen();
    if ( !QX11Info::appDefaultVisual(screen)) {
	// make Motif use the same visual/colormap/depth as Qt (if Qt
	// is not using the default)
	XtSetArg(realargs[argcount], XtNvisual, QX11Info::appVisual(screen));
	++argcount;
	XtSetArg(realargs[argcount], XtNcolormap, QX11Info::appColormap(screen));
	++argcount;
	XtSetArg(realargs[argcount], XtNdepth, QX11Info::appDepth(screen));
	++argcount;
    }

    // create the dialog shell
    if ( parent ) {
        if (!name)
            d->shell = XtCreatePopupShell( "QtMotifDialog", qmotifDialogWidgetClass, parent,
				       realargs, argcount );
        else
            d->shell = XtCreatePopupShell( name, qmotifDialogWidgetClass, parent,
				       realargs, argcount );
    } else {
        if (!name)
            d->shell = XtAppCreateShell( "QtMotifDialog", "QtMotifDialog", qmotifDialogWidgetClass,
                                         QtMotif::display(), realargs, argcount );
        else
            d->shell = XtAppCreateShell( name, name, qmotifDialogWidgetClass,
                                         QtMotif::display(), realargs, argcount );
    }

    ( (QtMotifDialogWidget) d->shell )->qmotifdialog.dialog = this;

    delete [] realargs;
    realargs = 0;
}
Ejemplo n.º 15
0
void X11EmbedContainer::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    if (!d->updatesEnabled) {
        return;
    }

    if (!d->picture) {
        FdoSelectionManager::painter()->updateContainer(this);
        return;
    }

    // Taking a detour via a QPixmap is unfortunately the only way we can get
    // the window contents into Qt's backing store.
    QPixmap pixmap(size());
    pixmap = toX11Pixmap(pixmap);
    pixmap.fill(Qt::transparent);
    XRenderComposite(x11Info().display(), PictOpSrc, d->picture, None, pixmap.x11PictureHandle(),
                     0, 0, 0, 0, 0, 0, width(), height());
    QPainter p(this);
    p.drawPixmap(0, 0, pixmap);
}
Ejemplo n.º 16
0
void OgreWidget::create_render_window ()
{
    if (win_) return;

    bool stealparent (parentWidget() != NULL);
    QWidget *nativewin ((stealparent)? parentWidget () : this);

    Ogre::NameValuePairList params;
    Ogre::String winhandle;

#ifdef Q_WS_WIN
    // According to Ogre Docs
    // positive integer for W32 (HWND handle)
    winhandle = Ogre::StringConverter::toString 
        ((unsigned int) 
         (nativewin-> winId ()));

    //Add the external window handle parameters to the existing params set.
    params["externalWindowHandle"] = winhandle;
#endif

#ifdef Q_WS_X11
    // GLX - According to Ogre Docs:
    // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)
    QX11Info info = x11Info ();

    winhandle  = Ogre::StringConverter::toString 
        ((unsigned long)
         (info.display ()));
    winhandle += ":";

    winhandle += Ogre::StringConverter::toString 
        ((unsigned int)
         (info.screen ()));
    winhandle += ":";
    
    winhandle += Ogre::StringConverter::toString 
        ((unsigned long)
         nativewin-> winId());
         //(isHidden ()) ? 
         //nativewin-> effectiveWinId () : 
         //nativewin-> winId ());

    //Add the external window handle parameters to the existing params set.
    params["parentWindowHandle"] = winhandle;
#endif

    win_ = root_-> createRenderWindow ("View", width(), height(), false, &params);

    // take over ogre window
    // needed with parent windows
    if (stealparent)
    {
        WId ogre_winid = 0x0;
#ifndef Q_WS_WIN
        win_-> getCustomAttribute ("WINDOW", &ogre_winid);
#else
        win_-> getCustomAttribute ("HWND", &ogre_winid);
#endif
        assert (ogre_winid);
        create (ogre_winid);
    }
}
Ejemplo n.º 17
0
    Ogre::RenderWindow* ExternalRenderWindow::CreateRenderWindow(const std::string &name,  int width, int height, int left, int top, bool fullscreen)
    {
        bool stealparent 
            ((parentWidget())? true : false);

        QWidget *nativewin 
            ((stealparent)? parentWidget() : this);

        Ogre::NameValuePairList params;
        Ogre::String winhandle;

#ifdef Q_WS_WIN
        // According to Ogre Docs
        // positive integer for W32 (HWND handle)
        winhandle = Ogre::StringConverter::toString 
            ((unsigned int) 
             (nativewin-> winId ()));

        //Add the external window handle parameters to the existing params set.
        params["externalWindowHandle"] = winhandle;

#endif

#ifdef Q_WS_MAC
    // qt docs say it's a HIViewRef on carbon,
    // carbon docs say HIViewGetWindow gets a WindowRef out of it

#if 0
    HIViewRef vref = (HIViewRef) nativewin-> winId ();
    WindowRef wref = HIViewGetWindow(vref);
        winhandle = Ogre::StringConverter::toString(
           (unsigned long) (HIViewGetRoot(wref)));
#else
        // according to
        // http://www.ogre3d.org/forums/viewtopic.php?f=2&t=27027 does
        winhandle = Ogre::StringConverter::toString(
                     (unsigned long) nativewin->winId());
#endif
        //Add the external window handle parameters to the existing params set.
        params["externalWindowHandle"] = winhandle;
#endif

#ifdef Q_WS_X11
        // GLX - According to Ogre Docs:
        // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)
        QX11Info info =  x11Info ();

        winhandle  = Ogre::StringConverter::toString 
            ((unsigned long)
             (info.display ()));
        winhandle += ":";

        winhandle += Ogre::StringConverter::toString 
            ((unsigned int)
             (info.screen ()));
        winhandle += ":";
        
        winhandle += Ogre::StringConverter::toString 
            ((unsigned long)
             nativewin-> winId());

        //Add the external window handle parameters to the existing params set.
        params["parentWindowHandle"] = winhandle;
#endif

        // Window position to params
        if (left != -1)
            params["left"] = ToString(left);
        if (top != -1)
            params["top"] = ToString(top);

        render_window_ = Ogre::Root::getSingletonPtr()-> createRenderWindow(name, width, height, fullscreen, &params);

        return render_window_;

    }
Ejemplo n.º 18
0
/*!
    \fn void CSizeGrip::mousePressEvent(QMouseEvent * event)

    Receives the mouse press events for the widget, and primes the
    resize operation. The mouse press event is passed in the \a event
    parameter.
*/
void CSizeGrip::mousePressEvent(QMouseEvent * e)
{
    ungrabGesture(Qt::TapAndHoldGesture);

    if (e->button() != Qt::LeftButton) {
        QWidget::mousePressEvent(e);
        return;
    }


    QWidget *tlw = qt_sizegrip_topLevelWidget();
    p = e->globalPos();
    gotMousePress = true;
    r = tlw->geometry();

#ifdef Q_WS_X11
    #if QT_VERSION >= 0x050000
    // Use a native X11 sizegrip for "real" top-level windows if supported.
    if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE))
        && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
        && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) {
        XEvent xev;
        xev.xclient.type = ClientMessage;
        xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE);
        xev.xclient.display = X11->display;
        xev.xclient.window = tlw->winId();
        xev.xclient.format = 32;
        xev.xclient.data.l[0] = e->globalPos().x();
        xev.xclient.data.l[1] = e->globalPos().y();
        if (atBottom())
            xev.xclient.data.l[2] = atLeft() ? 6 : 4; // bottomleft/bottomright
        else
            xev.xclient.data.l[2] = atLeft() ? 0 : 2; // topleft/topright
        xev.xclient.data.l[3] = Button1;
        xev.xclient.data.l[4] = 0;
        XUngrabPointer(X11->display, X11->time);
        XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False,
                   SubstructureRedirectMask | SubstructureNotifyMask, &xev);
        return;
    }
#endif
#endif // Q_WS_X11
#ifdef Q_WS_WIN
    #if QT_VERSION >= 0x050000
    if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) {
        uint orientation = 0;
        if (atBottom())
            orientation = atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT;
        else
            orientation = atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT;

        ReleaseCapture();
        PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0);
        return;
    }
#endif
#endif // Q_WS_WIN

    // Find available desktop/workspace geometry.
    QRect availableGeometry;
    bool hasVerticalSizeConstraint = true;
    bool hasHorizontalSizeConstraint = true;
    if (tlw->isWindow())
        availableGeometry = QApplication::desktop()->availableGeometry(tlw);
    else {
        const QWidget *tlwParent = tlw->parentWidget();
        // Check if tlw is inside QAbstractScrollArea/QScrollArea.
        // If that's the case tlw->parentWidget() will return the viewport
        // and tlw->parentWidget()->parentWidget() will return the scroll area.
#ifndef QT_NO_SCROLLAREA
        QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget());
        if (scrollArea) {
            hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
            hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
        }
#endif // QT_NO_SCROLLAREA
        availableGeometry = tlwParent->contentsRect();
    }

    // Find frame geometries, title bar height, and decoration sizes.
    const QRect frameGeometry = tlw->frameGeometry();
    const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0);
    const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0);
    const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0);

    // Determine dyMax depending on whether the sizegrip is at the bottom
    // of the widget or not.
    if (atBottom()) {
        if (hasVerticalSizeConstraint)
            dyMax = availableGeometry.bottom() - r.bottom() - bottomDecoration;
        else
            dyMax = INT_MAX;
    } else {
        if (hasVerticalSizeConstraint)
            dyMax = availableGeometry.y() - r.y() + titleBarHeight;
        else
            dyMax = -INT_MAX;
    }

    // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace
    // geometry, the size grip geometry and the width of the decoration.
    if (atLeft()) {
        if (hasHorizontalSizeConstraint)
            dxMax = availableGeometry.x() - r.x() + leftRightDecoration;
        else
            dxMax = -INT_MAX;
    } else {
        if (hasHorizontalSizeConstraint)
            dxMax = availableGeometry.right() - r.right() - leftRightDecoration;
        else
            dxMax = INT_MAX;
    }
}
// setup x or xvideo
void ffmpegWidget::xvSetup() {
    XvAdaptorInfo * ainfo;
    XvEncodingInfo *encodings;
    unsigned int adaptors, nencode;
    unsigned int ver, rel, extmaj, extev, exterr;
    // get display number
    this->dpy = x11Info().display();
    // Grab the window id and setup a graphics context
    this->w = this->winId();
    this->gc = XCreateGC(this->dpy, this->w, 0, 0);
    // Now try and setup xv
    // return version and release of extension
    if (XvQueryExtension(this->dpy, &ver, &rel, &extmaj, &extev, &exterr) != Success) {
        printf("XvQueryExtension failed, using QImage fallback mode\n");
        return;
    }
    //printf("Ver: %d, Rel: %d, ExtMajor: %d, ExtEvent: %d, ExtError: %d\n", ver, rel, extmaj, extev, exterr);
    //Ver: 2, Rel: 2, ExtMajor: 140, ExtEvent: 75, ExtError: 150
    // return adaptor information for the screen
    if (XvQueryAdaptors(this->dpy, QX11Info::appRootWindow(),
            &adaptors, &ainfo) != Success) {
        printf("XvQueryAdaptors failed, using QImage fallback mode\n");
        return;
    }
    // see if we have any adapters
    if (adaptors <= 0) {
        printf("No xv adaptors found, using QImage fallback mode\n");
        return;
    }
    // grab the port from the first adaptor
    int gotPort = 0;
    for(int p = 0; p < (int) ainfo[0].num_ports; p++) {
        if(XvGrabPort(this->dpy, ainfo[0].base_id + p, CurrentTime) == Success) {
            this->xv_port = ainfo[0].base_id + p;
            gotPort = 1;
            break;
        }
    }
    // if we didn't find a port
    if (!gotPort) {
        printf("No xv ports free, using QImage fallback mode\n");
        return;
    }
    // get max XV Image size
    int gotEncodings = 0;
    XvQueryEncodings(this->dpy, ainfo[0].base_id, &nencode, &encodings);
    if (encodings && nencode && (ainfo[0].type & XvImageMask)) {
        for(unsigned int n = 0; n < nencode; n++) {
            if(!strcmp(encodings[n].name, "XV_IMAGE")) {
                this->maxW = encodings[n].width;
                this->maxH = encodings[n].height;
                gotEncodings = 1;
                break;
            }
        }
    }
    // if we didn't find a list of encodings
    if (!gotEncodings) {
        printf("No encodings information, using QImage fallback mode\n");
        return;
    }
    // only support I420 mode for now
    int num_formats = 0;
    XvImageFormatValues * vals = XvListImageFormats(this->dpy,
        this->xv_port, &num_formats);
    for (int i=0; i<num_formats; i++) {
        if (strcmp(vals->guid, "I420") == 0) {
            this->xv_format = vals->id;
            this->ff_fmt = PIX_FMT_YUVJ420P;
            // Widget is responsible for painting all its pixels with an opaque color
            setAttribute(Qt::WA_OpaquePaintEvent);
            setAttribute(Qt::WA_PaintOnScreen);
            return;
        }
        vals++;
    }
    printf("Display doesn't support I420 mode, using QImage fallback mode\n");
    return;
}
Ejemplo n.º 20
0
void Unity2dPanel::slotWorkAreaResized(int screen)
{
    if (x11Info().screen() == screen) {
        d->updateEdge();
    }
}
Ejemplo n.º 21
0
/*!
  Paint event
  \param event Paint event
*/
void QwtPlotCanvas::paintEvent( QPaintEvent *event )
{
    QPainter painter( this );
    painter.setClipRegion( event->region() );

    if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) &&
        d_data->backingStore != NULL )
    {
        QPixmap &bs = *d_data->backingStore;
        if ( bs.size() != size() )
        {
            bs = QPixmap( size() );

#ifdef Q_WS_X11
            if ( bs.x11Info().screen() != x11Info().screen() )
                bs.x11SetScreen( x11Info().screen() );
#endif

            if ( testAttribute(Qt::WA_StyledBackground) )
            {
                QPainter p( &bs );
                qwtFillBackground( &p, this );
                drawCanvas( &p, true );
            }
            else
            {
                QPainter p;
                if ( d_data->borderRadius <= 0.0 )
                {
#if QT_VERSION >= 0x050000
                    QwtPainter::fillPixmap( this, bs );
#else
                    bs.fill( this, 0, 0 );
#endif
                    p.begin( &bs );
                    drawCanvas( &p, false );
                }
                else
                {
                    p.begin( &bs );
                    qwtFillBackground( &p, this );
                    drawCanvas( &p, true );
                }

                if ( frameWidth() > 0 )
                    drawBorder( &p );
            }
        }

        painter.drawPixmap( 0, 0, *d_data->backingStore );
    }
    else
    {
        if ( testAttribute(Qt::WA_StyledBackground ) )
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                qwtFillBackground( &painter, this );
                drawCanvas( &painter, true );
            }
            else
            {
                drawCanvas( &painter, false );
            }
        }
        else
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                if ( autoFillBackground() )
                    qwtDrawBackground( &painter, this );
            }

            drawCanvas( &painter, false );

            if ( frameWidth() > 0 ) 
                drawBorder( &painter );
        }
    }

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
        drawFocusIndicator( &painter );
}
/*!
  Paint event
  \param event Paint event
*/
void QwtPlotCanvas::paintEvent( QPaintEvent *event )
{
    QPainter painter( this );
    painter.setClipRegion( event->region() );

    if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) &&
        d_data->backingStore != NULL )
    {
        QPixmap &bs = *d_data->backingStore;
        if ( bs.size() != size() )
        {
            bs = QPixmap( size() );

#ifdef Q_WS_X11
            if ( bs.x11Info().screen() != x11Info().screen() )
                bs.x11SetScreen( x11Info().screen() );
#endif

            if ( testAttribute(Qt::WA_StyledBackground) )
            {
                QPainter p( &bs );
                qwtFillBackground( &p, this );
                drawCanvas( &p, true );
            }
            else
            {
                QPainter p;
                if ( d_data->borderRadius <= 0.0 )
                {
                    qwtFillPixmap( this, bs );
                    p.begin( &bs );
                    drawCanvas( &p, false );
                }
                else
                {
                    p.begin( &bs );
                    qwtFillBackground( &p, this );
                    drawCanvas( &p, true );
                }

                if ( frameWidth() > 0 )
                    drawBorder( &p );
            }
        }

        painter.drawPixmap( 0, 0, *d_data->backingStore );
    }
    else
    {
        if ( testAttribute(Qt::WA_StyledBackground ) )
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                qwtFillBackground( &painter, this );
                drawCanvas( &painter, true );
            }
            else
            {
                drawCanvas( &painter, false );
            }
        }
        else
        {
            if ( testAttribute( Qt::WA_OpaquePaintEvent ) )
            {
                if ( autoFillBackground() )
                {
                    qwtFillBackground( &painter, this );
                    qwtDrawBackground( &painter, this );
                }
            }
            else
            {
                if ( borderRadius() > 0.0 )
                {
                    QPainterPath clipPath;
                    clipPath.addRect( rect() );
                    clipPath = clipPath.subtracted( borderPath( rect() ) );

                    painter.save();

                    painter.setClipPath( clipPath, Qt::IntersectClip );
                    qwtFillBackground( &painter, this );
                    qwtDrawBackground( &painter, this );

                    painter.restore();
                }
            }

            drawCanvas( &painter, false );

            if ( frameWidth() > 0 ) 
                drawBorder( &painter );
        }
    }

    if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
        drawFocusIndicator( &painter );
}
Ejemplo n.º 23
0
Ogre::RenderWindow *QOgreUIView::CreateRenderWindow ()
{
    bool stealparent 
        ((parentWidget())? true : false);

    QWidget *nativewin 
        ((stealparent)? parentWidget() : this);

    Ogre::NameValuePairList params;
    Ogre::String winhandle;

#ifdef Q_WS_WIN
    // According to Ogre Docs
    // positive integer for W32 (HWND handle)
    winhandle = Ogre::StringConverter::toString 
        ((unsigned int) 
         (nativewin-> winId ()));

    //Add the external window handle parameters to the existing params set.
    params["externalWindowHandle"] = winhandle;
#endif

#ifdef Q_WS_X11
    // GLX - According to Ogre Docs:
    // poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)
    QX11Info info =  x11Info ();

    winhandle  = Ogre::StringConverter::toString 
        ((unsigned long)
         (info.display ()));
    winhandle += ":";

    winhandle += Ogre::StringConverter::toString 
        ((unsigned int)
         (info.screen ()));
    winhandle += ":";
    
    winhandle += Ogre::StringConverter::toString 
        ((unsigned long)
         nativewin-> winId());

    //Add the external window handle parameters to the existing params set.
    params["parentWindowHandle"] = winhandle;
#endif

    QSize size (nativewin-> size());
    win_ = Ogre::Root::getSingletonPtr()-> 
        createRenderWindow ("View", size.width(), size.height(), false, &params);

    // take over ogre window
    // needed with parent windows
    if (stealparent)
    {
        WId ogre_winid = 0x0;
#ifndef Q_WS_WIN
        win_-> getCustomAttribute ("WINDOW", &ogre_winid);
#else
        win_-> getCustomAttribute ("HWND", &ogre_winid);
#endif
        assert (ogre_winid);
        create (ogre_winid);
    }

    return win_;
}
Ejemplo n.º 24
0
	/**
	* @brief setup the rendering context
	* @author Kito Berg-Taylor
	*/
	void OgreWidget::initializeGL()
	{
		//== Creating and Acquiring Ogre Window ==//

		// Get the parameters of the window QT created
		Ogre::String winHandle;
	#ifdef WIN32
		// Windows code
		winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
	#elif MACOS
		// Mac code, tested on Mac OSX 10.6 using Qt 4.7.4 and Ogre 1.7.3
		Ogre::String winHandle  = Ogre::StringConverter::toString(winId());
	#else
		// Unix code
		QX11Info info = x11Info();
		winHandle  = Ogre::StringConverter::toString((unsigned long)(info.display()));
		winHandle += ":";
		winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
		winHandle += ":";
		winHandle += Ogre::StringConverter::toString((unsigned long)(this->parentWidget()->winId()));
	#endif

		Ogre::NameValuePairList params;
	#ifndef MACOS
		// code for Windows and Linux
		params["parentWindowHandle"] = winHandle;
		_mOgreWindow = _mOgreRoot->createRenderWindow(	"QOgreWidget_RenderWindow",
														this->width(),
														this->height(),
														false,
														&params);

		_mOgreWindow->setActive(true);
		WId ogreWinId = 0x0;
		_mOgreWindow->getCustomAttribute("WINDOW", &ogreWinId);

		assert(ogreWinId);

		// bug fix, extract geometry
		QRect geo = this->frameGeometry();

		// create new window
		this->create(ogreWinId);

		// set geometrie infos to new window
		this->setGeometry(geo);

	#else
		// code for Mac
		params["externalWindowHandle"] = winHandle;
		params["macAPI"] = "cocoa";
		params["macAPICocoaUseNSView"] = "true";
		mOgreWindow = mOgreRoot->createRenderWindow("QOgreWidget_RenderWindow",
													width(), height(), false, &params);
		mOgreWindow->setActive(true);
		makeCurrent();
	#endif

		setAttribute(Qt::WA_PaintOnScreen, true);
		setAttribute(Qt::WA_NoBackground);

		//== Ogre Initialization ==//
		Ogre::SceneType scene_manager_type = Ogre::ST_EXTERIOR_CLOSE;

		_mSceneMgr = _mOgreRoot->createSceneManager(scene_manager_type);
		_mSceneMgr->setAmbientLight(Ogre::ColourValue(1.0f, 1.0f, 1.0f));

		_mCamera = _mSceneMgr->createCamera("QOgreWidget_Cam");
		_mCamera->setPosition(Ogre::Vector3(0, 0, 80));
		_mCamera->lookAt(Ogre::Vector3(0, 0, -300));
		_mCamera->setNearClipDistance(1.0f);

		Ogre::Viewport *mViewport = _mOgreWindow->addViewport(_mCamera);
		mViewport->setBackgroundColour(Ogre::ColourValue(0.1f, 0.1f, 1.0f));




		/*
		Ogre::ConfigFile cf;
		cf.load("resources.cfg");

		// Go through all sections & settings in the file
		Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

		Ogre::String secName, typeName, archName;
		while (seci.hasMoreElements())
		{
			secName = seci.peekNextKey();
			Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
			Ogre::ConfigFile::SettingsMultiMap::iterator i;
			for (i = settings->begin(); i != settings->end(); ++i)
			{
				typeName = i->first;
				archName = i->second;
				Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
					archName, typeName, secName);
			}
		}

		// load resources
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
		//-------------------------------------------------------------------------------------
		// Create the scene
		Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");

		Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		headNode->attachObject(ogreHead);

		// Set ambient light
		mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));

		// Create a light
		Ogre::Light* l = mSceneMgr->createLight("MainLight");
		l->setPosition(20,80,50);
		*/
	}
Ejemplo n.º 25
0
void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, bool deleteOldContext)
{
    Q_D(QGLWidget);
    if (context == 0) {
        qWarning("QGLWidget::setContext: Cannot set null context");
        return;
    }
    if (!context->deviceIsPixmap() && context->device() != this) {
        qWarning("QGLWidget::setContext: Context must refer to this widget");
        return;
    }

    if (d->glcx)
        d->glcx->doneCurrent();
    QGLContext* oldcx = d->glcx;
    d->glcx = context;

    if (parentWidget()) {
        // force creation of delay-created widgets
        parentWidget()->winId();
        if (parentWidget()->x11Info().screen() != x11Info().screen())
            d_func()->xinfo = parentWidget()->d_func()->xinfo;
    }

    bool visible = isVisible();
    if (visible)
        hide();

    XVisualInfo vi;

    int err = XMatchVisualInfo(x11Info().display(), x11Info().screen(), x11Info().depth(), TrueColor, &vi);
    if (err == 0) {
        qWarning("Error: Couldn't get a matching X visual for format");
        return;
    }

    XSetWindowAttributes a;

    Window p = RootWindow(X11->display, vi.screen);
    if (parentWidget())
        p = parentWidget()->winId();

    QColormap colmap = QColormap::instance(vi.screen);
    a.background_pixel = colmap.pixel(palette().color(backgroundRole()));
    a.border_pixel = colmap.pixel(Qt::black);

    Window w = XCreateWindow(X11->display, p, x(), y(), width(), height(),
                             0, vi.depth, InputOutput, vi.visual,
                             CWBackPixel|CWBorderPixel, &a);

    if (deleteOldContext)
        delete oldcx;
    oldcx = 0;

    create(w); // Create with the ID of the window we've just created

    d->eglSurfaceWindowId = w; // Remember the window id we created the surface for

    if (visible)
        show();

    bool createFailed = false;
    if (!d->glcx->isValid()) {
        if (!d->glcx->create(shareContext ? shareContext : oldcx))
            createFailed = true;
    }
    if (createFailed) {
        if (deleteOldContext)
            delete oldcx;
        return;
    }

    if (d->glcx->windowCreated() || d->glcx->deviceIsPixmap()) {
        if (deleteOldContext)
            delete oldcx;
        return;
    }

    d->glcx->setWindowCreated(true);
}
Ejemplo n.º 26
0
void X11EmbedContainer::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    if (!d->updatesEnabled) {
        return;
    }

    if (!d->picture) {
        FdoSelectionManager::painter()->updateContainer(this);
        return;
    }

    QPainter p(this);

    // Paint the background
    // Translate the painter to ensure the background brush is aligned with the
    // rest of the panel
    p.translate(-x(), -y());
    p.eraseRect(0, 0, x() + width(), y() + height());
    p.translate(x(), y());

    // Taking a detour via a QPixmap is unfortunately the only way we can get
    // the window contents into Qt's backing store.
    QPixmap pixmap(size());
    if (pixmap.paintEngine()->type() != QPaintEngine::X11) {
        // If we're using the raster or OpenGL graphics systems, a QPixmap isn't an X pixmap,
        // so we have to get the window contents into a QImage and then draw that.
        Display *dpy = x11Info().display();

        // XXX We really should keep a cached copy of the image client side, and only
        //     update it in response to a damage event.
        Pixmap pixmap = XCompositeNameWindowPixmap(dpy, clientWinId());

        // Extract XImage from pixmap, trying to cope with different behaviors.
        // There are two possible sizes: 
        // #1: width() x height(), which is 24 x 24 in our situation
        // #2: d->attr.width x d->attr.height
        //
        // - Mumble 1.2.3 returns a correct image when asked for an image of
        // size #1 , but returns a 22 x 22 cropped icon when asked for an image
        // of size #2.
        //
        // - Pidgin 2.7.9 returns a NULL image when asked for an image of size
        // #1 but returns a correct 16 x 16 image when asked for an image of
        // size #2.
        XImage *ximage = XGetImage(dpy, pixmap, 0, 0, width(), height(), AllPlanes, ZPixmap);
        if (!ximage) {
            int ximageWidth = qMin(d->attr.width, width());
            int ximageHeight = qMin(d->attr.height, height());
            ximage = XGetImage(dpy, pixmap, 0, 0, ximageWidth, ximageHeight, AllPlanes, ZPixmap);
        }
        XFreePixmap(dpy, pixmap);
        if (!ximage) {
            //UQ_WARNING << "Failed to get an XImage from X11 window with XID=" << clientWinId();
            return;
        }
        // This is safe to do since we only composite ARGB32 windows, and PictStandardARGB32
        // matches QImage::Format_ARGB32_Premultiplied.
        QImage image((const uchar*)ximage->data, ximage->width, ximage->height, ximage->bytes_per_line,
                     QImage::Format_ARGB32_Premultiplied);

        p.drawImage((width() - image.width()) / 2, (height() - image.height()) / 2, image);

        XDestroyImage(ximage);
    } else {
        pixmap.fill(Qt::transparent);

        XRenderComposite(x11Info().display(), PictOpSrc, d->picture, None, pixmap.x11PictureHandle(),
                         0, 0, 0, 0, 0, 0, width(), height());

        p.drawPixmap(0, 0, pixmap);
    }
}