2019-12-31 06:17:17 +00:00
|
|
|
#pragma once
|
2020-01-07 08:55:36 +00:00
|
|
|
#include <QtCore/QByteArray>
|
2020-08-29 12:19:28 +00:00
|
|
|
#include <QtCore/QMetaType>
|
2020-05-20 13:25:16 +00:00
|
|
|
#include <QtCore/QString>
|
2020-10-19 15:14:49 +00:00
|
|
|
#include <functional>
|
2019-12-31 06:17:17 +00:00
|
|
|
#include <initializer_list>
|
2020-01-02 06:13:03 +00:00
|
|
|
#include <optional>
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-08-29 12:19:28 +00:00
|
|
|
Q_DECLARE_METATYPE(std::optional<bool>);
|
2020-10-19 15:14:49 +00:00
|
|
|
Q_DECLARE_METATYPE(std::function<void()>);
|
2020-08-29 12:19:28 +00:00
|
|
|
|
2020-01-07 08:55:36 +00:00
|
|
|
class ByteStream;
|
|
|
|
|
2020-09-01 14:00:48 +00:00
|
|
|
class QComboBox;
|
2020-03-21 14:50:09 +00:00
|
|
|
class QFrame;
|
2020-01-06 05:14:47 +00:00
|
|
|
class QKeyEvent;
|
2019-12-31 06:17:17 +00:00
|
|
|
class QTableView;
|
2020-10-19 15:14:49 +00:00
|
|
|
class QTreeView;
|
2020-10-30 14:38:06 +00:00
|
|
|
class QVariant;
|
2020-01-06 05:14:47 +00:00
|
|
|
class QWidget;
|
2020-05-20 13:25:16 +00:00
|
|
|
class QUrl;
|
2019-12-31 06:17:17 +00:00
|
|
|
|
|
|
|
namespace QtUtils {
|
|
|
|
|
2020-03-21 14:50:09 +00:00
|
|
|
/// Creates a horizontal line widget.
|
|
|
|
QFrame* CreateHorizontalLine(QWidget* parent);
|
|
|
|
|
2020-01-06 05:14:47 +00:00
|
|
|
/// Returns the greatest parent of a widget, i.e. its dialog/window.
|
|
|
|
QWidget* GetRootWidget(QWidget* widget, bool stop_at_window_or_dialog = true);
|
|
|
|
|
2020-08-11 18:17:01 +00:00
|
|
|
/// Resizes columns of the table view to at the specified widths. A negative width will stretch the column to use the
|
2019-12-31 06:17:17 +00:00
|
|
|
/// remaining space.
|
|
|
|
void ResizeColumnsForTableView(QTableView* view, const std::initializer_list<int>& widths);
|
2020-10-19 15:14:49 +00:00
|
|
|
void ResizeColumnsForTreeView(QTreeView* view, const std::initializer_list<int>& widths);
|
2019-12-31 06:17:17 +00:00
|
|
|
|
2020-01-02 06:13:03 +00:00
|
|
|
/// Returns a string identifier for a Qt key ID.
|
|
|
|
QString GetKeyIdentifier(int key);
|
|
|
|
|
|
|
|
/// Returns the integer Qt key ID for an identifier.
|
|
|
|
std::optional<int> GetKeyIdForIdentifier(const QString& key_identifier);
|
|
|
|
|
2020-01-06 05:14:47 +00:00
|
|
|
/// Stringizes a key event.
|
|
|
|
QString KeyEventToString(const QKeyEvent* ke);
|
|
|
|
|
|
|
|
/// Returns an integer id for a stringized key event. Modifiers are in the upper bits.
|
|
|
|
std::optional<int> ParseKeyString(const QString& key_str);
|
|
|
|
|
|
|
|
/// Returns a key id for a key event, including any modifiers.
|
|
|
|
int KeyEventToInt(const QKeyEvent* ke);
|
|
|
|
|
2020-01-07 08:55:36 +00:00
|
|
|
/// Reads a whole stream to a Qt byte array.
|
|
|
|
QByteArray ReadStreamToQByteArray(ByteStream* stream, bool rewind = false);
|
|
|
|
|
|
|
|
/// Creates a stream from a Qt byte array.
|
|
|
|
bool WriteQByteArrayToStream(QByteArray& arr, ByteStream* stream);
|
|
|
|
|
2020-05-20 13:25:16 +00:00
|
|
|
/// Opens a URL with the default handler.
|
|
|
|
void OpenURL(QWidget* parent, const QUrl& qurl);
|
|
|
|
|
|
|
|
/// Opens a URL string with the default handler.
|
|
|
|
void OpenURL(QWidget* parent, const char* url);
|
|
|
|
|
2020-09-01 14:00:48 +00:00
|
|
|
/// Fills a combo box with resolution scale options.
|
|
|
|
void FillComboBoxWithResolutionScales(QComboBox* cb);
|
|
|
|
|
2020-10-30 14:38:06 +00:00
|
|
|
/// Fills a combo box with multisampling options.
|
|
|
|
QVariant GetMSAAModeValue(uint multisamples, bool ssaa);
|
|
|
|
void DecodeMSAAModeValue(const QVariant& userdata, uint* multisamples, bool* ssaa);
|
|
|
|
void FillComboBoxWithMSAAModes(QComboBox* cb);
|
|
|
|
|
2020-11-03 11:21:11 +00:00
|
|
|
/// Fills a combo box with emulation speed options.
|
|
|
|
void FillComboBoxWithEmulationSpeeds(QComboBox* cb);
|
|
|
|
|
2020-12-26 14:43:43 +00:00
|
|
|
/// Prompts for an address in hex.
|
|
|
|
std::optional<unsigned> PromptForAddress(QWidget* parent, const QString& title, const QString& label, bool code);
|
2020-12-18 09:04:31 +00:00
|
|
|
|
2019-12-31 06:17:17 +00:00
|
|
|
} // namespace QtUtils
|