File indexing completed on 2025-01-12 03:58:10
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "base_dialog.hpp" 0008 0009 0010 #include <QPainter> 0011 #include <QPaintEvent> 0012 #include <QKeyEvent> 0013 #include <QDebug> 0014 0015 glaxnimate::android::BaseDialog::BaseDialog(QWidget *parent) 0016 : QDialog(parent) 0017 { 0018 // setWindowFlags(Qt::Window); 0019 // setAttribute(Qt::WA_TranslucentBackground, false); 0020 // setWindowState(windowState() | Qt::WindowFullScreen); 0021 #ifdef Q_OS_ANDROID 0022 showMaximized(); 0023 #endif 0024 setVisible(false); 0025 } 0026 0027 int glaxnimate::android::BaseDialog::exec() 0028 { 0029 #ifdef Q_OS_ANDROID 0030 showMaximized(); 0031 #endif 0032 setFocus(); 0033 return QDialog::exec(); 0034 } 0035 0036 void glaxnimate::android::BaseDialog::paintEvent(QPaintEvent *ev) 0037 { 0038 QPainter p(this); 0039 p.fillRect(ev->rect(), palette().window()); 0040 QDialog::paintEvent(ev); 0041 0042 } 0043 0044 void glaxnimate::android::BaseDialog::keyReleaseEvent(QKeyEvent * ev) 0045 { 0046 QDialog::keyReleaseEvent(ev); 0047 0048 if ( ev->key() == Qt::Key_Back ) 0049 { 0050 reject(); 0051 ev->accept(); 0052 } 0053 } 0054 0055 bool glaxnimate::android::BaseDialog::eventFilter(QObject *object, QEvent *event) 0056 { 0057 if ( event->type() == QEvent::KeyPress ) 0058 { 0059 auto key_event = static_cast<QKeyEvent*>(event); 0060 if ( key_event->key() == Qt::Key_Back ) 0061 { 0062 reject(); 0063 return true; 0064 } 0065 } 0066 0067 return QDialog::eventFilter(object, event); 0068 } 0069 0070 glaxnimate::android::DialogFixerFilter::DialogFixerFilter(QDialog *target) 0071 { 0072 set_target(target); 0073 } 0074 0075 void glaxnimate::android::DialogFixerFilter::set_target(QDialog *target) 0076 { 0077 if ( target ) 0078 { 0079 target->installEventFilter(this); 0080 bool visible = target->isVisible(); 0081 target->showMaximized(); 0082 if ( !visible ) 0083 target->hide(); 0084 } 0085 } 0086 0087 bool glaxnimate::android::DialogFixerFilter::eventFilter(QObject *object, QEvent *event) 0088 { 0089 if ( target ) 0090 { 0091 if ( event->type() == QEvent::KeyRelease ) 0092 { 0093 auto key_event = static_cast<QKeyEvent*>(event); 0094 if ( key_event->key() == Qt::Key_Back ) 0095 target->reject(); 0096 } 0097 } 0098 0099 return QObject::eventFilter(object, event); 0100 }