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

📄 qcursor_x11.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 <qdatastream.h>#include <private/qcursor_p.h>#include <private/qt_x11_p.h>#include <qbitmap.h>#include <qcursor.h>#include <X11/cursorfont.h>#ifndef QT_NO_XCURSOR#  include <X11/Xcursor/Xcursor.h>#endif // QT_NO_XCURSOR#ifndef QT_NO_XFIXES#  include <X11/extensions/Xfixes.h>#endif // QT_NO_XFIXES#include "qx11info_x11.h"// Define QT_USE_APPROXIMATE_CURSORS when compiling if you REALLY want to// use the ugly X11 cursors.extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp/*****************************************************************************  Internal QCursorData class *****************************************************************************/QCursorData::QCursorData(Qt::CursorShape s)    : cshape(s), bm(0), bmm(0), hx(0), hy(0), hcurs(0), pm(0), pmm(0){    ref = 1;}QCursorData::~QCursorData(){    Display *dpy = X11 ? X11->display : (Display*)0;    // Add in checking for the display too as on HP-UX    // we seem to get a core dump as the cursor data is    // deleted again from main() on exit...    if (hcurs && dpy)        XFreeCursor(dpy, hcurs);    if (pm && dpy)        XFreePixmap(dpy, pm);    if (pmm && dpy)        XFreePixmap(dpy, pmm);    delete bm;    delete bmm;}QCursor::QCursor(Qt::HANDLE cursor){    if (!QCursorData::initialized)        QCursorData::initialize();    d = new QCursorData(Qt::CustomCursor);    d->hcurs = cursor;}QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY){    if (!QCursorData::initialized)        QCursorData::initialize();    if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {        qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");        QCursorData *c = qt_cursorTable[0];        c->ref.ref();        return c;    }    QCursorData *d = new QCursorData;    d->ref = 1;    d->bm  = new QBitmap(bitmap);    d->bmm = new QBitmap(mask);    d->hcurs = 0;    d->cshape = Qt::BitmapCursor;    d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;    d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;    d->fg.red   = 0x0000;    d->fg.green = 0x0000;    d->fg.blue  = 0x0000;    d->bg.red   = 0xffff;    d->bg.green = 0xffff;    d->bg.blue  = 0xffff;    return d;}Qt::HANDLE QCursor::handle() const{    if (!QCursorData::initialized)        QCursorData::initialize();    if (!d->hcurs)        d->update();    return d->hcurs;}/*!    Returns the position of the cursor (hot spot) in global screen    coordinates.    You can call QWidget::mapFromGlobal() to translate it to widget    coordinates.    \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()*/QPoint QCursor::pos(){    Window root;    Window child;    int root_x, root_y, win_x, win_y;    uint buttons;    Display* dpy = X11->display;    for (int i = 0; i < ScreenCount(dpy); ++i) {        if (XQueryPointer(dpy, QX11Info::appRootWindow(i), &root, &child, &root_x, &root_y,                          &win_x, &win_y, &buttons))            return QPoint(root_x, root_y);    }    return QPoint();}/*! \internal*/int QCursor::x11Screen(){    Window root;    Window child;    int root_x, root_y, win_x, win_y;    uint buttons;    Display* dpy = X11->display;    for (int i = 0; i < ScreenCount(dpy); ++i) {        if (XQueryPointer(dpy, QX11Info::appRootWindow(i), &root, &child, &root_x, &root_y,                          &win_x, &win_y, &buttons))            return i;    }    return -1;}/*!    Moves the cursor (hot spot) to the global screen position (\a x,    \a y).    You can call QWidget::mapToGlobal() to translate widget    coordinates to global screen coordinates.    \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()*/void QCursor::setPos(int x, int y){    QPoint current, target(x, y);    // this is copied from pos(), since we need the screen number for the correct    // root window in the XWarpPointer call    Window root;    Window child;    int root_x, root_y, win_x, win_y;    uint buttons;    Display* dpy = X11->display;    int screen;    for (screen = 0; screen < ScreenCount(dpy); ++screen) {        if (XQueryPointer(dpy, QX11Info::appRootWindow(screen), &root, &child, &root_x, &root_y,                          &win_x, &win_y, &buttons)) {            current = QPoint(root_x, root_y);            break;        }    }    if (screen >= ScreenCount(dpy))        return;    // Need to check, since some X servers generate null mouse move    // events, causing looping in applications which call setPos() on    // every mouse move event.    //    if (current == target)        return;    XWarpPointer(X11->display, XNone, QX11Info::appRootWindow(screen), 0, 0, 0, 0, x, y);}/*!    \fn void QCursor::setPos (const QPoint &p)    \overload    Moves the cursor (hot spot) to the global screen position at point    \a p.*//*!    \internal    Creates the cursor.*/void QCursorData::update(){    if (!QCursorData::initialized)        QCursorData::initialize();    if (hcurs)        return;    Display *dpy = X11->display;    Window rootwin = QX11Info::appRootWindow();    if (cshape == Qt::BitmapCursor) {#ifndef QT_NO_XRENDER        if (!pixmap.isNull() && X11->use_xrender) {            hcurs = XRenderCreateCursor (X11->display, pixmap.x11PictureHandle(), hx, hy);        } else#endif        {            hcurs = XCreatePixmapCursor(dpy, bm->handle(), bmm->handle(), &fg, &bg, hx, hy);        }        return;    }    static const char *cursorNames[] = {        "left_ptr",        "up_arrow",        "cross",        "wait",        "ibeam",        "size_ver",        "size_hor",        "size_bdiag",        "size_fdiag",        "size_all",        "blank",        "split_v",        "split_h",        "pointing_hand",        "forbidden",        "whats_this",        "left_ptr_watch",        "openhand",        "closedhand"    };#ifndef QT_NO_XCURSOR    hcurs = XcursorLibraryLoadCursor(dpy, cursorNames[cshape]);    if (hcurs)        return;#endif // QT_NO_XCURSOR    static const char cur_blank_bits[] = {        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };    // Non-standard X11 cursors are created from bitmaps#ifndef QT_USE_APPROXIMATE_CURSORS    static const char cur_ver_bits[] = {        0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,        0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f,        0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 };    static const char mcur_ver_bits[] = {        0x00, 0x00, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f,        0xfc, 0x7f, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xfc, 0x7f, 0xf8, 0x3f,        0xf0, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03 };    static const char cur_hor_bits[] = {        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x30, 0x18,

⌨️ 快捷键说明

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