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 "qmlkeyevent.h"
0019 #include <QQmlEngine>
0020 
0021 QmlKeyEvent::QmlKeyEvent(QKeyEvent *keyEvent, QObject *parent)
0022     : QObject(parent)
0023     , m_keyEvent(keyEvent)
0024 {
0025 }
0026 
0027 int QmlKeyEvent::count() const
0028 {
0029     if (!m_keyEvent) {
0030         return -1;
0031     }
0032     return m_keyEvent->count();
0033 }
0034 
0035 bool QmlKeyEvent::isAutoRepeat() const
0036 {
0037     if (!m_keyEvent) {
0038         return false;
0039     }
0040     return m_keyEvent->isAutoRepeat();
0041 }
0042 
0043 int QmlKeyEvent::key() const
0044 {
0045     if (!m_keyEvent) {
0046         return -1;
0047     }
0048     return m_keyEvent->key();
0049 }
0050 
0051 int QmlKeyEvent::modifiers() const
0052 {
0053     if (!m_keyEvent) {
0054         return -1;
0055     }
0056     return static_cast<int>(m_keyEvent->modifiers());
0057 }
0058 
0059 quint32 QmlKeyEvent::nativeModifiers() const
0060 {
0061     if (!m_keyEvent) {
0062         return 0;
0063     }
0064     return static_cast<quint32>(m_keyEvent->nativeModifiers());
0065 }
0066 
0067 quint32 QmlKeyEvent::nativeScanCode() const
0068 {
0069     if (!m_keyEvent) {
0070         return 0;
0071     }
0072     return static_cast<quint32>(m_keyEvent->nativeScanCode());
0073 }
0074 
0075 quint32 QmlKeyEvent::nativeVirtualKey() const
0076 {
0077     if (!m_keyEvent) {
0078         return 0;
0079     }
0080     return static_cast<quint32>(m_keyEvent->nativeVirtualKey());
0081 }
0082 
0083 QString QmlKeyEvent::text() const
0084 {
0085     if (!m_keyEvent) {
0086         return {};
0087     }
0088     return m_keyEvent->text();
0089 }
0090 
0091 void QmlKeyEvent::clear()
0092 {
0093     m_keyEvent = nullptr;
0094 }