mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-28 22:09:01 +02:00
[desktop] Port some QtCommon changes from QML branch (#3703)
- Linker now resolves implementation differences - Remove unneeded ifdefs - Better abstractions overall Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3703 Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
parent
07e3a2aa46
commit
0ff1d215c8
36 changed files with 405 additions and 371 deletions
|
|
@ -1,75 +1,27 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <QLineEdit>
|
||||
#include "frontend.h"
|
||||
#include "qt_common/qt_common.h"
|
||||
|
||||
#ifdef YUZU_QT_WIDGETS
|
||||
#include <QFileDialog>
|
||||
#endif
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QInputDialog>
|
||||
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
QString* selectedFilter, Options options) {
|
||||
#ifdef YUZU_QT_WIDGETS
|
||||
return QFileDialog::getSaveFileName(rootObject, title, dir, filter, selectedFilter, options);
|
||||
#endif
|
||||
QString* selectedFilter) {
|
||||
return QFileDialog::getSaveFileName(rootObject, title, dir, filter, selectedFilter);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -7,11 +7,7 @@
|
|||
#include <QGuiApplication>
|
||||
#include "qt_common/qt_common.h"
|
||||
|
||||
#ifdef YUZU_QT_WIDGETS
|
||||
#include <QFileDialog>
|
||||
#include <QWidget>
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* manages common functionality e.g. message boxes and such for Qt/QML
|
||||
|
|
@ -20,60 +16,39 @@ namespace QtCommon::Frontend {
|
|||
|
||||
Q_NAMESPACE
|
||||
|
||||
#ifdef YUZU_QT_WIDGETS
|
||||
using Options = QFileDialog::Options;
|
||||
using Option = QFileDialog::Option;
|
||||
|
||||
using StandardButton = QMessageBox::StandardButton;
|
||||
using StandardButtons = QMessageBox::StandardButtons;
|
||||
|
||||
using Icon = QMessageBox::Icon;
|
||||
#else
|
||||
enum Option {
|
||||
ShowDirsOnly = 0x00000001,
|
||||
DontResolveSymlinks = 0x00000002,
|
||||
DontConfirmOverwrite = 0x00000004,
|
||||
DontUseNativeDialog = 0x00000008,
|
||||
ReadOnly = 0x00000010,
|
||||
HideNameFilterDetails = 0x00000020,
|
||||
DontUseCustomDirectoryIcons = 0x00000040
|
||||
};
|
||||
Q_ENUM_NS(Option)
|
||||
Q_DECLARE_FLAGS(Options, Option)
|
||||
Q_FLAG_NS(Options)
|
||||
|
||||
enum StandardButton {
|
||||
// keep this in sync with QDialogButtonBox::StandardButton and QPlatformDialogHelper::StandardButton
|
||||
NoButton = 0x00000000,
|
||||
Ok = 0x00000400,
|
||||
Save = 0x00000800,
|
||||
SaveAll = 0x00001000,
|
||||
Open = 0x00002000,
|
||||
Yes = 0x00004000,
|
||||
YesToAll = 0x00008000,
|
||||
No = 0x00010000,
|
||||
NoToAll = 0x00020000,
|
||||
Abort = 0x00040000,
|
||||
Retry = 0x00080000,
|
||||
Ignore = 0x00100000,
|
||||
Close = 0x00200000,
|
||||
Cancel = 0x00400000,
|
||||
Discard = 0x00800000,
|
||||
Help = 0x01000000,
|
||||
Apply = 0x02000000,
|
||||
Reset = 0x04000000,
|
||||
RestoreDefaults = 0x08000000,
|
||||
// keep this in sync with QDialogButtonBox::StandardButton and
|
||||
// QPlatformDialogHelper::StandardButton
|
||||
NoButton = 0x00000000,
|
||||
Ok = 0x00000400,
|
||||
Save = 0x00000800,
|
||||
SaveAll = 0x00001000,
|
||||
Open = 0x00002000,
|
||||
Yes = 0x00004000,
|
||||
YesToAll = 0x00008000,
|
||||
No = 0x00010000,
|
||||
NoToAll = 0x00020000,
|
||||
Abort = 0x00040000,
|
||||
Retry = 0x00080000,
|
||||
Ignore = 0x00100000,
|
||||
Close = 0x00200000,
|
||||
Cancel = 0x00400000,
|
||||
Discard = 0x00800000,
|
||||
Help = 0x01000000,
|
||||
Apply = 0x02000000,
|
||||
Reset = 0x04000000,
|
||||
RestoreDefaults = 0x08000000,
|
||||
|
||||
FirstButton = Ok, // internal
|
||||
LastButton = RestoreDefaults, // internal
|
||||
FirstButton = Ok, // internal
|
||||
LastButton = RestoreDefaults, // internal
|
||||
|
||||
YesAll = YesToAll, // obsolete
|
||||
NoAll = NoToAll, // obsolete
|
||||
YesAll = YesToAll, // obsolete
|
||||
NoAll = NoToAll, // obsolete
|
||||
|
||||
Default = 0x00000100, // obsolete
|
||||
Escape = 0x00000200, // obsolete
|
||||
FlagMask = 0x00000300, // obsolete
|
||||
ButtonMask = ~FlagMask // obsolete
|
||||
Default = 0x00000100, // obsolete
|
||||
Escape = 0x00000200, // obsolete
|
||||
FlagMask = 0x00000300, // obsolete
|
||||
ButtonMask = ~FlagMask // obsolete
|
||||
};
|
||||
Q_ENUM_NS(StandardButton)
|
||||
|
||||
|
|
@ -83,7 +58,7 @@ typedef StandardButton Button;
|
|||
Q_DECLARE_FLAGS(StandardButtons, StandardButton)
|
||||
Q_FLAG_NS(StandardButtons)
|
||||
|
||||
enum Icon {
|
||||
enum class Icon {
|
||||
// keep this in sync with QMessageDialogOptions::StandardIcon
|
||||
NoIcon = 0,
|
||||
Information = 1,
|
||||
|
|
@ -93,29 +68,26 @@ enum Icon {
|
|||
};
|
||||
Q_ENUM_NS(Icon)
|
||||
|
||||
#endif
|
||||
|
||||
// TODO(crueter) widgets-less impl, choices et al.
|
||||
StandardButton ShowMessage(Icon icon,
|
||||
const QString &title,
|
||||
const QString &text,
|
||||
StandardButton ShowMessage(Icon icon, const QString& title, const QString& text,
|
||||
StandardButtons buttons = StandardButton::NoButton,
|
||||
QObject *parent = nullptr);
|
||||
QObject* parent = nullptr);
|
||||
|
||||
#define UTIL_OVERRIDES(level) \
|
||||
inline StandardButton level(QObject *parent, \
|
||||
const QString &title, \
|
||||
const QString &text, \
|
||||
StandardButtons buttons = StandardButton::Ok) \
|
||||
{ \
|
||||
return ShowMessage(Icon::level, title, text, buttons, parent); \
|
||||
} \
|
||||
inline StandardButton level(const QString title, \
|
||||
const QString &text, \
|
||||
StandardButtons buttons \
|
||||
= StandardButton::Ok) \
|
||||
{ \
|
||||
return ShowMessage(Icon::level, title, text, buttons, rootObject); \
|
||||
#define UTIL_OVERRIDES(level) \
|
||||
inline StandardButton level(QObject* parent, const QString& title, const QString& text, \
|
||||
StandardButtons buttons) { \
|
||||
return ShowMessage(Icon::level, title, text, buttons, parent); \
|
||||
} \
|
||||
inline StandardButton level(QObject* parent, const QString& title, const QString& text, \
|
||||
int buttons = StandardButton::Ok) { \
|
||||
return ShowMessage(Icon::level, title, text, StandardButtons(buttons), parent); \
|
||||
} \
|
||||
inline StandardButton level(const QString title, const QString& text, \
|
||||
StandardButtons buttons) { \
|
||||
return ShowMessage(Icon::level, title, text, buttons, rootObject); \
|
||||
} \
|
||||
inline StandardButton level(const QString& title, const QString& text, \
|
||||
int buttons = StandardButton::Ok) { \
|
||||
return ShowMessage(Icon::level, title, text, StandardButtons(buttons), rootObject); \
|
||||
}
|
||||
|
||||
UTIL_OVERRIDES(Information)
|
||||
|
|
@ -123,27 +95,17 @@ UTIL_OVERRIDES(Warning)
|
|||
UTIL_OVERRIDES(Critical)
|
||||
UTIL_OVERRIDES(Question)
|
||||
|
||||
const QString GetOpenFileName(const QString &title,
|
||||
const QString &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter = nullptr,
|
||||
Options options = Options());
|
||||
const QString GetOpenFileName(const QString& title, const QString& dir, const QString& filter,
|
||||
QString* selectedFilter = nullptr);
|
||||
|
||||
const QStringList GetOpenFileNames(const QString &title,
|
||||
const QString &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter = nullptr,
|
||||
Options options = Options());
|
||||
const QStringList GetOpenFileNames(const QString& title, const QString& dir, const QString& filter,
|
||||
QString* selectedFilter = nullptr);
|
||||
|
||||
const QString GetSaveFileName(const QString &title,
|
||||
const QString &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter = nullptr,
|
||||
Options options = Options());
|
||||
const QString GetSaveFileName(const QString& title, const QString& dir, const QString& filter,
|
||||
QString* selectedFilter = nullptr);
|
||||
|
||||
const QString GetExistingDirectory(const QString &caption = QString(),
|
||||
const QString &dir = QString(),
|
||||
Options options = Option::ShowDirsOnly);
|
||||
const QString GetExistingDirectory(const QString& caption = QString(),
|
||||
const QString& dir = QString());
|
||||
|
||||
int Choice(const QString& title = QString(), const QString& caption = QString(),
|
||||
const QStringList& options = {});
|
||||
|
|
|
|||
17
src/qt_common/abstract/progress.cpp
Normal file
17
src/qt_common/abstract/progress.cpp
Normal file
|
|
@ -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)
|
||||
{}
|
||||
|
||||
}
|
||||
45
src/qt_common/abstract/progress.h
Normal file
45
src/qt_common/abstract/progress.h
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue