175 lines
7.4 KiB
C++
175 lines
7.4 KiB
C++
#ifndef __UTILITIES_H__
|
|
#define __UTILITIES_H__
|
|
|
|
#include <QObject>
|
|
#include <QFile>
|
|
#include <QColor>
|
|
#include <QtQml/qqml.h>
|
|
#include <QQuickWindow>
|
|
|
|
#define Q_PROPERTY_AUTO(TYPE, M) \
|
|
Q_PROPERTY(TYPE M MEMBER m_##M NOTIFY M##Changed) \
|
|
public: \
|
|
Q_SIGNAL void M##Changed(); \
|
|
void M(const TYPE &in_##M) { \
|
|
m_##M = in_##M; \
|
|
Q_EMIT M##Changed(); \
|
|
} \
|
|
TYPE M() { \
|
|
return m_##M; \
|
|
} \
|
|
\
|
|
private: \
|
|
TYPE m_##M;
|
|
|
|
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
|
Q_PROPERTY(TYPE M READ M NOTIFY M##Changed FINAL) \
|
|
public: \
|
|
Q_SIGNAL void M##Changed(); \
|
|
void M(const TYPE &in_##M) { \
|
|
m_##M = in_##M; \
|
|
Q_EMIT M##Changed(); \
|
|
} \
|
|
TYPE M() { \
|
|
return m_##M; \
|
|
} \
|
|
\
|
|
private: \
|
|
TYPE m_##M;
|
|
|
|
#define Q_PROPERTY_AUTO_P(TYPE, M) \
|
|
Q_PROPERTY(TYPE M MEMBER m_##M NOTIFY M##Changed) \
|
|
public: \
|
|
Q_SIGNAL void M##Changed(); \
|
|
void M(TYPE in_##M) { \
|
|
m_##M = in_##M; \
|
|
Q_EMIT M##Changed(); \
|
|
} \
|
|
TYPE M() { \
|
|
return m_##M; \
|
|
} \
|
|
\
|
|
private: \
|
|
TYPE m_##M;
|
|
|
|
namespace WindowType {
|
|
Q_NAMESPACE
|
|
enum LaunchMode {
|
|
Standard = 0x0000,
|
|
SingleTask = 0x0001,
|
|
SingleInstance = 0x0002,
|
|
};
|
|
Q_ENUM_NS(LaunchMode)
|
|
QML_ELEMENT
|
|
} // namespace WindowType
|
|
|
|
namespace ThemeType {
|
|
Q_NAMESPACE
|
|
enum DarkMode {
|
|
System = 0x0000,
|
|
Light = 0x0001,
|
|
Dark = 0x0002,
|
|
};
|
|
Q_ENUM_NS(DarkMode)
|
|
QML_ELEMENT
|
|
} // namespace ThemeType
|
|
|
|
namespace ContentDialogType {
|
|
Q_NAMESPACE
|
|
enum ButtonFlag {
|
|
NeutralButton = 0x0001,
|
|
NegativeButton = 0x0002,
|
|
PositiveButton = 0x0004,
|
|
};
|
|
Q_ENUM_NS(ButtonFlag)
|
|
QML_ELEMENT
|
|
} // namespace ContentDialogType
|
|
|
|
class Utilities : public QObject {
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
QML_SINGLETON
|
|
|
|
private:
|
|
explicit Utilities(QObject *parent = nullptr);
|
|
|
|
public:
|
|
static Utilities *instance();
|
|
static Utilities *create(QQmlEngine *, QJSEngine *);
|
|
|
|
Q_INVOKABLE int qtMajor();
|
|
|
|
Q_INVOKABLE int qtMinor();
|
|
|
|
Q_INVOKABLE bool isMacos();
|
|
|
|
Q_INVOKABLE bool isLinux();
|
|
|
|
Q_INVOKABLE bool isWin();
|
|
|
|
Q_INVOKABLE void clipText(const QString &text);
|
|
|
|
Q_INVOKABLE QString uuid();
|
|
|
|
Q_INVOKABLE QString readFile(const QString &fileName);
|
|
|
|
Q_INVOKABLE void setQuitOnLastWindowClosed(bool val);
|
|
|
|
Q_INVOKABLE void setOverrideCursor(Qt::CursorShape shape);
|
|
|
|
Q_INVOKABLE void restoreOverrideCursor();
|
|
|
|
Q_INVOKABLE QString html2PlantText(const QString &html);
|
|
|
|
Q_INVOKABLE QString toLocalPath(const QUrl &url);
|
|
|
|
Q_INVOKABLE void deleteLater(QObject *p);
|
|
|
|
Q_INVOKABLE QString getFileNameByUrl(const QUrl &url);
|
|
|
|
Q_INVOKABLE QRect getVirtualGeometry();
|
|
|
|
Q_INVOKABLE QString getApplicationDirPath();
|
|
|
|
Q_INVOKABLE QUrl getUrlByFilePath(const QString &path);
|
|
|
|
Q_INVOKABLE QColor withOpacity(const QColor &, qreal alpha);
|
|
|
|
Q_INVOKABLE QString md5(const QString &text);
|
|
|
|
Q_INVOKABLE QString sha256(const QString &text);
|
|
|
|
Q_INVOKABLE QString toBase64(const QString &text);
|
|
|
|
Q_INVOKABLE QString fromBase64(const QString &text);
|
|
|
|
Q_INVOKABLE bool removeDir(const QString &dirPath);
|
|
|
|
Q_INVOKABLE bool removeFile(const QString &filePath);
|
|
|
|
Q_INVOKABLE void showFileInFolder(const QString &path);
|
|
|
|
Q_INVOKABLE bool isSoftware();
|
|
|
|
Q_INVOKABLE qint64 currentTimestamp();
|
|
|
|
Q_INVOKABLE QPoint cursorPos();
|
|
|
|
Q_INVOKABLE QIcon windowIcon();
|
|
|
|
Q_INVOKABLE int cursorScreenIndex();
|
|
|
|
Q_INVOKABLE int windowBuildNumber();
|
|
|
|
Q_INVOKABLE bool isWindows11OrGreater();
|
|
|
|
Q_INVOKABLE bool isWindows10OrGreater();
|
|
|
|
Q_INVOKABLE QRect desktopAvailableGeometry(QQuickWindow *window);
|
|
|
|
Q_INVOKABLE QString getWallpaperFilePath();
|
|
|
|
Q_INVOKABLE QColor imageMainColor(const QImage &image, double bright = 1);
|
|
};
|
|
|
|
#endif // __UTILITIES_H__
|