mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-01-23 04:14:35 +08:00
update
This commit is contained in:
parent
79a7c97fe8
commit
b2471bcf0d
@ -9,10 +9,10 @@ FluScrollablePage{
|
||||
|
||||
title:"Captcha"
|
||||
|
||||
|
||||
FluCaptcha{
|
||||
id:captcha
|
||||
Layout.topMargin: 20
|
||||
ignoreCase:switch_case.checked
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
@ -30,6 +30,13 @@ FluScrollablePage{
|
||||
}
|
||||
}
|
||||
|
||||
FluToggleSwitch{
|
||||
id:switch_case
|
||||
text:"Ignore Case"
|
||||
checked: true
|
||||
Layout.topMargin: 10
|
||||
}
|
||||
|
||||
RowLayout{
|
||||
spacing: 10
|
||||
Layout.topMargin: 10
|
||||
@ -49,6 +56,4 @@ FluScrollablePage{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ FluScrollablePage{
|
||||
|
||||
title:"Captcha"
|
||||
|
||||
|
||||
FluCaptcha{
|
||||
id:captcha
|
||||
Layout.topMargin: 20
|
||||
ignoreCase:switch_case.checked
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
@ -31,6 +31,13 @@ FluScrollablePage{
|
||||
}
|
||||
}
|
||||
|
||||
FluToggleSwitch{
|
||||
id:switch_case
|
||||
text:"Ignore Case"
|
||||
checked: true
|
||||
Layout.topMargin: 10
|
||||
}
|
||||
|
||||
RowLayout{
|
||||
spacing: 10
|
||||
Layout.topMargin: 10
|
||||
@ -50,6 +57,4 @@ FluScrollablePage{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -10,19 +10,7 @@
|
||||
#include <QClipboard>
|
||||
#include "Def.h"
|
||||
|
||||
FluApp* FluApp::m_instance = nullptr;
|
||||
|
||||
FluApp *FluApp::getInstance()
|
||||
{
|
||||
if(FluApp::m_instance == nullptr){
|
||||
FluApp::m_instance = new FluApp;
|
||||
}
|
||||
return FluApp::m_instance;
|
||||
}
|
||||
|
||||
FluApp::FluApp(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluApp::FluApp(QObject *parent):QObject{parent}{
|
||||
httpInterceptor(nullptr);
|
||||
}
|
||||
|
||||
@ -83,8 +71,7 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegist
|
||||
view->setColor(QColor(Qt::transparent));
|
||||
}
|
||||
|
||||
QJsonArray FluApp::awesomelist(const QString& keyword)
|
||||
{
|
||||
QJsonArray FluApp::awesomelist(const QString& keyword){
|
||||
QJsonArray arr;
|
||||
QMetaEnum enumType = Fluent_Awesome::staticMetaObject.enumerator(Fluent_Awesome::staticMetaObject.indexOfEnumerator("Fluent_AwesomeType"));
|
||||
for(int i=0; i < enumType.keyCount(); ++i){
|
||||
|
11
src/FluApp.h
11
src/FluApp.h
@ -11,6 +11,7 @@
|
||||
#include "FluRegister.h"
|
||||
#include "FluHttpInterceptor.h"
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
/**
|
||||
* @brief The FluApp class
|
||||
@ -25,13 +26,10 @@ class FluApp : public QObject
|
||||
QML_SINGLETON
|
||||
private:
|
||||
explicit FluApp(QObject *parent = nullptr);
|
||||
public:
|
||||
~FluApp();
|
||||
static FluApp *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
|
||||
{
|
||||
return getInstance();
|
||||
}
|
||||
static FluApp *getInstance();
|
||||
public:
|
||||
SINGLETONG(FluApp)
|
||||
static FluApp *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
Q_INVOKABLE void run();
|
||||
Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluRegister* fluRegister = nullptr);
|
||||
Q_INVOKABLE void init(QQuickWindow *window);
|
||||
@ -41,7 +39,6 @@ public:
|
||||
public:
|
||||
QMap<quint64, QQuickWindow*> wnds;
|
||||
private:
|
||||
static FluApp* m_instance;
|
||||
QWindow *appWindow;
|
||||
};
|
||||
|
||||
|
@ -5,9 +5,8 @@
|
||||
#include <QRandomGenerator>
|
||||
#include <qmath.h>
|
||||
|
||||
FluCaptcha::FluCaptcha(QQuickItem *parent)
|
||||
: QQuickPaintedItem(parent)
|
||||
{
|
||||
FluCaptcha::FluCaptcha(QQuickItem *parent):QQuickPaintedItem(parent){
|
||||
ignoreCase(true);
|
||||
QFont fontStype;
|
||||
fontStype.setPixelSize(28);
|
||||
fontStype.setBold(true);
|
||||
@ -17,8 +16,7 @@ FluCaptcha::FluCaptcha(QQuickItem *parent)
|
||||
refresh();
|
||||
}
|
||||
|
||||
void FluCaptcha::paint(QPainter* painter)
|
||||
{
|
||||
void FluCaptcha::paint(QPainter* painter){
|
||||
painter->save();
|
||||
painter->fillRect(boundingRect().toRect(),QColor(255,255,255,255));
|
||||
QPen pen;
|
||||
@ -72,5 +70,8 @@ void FluCaptcha::refresh(){
|
||||
}
|
||||
|
||||
bool FluCaptcha::verify(const QString& code){
|
||||
if(_ignoreCase){
|
||||
return this->_code.toUpper() == code.toUpper();
|
||||
}
|
||||
return this->_code == code;
|
||||
}
|
||||
|
@ -10,15 +10,17 @@ class FluCaptcha : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QFont,font);
|
||||
Q_PROPERTY_AUTO(bool,ignoreCase);
|
||||
QML_NAMED_ELEMENT(FluCaptcha)
|
||||
private:
|
||||
int _generaNumber(int number);
|
||||
QString _code;
|
||||
public:
|
||||
explicit FluCaptcha(QQuickItem *parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
Q_INVOKABLE void refresh();
|
||||
Q_INVOKABLE bool verify(const QString& code);
|
||||
private:
|
||||
QString _code;
|
||||
};
|
||||
|
||||
#endif // FLUCAPTCHA_H
|
||||
|
@ -1,7 +1,4 @@
|
||||
#include "FluColorSet.h"
|
||||
|
||||
FluColorSet::FluColorSet(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
FluColorSet::FluColorSet(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
@ -1,18 +1,6 @@
|
||||
#include "FluColors.h"
|
||||
|
||||
FluColors* FluColors::m_instance = nullptr;
|
||||
|
||||
FluColors *FluColors::getInstance()
|
||||
{
|
||||
if(FluColors::m_instance == nullptr){
|
||||
FluColors::m_instance = new FluColors;
|
||||
}
|
||||
return FluColors::m_instance;
|
||||
}
|
||||
|
||||
FluColors::FluColors(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluColors::FluColors(QObject *parent):QObject{parent}{
|
||||
Transparent("#00000000");
|
||||
Black("#000000");
|
||||
White("#ffffff");
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QtQml/qqml.h>
|
||||
#include "FluColorSet.h"
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
/**
|
||||
* @brief The FluColors class
|
||||
@ -49,13 +50,9 @@ class FluColors : public QObject
|
||||
QML_SINGLETON
|
||||
private:
|
||||
explicit FluColors(QObject *parent = nullptr);
|
||||
static FluColors* m_instance;
|
||||
public:
|
||||
static FluColors *getInstance();
|
||||
static FluColors *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
|
||||
{
|
||||
return getInstance();
|
||||
}
|
||||
SINGLETONG(FluColors)
|
||||
static FluColors *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
};
|
||||
|
||||
#endif // FLUCOLORS_H
|
||||
|
@ -1,38 +1,21 @@
|
||||
#include "FluEventBus.h"
|
||||
|
||||
FluEventBus* FluEventBus::m_instance = nullptr;
|
||||
|
||||
FluEvent::FluEvent(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
FluEvent::FluEvent(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
FluEventBus *FluEventBus::getInstance()
|
||||
{
|
||||
if(FluEventBus::m_instance == nullptr){
|
||||
FluEventBus::m_instance = new FluEventBus;
|
||||
}
|
||||
return FluEventBus::m_instance;
|
||||
}
|
||||
|
||||
FluEventBus::FluEventBus(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
FluEventBus::FluEventBus(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
void FluEventBus::registerEvent(FluEvent* event){
|
||||
eventData.append(event);
|
||||
_eventData.append(event);
|
||||
}
|
||||
|
||||
|
||||
void FluEventBus::unRegisterEvent(FluEvent* event){
|
||||
eventData.removeOne(event);
|
||||
_eventData.removeOne(event);
|
||||
}
|
||||
|
||||
void FluEventBus::post(const QString& name,const QMap<QString, QVariant>& data){
|
||||
foreach (auto event, eventData) {
|
||||
foreach (auto event, _eventData) {
|
||||
if(event->name()==name){
|
||||
Q_EMIT event->triggered(data);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QtQml/qqml.h>
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
class FluEvent : public QObject{
|
||||
Q_OBJECT
|
||||
@ -20,19 +21,15 @@ class FluEventBus : public QObject
|
||||
QML_NAMED_ELEMENT(FluEventBus)
|
||||
QML_SINGLETON
|
||||
private:
|
||||
static FluEventBus* m_instance;
|
||||
explicit FluEventBus(QObject *parent = nullptr);
|
||||
public:
|
||||
static FluEventBus *getInstance();
|
||||
static FluEventBus *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
|
||||
{
|
||||
return getInstance();
|
||||
}
|
||||
SINGLETONG(FluEventBus)
|
||||
static FluEventBus *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
Q_INVOKABLE void registerEvent(FluEvent* event);
|
||||
Q_INVOKABLE void unRegisterEvent(FluEvent* event);
|
||||
Q_INVOKABLE void post(const QString& name,const QMap<QString, QVariant>& params = {});
|
||||
private:
|
||||
QList<FluEvent*> eventData;
|
||||
QList<FluEvent*> _eventData;
|
||||
};
|
||||
|
||||
#endif // FLUEVENTBUS_H
|
||||
|
@ -14,9 +14,7 @@
|
||||
#include "FluApp.h"
|
||||
#include "FluTools.h"
|
||||
|
||||
HttpRequest::HttpRequest(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
HttpRequest::HttpRequest(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> HttpRequest::toMap(){
|
||||
@ -55,14 +53,10 @@ QString HttpRequest::httpId(){
|
||||
return FluTools::getInstance()->sha256(QJsonDocument::fromVariant(QVariant(toMap())).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
HttpCallable::HttpCallable(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
HttpCallable::HttpCallable(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
FluHttp::FluHttp(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluHttp::FluHttp(QObject *parent):QObject{parent}{
|
||||
retry(3);
|
||||
timeout(15000);
|
||||
cacheMode(FluHttpType::CacheMode::NoCache);
|
||||
|
@ -1,7 +1,4 @@
|
||||
#include "FluHttpInterceptor.h"
|
||||
|
||||
FluHttpInterceptor::FluHttpInterceptor(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
FluHttpInterceptor::FluHttpInterceptor(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
@ -10,9 +10,6 @@ class FluHttpInterceptor : public QObject
|
||||
QML_NAMED_ELEMENT(FluHttpInterceptor)
|
||||
public:
|
||||
explicit FluHttpInterceptor(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // FLUHTTPINTERCEPTOR_H
|
||||
|
@ -3,9 +3,7 @@
|
||||
#include "FluApp.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
FluRegister::FluRegister(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluRegister::FluRegister(QObject *parent):QObject{parent}{
|
||||
from(nullptr);
|
||||
to(nullptr);
|
||||
path("");
|
||||
|
@ -1,19 +1,6 @@
|
||||
#include "FluTextStyle.h"
|
||||
|
||||
FluTextStyle* FluTextStyle::m_instance = nullptr;
|
||||
|
||||
FluTextStyle *FluTextStyle::getInstance()
|
||||
{
|
||||
if(FluTextStyle::m_instance == nullptr){
|
||||
FluTextStyle::m_instance = new FluTextStyle;
|
||||
}
|
||||
return FluTextStyle::m_instance;
|
||||
}
|
||||
|
||||
|
||||
FluTextStyle::FluTextStyle(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluTextStyle::FluTextStyle(QObject *parent):QObject{parent}{
|
||||
QFont caption;
|
||||
caption.setPixelSize(12);
|
||||
Caption(caption);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QFont>
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
class FluTextStyle : public QObject
|
||||
{
|
||||
@ -21,13 +22,9 @@ public:
|
||||
QML_SINGLETON
|
||||
private:
|
||||
explicit FluTextStyle(QObject *parent = nullptr);
|
||||
static FluTextStyle* m_instance;
|
||||
public:
|
||||
static FluTextStyle *getInstance();
|
||||
static FluTextStyle *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
|
||||
{
|
||||
return getInstance();
|
||||
}
|
||||
SINGLETONG(FluTextStyle)
|
||||
static FluTextStyle *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
};
|
||||
|
||||
#endif // FLUTEXTSTYLE_H
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "FluTheme.h"
|
||||
|
||||
#include "Def.h"
|
||||
#include "FluColors.h"
|
||||
#include <QGuiApplication>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||
#include <QStyleHints>
|
||||
#elif ((QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)))
|
||||
@ -10,22 +9,10 @@
|
||||
#else
|
||||
#include <QPalette>
|
||||
#endif
|
||||
#include "Def.h"
|
||||
#include "FluColors.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
|
||||
FluTheme* FluTheme::m_instance = nullptr;
|
||||
|
||||
FluTheme *FluTheme::getInstance()
|
||||
{
|
||||
if(FluTheme::m_instance == nullptr){
|
||||
FluTheme::m_instance = new FluTheme;
|
||||
}
|
||||
return FluTheme::m_instance;
|
||||
}
|
||||
|
||||
FluTheme::FluTheme(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluTheme::FluTheme(QObject *parent):QObject{parent}{
|
||||
connect(this,&FluTheme::darkModeChanged,this,[=]{
|
||||
Q_EMIT darkChanged();
|
||||
});
|
||||
@ -37,8 +24,7 @@ FluTheme::FluTheme(QObject *parent)
|
||||
qApp->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool FluTheme::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
bool FluTheme::eventFilter(QObject *obj, QEvent *event){
|
||||
Q_UNUSED(obj);
|
||||
if (event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange)
|
||||
{
|
||||
@ -50,8 +36,7 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FluTheme::systemDark()
|
||||
{
|
||||
bool FluTheme::systemDark(){
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||
return (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark);
|
||||
#elif ((QT_VERSION >= QT_VERSION_CHECK(6, 2, 1)))
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QtQml/qqml.h>
|
||||
#include "FluColorSet.h"
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
/**
|
||||
* @brief The FluTheme class
|
||||
@ -20,21 +21,17 @@ class FluTheme : public QObject
|
||||
QML_NAMED_ELEMENT(FluTheme)
|
||||
QML_SINGLETON
|
||||
private:
|
||||
static FluTheme* m_instance;
|
||||
explicit FluTheme(QObject *parent = nullptr);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
bool systemDark();
|
||||
public:
|
||||
static FluTheme *getInstance();
|
||||
static FluTheme *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
|
||||
{
|
||||
return getInstance();
|
||||
}
|
||||
SINGLETONG(FluTheme)
|
||||
static FluTheme *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
bool dark();
|
||||
Q_SIGNAL void darkChanged();
|
||||
private:
|
||||
bool _dark;
|
||||
bool _systemDark;
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
bool systemDark();
|
||||
};
|
||||
|
||||
#endif // FLUTHEME_H
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "FluTools.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QClipboard>
|
||||
#include <QUuid>
|
||||
@ -11,21 +12,7 @@
|
||||
#include <QCryptographicHash>
|
||||
#include <QTextDocument>
|
||||
|
||||
FluTools* FluTools::m_instance = nullptr;
|
||||
|
||||
FluTools *FluTools::getInstance()
|
||||
{
|
||||
if(FluTools::m_instance == nullptr){
|
||||
FluTools::m_instance = new FluTools;
|
||||
}
|
||||
return FluTools::m_instance;
|
||||
}
|
||||
|
||||
|
||||
FluTools::FluTools(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
FluTools::FluTools(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
void FluTools::clipText(const QString& text){
|
||||
@ -36,8 +23,7 @@ QString FluTools::uuid(){
|
||||
return QUuid::createUuid().toString();
|
||||
}
|
||||
|
||||
QString FluTools::readFile(const QString &fileName)
|
||||
{
|
||||
QString FluTools::readFile(const QString &fileName){
|
||||
QString content;
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
@ -132,18 +118,15 @@ QColor FluTools::colorAlpha(const QColor& color,qreal alpha){
|
||||
return QColor(color.red(),color.green(),color.blue(),255*alpha);
|
||||
}
|
||||
|
||||
QString FluTools::md5(QString text)
|
||||
{
|
||||
QString FluTools::md5(QString text){
|
||||
return QCryptographicHash::hash(text.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
QString FluTools::toBase64(QString text)
|
||||
{
|
||||
QString FluTools::toBase64(QString text){
|
||||
return text.toUtf8().toBase64();
|
||||
}
|
||||
|
||||
QString FluTools::fromBase64(QString text)
|
||||
{
|
||||
QString FluTools::fromBase64(QString text){
|
||||
return QByteArray::fromBase64(text.toUtf8());
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QFile>
|
||||
#include <QColor>
|
||||
#include <QtQml/qqml.h>
|
||||
#include "singleton.h"
|
||||
|
||||
/**
|
||||
* @brief The FluTools class
|
||||
@ -12,71 +13,39 @@
|
||||
class FluTools : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QML_NAMED_ELEMENT(FluTools)
|
||||
QML_SINGLETON
|
||||
private:
|
||||
explicit FluTools(QObject *parent = nullptr);
|
||||
static FluTools* m_instance;
|
||||
public:
|
||||
static FluTools *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
|
||||
{
|
||||
return getInstance();
|
||||
}
|
||||
static FluTools *getInstance();
|
||||
|
||||
SINGLETONG(FluTools)
|
||||
static FluTools *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine){return getInstance();}
|
||||
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 deleteItem(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 colorAlpha(const QColor&,qreal alpha);
|
||||
|
||||
Q_INVOKABLE QString md5(QString text);
|
||||
|
||||
Q_INVOKABLE QString sha256(QString text);
|
||||
|
||||
Q_INVOKABLE QString toBase64(QString text);
|
||||
|
||||
Q_INVOKABLE QString fromBase64(QString text);
|
||||
|
||||
Q_INVOKABLE bool removeDir(QString dirPath);
|
||||
|
||||
Q_INVOKABLE bool removeFile(QString filePath);
|
||||
|
||||
Q_INVOKABLE void showFileInFolder(QString path);
|
||||
|
||||
};
|
||||
|
||||
#endif // FLUTOOLS_H
|
||||
|
@ -3,63 +3,44 @@
|
||||
#include <QQuickItem>
|
||||
#include "Def.h"
|
||||
|
||||
ViewModelManager* ViewModelManager::m_instance = nullptr;
|
||||
|
||||
ViewModelManager *ViewModelManager::getInstance()
|
||||
{
|
||||
if(ViewModelManager::m_instance == nullptr){
|
||||
ViewModelManager::m_instance = new ViewModelManager;
|
||||
}
|
||||
return ViewModelManager::m_instance;
|
||||
Model::Model(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
Model::Model(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
Model::~Model(){
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
{
|
||||
}
|
||||
|
||||
ViewModelManager::ViewModelManager(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
ViewModelManager::ViewModelManager(QObject *parent): QObject{parent}{
|
||||
}
|
||||
|
||||
void ViewModelManager::insertViewModel(FluViewModel* value){
|
||||
m_viewmodel.append(value);
|
||||
_viewmodel.append(value);
|
||||
}
|
||||
|
||||
void ViewModelManager::deleteViewModel(FluViewModel* value){
|
||||
m_viewmodel.removeOne(value);
|
||||
_viewmodel.removeOne(value);
|
||||
}
|
||||
|
||||
QObject* ViewModelManager::getModel(const QString& key){
|
||||
return m_data.value(key);
|
||||
return _data.value(key);
|
||||
}
|
||||
|
||||
void ViewModelManager::insert(const QString& key,QObject* value){
|
||||
m_data.insert(key,value);
|
||||
_data.insert(key,value);
|
||||
}
|
||||
|
||||
bool ViewModelManager::exist(const QString& key){
|
||||
return m_data.contains(key);
|
||||
return _data.contains(key);
|
||||
}
|
||||
|
||||
void ViewModelManager::refreshViewModel(FluViewModel* viewModel,QString key,QVariant value){
|
||||
foreach (auto item, m_viewmodel) {
|
||||
foreach (auto item, _viewmodel) {
|
||||
if(item->getKey() == viewModel->getKey()){
|
||||
item->setProperty(key.toStdString().c_str(),value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PropertyObserver::PropertyObserver(QString name,QObject* model,QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
PropertyObserver::PropertyObserver(QString name,QObject* model,QObject *parent):QObject{parent}{
|
||||
_name = name;
|
||||
_model = model;
|
||||
_property = QQmlProperty(parent,_name);
|
||||
@ -75,9 +56,7 @@ void PropertyObserver::_propertyChange(){
|
||||
ViewModelManager::getInstance()->refreshViewModel((FluViewModel*)parent(),_name,value);
|
||||
}
|
||||
|
||||
FluViewModel::FluViewModel(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
FluViewModel::FluViewModel(QObject *parent):QObject{parent}{
|
||||
ViewModelManager::getInstance()->insertViewModel(this);
|
||||
scope(FluViewModelType::Scope::Window);
|
||||
}
|
||||
@ -86,12 +65,10 @@ FluViewModel::~FluViewModel(){
|
||||
ViewModelManager::getInstance()->deleteViewModel(this);
|
||||
}
|
||||
|
||||
void FluViewModel::classBegin()
|
||||
{
|
||||
void FluViewModel::classBegin(){
|
||||
}
|
||||
|
||||
void FluViewModel::componentComplete()
|
||||
{
|
||||
void FluViewModel::componentComplete(){
|
||||
auto o = parent();
|
||||
while (nullptr != o) {
|
||||
_window = o;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QQuickWindow>
|
||||
#include <QQmlProperty>
|
||||
#include "stdafx.h"
|
||||
#include "singleton.h"
|
||||
|
||||
class Model : public QObject{
|
||||
Q_OBJECT
|
||||
@ -52,7 +53,7 @@ class ViewModelManager:public QObject{
|
||||
private:
|
||||
explicit ViewModelManager(QObject *parent = nullptr);
|
||||
public:
|
||||
static ViewModelManager *getInstance();
|
||||
SINGLETONG(ViewModelManager)
|
||||
bool exist(const QString& key);
|
||||
void insert(const QString& key,QObject* value);
|
||||
QObject* getModel(const QString& key);
|
||||
@ -60,9 +61,8 @@ public:
|
||||
void deleteViewModel(FluViewModel* value);
|
||||
void refreshViewModel(FluViewModel* viewModel,QString key,QVariant value);
|
||||
private:
|
||||
static ViewModelManager* m_instance;
|
||||
QMap<QString,QObject*> m_data;
|
||||
QList<FluViewModel*> m_viewmodel;
|
||||
QMap<QString,QObject*> _data;
|
||||
QList<FluViewModel*> _viewmodel;
|
||||
};
|
||||
|
||||
#endif // FLUVIEWMODEL_H
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "FluWatermark.h"
|
||||
|
||||
FluWatermark::FluWatermark(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
{
|
||||
FluWatermark::FluWatermark(QQuickItem* parent) : QQuickPaintedItem(parent){
|
||||
gap(QPoint(100,100));
|
||||
offset(QPoint(_gap.x()/2,_gap.y()/2));
|
||||
rotate(22);
|
||||
@ -16,8 +15,7 @@ FluWatermark::FluWatermark(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
connect(this,&FluWatermark::textSizeChanged,this,[=]{update();});
|
||||
}
|
||||
|
||||
void FluWatermark::paint(QPainter* painter)
|
||||
{
|
||||
void FluWatermark::paint(QPainter* painter){
|
||||
QFont font;
|
||||
font.setPixelSize(_textSize);
|
||||
painter->setFont(font);
|
||||
|
@ -2,17 +2,13 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QMetaMethod>
|
||||
|
||||
std::shared_ptr<MainThread> MainThread::createShared(QObject* bindObject)
|
||||
{
|
||||
std::shared_ptr<MainThread> MainThread::createShared(QObject* bindObject){
|
||||
return std::shared_ptr<MainThread>(new MainThread(bindObject), [=](QObject* mainThread) {
|
||||
mainThread->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
MainThread::MainThread(QObject* bindObject)
|
||||
: mBindObject(bindObject)
|
||||
, mIgnoreNullObject(bindObject == nullptr)
|
||||
{
|
||||
MainThread::MainThread(QObject* bindObject): _bindObject(bindObject), _ignoreNullObject(bindObject == nullptr){
|
||||
qRegisterMetaType<std::function<void()>>("std::function<void()>");
|
||||
auto mainUIThread = qApp->thread();
|
||||
if (this->thread() != mainUIThread)
|
||||
@ -21,18 +17,15 @@ MainThread::MainThread(QObject* bindObject)
|
||||
}
|
||||
}
|
||||
|
||||
MainThread::~MainThread()
|
||||
{
|
||||
MainThread::~MainThread(){
|
||||
}
|
||||
|
||||
void MainThread::post(std::function<void()> func)
|
||||
{
|
||||
void MainThread::post(std::function<void()> func){
|
||||
QMetaObject::invokeMethod(createShared().get(), "mainThreadSlot", Q_ARG(std::function<void()>, func));
|
||||
}
|
||||
|
||||
void MainThread::mainThreadSlot(std::function<void()> func)
|
||||
{
|
||||
if ((mIgnoreNullObject || mBindObject) && func)
|
||||
void MainThread::mainThreadSlot(std::function<void()> func){
|
||||
if ((_ignoreNullObject || _bindObject) && func)
|
||||
{
|
||||
func();
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ class MainThread : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
static void post(std::function<void()> func);
|
||||
~MainThread();
|
||||
private:
|
||||
@ -18,7 +17,7 @@ private slots:
|
||||
void mainThreadSlot(std::function<void()> func);
|
||||
private:
|
||||
MainThread(QObject* bindObject = nullptr);
|
||||
QPointer<QObject> mBindObject;
|
||||
bool mIgnoreNullObject{ false };
|
||||
QPointer<QObject> _bindObject;
|
||||
bool _ignoreNullObject{ false };
|
||||
};
|
||||
#endif // MAINTHREAD_H
|
||||
|
@ -6,8 +6,7 @@
|
||||
|
||||
using namespace ZXing;
|
||||
|
||||
QRCode::QRCode(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
{
|
||||
QRCode::QRCode(QQuickItem* parent):QQuickPaintedItem(parent){
|
||||
color(QColor(0,0,0,255));
|
||||
bgColor(QColor(255,255,255,255));
|
||||
size(100);
|
||||
@ -24,8 +23,7 @@ QRCode::QRCode(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
}
|
||||
|
||||
|
||||
void QRCode::paint(QPainter* painter)
|
||||
{
|
||||
void QRCode::paint(QPainter* painter){
|
||||
if(_text.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ class QRCode : public QQuickPaintedItem
|
||||
public:
|
||||
explicit QRCode(QQuickItem *parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
|
||||
};
|
||||
|
||||
#endif // QRCODE_H
|
||||
|
@ -6,12 +6,9 @@
|
||||
#include <QtMath>
|
||||
#include <QDateTime>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include "Def.h"
|
||||
|
||||
|
||||
Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
{
|
||||
Screenshot::Screenshot(QQuickItem* parent):QQuickPaintedItem(parent){
|
||||
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
|
||||
maskColor(QColor(0,0,0,150));
|
||||
start(QPoint(0,0));
|
||||
@ -20,8 +17,7 @@ Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
connect(this,&Screenshot::endChanged,this,[=]{update();});
|
||||
}
|
||||
|
||||
void Screenshot::paint(QPainter* painter)
|
||||
{
|
||||
void Screenshot::paint(QPainter* painter){
|
||||
painter->save();
|
||||
painter->fillRect(_desktopGeometry,_maskColor);
|
||||
painter->setCompositionMode(QPainter::CompositionMode_Clear);
|
||||
@ -29,8 +25,7 @@ void Screenshot::paint(QPainter* painter)
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedItem(parent)
|
||||
{
|
||||
ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedItem(parent){
|
||||
_devicePixelRatio = qApp->primaryScreen()->devicePixelRatio();
|
||||
_desktopGeometry = qApp->primaryScreen()->virtualGeometry();
|
||||
_desktopPixmap = qApp->primaryScreen()->grabWindow(0, _desktopGeometry.x(), _desktopGeometry.y(), _desktopGeometry.width(), _desktopGeometry.height());
|
||||
@ -45,8 +40,7 @@ ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedIt
|
||||
setHeight(h);
|
||||
}
|
||||
|
||||
void ScreenshotBackground::paint(QPainter* painter)
|
||||
{
|
||||
void ScreenshotBackground::paint(QPainter* painter){
|
||||
painter->save();
|
||||
_sourcePixmap = _desktopPixmap.copy();
|
||||
painter->drawPixmap(_desktopGeometry,_sourcePixmap);
|
||||
|
@ -29,7 +29,6 @@ private:
|
||||
QRect _captureRect;
|
||||
};
|
||||
|
||||
|
||||
class Screenshot : public QQuickPaintedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -40,7 +39,6 @@ class Screenshot : public QQuickPaintedItem
|
||||
public:
|
||||
Screenshot(QQuickItem* parent = nullptr);
|
||||
void paint(QPainter* painter) override;
|
||||
|
||||
private:
|
||||
QRect _desktopGeometry;
|
||||
};
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
#include "FluRegister.h"
|
||||
|
||||
WindowHelper::WindowHelper(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
|
||||
WindowHelper::WindowHelper(QObject *parent):QObject{parent}{
|
||||
}
|
||||
|
||||
void WindowHelper::initWindow(QQuickWindow* window){
|
||||
|
@ -17,21 +17,8 @@ class WindowHelper : public QObject
|
||||
QML_NAMED_ELEMENT(WindowHelper)
|
||||
public:
|
||||
explicit WindowHelper(QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief initWindow FluWindow中初始化调用
|
||||
* @param window
|
||||
*/
|
||||
Q_INVOKABLE void initWindow(QQuickWindow* window);
|
||||
|
||||
/**
|
||||
* @brief createRegister 创建一个FluRegsiter对象,在FluWindow中registerForWindowResult方法调用
|
||||
* @param window
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path);
|
||||
|
||||
private:
|
||||
QQuickWindow* window;
|
||||
};
|
||||
|
47
src/singleton.h
Normal file
47
src/singleton.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef SINGLETON_H
|
||||
#define SINGLETON_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QScopedPointer>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
template <typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T* getInstance();
|
||||
|
||||
Singleton(const Singleton& other) = delete;
|
||||
Singleton<T>& operator=(const Singleton& other) = delete;
|
||||
|
||||
private:
|
||||
static std::mutex mutex;
|
||||
static T* instance;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::mutex Singleton<T>::mutex;
|
||||
template <typename T>
|
||||
T* Singleton<T>::instance;
|
||||
template <typename T>
|
||||
T* Singleton<T>::getInstance() {
|
||||
if (instance == nullptr) {
|
||||
std::lock_guard<std::mutex> locker(mutex);
|
||||
if (instance == nullptr) {
|
||||
instance = new T();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
#define SINGLETONG(Class) \
|
||||
private: \
|
||||
friend class Singleton<Class>; \
|
||||
friend struct QScopedPointerDeleter<Class>; \
|
||||
\
|
||||
public: \
|
||||
static Class* getInstance() { \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
}
|
||||
|
||||
#endif // SINGLETON_H
|
Loading…
Reference in New Issue
Block a user