This commit is contained in:
朱子楚\zhuzi 2024-04-24 10:37:15 +08:00
parent 83507a6ed5
commit 5fd7c7d10e
8 changed files with 33 additions and 33 deletions

View File

@ -15,7 +15,7 @@ public:
void paint(QPainter *painter) override; void paint(QPainter *painter) override;
Q_INVOKABLE [[maybe_unused]] void start(int w, int h, const QPoint &center, int radius); [[maybe_unused]] Q_INVOKABLE void start(int w, int h, const QPoint &center, int radius);
Q_SIGNAL void imageChanged(); Q_SIGNAL void imageChanged();

View File

@ -22,7 +22,7 @@ SINGLETON(InitializrHelper)
~InitializrHelper() override; ~InitializrHelper() override;
Q_INVOKABLE [[maybe_unused]] void generate(const QString &name, const QString &path); [[maybe_unused]] Q_INVOKABLE void generate(const QString &name, const QString &path);
Q_SIGNAL void error(const QString &message); Q_SIGNAL void error(const QString &message);

View File

@ -1,5 +1,4 @@
#include "FluAccentColor.h" #include "FluAccentColor.h"
FluAccentColor::FluAccentColor(QObject *parent) : QObject{parent} { FluAccentColor::FluAccentColor(QObject *parent) : QObject{parent} {
} }

View File

@ -109,7 +109,7 @@ FluColors::FluColors(QObject *parent) : QObject{parent} {
_Green = green; _Green = green;
} }
[[maybe_unused]] FluAccentColor *FluColors::createAccentColor(const QColor& primaryColor) { [[maybe_unused]] FluAccentColor *FluColors::createAccentColor(const QColor &primaryColor) {
auto accentColor = new FluAccentColor(this); auto accentColor = new FluAccentColor(this);
accentColor->normal(primaryColor); accentColor->normal(primaryColor);
accentColor->dark(FluTools::getInstance()->withOpacity(primaryColor, 0.9)); accentColor->dark(FluTools::getInstance()->withOpacity(primaryColor, 0.9));

View File

@ -55,7 +55,7 @@ private:
public: public:
SINGLETON(FluColors) SINGLETON(FluColors)
[[maybe_unused]] Q_INVOKABLE FluAccentColor *createAccentColor(const QColor& primaryColor); [[maybe_unused]] Q_INVOKABLE FluAccentColor *createAccentColor(const QColor &primaryColor);
static FluColors *create(QQmlEngine *, QJSEngine *) { return getInstance(); } static FluColors *create(QQmlEngine *, QJSEngine *) { return getInstance(); }
}; };

View File

@ -112,7 +112,7 @@ void FluFrameless::componentComplete() {
::RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); ::RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
}); });
#endif #endif
h = h + _appbar->height(); h = qRound(h + _appbar->height());
if (_fixSize) { if (_fixSize) {
window()->setMaximumSize(QSize(w, h)); window()->setMaximumSize(QSize(w, h));
window()->setMinimumSize(QSize(w, h)); window()->setMinimumSize(QSize(w, h));
@ -146,7 +146,7 @@ void FluFrameless::componentComplete() {
auto *wp = reinterpret_cast<WINDOWPOS *>(lParam); auto *wp = reinterpret_cast<WINDOWPOS *>(lParam);
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0) { if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0) {
wp->flags |= SWP_NOCOPYBITS; wp->flags |= SWP_NOCOPYBITS;
*result = ::DefWindowProcW(hwnd, uMsg, wParam, lParam); *result = static_cast<QT_NATIVE_EVENT_RESULT_TYPE>(::DefWindowProcW(hwnd, uMsg, wParam, lParam));
return true; return true;
} }
return false; return false;
@ -158,7 +158,7 @@ void FluFrameless::componentComplete() {
const LONG originalBottom = clientRect->bottom; const LONG originalBottom = clientRect->bottom;
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
*result = hitTestResult; *result = static_cast<QT_NATIVE_EVENT_RESULT_TYPE>(hitTestResult);
return true; return true;
} }
int offsetSize; int offsetSize;
@ -175,12 +175,19 @@ void FluFrameless::componentComplete() {
if (!isCompositionEnabled()) { if (!isCompositionEnabled()) {
offsetSize = 0; offsetSize = 0;
} }
if (!isMaximum || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
clientRect->top = originalTop + offsetSize;
clientRect->bottom = originalBottom - offsetSize;
clientRect->left = originalLeft + offsetSize;
clientRect->right = originalRight - offsetSize;
#else
if (!isMaximum) {
clientRect->top = originalTop + offsetSize; clientRect->top = originalTop + offsetSize;
clientRect->bottom = originalBottom - offsetSize; clientRect->bottom = originalBottom - offsetSize;
clientRect->left = originalLeft + offsetSize; clientRect->left = originalLeft + offsetSize;
clientRect->right = originalRight - offsetSize; clientRect->right = originalRight - offsetSize;
} }
#endif
_setMaximizeHovered(false); _setMaximizeHovered(false);
*result = WVR_REDRAW; *result = WVR_REDRAW;
return true; return true;
@ -255,7 +262,7 @@ void FluFrameless::componentComplete() {
*result = FALSE; *result = FALSE;
return true; return true;
} else if (uMsg == WM_NCACTIVATE) { } else if (uMsg == WM_NCACTIVATE) {
*result = ::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1); *result = static_cast<QT_NATIVE_EVENT_RESULT_TYPE>(::DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1));
return true; return true;
} else if (uMsg == WM_GETMINMAXINFO) { } else if (uMsg == WM_GETMINMAXINFO) {
auto *minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam); auto *minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
@ -270,9 +277,9 @@ void FluFrameless::componentComplete() {
auto geometry = window()->screen()->availableGeometry(); auto geometry = window()->screen()->availableGeometry();
RECT rect; RECT rect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
if(!_fixSize){ if (!_fixSize) {
minmaxInfo->ptMinTrackSize.x = window()->minimumWidth() * pixelRatio + offsetXY.x(); minmaxInfo->ptMinTrackSize.x = qRound(window()->minimumWidth() * pixelRatio + offsetXY.x());
minmaxInfo->ptMinTrackSize.y = window()->minimumHeight() * pixelRatio + offsetXY.y() + _appbar->height() * pixelRatio; minmaxInfo->ptMinTrackSize.y = qRound(window()->minimumHeight() * pixelRatio + offsetXY.y() + _appbar->height() * pixelRatio);
} }
minmaxInfo->ptMaxPosition.x = rect.left - offsetXY.x(); minmaxInfo->ptMaxPosition.x = rect.left - offsetXY.x();
minmaxInfo->ptMaxPosition.y = rect.top - offsetXY.x(); minmaxInfo->ptMaxPosition.y = rect.top - offsetXY.x();
@ -294,11 +301,11 @@ void FluFrameless::componentComplete() {
} else if (uMsg == WM_SYSCOMMAND) { } else if (uMsg == WM_SYSCOMMAND) {
if (wParam == SC_MINIMIZE) { if (wParam == SC_MINIMIZE) {
if (window()->transientParent()) { if (window()->transientParent()) {
HWND hwnd = reinterpret_cast<HWND>(window()->transientParent()->winId()); auto _hwnd = reinterpret_cast<HWND>(window()->transientParent()->winId());
::ShowWindow(hwnd, 2); ::ShowWindow(_hwnd, 2);
} else { } else {
HWND hwnd = reinterpret_cast<HWND>(window()->winId()); auto _hwnd = reinterpret_cast<HWND>(window()->winId());
::ShowWindow(hwnd, 2); ::ShowWindow(_hwnd, 2);
} }
return true; return true;
} }

View File

@ -29,10 +29,10 @@ FluTheme::FluTheme(QObject *parent) : QObject{parent} {
}); });
connect(this, &FluTheme::darkChanged, this, [=] { refreshColors(); }); connect(this, &FluTheme::darkChanged, this, [=] { refreshColors(); });
connect(this, &FluTheme::accentColorChanged, this, [=] { refreshColors(); }); connect(this, &FluTheme::accentColorChanged, this, [=] { refreshColors(); });
connect(&_watcher, &QFileSystemWatcher::fileChanged, this, [=](const QString &path){ connect(&_watcher, &QFileSystemWatcher::fileChanged, this, [=](const QString &path) {
Q_EMIT desktopImagePathChanged(); Q_EMIT desktopImagePathChanged();
}); });
connect(this, &FluTheme::blurBehindWindowEnabledChanged, this, [=] {checkUpdateDesktopImage();}); connect(this, &FluTheme::blurBehindWindowEnabledChanged, this, [=] { checkUpdateDesktopImage(); });
startTimer(1000); startTimer(1000);
} }
@ -74,15 +74,15 @@ bool FluTheme::dark() const {
} }
} }
void FluTheme::checkUpdateDesktopImage(){ void FluTheme::checkUpdateDesktopImage() {
if(!_blurBehindWindowEnabled){ if (!_blurBehindWindowEnabled) {
return; return;
} }
QThreadPool::globalInstance()->start([=]() { QThreadPool::globalInstance()->start([=]() {
_mutex.lock(); _mutex.lock();
auto path = FluTools::getInstance()->getWallpaperFilePath(); auto path = FluTools::getInstance()->getWallpaperFilePath();
if(_desktopImagePath != path){ if (_desktopImagePath != path) {
if(!_desktopImagePath.isEmpty()){ if (!_desktopImagePath.isEmpty()) {
_watcher.removePath(_desktopImagePath); _watcher.removePath(_desktopImagePath);
} }
desktopImagePath(path); desktopImagePath(path);
@ -92,7 +92,6 @@ void FluTheme::checkUpdateDesktopImage(){
}); });
} }
void FluTheme::timerEvent(QTimerEvent *event) void FluTheme::timerEvent(QTimerEvent *event) {
{
checkUpdateDesktopImage(); checkUpdateDesktopImage();
} }

View File

@ -1,5 +1,4 @@
#ifndef FLUTHEME_H #pragma once
#define FLUTHEME_H
#include <QObject> #include <QObject>
#include <QtQml/qqml.h> #include <QtQml/qqml.h>
@ -18,7 +17,7 @@
*/ */
class FluTheme : public QObject { class FluTheme : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool dark READ dark NOTIFY darkChanged) Q_PROPERTY(bool dark READ dark NOTIFY darkChanged)
Q_PROPERTY_AUTO_P(FluAccentColor*, accentColor); Q_PROPERTY_AUTO_P(FluAccentColor*, accentColor);
Q_PROPERTY_AUTO(QColor, primaryColor); Q_PROPERTY_AUTO(QColor, primaryColor);
Q_PROPERTY_AUTO(QColor, backgroundColor); Q_PROPERTY_AUTO(QColor, backgroundColor);
@ -49,8 +48,6 @@ private:
void refreshColors(); void refreshColors();
void updateBackgroundMainColor();
protected: protected:
void timerEvent(QTimerEvent *event) override; void timerEvent(QTimerEvent *event) override;
@ -71,5 +68,3 @@ private:
QFileSystemWatcher _watcher; QFileSystemWatcher _watcher;
QMutex _mutex; QMutex _mutex;
}; };
#endif // FLUTHEME_H