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

📄 qcontext2dcanvas.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the example classes 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 "qcontext2dcanvas.h"#include "context2d.h"#include "domimage.h"#include <QApplication>#include <QPainter>#include <QPaintEvent>#include <QMouseEvent>#include <QDateTime>struct FakeDomEvent{    enum KeyCodes  {        DOM_VK_UNDEFINED            = 0x0,        DOM_VK_RIGHT_ALT            = 0x12,        DOM_VK_LEFT_ALT             = 0x12,        DOM_VK_LEFT_CONTROL         = 0x11,        DOM_VK_RIGHT_CONTROL        = 0x11,        DOM_VK_LEFT_SHIFT           = 0x10,        DOM_VK_RIGHT_SHIFT          = 0x10,        DOM_VK_META                 = 0x9D,        DOM_VK_BACK_SPACE           = 0x08,        DOM_VK_CAPS_LOCK            = 0x14,        DOM_VK_DELETE               = 0x7F,        DOM_VK_END                  = 0x23,        DOM_VK_ENTER                = 0x0D,        DOM_VK_ESCAPE               = 0x1B,        DOM_VK_HOME                 = 0x24,        DOM_VK_NUM_LOCK             = 0x90,        DOM_VK_PAUSE                = 0x13,        DOM_VK_PRINTSCREEN          = 0x9A,        DOM_VK_SCROLL_LOCK          = 0x91,        DOM_VK_SPACE                = 0x20,        DOM_VK_TAB                  = 0x09,        DOM_VK_LEFT                 = 0x25,        DOM_VK_RIGHT                = 0x27,        DOM_VK_UP                   = 0x26,        DOM_VK_DOWN                 = 0x28,        DOM_VK_PAGE_DOWN            = 0x22,        DOM_VK_PAGE_UP              = 0x21,        DOM_VK_F1                   = 0x70,        DOM_VK_F2                   = 0x71,        DOM_VK_F3                   = 0x72,        DOM_VK_F4                   = 0x73,        DOM_VK_F5                   = 0x74,        DOM_VK_F6                   = 0x75,        DOM_VK_F7                   = 0x76,        DOM_VK_F8                   = 0x77,        DOM_VK_F9                   = 0x78,        DOM_VK_F10                  = 0x79,        DOM_VK_F11                  = 0x7A,        DOM_VK_F12                  = 0x7B,        DOM_VK_F13                  = 0xF000,        DOM_VK_F14                  = 0xF001,        DOM_VK_F15                  = 0xF002,        DOM_VK_F16                  = 0xF003,        DOM_VK_F17                  = 0xF004,        DOM_VK_F18                  = 0xF005,        DOM_VK_F19                  = 0xF006,        DOM_VK_F20                  = 0xF007,        DOM_VK_F21                  = 0xF008,        DOM_VK_F22                  = 0xF009,        DOM_VK_F23                  = 0xF00A,        DOM_VK_F24                  = 0xF00B    };    FakeDomEvent();    FakeDomEvent(QMouseEvent *e, QScriptEngine *eng);    FakeDomEvent(QKeyEvent *e, QScriptEngine *eng);    void setupModifiers(QInputEvent *e, QScriptEngine *eng);    static int qtToDomKey(int keyCode);    static void setupDefaults(QScriptEngine *e);    static void setup(QScriptEngine *e);    static QScriptValue m_proto;};Q_DECLARE_METATYPE(FakeDomEvent)FakeDomEvent::FakeDomEvent(){}FakeDomEvent::FakeDomEvent(QMouseEvent *e, QScriptEngine *eng){    setupDefaults(eng);    setupModifiers(e, eng);    m_proto.setProperty("type",                        QScriptValue(eng, QLatin1String("mouseevent")));    int button = 0;    if (e->button() == Qt::RightButton)        button = 2;    else if (e->button() == Qt::MidButton)        button = 1;    m_proto.setProperty("button", QScriptValue(eng, button));    m_proto.setProperty("clientX", QScriptValue(eng, e->x()));    m_proto.setProperty("clientY", QScriptValue(eng, e->y()));    m_proto.setProperty("layerX", QScriptValue(eng, e->x()));    m_proto.setProperty("layerY", QScriptValue(eng, e->y()));    m_proto.setProperty("pageX", QScriptValue(eng, e->x()));    m_proto.setProperty("pageY", QScriptValue(eng, e->y()));    m_proto.setProperty("screenX", QScriptValue(eng, e->globalX()));    m_proto.setProperty("screenY", QScriptValue(eng, e->globalY()));    eng->setDefaultPrototype(qMetaTypeId<FakeDomEvent>(), m_proto);}FakeDomEvent::FakeDomEvent(QKeyEvent *e, QScriptEngine *eng){    setupDefaults(eng);    setupModifiers(e, eng);    m_proto.setProperty("type", QScriptValue(eng, QLatin1String("keyevent")));    m_proto.setProperty("isChar", QScriptValue(eng, !e->text().isEmpty()));    m_proto.setProperty("charCode", QScriptValue(eng, e->text()));    m_proto.setProperty("keyCode", QScriptValue(eng, qtToDomKey(e->key())));    m_proto.setProperty("which", QScriptValue(eng, e->key()));    eng->setDefaultPrototype(qMetaTypeId<FakeDomEvent>(), m_proto);}void FakeDomEvent::setupModifiers(QInputEvent *e, QScriptEngine *eng){    if (e->modifiers() & Qt::AltModifier)        m_proto.setProperty("altKey", QScriptValue(eng, true));    else        m_proto.setProperty("altKey", QScriptValue(eng, false));    if (e->modifiers() & Qt::ControlModifier)        m_proto.setProperty("ctrlKey", QScriptValue(eng, true));    else        m_proto.setProperty("ctrlKey", QScriptValue(eng, false));    if (e->modifiers() & Qt::MetaModifier)        m_proto.setProperty("metaKey", QScriptValue(eng, true));    else        m_proto.setProperty("metaKey", QScriptValue(eng, false));    if (e->modifiers() & Qt::ShiftModifier)        m_proto.setProperty("shiftKey", QScriptValue(eng, true));    else        m_proto.setProperty("shiftKey", QScriptValue(eng, true));}int FakeDomEvent::qtToDomKey(int keyCode){    switch (keyCode) {    case Qt::Key_Backspace:        return  DOM_VK_BACK_SPACE;    case Qt::Key_Enter:        return  DOM_VK_ENTER;    case Qt::Key_Return:        return  DOM_VK_ENTER;    case Qt::Key_NumLock:        return  DOM_VK_NUM_LOCK;    case Qt::Key_Alt:        return  DOM_VK_RIGHT_ALT;    case Qt::Key_Control:        return  DOM_VK_LEFT_CONTROL;    case Qt::Key_Shift:        return  DOM_VK_LEFT_SHIFT;    case Qt::Key_Meta:        return  DOM_VK_META;    case Qt::Key_CapsLock:        return  DOM_VK_CAPS_LOCK;    case Qt::Key_Delete:        return  DOM_VK_DELETE;    case Qt::Key_End:        return  DOM_VK_END;    case Qt::Key_Escape:        return  DOM_VK_ESCAPE;    case Qt::Key_Home:        return  DOM_VK_HOME;    case Qt::Key_Pause:        return  DOM_VK_PAUSE;    case Qt::Key_Print:        return  DOM_VK_PRINTSCREEN;    case Qt::Key_ScrollLock:        return  DOM_VK_SCROLL_LOCK;    case Qt::Key_Left:        return  DOM_VK_LEFT;    case Qt::Key_Right:        return  DOM_VK_RIGHT;    case Qt::Key_Up:        return  DOM_VK_UP;    case Qt::Key_Down:        return  DOM_VK_DOWN;    case Qt::Key_PageDown:        return  DOM_VK_PAGE_DOWN;    case Qt::Key_PageUp:        return  DOM_VK_PAGE_UP;    case Qt::Key_F1:        return  DOM_VK_F1;    case Qt::Key_F2:        return  DOM_VK_F2;    case Qt::Key_F3:        return  DOM_VK_F3;    case Qt::Key_F4:        return  DOM_VK_F4;    case Qt::Key_F5:        return  DOM_VK_F5;    case Qt::Key_F6:        return  DOM_VK_F6;    case Qt::Key_F7:        return  DOM_VK_F7;    case Qt::Key_F8:        return  DOM_VK_F8;    case Qt::Key_F9:        return  DOM_VK_F9;    case Qt::Key_F10:        return  DOM_VK_F10;    case Qt::Key_F11:        return  DOM_VK_F11;    case Qt::Key_F12:        return  DOM_VK_F12;    case Qt::Key_F13:        return  DOM_VK_F13;    case Qt::Key_F14:        return  DOM_VK_F14;    case Qt::Key_F15:        return  DOM_VK_F15;    case Qt::Key_F16:        return  DOM_VK_F16;    case Qt::Key_F17:        return  DOM_VK_F17;    case Qt::Key_F18:        return  DOM_VK_F18;    case Qt::Key_F19:        return  DOM_VK_F19;    case Qt::Key_F20:        return  DOM_VK_F20;    case Qt::Key_F21:        return  DOM_VK_F21;    case Qt::Key_F22:        return  DOM_VK_F22;    case Qt::Key_F23:        return  DOM_VK_F23;    case Qt::Key_F24:

⌨️ 快捷键说明

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