File indexing completed on 2024-12-22 04:41:13
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "qmlmouseevent.h" 0019 #include <QQmlEngine> 0020 0021 QmlMouseEvent::QmlMouseEvent(QMouseEvent *mouseEvent, QObject *parent) 0022 : QObject(parent) 0023 , m_mouseEvent(mouseEvent) 0024 { 0025 } 0026 0027 int QmlMouseEvent::button() const 0028 { 0029 if (!m_mouseEvent) { 0030 return -1; 0031 } 0032 return static_cast<int>(m_mouseEvent->button()); 0033 } 0034 0035 int QmlMouseEvent::buttons() const 0036 { 0037 if (!m_mouseEvent) { 0038 return -1; 0039 } 0040 return static_cast<int>(m_mouseEvent->buttons()); 0041 } 0042 0043 QPoint QmlMouseEvent::globalPos() const 0044 { 0045 if (!m_mouseEvent) { 0046 return QPoint(-1, -1); 0047 } 0048 return m_mouseEvent->globalPosition().toPoint(); 0049 } 0050 0051 int QmlMouseEvent::globalX() const 0052 { 0053 if (!m_mouseEvent) { 0054 return -1; 0055 } 0056 return m_mouseEvent->globalPosition().toPoint().x(); 0057 } 0058 0059 int QmlMouseEvent::globalY() const 0060 { 0061 if (!m_mouseEvent) { 0062 return -1; 0063 } 0064 return m_mouseEvent->globalPosition().toPoint().y(); 0065 } 0066 0067 QPointF QmlMouseEvent::localPos() const 0068 { 0069 if (!m_mouseEvent) { 0070 return QPointF(-1, -1); 0071 } 0072 return m_mouseEvent->position(); 0073 } 0074 0075 QPoint QmlMouseEvent::pos() const 0076 { 0077 if (!m_mouseEvent) { 0078 return QPoint(-1, -1); 0079 } 0080 return m_mouseEvent->position().toPoint(); 0081 } 0082 0083 QPointF QmlMouseEvent::screenPos() const 0084 { 0085 if (!m_mouseEvent) { 0086 return QPointF(-1, -1); 0087 } 0088 return m_mouseEvent->globalPosition(); 0089 } 0090 0091 int QmlMouseEvent::source() const 0092 { 0093 if (!m_mouseEvent) { 0094 return -1; 0095 } 0096 return static_cast<int>(m_mouseEvent->source()); 0097 } 0098 0099 QPointF QmlMouseEvent::windowPos() const 0100 { 0101 if (!m_mouseEvent) { 0102 return QPointF(-1, -1); 0103 } 0104 return m_mouseEvent->scenePosition(); 0105 } 0106 0107 int QmlMouseEvent::x() const 0108 { 0109 if (!m_mouseEvent) { 0110 return -1; 0111 } 0112 return m_mouseEvent->position().toPoint().x(); 0113 } 0114 0115 int QmlMouseEvent::y() const 0116 { 0117 if (!m_mouseEvent) { 0118 return -1; 0119 } 0120 return m_mouseEvent->position().toPoint().y(); 0121 } 0122 0123 void QmlMouseEvent::clear() 0124 { 0125 m_mouseEvent = nullptr; 0126 }