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

📄 qmousepc_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** 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 "qmousepc_qws.h"#include "qwindowsystem_qws.h"#include "qsocketnotifier.h"#include "qwsevent_qws.h"#include "qwscommand_qws_p.h"#include "qwsutils_qws.h"#include "qapplication.h"#include "qpolygon.h"#include "qtimer.h"#include "qfile.h"#include "qtextstream.h"#include "qstringlist.h"#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <termios.h>#include <qscreen_qws.h>//#define QWS_MOUSE_DEBUG/* * Automatic-detection mouse driver */class QWSPcMouseSubHandler {protected:    enum { max_buf=32 };    int fd;    uchar buffer[max_buf];    int nbuf;    QPoint motion;    int bstate;    int wheel;    int goodness;    int badness;    virtual int tryData()=0;public:    QWSPcMouseSubHandler(int f) : fd(f)    {        initState();    }    virtual ~QWSPcMouseSubHandler() {}    int file() const { return fd; }    void closeIfNot(int& f)    {        if (fd != f) {            f = fd;            close(fd);        }    }    void initState() { nbuf = bstate = goodness = badness = 0; }    void worse(int by=1) { badness+=by; }    bool reliable() const { return goodness >= 5 && badness < 50; }    int buttonState() const { return bstate; }    bool motionPending() const { return motion!=QPoint(0,0); }    QPoint takeMotion() { QPoint r=motion; motion=QPoint(0,0); return r; }    int takeWheel() { int result = wheel; wheel = 0; return result; }    void appendData(uchar* data, int length)    {        memcpy(buffer+nbuf, data, length);        nbuf += length;    }    enum UsageResult { Insufficient, Motion, Button };    UsageResult useData()    {        int pbstate = bstate;        int n = tryData();#ifdef QWS_MOUSE_DEBUG        if (n) {            fprintf(stderr, "QWSPcMouseSubHandler tryData read %d bytes:", n);            for (int i=0; i<n; ++i)                fprintf(stderr, " %02x", buffer[i]);            fprintf(stderr, "\n");        }#endif        if (n > 0) {            if (n<nbuf)                memmove(buffer, buffer+n, nbuf-n);            nbuf -= n;            return (wheel || pbstate != bstate) ? Button : Motion;        }        return Insufficient;    }};class QWSPcMouseSubHandler_intellimouse : public QWSPcMouseSubHandler {    int packetsize;public:    QWSPcMouseSubHandler_intellimouse(int f) : QWSPcMouseSubHandler(f)    {        init();    }    void init()    {        int n;        uchar reply[20];        tcflush(fd,TCIOFLUSH);        static const uchar initseq[] = { 243, 200, 243, 100, 243, 80 };        static const uchar query[] = { 0xf2 };        if (write(fd, initseq, sizeof(initseq))!=sizeof(initseq)) {            badness = 100;            return;        }        usleep(10000);        tcflush(fd,TCIOFLUSH);        if (write(fd, query, sizeof(query))!=sizeof(query)) {            badness = 100;            return;        }        usleep(10000);        n = read(fd, reply, 20);        if (n > 0) {            goodness = 10;            switch (reply[n-1]) {              case 3:              case 4:                packetsize = 4;                break;             default:                packetsize = 3;            }        } else {            badness = 100;        }    }    int tryData()    {        if (nbuf >= packetsize) {            //int overflow = (buffer[0]>>6)& 0x03;            if (/*overflow ||*/ !(buffer[0] & 8)) {                badness++;                return 1;            } else {                QPoint delta((buffer[0] & 0x10) ? buffer[1]-256 : buffer[1],                       (buffer[0] & 0x20) ? 256-buffer[2] : -buffer[2]);                motion += delta;                int nbstate = buffer[0] & 0x7;#ifdef QWS_MOUSE_DEBUG                int debugwheel =#endif                wheel = packetsize > 3 ? -(signed char)buffer[3] : 0;                if (wheel < -2 || wheel > 2)                    wheel = 0;                wheel *= 120; // WHEEL_DELTA?#ifdef QWS_MOUSE_DEBUG                qDebug("Intellimouse: motion %d,%d, state %d, raw wheel %d, wheel %d", motion.x(), motion.y(), nbstate, debugwheel, wheel);#endif                if (motion.x() || motion.y() || bstate != nbstate || wheel) {                    bstate = nbstate;                    goodness++;                } else {                    badness++;                    return 1;                }            }            return packetsize;        }        return 0;    }};class QWSPcMouseSubHandler_mouseman : public QWSPcMouseSubHandler {    int packetsize;public:    QWSPcMouseSubHandler_mouseman(int f) : QWSPcMouseSubHandler(f)    {        init();    }    void init()    {        tcflush(fd,TCIOFLUSH);        write(fd,"",1);        usleep(50000);        write(fd,"@EeI!",5);        usleep(10000);        static const char ibuf[] = { 246, 244 };        write(fd,ibuf,1);        write(fd,ibuf+1,1);        tcflush(fd,TCIOFLUSH);        usleep(10000);        char buf[100];        while (read(fd, buf, 100) > 0) { }  // eat unwanted replies    }    int tryData()    {        if (nbuf >= 3) {            int nbstate = 0;            if (buffer[0] & 0x01)                nbstate |= Qt::LeftButton;            if (buffer[0] & 0x02)                nbstate |= Qt::RightButton;            if (buffer[0] & 0x04)                nbstate |= Qt::MidButton;            int overflow = (buffer[0]>>6)& 0x03;            if (overflow) {                //### wheel events signalled with overflow bit, ignore for now                badness++;                return 1;            } else {                bool xs = buffer[0] & 0x10;                bool ys = buffer[0] & 0x20;                int dx = xs ? buffer[1]-256 : buffer[1];                int dy = ys ? buffer[2]-256 : buffer[2];                motion += QPoint(dx, -dy);                if (motion.x() || motion.y() || bstate != nbstate) {                    bstate = nbstate;                    goodness++;                } else {                    badness++;                    return 1;                }            }            return 3;        }        return 0;    }};class QWSPcMouseSubHandler_serial : public QWSPcMouseSubHandler {public:    QWSPcMouseSubHandler_serial(int f) : QWSPcMouseSubHandler(f)    {        initSerial();    }protected:    void setflags(int f)    {        termios tty;        tcgetattr(fd, &tty);        tty.c_iflag     = IGNBRK | IGNPAR;        tty.c_oflag     = 0;        tty.c_lflag     = 0;        tty.c_cflag     = f | CREAD | CLOCAL | HUPCL;#if !defined(Q_OS_DARWIN) && !defined(Q_OS_SOLARIS) && !defined(Q_OS_INTEGRITY)        tty.c_line      = 0;#endif        tty.c_cc[VTIME] = 0;        tty.c_cc[VMIN]  = 1;        tcsetattr(fd, TCSANOW, &tty);    }private:    void initSerial()    {        int speed[4] = { B9600, B4800, B2400, B1200 };        for (int n = 0; n < 4; n++) {            setflags(CSTOPB | speed[n]);            write(fd, "*q", 2);            usleep(10000);        }    }};class QWSPcMouseSubHandler_mousesystems : public QWSPcMouseSubHandler_serial {public:    // ##### This driver has not been tested    QWSPcMouseSubHandler_mousesystems(int f) : QWSPcMouseSubHandler_serial(f)    {        init();    }    void init()    {        setflags(B1200|CS8|CSTOPB);        // 60Hz        if (write(fd, "R", 1)!=1) {            badness = 100;            return;        }        tcflush(fd,TCIOFLUSH);    }    int tryData()    {        if (nbuf >= 5) {            if ((buffer[0] & 0xf8) != 0x80) {                badness++;                return 1;            }            motion +=                QPoint((signed char)buffer[1] + (signed char)buffer[3],                       -(signed char)buffer[2] + (signed char)buffer[4]);            int t = ~buffer[0];            int nbstate = ((t&3) << 1) | ((t&4) >> 2);            if (motion.x() || motion.y() || bstate != nbstate) {                bstate = nbstate;                goodness++;            } else {                badness++;                return 1;            }            return 5;        }        return 0;    }};class QWSPcMouseSubHandler_ms : public QWSPcMouseSubHandler_serial {    int mman;public:    QWSPcMouseSubHandler_ms(int f) : QWSPcMouseSubHandler_serial(f)    {        mman=0;

⌨️ 快捷键说明

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