⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qscreenvnc_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qscreenvnc_qws.h"#ifndef QT_NO_QWS_VNC#include "qscreenvnc_p.h"#include "qwindowsystem_qws.h"#include "qwsdisplay_qws.h"#include "qscreendriverfactory_qws.h"#include <QtCore/qtimer.h>#include <QtCore/qregexp.h>#include <QtGui/qwidget.h>#include <QtGui/qpolygon.h>#include <QtGui/qpainter.h>#include <qdebug.h>#include <private/qwindowsurface_qws_p.h>#include <private/qwssignalhandler_p.h>#include <private/qwidget_p.h>#include <stdlib.h>//#define QT_QWS_VNC_DEBUGextern QString qws_qtePipeFilename();#ifndef QT_NO_QWS_CURSORinline void QVNCCursor::setDirty(const QRect &r) const{    screen->d_ptr->setDirty(r, true);}void QVNCCursor::hide(){    QScreenCursor::hide();    if (enable)        setDirty(boundingRect());}void QVNCCursor::show(){    QScreenCursor::show();    if (!enable)        setDirty(boundingRect());}void QVNCCursor::set(const QImage &image, int hotx, int hoty){    QRegion dirty = boundingRect();    QScreenCursor::set(image, hotx, hoty);    dirty |= boundingRect();    if (enable) {        const QVector<QRect> rects = dirty.rects();        for (int i = 0; i < rects.size(); ++i)            setDirty(rects.at(i));    }}void QVNCCursor::move(int x, int y){    QRegion dirty = boundingRect();    QScreenCursor::move(x, y);    dirty |= boundingRect();    if (enable) {        const QVector<QRect> rects = dirty.rects();        for (int i = 0; i < rects.size(); ++i)            setDirty(rects.at(i));    }}#endif // QT_NO_QWS_CURSORQVNCScreenPrivate::QVNCScreenPrivate(QVNCScreen *parent)    : dpiX(72), dpiY(72), doOnScreenSurface(false), refreshRate(25),      vncServer(0), subscreen(0), q_ptr(parent){#ifndef QT_NO_QWS_MULTIPROCESS    shm = 0;#endif#ifndef QT_NO_QWS_SIGNALHANDLER    QWSSignalHandler::instance()->addObject(this);#endif}QVNCScreenPrivate::~QVNCScreenPrivate(){#ifndef QT_NO_QWS_MULTIPROCESS    if (shm) {        if (QApplication::type() == QApplication::GuiServer)            shm->destroy();        delete shm;    }#else    if (!subscreen) {        delete[] q_ptr->data;        q_ptr->data = 0;    }#endif    delete subscreen;}void QVNCScreenPrivate::configure(){    if (subscreen) {        q_ptr->d = subscreen->depth();        q_ptr->w = subscreen->width();        q_ptr->h = subscreen->height();        q_ptr->dw = subscreen->deviceWidth();        q_ptr->dh = subscreen->deviceHeight();        q_ptr->lstep = subscreen->linestep();        q_ptr->data = subscreen->base();        q_ptr->physWidth = subscreen->physicalWidth();        q_ptr->physHeight = subscreen->physicalHeight();        q_ptr->setPixelFormat(subscreen->pixelFormat());        q_ptr->setOffset(subscreen->offset());    } else {        q_ptr->lstep = (q_ptr->dw * q_ptr->d + 7) / 8;        q_ptr->size = q_ptr->h * q_ptr->lstep;        q_ptr->mapsize = q_ptr->size;        q_ptr->physWidth = qRound(q_ptr->dw * 25.4 / dpiX);        q_ptr->physHeight = qRound(q_ptr->dh * 25.4 / dpiY);        switch (q_ptr->d) {        case 1:            q_ptr->setPixelFormat(QImage::Format_Mono); //### LSB???            break;        case 8:            q_ptr->setPixelFormat(QImage::Format_Indexed8);            break;        case 16:            q_ptr->setPixelFormat(QImage::Format_RGB16);            break;        case 32:            q_ptr->setPixelFormat(QImage::Format_ARGB32_Premultiplied);            break;        }#ifndef QT_NO_QWS_MULTIPROCESS        if (shm) {            if (QApplication::type() == QApplication::GuiServer)                shm->destroy();            delete shm;        }        shm = new QSharedMemory(q_ptr->size, qws_qtePipeFilename(),                                q_ptr->displayId);        if (!shm->create())            qDebug("QVNCScreen could not create shared memory");        if (!shm->attach())            qDebug("QVNCScreen could not attach to shared memory");        q_ptr->data = reinterpret_cast<uchar*>(shm->base());#else        if (q_ptr->data)            delete[] q_ptr->data;        q_ptr->data = new uchar[q_ptr->size];#endif    }}//===========================================================================static const struct {    int keysym;    int keycode;} keyMap[] = {    { 0xff08, Qt::Key_Backspace },    { 0xff09, Qt::Key_Tab       },    { 0xff0d, Qt::Key_Return    },    { 0xff1b, Qt::Key_Escape    },    { 0xff63, Qt::Key_Insert    },    { 0xffff, Qt::Key_Delete    },    { 0xff50, Qt::Key_Home      },    { 0xff57, Qt::Key_End       },    { 0xff55, Qt::Key_PageUp    },    { 0xff56, Qt::Key_PageDown  },    { 0xff51, Qt::Key_Left      },    { 0xff52, Qt::Key_Up        },    { 0xff53, Qt::Key_Right     },    { 0xff54, Qt::Key_Down      },    { 0xffbe, Qt::Key_F1        },    { 0xffbf, Qt::Key_F2        },    { 0xffc0, Qt::Key_F3        },    { 0xffc1, Qt::Key_F4        },    { 0xffc2, Qt::Key_F5        },    { 0xffc3, Qt::Key_F6        },    { 0xffc4, Qt::Key_F7        },    { 0xffc5, Qt::Key_F8        },    { 0xffc6, Qt::Key_F9        },    { 0xffc7, Qt::Key_F10       },    { 0xffc8, Qt::Key_F11       },    { 0xffc9, Qt::Key_F12       },    { 0xffe1, Qt::Key_Shift     },    { 0xffe2, Qt::Key_Shift     },    { 0xffe3, Qt::Key_Control   },    { 0xffe4, Qt::Key_Control   },    { 0xffe7, Qt::Key_Meta      },    { 0xffe8, Qt::Key_Meta      },    { 0xffe9, Qt::Key_Alt       },    { 0xffea, Qt::Key_Alt       },    { 0, 0 }};void QRfbRect::read(QTcpSocket *s){    quint16 buf[4];    s->read((char*)buf, 8);    x = ntohs(buf[0]);    y = ntohs(buf[1]);    w = ntohs(buf[2]);    h = ntohs(buf[3]);}void QRfbRect::write(QTcpSocket *s) const{    quint16 buf[4];    buf[0] = htons(x);    buf[1] = htons(y);    buf[2] = htons(w);    buf[3] = htons(h);    s->write((char*)buf, 8);}void QRfbPixelFormat::read(QTcpSocket *s){    char buf[16];    s->read(buf, 16);    bitsPerPixel = buf[0];    depth = buf[1];    bigEndian = buf[2];    trueColor = buf[3];    quint16 a = ntohs(*(quint16 *)(buf + 4));    redBits = 0;    while (a) { a >>= 1; redBits++; }    a = ntohs(*(quint16 *)(buf + 6));    greenBits = 0;    while (a) { a >>= 1; greenBits++; }    a = ntohs(*(quint16 *)(buf + 8));    blueBits = 0;    while (a) { a >>= 1; blueBits++; }    redShift = buf[10];    greenShift = buf[11];    blueShift = buf[12];}void QRfbPixelFormat::write(QTcpSocket *s){    char buf[16];    buf[0] = bitsPerPixel;    buf[1] = depth;    buf[2] = bigEndian;    buf[3] = trueColor;    quint16 a = 0;    for (int i = 0; i < redBits; i++) a = (a << 1) | 1;    *(quint16 *)(buf + 4) = htons(a);    a = 0;    for (int i = 0; i < greenBits; i++) a = (a << 1) | 1;    *(quint16 *)(buf + 6) = htons(a);    a = 0;    for (int i = 0; i < blueBits; i++) a = (a << 1) | 1;    *(quint16 *)(buf + 8) = htons(a);    buf[10] = redShift;    buf[11] = greenShift;    buf[12] = blueShift;    s->write(buf, 16);}void QRfbServerInit::setName(const char *n){    delete[] name;    name = new char [strlen(n) + 1];    strcpy(name, n);}void QRfbServerInit::read(QTcpSocket *s){    s->read((char *)&width, 2);    width = ntohs(width);    s->read((char *)&height, 2);    height = ntohs(height);    format.read(s);    quint32 len;    s->read((char *)&len, 4);    len = ntohl(len);    name = new char [len + 1];    s->read(name, len);    name[len] = '\0';}void QRfbServerInit::write(QTcpSocket *s){    quint16 t = htons(width);    s->write((char *)&t, 2);    t = htons(height);    s->write((char *)&t, 2);    format.write(s);    quint32 len = strlen(name);    len = htonl(len);    s->write((char *)&len, 4);    s->write(name, strlen(name));}bool QRfbSetEncodings::read(QTcpSocket *s){    if (s->bytesAvailable() < 3)        return false;    char tmp;    s->read(&tmp, 1);        // padding    s->read((char *)&count, 2);    count = ntohs(count);    return true;}bool QRfbFrameBufferUpdateRequest::read(QTcpSocket *s){    if (s->bytesAvailable() < 9)        return false;    s->read(&incremental, 1);    rect.read(s);    return true;}bool QRfbKeyEvent::read(QTcpSocket *s){    if (s->bytesAvailable() < 7)        return false;    s->read(&down, 1);    quint16 tmp;    s->read((char *)&tmp, 2);  // padding    quint32 key;    s->read((char *)&key, 4);    key = ntohl(key);    unicode = 0;    keycode = 0;    int i = 0;    while (keyMap[i].keysym && !keycode) {        if (keyMap[i].keysym == (int)key)            keycode = keyMap[i].keycode;        i++;    }    if (!keycode) {        if (key <= 0xff) {            unicode = key;            if (key >= 'a' && key <= 'z')                keycode = Qt::Key_A + key - 'a';            else if (key >= ' ' && key <= '~')                keycode = Qt::Key_Space + key - ' ';        }    }    return true;}bool QRfbPointerEvent::read(QTcpSocket *s){    if (s->bytesAvailable() < 5)        return false;    char buttonMask;    s->read(&buttonMask, 1);    buttons = 0;    if (buttonMask & 1)        buttons |= Qt::LeftButton;    if (buttonMask & 2)        buttons |= Qt::MidButton;    if (buttonMask & 4)        buttons |= Qt::RightButton;    quint16 tmp;    s->read((char *)&tmp, 2);    x = ntohs(tmp);    s->read((char *)&tmp, 2);    y = ntohs(tmp);    return true;}bool QRfbClientCutText::read(QTcpSocket *s){    if (s->bytesAvailable() < 7)        return false;    char tmp[3];    s->read(tmp, 3);        // padding    s->read((char *)&length, 4);    length = ntohl(length);    return true;}//===========================================================================QVNCServer::QVNCServer(QVNCScreen *screen)    : qvnc_screen(screen){    init(5900);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -