qmouse_qws.cpp

来自「QT 开发环境里面一个很重要的文件」· C++ 代码 · 共 577 行 · 第 1/2 页

CPP
577
字号
/******************************************************************************** Copyright (C) 1992-2006 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://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** 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 "qmouse_qws.h"#include "qwindowsystem_qws.h"#include "qscreen_qws.h"#include "qapplication.h"#include "qtextstream.h"#include "qfile.h"#include "qdebug.h"#include "qscreen_qws.h"/*!    \class QWSPointerCalibrationData    \ingroup qws    \brief The QWSPointerCalibrationData class is a container for data    used in calibration of a mouse handler.    QWSPointerCalibrationData stores device and screen coordinates in    the devPoints and screenPoints variables, respectively.    A calibration program should create an instance of this class,    fill the devPoints and screenPoints variables with its device and    screen coordinates, and pass the QWSPointerCalibrationData object    to an instance of the QWSMouseHandler class using the    QWSMouseHandler::calibrate() function.    \sa QWSCalibratedMouseHandler, {qtopiacore/mousecalibration}{Mouse    Calibration Example}*//*!    \variable QWSPointerCalibrationData::devPoints    \brief the raw device coordinates for each value of the Location enum.*//*!    \variable QWSPointerCalibrationData::screenPoints    \brief the logical screen coordinates for each value of the Location enum.*//*!    \enum QWSPointerCalibrationData::Location    This enum describes the various logical positions that can be    specified by the devPoints and screenPoints variables.    \value TopLeft           Index of the top left corner of the screen.    \value BottomLeft     Index of the bottom left corner of the screen.    \value BottomRight   Index of the bottom right corner of the screen.    \value TopRight         Index of the top right corner of the screen.    \value Center            Index of the center of the screen.    \value LastLocation   Last index in the pointer arrays.*/class QWSMouseHandlerPrivate{public:    QWSMouseHandlerPrivate() : screen(qt_screen) {}    const QScreen *screen;};/*!    \class QWSMouseHandler    \ingroup qws    \brief The QWSMouseHandler class is a base class for mouse drivers in    Qtopia Core.    Note that this class is only available in \l {Qtopia Core}.    \l {Qtopia Core} provides ready-made drivers for several mouse    protocols, see the \l {Qtopia Core Pointer Handling}{pointer    handling} documentation for details. Custom mouse drivers can be    implemented by subclassing the QWSMouseHandler class and creating    a mouse driver plugin (derived from QMouseDriverPlugin). \l    {Qtopia Core}'s implementation of the QMouseDriverFactory class    will automatically detect the plugin, and load the driver into the    server application at runtime using Qt's \l {How to Create Qt    Plugins}{plugin system}.    The mouse driver receives mouse events from the system device and    encapsulates each event with an instance of the QWSEvent class    which it then passes to the server application (the server is    responsible for propagating the event to the appropiate    client). To receive mouse events, a QWSMouseHandler object will    usually create a QSocketNotifier object for the given device. The    QSocketNotifier class provides support for monitoring activity on    a file descriptor. When the socket notifier receives data, it will    call the mouse driver's mouseChanged() function to send the event    to the \l {Qtopia Core} server application for relaying to    clients.    If you are creating a driver for a device that needs calibration    or noise reduction, such as a touchscreen, use the    QWSCalibratedMouseHandler subclass instead to take advantage of    the calibrate() and clearCalibration() functions. The \l    {qtopiacore/mousecalibration}{Mouse Calibration example}    demonstrates how to write a simple program using the mechanisms    provided by the QWSMouseHandler class to calibrate a mouse driver.    Note that when deriving from the QWSMouseHandler class, the    resume() and suspend() functions must be reimplemented to control    the flow of mouse input, i.e., the default implementation does    nothing. Reimplementations of these functions typically call the    QSocketNotifier::setEnabled() function to enable or disable the    socket notifier, respectively.    In addition, QWSMouseHandler provides the setScreen() function    that allows you to specify a screen for your mouse driver and the    limitToScreen() function that ensures that a given position is    within this screen's boundaries (changing the position if    necessary). Finally, QWSMouseHandler provides the pos() function    returning the current mouse position.    \sa QMouseDriverPlugin, QMouseDriverFactory, {Qtopia Core Pointer    Handling}*//*!    \fn void QWSMouseHandler::suspend()    Implement this function to suspend reading and handling of mouse    events, e.g., call the QSocketNotifier::setEnabled() function to    disable the socket notifier.    \sa resume()*//*!    \fn void QWSMouseHandler::resume()    Implement this function to resume reading and handling mouse    events, e.g., call the QSocketNotifier::setEnabled() function to    enable the socket notifier.    \sa suspend()*//*!    \fn virtual void QWSMouseHandler::getCalibration(QWSPointerCalibrationData *) const    \internal*//*!    \fn const QPoint &QWSMouseHandler::pos() const    Returns the current mouse position.    \sa mouseChanged(), limitToScreen()*//*!    Constructs a mouse driver. The \a driver and \a device arguments    are passed by the QWS_MOUSE_PROTO environment variable.    Call the QWSServer::setMouseHandler() function to make the newly    created mouse driver, the primary driver. Note that the primary    driver is controlled by the system, i.e., the system will delete    it upon exit.*/QWSMouseHandler::QWSMouseHandler(const QString &, const QString &)    : mousePos(QWSServer::mousePosition), d_ptr(new QWSMouseHandlerPrivate){}/*!    Destroys this mouse driver.    Do not call this function if this driver is the primary mouse    handler, i.e., if QWSServer::setMouseHandler() function has been    called passing this driver as argument. The primary mouse    driver is deleted by the system.*/QWSMouseHandler::~QWSMouseHandler(){    delete d_ptr;}/*!    Ensures that the given \a position is within the screen's    boundaries, changing the \a position if necessary.    \sa pos(), setScreen()*/void QWSMouseHandler::limitToScreen(QPoint &position){    position.setX(qMin(d_ptr->screen->deviceWidth() - 1, qMax(0, position.x())));    position.setY(qMin(d_ptr->screen->deviceHeight() - 1, qMax(0, position.y())));}/*!    \since 4.2    Sets the screen for this mouse driver to be the given \a screen.    \sa limitToScreen()*/void QWSMouseHandler::setScreen(const QScreen *screen){    d_ptr->screen = (screen ? screen : qt_screen);}/*!    Notifies the system of a new mouse event.    This function updates the current mouse position and sends the    event to the \l {Qtopia Core} server application for delivery to    the correct widget.  Note that a custom mouse driver must call    this function whenever it wants to deliver a new mouse event.    The given \a position is the global position of the mouse cursor.    The \a state parameter is a bitmask of the Qt::MouseButton enum's    values, indicating which mouse buttons are pressed. The \a wheel    parameter is the delta value of the mouse wheel as returned by    QWheelEvent::delta().    \sa pos()*/void QWSMouseHandler::mouseChanged(const QPoint &position, int state, int wheel){    mousePos = position + d_ptr->screen->offset();    QWSServer::sendMouseEvent(mousePos, state, wheel);}/*!    \fn QWSMouseHandler::clearCalibration()    This virtual function allows subclasses of QWSMouseHandler to    clear the calibration information. Note that the default    implementation does nothing.    \sa QWSCalibratedMouseHandler::clearCalibration(), calibrate()*//*!    \fn QWSMouseHandler::calibrate(const QWSPointerCalibrationData *data)    This virtual function allows subclasses of QWSMouseHandler to set    the calibration information passed in the given \a data. Note that    the default implementation does nothing.    \sa QWSCalibratedMouseHandler::calibrate(), clearCalibration()*//*!    \class QWSCalibratedMouseHandler    \ingroup qws    \brief The QWSCalibratedMouseHandler class implements a mouse    driver providing calibration and noise reduction.    A mouse driver handles events from system devices and generates    mouse events. Custom mouse drivers can be added by subclassing the    QMouseDriverPlugin class, using the QMouseDriverFactory class to    dynamically load the driver into the application.    Derive from the QWSCalibratedMouseHandler class when the system    device does not have a fixed mapping between device and screen    coordinates and/or produces noisy events, e.g. a touchscreen.    QWSCalibratedMouseHandler provides an implementation of the    calibrate() function to update the calibration parameters based on    coordinate mapping of the given calibration data. The calibration    data is represented by an QWSCalibrationData object. The linear

⌨️ 快捷键说明

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