This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/example/doric/utils/DoricUtils.h

55 lines
1.3 KiB
C
Raw Normal View History

2021-02-04 16:59:58 +08:00
#ifndef UTILS_H
#define UTILS_H
2021-02-24 10:50:41 +08:00
#include <QColor>
2021-02-04 16:59:58 +08:00
#include <QFile>
#include <QResource>
#include <QString>
#include <QTextStream>
#include "DoricExport.h"
class DORIC_EXPORT DoricUtils {
2021-02-04 16:59:58 +08:00
public:
static QString readAssetFile(QString preffix, QString assetName) {
QResource resource(":" + preffix + "/" + assetName);
QFile *file = new QFile(resource.fileName());
file->open(QFile::ReadOnly | QFile::Text);
QTextStream in(file);
2021-05-14 21:05:56 +08:00
in.setCodec("UTF-8");
2021-02-04 16:59:58 +08:00
QString content = in.readAll();
file->close();
delete file;
return content;
}
2021-06-10 11:05:31 +08:00
static QString readAssetFile(QString resourcePath) {
QResource resource(":" + resourcePath);
QFile *file = new QFile(resource.fileName());
file->open(QFile::ReadOnly | QFile::Text);
QTextStream in(file);
in.setCodec("UTF-8");
QString content = in.readAll();
file->close();
delete file;
return content;
}
template <typename Base, typename T>
static inline bool instanceof (const T *) {
return std::is_base_of<Base, T>::value;
}
2021-02-24 10:50:41 +08:00
static QColor doricColor(long colorValue) {
float a = ((colorValue >> 24) & 0xff);
float r = ((colorValue >> 16) & 0xff);
float g = ((colorValue >> 8) & 0xff);
float b = ((colorValue >> 0) & 0xff);
return QColor(r, g, b, a);
}
2021-02-04 16:59:58 +08:00
};
#endif // UTILS_H