From 77d17d054b8baff411613206a099af36f8e0bc43 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Wed, 21 Jul 2010 16:07:34 +0200 Subject: Quick-and-dirty grabWindoe() implementation for the VNC plugin --- src/plugins/platforms/vnc/qvncintegration.cpp | 44 +++++++++++++++++++++------ src/plugins/platforms/vnc/qvncintegration.h | 2 ++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/vnc/qvncintegration.cpp b/src/plugins/platforms/vnc/qvncintegration.cpp index 16fa5bb..331c16a 100644 --- a/src/plugins/platforms/vnc/qvncintegration.cpp +++ b/src/plugins/platforms/vnc/qvncintegration.cpp @@ -156,16 +156,6 @@ QPixmapData *QVNCIntegration::createPixmapData(QPixmapData::PixelType type) cons return new QRasterPixmapData(type); } -// QWindowSurface *QVNCIntegration::createWindowSurface(QWidget *widget) const -// { -// if (widget->windowType() == Qt::Desktop) -// return 0; // Don't create an explicit window surface for the destkop. -// QFbWindowSurface * surface; -// surface = new QFbWindowSurface(mPrimaryScreen, widget); -// mPrimaryScreen->addWindowSurface(surface); -// return surface; -// } - QWindowSurface *QVNCIntegration::createWindowSurface(QWidget *widget, WId) const { QFbWindowSurface * surface; @@ -192,6 +182,40 @@ QPlatformWindow *QVNCIntegration::createPlatformWindow(QWidget *widget, WId /*wi return w; } +QPixmap QVNCIntegration::grabWindow(WId window, int x, int y, int width, int height) const +{ +// qDebug() << "QVNCIntegration::grabWindow" << window << x << y << width << height; + + if (window == 0) { //desktop + QImage *desktopImage = mPrimaryScreen->image(); + if (x==0 && y == 0 && width < 0 && height < 0) { + return QPixmap::fromImage(*desktopImage); + } + if (width < 0) + width = desktopImage->width() - x; + if (height < 0) + height = desktopImage->height() - y; + int bytesPerPixel = desktopImage->depth()/8; //We don't support 1, 2, or 4 bpp + QImage img(desktopImage->scanLine(y) + bytesPerPixel*x, width, height, desktopImage->bytesPerLine(), desktopImage->format()); + return QPixmap::fromImage(img); + } + QWidget *win = QWidget::find(window); + if (win) { + QRect r = win->geometry(); + if (width < 0) + width = r.width() - x; + if (height < 0) + height = r.height() - y; + QImage *desktopImage = mPrimaryScreen->image(); + int bytesPerPixel = desktopImage->depth()/8; //We don't support 1, 2, or 4 bpp + + QImage img(desktopImage->scanLine(r.top() + y) + bytesPerPixel*(r.left()+x), width, height, desktopImage->bytesPerLine(), desktopImage->format()); + return QPixmap::fromImage(img); + } + return QPixmap(); +} + + void QVNCIntegration::moveToScreen(QWidget *window, int screen) { if (virtualDesktop) { // all windows exist on all screens in virtual desktop mode diff --git a/src/plugins/platforms/vnc/qvncintegration.h b/src/plugins/platforms/vnc/qvncintegration.h index d49e051..241993d 100644 --- a/src/plugins/platforms/vnc/qvncintegration.h +++ b/src/plugins/platforms/vnc/qvncintegration.h @@ -84,6 +84,8 @@ public: QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; + QPixmap grabWindow(WId window, int x, int y, int width, int height) const; + QList screens() const { return mScreens; } bool isVirtualDesktop() { return virtualDesktop; } -- cgit v0.12