Browse Source
[desktop] Port some QtCommon changes from QML branch
[desktop] Port some QtCommon changes from QML branch
- Linker now resolves implementation differences - Remove unneeded ifdefs - Better abstractions overall Signed-off-by: crueter <crueter@eden-emu.dev>pull/3703/head
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
20 changed files with 391 additions and 358 deletions
-
4.ci/license-header.sh
-
1src/CMakeLists.txt
-
6src/qt_common/CMakeLists.txt
-
64src/qt_common/abstract/frontend.cpp
-
84src/qt_common/abstract/frontend.h
-
17src/qt_common/abstract/progress.cpp
-
45src/qt_common/abstract/progress.h
-
4src/qt_common/abstract/qt_progress_dialog.cpp
-
47src/qt_common/abstract/qt_progress_dialog.h
-
10src/qt_common/config/qt_config.cpp
-
13src/qt_common/qt_common.cpp
-
8src/qt_common/qt_common.h
-
156src/qt_common/util/content.cpp
-
2src/qt_common/util/content.h
-
24src/qt_common/util/game.cpp
-
16src/qt_common/util/path.cpp
-
1src/yuzu/CMakeLists.txt
-
119src/yuzu/libqt_common.cpp
-
37src/yuzu/libqt_common.h
-
3src/yuzu/main_window.cpp
@ -1,75 +1,27 @@ |
|||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
|
||||
#include <QLineEdit>
|
|
||||
#include "frontend.h"
|
#include "frontend.h"
|
||||
#include "qt_common/qt_common.h"
|
|
||||
|
|
||||
#ifdef YUZU_QT_WIDGETS
|
|
||||
#include <QFileDialog>
|
|
||||
#endif
|
|
||||
|
|
||||
#include <QAbstractButton>
|
|
||||
#include <QInputDialog>
|
|
||||
|
|
||||
namespace QtCommon::Frontend { |
namespace QtCommon::Frontend { |
||||
|
|
||||
StandardButton ShowMessage(Icon icon, const QString& title, const QString& text, |
|
||||
StandardButtons buttons, QObject* parent) { |
|
||||
#ifdef YUZU_QT_WIDGETS
|
|
||||
QMessageBox* box = new QMessageBox(icon, title, text, buttons, (QWidget*)parent); |
|
||||
return static_cast<QMessageBox::StandardButton>(box->exec()); |
|
||||
#endif
|
|
||||
// TODO(crueter): If Qt Widgets is disabled...
|
|
||||
// need a way to reference icon/buttons too
|
|
||||
} |
|
||||
|
|
||||
const QString GetOpenFileName(const QString& title, const QString& dir, const QString& filter, |
const QString GetOpenFileName(const QString& title, const QString& dir, const QString& filter, |
||||
QString* selectedFilter, Options options) { |
|
||||
#ifdef YUZU_QT_WIDGETS
|
|
||||
return QFileDialog::getOpenFileName(rootObject, title, dir, filter, selectedFilter, options); |
|
||||
#endif
|
|
||||
|
QString* selectedFilter) { |
||||
|
return QFileDialog::getOpenFileName(rootObject, title, dir, filter, selectedFilter); |
||||
} |
} |
||||
|
|
||||
const QStringList GetOpenFileNames(const QString& title, const QString& dir, const QString& filter, |
const QStringList GetOpenFileNames(const QString& title, const QString& dir, const QString& filter, |
||||
QString* selectedFilter, Options options) { |
|
||||
#ifdef YUZU_QT_WIDGETS
|
|
||||
return QFileDialog::getOpenFileNames(rootObject, title, dir, filter, selectedFilter, options); |
|
||||
#endif
|
|
||||
|
QString* selectedFilter) { |
||||
|
return QFileDialog::getOpenFileNames(rootObject, title, dir, filter, selectedFilter); |
||||
} |
} |
||||
|
|
||||
const QString GetSaveFileName(const QString& title, const QString& dir, const QString& filter, |
const QString GetSaveFileName(const QString& title, const QString& dir, const QString& filter, |
||||
QString* selectedFilter, Options options) { |
|
||||
#ifdef YUZU_QT_WIDGETS
|
|
||||
return QFileDialog::getSaveFileName(rootObject, title, dir, filter, selectedFilter, options); |
|
||||
#endif
|
|
||||
} |
|
||||
|
|
||||
const QString GetExistingDirectory(const QString& caption, const QString& dir, Options options) { |
|
||||
#ifdef YUZU_QT_WIDGETS
|
|
||||
return QFileDialog::getExistingDirectory(rootObject, caption, dir, options); |
|
||||
#endif
|
|
||||
} |
|
||||
|
|
||||
int Choice(const QString& title, const QString& caption, const QStringList& options) { |
|
||||
QMessageBox box(rootObject); |
|
||||
box.setText(caption); |
|
||||
box.setWindowTitle(title); |
|
||||
|
|
||||
for (const QString& opt : options) { |
|
||||
box.addButton(opt, QMessageBox::AcceptRole); |
|
||||
} |
|
||||
|
|
||||
box.addButton(QMessageBox::Cancel); |
|
||||
|
|
||||
box.exec(); |
|
||||
auto button = box.clickedButton(); |
|
||||
return options.indexOf(button->text()); |
|
||||
|
QString* selectedFilter) { |
||||
|
return QFileDialog::getSaveFileName(rootObject, title, dir, filter, selectedFilter); |
||||
} |
} |
||||
|
|
||||
const QString GetTextInput(const QString& title, const QString& caption, |
|
||||
const QString& defaultText) { |
|
||||
return QInputDialog::getText(rootObject, title, caption, QLineEdit::Normal, defaultText); |
|
||||
|
const QString GetExistingDirectory(const QString& caption, const QString& dir) { |
||||
|
return QFileDialog::getExistingDirectory(rootObject, caption, dir); |
||||
} |
} |
||||
|
|
||||
} // namespace QtCommon::Frontend
|
} // namespace QtCommon::Frontend
|
||||
@ -0,0 +1,17 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
|
||||
|
#include "progress.h"
|
||||
|
|
||||
|
namespace QtCommon::Frontend { |
||||
|
|
||||
|
QtProgressDialog::QtProgressDialog(const QString&, |
||||
|
const QString&, |
||||
|
int, |
||||
|
int, |
||||
|
QObject* parent, |
||||
|
Qt::WindowFlags) |
||||
|
: QObject(parent) |
||||
|
{} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project |
||||
|
// SPDX-License-Identifier: GPL-3.0-or-later |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <memory> |
||||
|
#include <QObject> |
||||
|
|
||||
|
namespace QtCommon::Frontend { |
||||
|
|
||||
|
class QtProgressDialog : public QObject { |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
QtProgressDialog(const QString& labelText, const QString& cancelButtonText, int minimum, |
||||
|
int maximum, QObject* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); |
||||
|
|
||||
|
virtual ~QtProgressDialog() = default; |
||||
|
|
||||
|
virtual bool wasCanceled() const = 0; |
||||
|
virtual void setWindowModality(Qt::WindowModality modality) = 0; |
||||
|
virtual void setMinimumDuration(int durationMs) = 0; |
||||
|
virtual void setAutoClose(bool autoClose) = 0; |
||||
|
virtual void setAutoReset(bool autoReset) = 0; |
||||
|
|
||||
|
public slots: |
||||
|
virtual void setTitle(QString title) = 0; |
||||
|
virtual void setLabelText(QString text) = 0; |
||||
|
virtual void setMinimum(int min) = 0; |
||||
|
virtual void setMaximum(int max) = 0; |
||||
|
virtual void setValue(int value) = 0; |
||||
|
|
||||
|
virtual bool close() = 0; |
||||
|
virtual void show() = 0; |
||||
|
}; |
||||
|
|
||||
|
std::unique_ptr<QtProgressDialog> newProgressDialog(const QString& labelText, |
||||
|
const QString& cancelButtonText, int minimum, |
||||
|
int maximum, |
||||
|
Qt::WindowFlags f = Qt::WindowFlags()); |
||||
|
|
||||
|
QtProgressDialog* newProgressDialogPtr(const QString& labelText, const QString& cancelButtonText, |
||||
|
int minimum, int maximum, |
||||
|
Qt::WindowFlags f = Qt::WindowFlags()); |
||||
|
|
||||
|
} // namespace QtCommon::Frontend |
||||
@ -1,4 +0,0 @@ |
|||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||
|
|
||||
#include "qt_progress_dialog.h"
|
|
||||
@ -1,47 +0,0 @@ |
|||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project |
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later |
|
||||
|
|
||||
#ifndef QT_PROGRESS_DIALOG_H |
|
||||
#define QT_PROGRESS_DIALOG_H |
|
||||
|
|
||||
#include <QWindow> |
|
||||
|
|
||||
#ifdef YUZU_QT_WIDGETS |
|
||||
#include <QProgressDialog> |
|
||||
#endif |
|
||||
|
|
||||
namespace QtCommon::Frontend { |
|
||||
#ifdef YUZU_QT_WIDGETS |
|
||||
|
|
||||
using QtProgressDialog = QProgressDialog; |
|
||||
|
|
||||
// TODO(crueter): QML impl |
|
||||
#else |
|
||||
class QtProgressDialog |
|
||||
{ |
|
||||
public: |
|
||||
QtProgressDialog(const QString &labelText, |
|
||||
const QString &cancelButtonText, |
|
||||
int minimum, |
|
||||
int maximum, |
|
||||
QObject *parent = nullptr, |
|
||||
Qt::WindowFlags f = Qt::WindowFlags()); |
|
||||
|
|
||||
bool wasCanceled() const; |
|
||||
void setWindowModality(Qt::WindowModality modality); |
|
||||
void setMinimumDuration(int durationMs); |
|
||||
void setAutoClose(bool autoClose); |
|
||||
void setAutoReset(bool autoReset); |
|
||||
|
|
||||
public slots: |
|
||||
void setLabelText(QString &text); |
|
||||
void setRange(int min, int max); |
|
||||
void setValue(int progress); |
|
||||
bool close(); |
|
||||
|
|
||||
void show(); |
|
||||
}; |
|
||||
#endif // YUZU_QT_WIDGETS |
|
||||
|
|
||||
} |
|
||||
#endif // QT_PROGRESS_DIALOG_H |
|
||||
@ -0,0 +1,119 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
|
||||
|
#include <QFileDialog>
|
||||
|
#include <QInputDialog>
|
||||
|
#include <QMessageBox>
|
||||
|
#include <QProgressDialog>
|
||||
|
#include <QAbstractButton>
|
||||
|
|
||||
|
#include "libqt_common.h"
|
||||
|
#include "qt_common/abstract/frontend.h"
|
||||
|
#include "qt_common/abstract/progress.h"
|
||||
|
#include "qt_common/qt_common.h"
|
||||
|
|
||||
|
namespace QtCommon::Frontend { |
||||
|
|
||||
|
StandardButton ShowMessage( |
||||
|
Icon icon, const QString &title, const QString &text, StandardButtons buttons, QObject *parent) |
||||
|
{ |
||||
|
QMessageBox *box = new QMessageBox(QMessageBox::Icon(int(icon)), title, text, QMessageBox::StandardButtons(int(buttons)), (QWidget *) parent); |
||||
|
return StandardButton(box->exec()); |
||||
|
} |
||||
|
|
||||
|
WidgetsProgressDialog::WidgetsProgressDialog(const QString& labelText, |
||||
|
const QString& cancelButtonText, int minimum, |
||||
|
int maximum, QWidget* parent, Qt::WindowFlags f) |
||||
|
: QtProgressDialog(labelText, cancelButtonText, minimum, maximum, parent, f), |
||||
|
m_dialog(new QProgressDialog(labelText, cancelButtonText, minimum, maximum, parent, f)) { |
||||
|
m_dialog->setAutoClose(false); |
||||
|
m_dialog->setAutoReset(false); |
||||
|
m_dialog->setMinimumDuration(100); |
||||
|
m_dialog->setWindowModality(Qt::WindowModal); |
||||
|
} |
||||
|
|
||||
|
bool WidgetsProgressDialog::wasCanceled() const { |
||||
|
return m_dialog->wasCanceled(); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setWindowModality(Qt::WindowModality modality) { |
||||
|
m_dialog->setWindowModality(modality); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setMinimumDuration(int durationMs) { |
||||
|
m_dialog->setMinimumDuration(durationMs); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setAutoClose(bool autoClose) { |
||||
|
m_dialog->setAutoClose(autoClose); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setAutoReset(bool autoReset) { |
||||
|
m_dialog->setAutoReset(autoReset); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setTitle(QString title) { |
||||
|
m_dialog->setWindowTitle(title); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setLabelText(QString text) { |
||||
|
m_dialog->setLabelText(text); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setMinimum(int min) { |
||||
|
m_dialog->setMinimum(min); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setMaximum(int max) { |
||||
|
m_dialog->setMaximum(max); |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::setValue(int value) { |
||||
|
m_dialog->setValue(value); |
||||
|
} |
||||
|
|
||||
|
bool WidgetsProgressDialog::close() { |
||||
|
m_dialog->close(); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void WidgetsProgressDialog::show() { |
||||
|
m_dialog->show(); |
||||
|
} |
||||
|
|
||||
|
std::unique_ptr<QtProgressDialog> newProgressDialog(const QString& labelText, const QString& cancelButtonText, |
||||
|
int minimum, int maximum, Qt::WindowFlags f) { |
||||
|
return std::make_unique<WidgetsProgressDialog>(labelText, cancelButtonText, minimum, maximum, |
||||
|
(QWidget*)rootObject, f); |
||||
|
} |
||||
|
|
||||
|
QtProgressDialog* newProgressDialogPtr(const QString& labelText, const QString& cancelButtonText, |
||||
|
int minimum, int maximum, |
||||
|
Qt::WindowFlags f) { |
||||
|
return new WidgetsProgressDialog(labelText, cancelButtonText, minimum, maximum, |
||||
|
(QWidget*)rootObject, f); |
||||
|
} |
||||
|
|
||||
|
int Choice(const QString& title, const QString& caption, const QStringList& options) { |
||||
|
QMessageBox box(rootObject); |
||||
|
box.setText(caption); |
||||
|
box.setWindowTitle(title); |
||||
|
|
||||
|
for (const QString& opt : options) { |
||||
|
box.addButton(opt, QMessageBox::AcceptRole); |
||||
|
} |
||||
|
|
||||
|
box.addButton(QMessageBox::Cancel); |
||||
|
|
||||
|
box.exec(); |
||||
|
auto button = box.clickedButton(); |
||||
|
return options.indexOf(button->text()); |
||||
|
} |
||||
|
|
||||
|
const QString GetTextInput(const QString& title, const QString& caption, |
||||
|
const QString& defaultText) { |
||||
|
return QInputDialog::getText(rootObject, title, caption, QLineEdit::Normal, defaultText); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} // namespace QtCommon::Frontend
|
||||
@ -0,0 +1,37 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project |
||||
|
// SPDX-License-Identifier: GPL-3.0-or-later |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "qt_common/abstract/progress.h" |
||||
|
|
||||
|
#include <QProgressDialog> |
||||
|
|
||||
|
namespace QtCommon::Frontend { |
||||
|
|
||||
|
class WidgetsProgressDialog : public QtProgressDialog { |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
WidgetsProgressDialog(const QString& labelText, const QString& cancelButtonText, int minimum, |
||||
|
int maximum, QWidget* parent = nullptr, Qt::WindowFlags f = {}); |
||||
|
|
||||
|
bool wasCanceled() const override; |
||||
|
void setWindowModality(Qt::WindowModality modality) override; |
||||
|
void setMinimumDuration(int durationMs) override; |
||||
|
void setAutoClose(bool autoClose) override; |
||||
|
void setAutoReset(bool autoReset) override; |
||||
|
|
||||
|
public slots: |
||||
|
void setTitle(QString title) override; |
||||
|
void setLabelText(QString text) override; |
||||
|
void setMinimum(int min) override; |
||||
|
void setMaximum(int max) override; |
||||
|
void setValue(int value) override; |
||||
|
bool close() override; |
||||
|
void show() override; |
||||
|
|
||||
|
private: |
||||
|
QProgressDialog* m_dialog; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue