Duckstation/src/duckstation-qt/qtutils.h

43 lines
1.3 KiB
C
Raw Normal View History

2019-12-31 06:17:17 +00:00
#pragma once
#include <QtCore/QString>
2020-01-07 08:55:36 +00:00
#include <QtCore/QByteArray>
2019-12-31 06:17:17 +00:00
#include <initializer_list>
#include <optional>
2019-12-31 06:17:17 +00:00
2020-01-07 08:55:36 +00:00
class ByteStream;
class QKeyEvent;
2019-12-31 06:17:17 +00:00
class QTableView;
class QWidget;
2019-12-31 06:17:17 +00:00
namespace QtUtils {
/// Returns the greatest parent of a widget, i.e. its dialog/window.
QWidget* GetRootWidget(QWidget* widget, bool stop_at_window_or_dialog = true);
2019-12-31 06:17:17 +00:00
/// Resizes columns of the table view to at the specified widths. A width of -1 will stretch the column to use the
/// remaining space.
void ResizeColumnsForTableView(QTableView* view, const std::initializer_list<int>& widths);
/// 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);
/// 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);
2019-12-31 06:17:17 +00:00
} // namespace QtUtils