* do not add a KStandardAction manually to actionCollection()
[kdenetwork.git] / krfb / qtframebuffer.cpp
blob6fd070e33c93ae4ae1a4915719445f09e74a06f3
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Alessandro Praduroux <pradu@pradu.it>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8 */
10 #include "qtframebuffer.h"
11 #include "qtframebuffer.moc"
13 #include <QTimer>
14 #include <QRegion>
15 #include <QPixmap>
16 #include <QBitmap>
19 const int UPDATE_TIME = 500;
21 QtFrameBuffer::QtFrameBuffer(WId id, QObject *parent)
22 : FrameBuffer(id, parent)
24 fbImage = QPixmap::grabWindow(win).toImage();
25 fb = new char[fbImage.numBytes()];
26 t = new QTimer(this);
27 connect(t, SIGNAL(timeout()), SLOT(updateFrameBuffer()));
31 QtFrameBuffer::~QtFrameBuffer()
33 delete [] fb;
36 int QtFrameBuffer::depth()
38 return fbImage.depth();
41 int QtFrameBuffer::height()
43 return fbImage.height();
46 int QtFrameBuffer::width()
48 return fbImage.width();
51 void QtFrameBuffer::getServerFormat(rfbPixelFormat& format)
53 format.bitsPerPixel = 32;
54 format.depth = 32;
55 format.trueColour = true;
57 format.bigEndian = false;
58 format.redShift = 16;
59 format.greenShift = 8;
60 format.blueShift = 0;
61 format.redMax = 0xff;
62 format.greenMax = 0xff;
63 format.blueMax = 0xff;
66 void QtFrameBuffer::updateFrameBuffer()
68 QImage img = QPixmap::grabWindow(win).toImage();
69 QSize imgSize = img.size();
72 // verify what part of the image need to be marked as changed
73 // fbImage is the previous version of the image,
74 // img is the current one
76 #if 0 // This is actually slower than updating the whole desktop...
78 QImage map(imgSize, QImage::Format_Mono);
79 map.fill(0);
81 for (int x = 0; x < imgSize.width(); x++) {
82 for (int y = 0; y < imgSize.height(); y++) {
83 if (img.pixel(x,y) != fbImage.pixel(x,y)) {
84 map.setPixel(x,y,1);
89 QRegion r(QBitmap::fromImage(map));
90 tiles = tiles + r.rects();
92 #else
93 tiles.append(img.rect());
94 #endif
96 memcpy(fb, (const char*)img.bits(), img.numBytes());
97 fbImage = img;
101 int QtFrameBuffer::paddedWidth()
103 return fbImage.width() * 4;
106 void QtFrameBuffer::startMonitor()
108 t->start(UPDATE_TIME);
111 void QtFrameBuffer::stopMonitor()
113 t->stop();