mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-07 03:25:24 +08:00
update
This commit is contained in:
115
src/FluTools.cpp
115
src/FluTools.cpp
@ -1,3 +1,7 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||
#pragma ide diagnostic ignored "readability-convert-member-functions-to-static"
|
||||
|
||||
#include "FluTools.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
@ -16,19 +20,19 @@
|
||||
#include <QDateTime>
|
||||
#include <QSettings>
|
||||
|
||||
FluTools::FluTools(QObject *parent):QObject{parent}{
|
||||
FluTools::FluTools(QObject *parent) : QObject{parent} {
|
||||
|
||||
}
|
||||
|
||||
void FluTools::clipText(const QString& text){
|
||||
void FluTools::clipText(const QString &text) {
|
||||
QGuiApplication::clipboard()->setText(text);
|
||||
}
|
||||
|
||||
QString FluTools::uuid(){
|
||||
QString FluTools::uuid() {
|
||||
return QUuid::createUuid().toString().remove('-').remove('{').remove('}');
|
||||
}
|
||||
|
||||
QString FluTools::readFile(const QString &fileName){
|
||||
QString FluTools::readFile(const QString &fileName) {
|
||||
QString content;
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
@ -38,7 +42,7 @@ QString FluTools::readFile(const QString &fileName){
|
||||
return content;
|
||||
}
|
||||
|
||||
bool FluTools::isMacos(){
|
||||
bool FluTools::isMacos() {
|
||||
#if defined(Q_OS_MACOS)
|
||||
return true;
|
||||
#else
|
||||
@ -46,7 +50,7 @@ bool FluTools::isMacos(){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluTools::isLinux(){
|
||||
bool FluTools::isLinux() {
|
||||
#if defined(Q_OS_LINUX)
|
||||
return true;
|
||||
#else
|
||||
@ -54,7 +58,7 @@ bool FluTools::isLinux(){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluTools::isWin(){
|
||||
bool FluTools::isWin() {
|
||||
#if defined(Q_OS_WIN)
|
||||
return true;
|
||||
#else
|
||||
@ -62,95 +66,94 @@ bool FluTools::isWin(){
|
||||
#endif
|
||||
}
|
||||
|
||||
int FluTools::qtMajor(){
|
||||
int FluTools::qtMajor() {
|
||||
const QString qtVersion = QString::fromLatin1(qVersion());
|
||||
const QStringList versionParts = qtVersion.split('.');
|
||||
return versionParts[0].toInt();
|
||||
}
|
||||
|
||||
int FluTools::qtMinor(){
|
||||
int FluTools::qtMinor() {
|
||||
const QString qtVersion = QString::fromLatin1(qVersion());
|
||||
const QStringList versionParts = qtVersion.split('.');
|
||||
return versionParts[1].toInt();
|
||||
}
|
||||
|
||||
void FluTools::setQuitOnLastWindowClosed(bool val){
|
||||
qApp->setQuitOnLastWindowClosed(val);
|
||||
void FluTools::setQuitOnLastWindowClosed(bool val) {
|
||||
QGuiApplication::setQuitOnLastWindowClosed(val);
|
||||
}
|
||||
|
||||
void FluTools::setOverrideCursor(Qt::CursorShape shape){
|
||||
qApp->setOverrideCursor(QCursor(shape));
|
||||
void FluTools::setOverrideCursor(Qt::CursorShape shape) {
|
||||
QGuiApplication::setOverrideCursor(QCursor(shape));
|
||||
}
|
||||
|
||||
void FluTools::restoreOverrideCursor(){
|
||||
qApp->restoreOverrideCursor();
|
||||
void FluTools::restoreOverrideCursor() {
|
||||
QGuiApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void FluTools::deleteLater(QObject *p){
|
||||
if(p){
|
||||
void FluTools::deleteLater(QObject *p) {
|
||||
if (p) {
|
||||
p->deleteLater();
|
||||
p = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QString FluTools::toLocalPath(const QUrl& url){
|
||||
QString FluTools::toLocalPath(const QUrl &url) {
|
||||
return url.toLocalFile();
|
||||
}
|
||||
|
||||
QString FluTools::getFileNameByUrl(const QUrl& url){
|
||||
QString FluTools::getFileNameByUrl(const QUrl &url) {
|
||||
return QFileInfo(url.toLocalFile()).fileName();
|
||||
}
|
||||
|
||||
QString FluTools::html2PlantText(const QString& html){
|
||||
QString FluTools::html2PlantText(const QString &html) {
|
||||
QTextDocument textDocument;
|
||||
textDocument.setHtml(html);
|
||||
return textDocument.toPlainText();
|
||||
}
|
||||
|
||||
QRect FluTools::getVirtualGeometry(){
|
||||
return qApp->primaryScreen()->virtualGeometry();
|
||||
QRect FluTools::getVirtualGeometry() {
|
||||
return QGuiApplication::primaryScreen()->virtualGeometry();
|
||||
}
|
||||
|
||||
QString FluTools::getApplicationDirPath(){
|
||||
return qApp->applicationDirPath();
|
||||
QString FluTools::getApplicationDirPath() {
|
||||
return QGuiApplication::applicationDirPath();
|
||||
}
|
||||
|
||||
QUrl FluTools::getUrlByFilePath(const QString& path){
|
||||
QUrl FluTools::getUrlByFilePath(const QString &path) {
|
||||
return QUrl::fromLocalFile(path);
|
||||
}
|
||||
|
||||
QColor FluTools::withOpacity(const QColor& color,qreal opacity){
|
||||
QColor FluTools::withOpacity(const QColor &color, qreal opacity) {
|
||||
int alpha = qRound(opacity * 255) & 0xff;
|
||||
return QColor::fromRgba((alpha << 24) | (color.rgba() & 0xffffff));
|
||||
}
|
||||
|
||||
QString FluTools::md5(QString text){
|
||||
QString FluTools::md5(const QString &text) {
|
||||
return QCryptographicHash::hash(text.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
QString FluTools::toBase64(QString text){
|
||||
QString FluTools::toBase64(const QString &text) {
|
||||
return text.toUtf8().toBase64();
|
||||
}
|
||||
|
||||
QString FluTools::fromBase64(QString text){
|
||||
QString FluTools::fromBase64(const QString &text) {
|
||||
return QByteArray::fromBase64(text.toUtf8());
|
||||
}
|
||||
|
||||
bool FluTools::removeDir(QString dirPath){
|
||||
bool FluTools::removeDir(const QString &dirPath) {
|
||||
QDir qDir(dirPath);
|
||||
return qDir.removeRecursively();
|
||||
}
|
||||
|
||||
bool FluTools::removeFile(QString filePath){
|
||||
bool FluTools::removeFile(const QString &filePath) {
|
||||
QFile file(filePath);
|
||||
return file.remove();
|
||||
}
|
||||
|
||||
QString FluTools::sha256(QString text){
|
||||
QString FluTools::sha256(const QString &text) {
|
||||
return QCryptographicHash::hash(text.toUtf8(), QCryptographicHash::Sha256).toHex();
|
||||
}
|
||||
|
||||
void FluTools::showFileInFolder(QString path){
|
||||
void FluTools::showFileInFolder(const QString &path) {
|
||||
#if defined(Q_OS_WIN)
|
||||
QProcess::startDetached("explorer.exe", {"/select,", QDir::toNativeSeparators(path)});
|
||||
#endif
|
||||
@ -166,29 +169,29 @@ void FluTools::showFileInFolder(QString path){
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FluTools::isSoftware(){
|
||||
bool FluTools::isSoftware() {
|
||||
return QQuickWindow::sceneGraphBackend() == "software";
|
||||
}
|
||||
|
||||
QPoint FluTools::cursorPos(){
|
||||
QPoint FluTools::cursorPos() {
|
||||
return QCursor::pos();
|
||||
}
|
||||
|
||||
qint64 FluTools::currentTimestamp(){
|
||||
qint64 FluTools::currentTimestamp() {
|
||||
return QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
QIcon FluTools::windowIcon(){
|
||||
QIcon FluTools::windowIcon() {
|
||||
return QGuiApplication::windowIcon();
|
||||
}
|
||||
|
||||
int FluTools::cursorScreenIndex(){
|
||||
int FluTools::cursorScreenIndex() {
|
||||
int screenIndex = 0;
|
||||
int screenCount = qApp->screens().count();
|
||||
int screenCount = QGuiApplication::screens().count();
|
||||
if (screenCount > 1) {
|
||||
QPoint pos = QCursor::pos();
|
||||
for (int i = 0; i < screenCount; ++i) {
|
||||
if (qApp->screens().at(i)->geometry().contains(pos)) {
|
||||
for (int i = 0; i <= screenCount - 1; ++i) {
|
||||
if (QGuiApplication::screens().at(i)->geometry().contains(pos)) {
|
||||
screenIndex = i;
|
||||
break;
|
||||
}
|
||||
@ -197,9 +200,9 @@ int FluTools::cursorScreenIndex(){
|
||||
return screenIndex;
|
||||
}
|
||||
|
||||
int FluTools::windowBuildNumber(){
|
||||
int FluTools::windowBuildNumber() {
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings regKey {QString::fromUtf8("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), QSettings::NativeFormat};
|
||||
QSettings regKey{QString::fromUtf8(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"), QSettings::NativeFormat};
|
||||
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
|
||||
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
|
||||
return buildNumber;
|
||||
@ -208,40 +211,42 @@ int FluTools::windowBuildNumber(){
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool FluTools::isWindows11OrGreater(){
|
||||
bool FluTools::isWindows11OrGreater() {
|
||||
static QVariant var;
|
||||
if(var.isNull()){
|
||||
if (var.isNull()) {
|
||||
#if defined(Q_OS_WIN)
|
||||
auto buildNumber = windowBuildNumber();
|
||||
if(buildNumber>=22000){
|
||||
if (buildNumber >= 22000) {
|
||||
var = QVariant::fromValue(true);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
var = QVariant::fromValue(false);
|
||||
return false;
|
||||
}else{
|
||||
return false;
|
||||
} else {
|
||||
return var.toBool();
|
||||
}
|
||||
}
|
||||
|
||||
bool FluTools::isWindows10OrGreater(){
|
||||
bool FluTools::isWindows10OrGreater() {
|
||||
static QVariant var;
|
||||
if(var.isNull()){
|
||||
if (var.isNull()) {
|
||||
#if defined(Q_OS_WIN)
|
||||
auto buildNumber = windowBuildNumber();
|
||||
if(buildNumber>=10240){
|
||||
if (buildNumber >= 10240) {
|
||||
var = QVariant::fromValue(true);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
var = QVariant::fromValue(false);
|
||||
return false;
|
||||
}else{
|
||||
return false;
|
||||
} else {
|
||||
return var.toBool();
|
||||
}
|
||||
}
|
||||
|
||||
QRect FluTools::desktopAvailableGeometry(QQuickWindow* window){
|
||||
QRect FluTools::desktopAvailableGeometry(QQuickWindow *window) {
|
||||
return window->screen()->availableGeometry();
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
Reference in New Issue
Block a user