This commit is contained in:
朱子楚\zhuzi 2024-04-23 13:41:26 +08:00
parent 2ddb7e3290
commit c7de653ba2
9 changed files with 121 additions and 60 deletions

View File

@ -24,7 +24,7 @@ FluContentPage {
leftMargin: 14 leftMargin: 14
} }
onClicked: { onClicked: {
grid_view.model = FluTheme.awesomeList(text_box.text) grid_view.model = FluApp.iconDatas(text_box.text)
} }
} }
GridView{ GridView{

View File

@ -4,6 +4,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QScreen> #include <QScreen>
#include <QDateTime> #include <QDateTime>
#include "FluTools.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#pragma comment (lib, "user32.lib") #pragma comment (lib, "user32.lib")
@ -13,6 +14,7 @@
#include <windowsx.h> #include <windowsx.h>
#include <dwmapi.h> #include <dwmapi.h>
static inline QByteArray qtNativeEventType() { static inline QByteArray qtNativeEventType() {
static const auto result = "windows_generic_MSG"; static const auto result = "windows_generic_MSG";
return result; return result;
@ -55,6 +57,7 @@ FluFrameless::FluFrameless(QQuickItem *parent) : QQuickItem{parent} {
_closeButton = nullptr; _closeButton = nullptr;
_topmost = false; _topmost = false;
_disabled = false; _disabled = false;
_isWindows11OrGreater = FluTools::getInstance()->isWindows11OrGreater();
} }
FluFrameless::~FluFrameless() = default; FluFrameless::~FluFrameless() = default;
@ -160,7 +163,10 @@ void FluFrameless::componentComplete() {
} }
int offsetSize; int offsetSize;
bool isMaximum = ::IsZoomed(hwnd); bool isMaximum = ::IsZoomed(hwnd);
offsetXY = QPoint(abs(clientRect->left - originalLeft), abs(clientRect->top - originalTop)); auto _offsetXY = QPoint(abs(clientRect->left - originalLeft), abs(clientRect->top - originalTop));
if (_offsetXY.x() != 0) {
offsetXY = _offsetXY;
}
if (isMaximum || _isFullScreen()) { if (isMaximum || _isFullScreen()) {
offsetSize = 0; offsetSize = 0;
} else { } else {
@ -179,6 +185,7 @@ void FluFrameless::componentComplete() {
*result = WVR_REDRAW; *result = WVR_REDRAW;
return true; return true;
} else if (uMsg == WM_NCHITTEST) { } else if (uMsg == WM_NCHITTEST) {
if (_isWindows11OrGreater) {
if (_hitMaximizeButton()) { if (_hitMaximizeButton()) {
if (*result == HTNOWHERE) { if (*result == HTNOWHERE) {
*result = HTZOOM; *result = HTZOOM;
@ -188,6 +195,7 @@ void FluFrameless::componentComplete() {
} }
_setMaximizeHovered(false); _setMaximizeHovered(false);
_setMaximizePressed(false); _setMaximizePressed(false);
}
*result = 0; *result = 0;
POINT nativeGlobalPos{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; POINT nativeGlobalPos{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
POINT nativeLocalPos = nativeGlobalPos; POINT nativeLocalPos = nativeGlobalPos;
@ -229,14 +237,14 @@ void FluFrameless::componentComplete() {
} }
*result = HTCLIENT; *result = HTCLIENT;
return true; return true;
} else if (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN) { } else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) {
if (_hitMaximizeButton()) { if (_hitMaximizeButton()) {
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_maximizeButton, &event); QGuiApplication::sendEvent(_maximizeButton, &event);
_setMaximizePressed(true); _setMaximizePressed(true);
return true; return true;
} }
} else if (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP) { } else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP)) {
if (_hitMaximizeButton()) { if (_hitMaximizeButton()) {
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_maximizeButton, &event); QGuiApplication::sendEvent(_maximizeButton, &event);
@ -256,6 +264,7 @@ void FluFrameless::componentComplete() {
minmaxInfo->ptMaxPosition.y = 0; minmaxInfo->ptMaxPosition.y = 0;
minmaxInfo->ptMaxSize.x = 0; minmaxInfo->ptMaxSize.x = 0;
minmaxInfo->ptMaxSize.y = 0; minmaxInfo->ptMaxSize.y = 0;
return false;
#else #else
auto pixelRatio = window()->devicePixelRatio(); auto pixelRatio = window()->devicePixelRatio();
auto geometry = window()->screen()->availableGeometry(); auto geometry = window()->screen()->availableGeometry();
@ -265,8 +274,8 @@ void FluFrameless::componentComplete() {
minmaxInfo->ptMaxPosition.y = rect.top - offsetXY.x(); minmaxInfo->ptMaxPosition.y = rect.top - offsetXY.x();
minmaxInfo->ptMaxSize.x = qRound(geometry.width() * pixelRatio) + offsetXY.x() * 2; minmaxInfo->ptMaxSize.x = qRound(geometry.width() * pixelRatio) + offsetXY.x() * 2;
minmaxInfo->ptMaxSize.y = qRound(geometry.height() * pixelRatio) + offsetXY.y() * 2; minmaxInfo->ptMaxSize.y = qRound(geometry.height() * pixelRatio) + offsetXY.y() * 2;
return true;
#endif #endif
return false;
} else if (uMsg == WM_NCRBUTTONDOWN) { } else if (uMsg == WM_NCRBUTTONDOWN) {
if (wParam == HTCAPTION) { if (wParam == HTCAPTION) {
_showSystemMenu(QCursor::pos()); _showSystemMenu(QCursor::pos());
@ -281,9 +290,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()) {
window()->transientParent()->showMinimized(); HWND hwnd = reinterpret_cast<HWND>(window()->transientParent()->winId());
::ShowWindow(hwnd, 2);
} else { } else {
window()->showMinimized(); HWND hwnd = reinterpret_cast<HWND>(window()->winId());
::ShowWindow(hwnd, 2);
} }
return true; return true;
} }
@ -395,16 +406,21 @@ void FluFrameless::showMaximized() {
HWND hwnd = reinterpret_cast<HWND>(window()->winId()); HWND hwnd = reinterpret_cast<HWND>(window()->winId());
::ShowWindow(hwnd, 3); ::ShowWindow(hwnd, 3);
#else #else
window()->showMaximized(); window()->setVisibility(QQuickWindow::Maximized);
#endif #endif
} }
[[maybe_unused]] void FluFrameless::showMinimized() { [[maybe_unused]] void FluFrameless::showMinimized() {
window()->showMinimized(); #ifdef Q_OS_WIN
HWND hwnd = reinterpret_cast<HWND>(window()->winId());
::ShowWindow(hwnd, 2);
#else
window()->setVisibility(QQuickWindow::Minimized);
#endif
} }
void FluFrameless::showNormal() { void FluFrameless::showNormal() {
window()->showNormal(); window()->setVisibility(QQuickWindow::Windowed);
} }
void FluFrameless::setHitTestVisible(QQuickItem *val) { void FluFrameless::setHitTestVisible(QQuickItem *val) {

View File

@ -73,5 +73,6 @@ private:
int _edges = 0; int _edges = 0;
int _margins = 8; int _margins = 8;
quint64 _clickTimer = 0; quint64 _clickTimer = 0;
bool _isWindows11OrGreater = false;
QList<QPointer<QQuickItem>> _hitTestList; QList<QPointer<QQuickItem>> _hitTestList;
}; };

View File

@ -59,12 +59,8 @@ FluTextBox{
duration: FluTheme.animationEnabled ? 83 : 0 duration: FluTheme.animationEnabled ? 83 : 0
} }
} }
contentItem: FluRectangle{ contentItem: FluClip{
radius: [4,4,4,4] radius: [5,5,5,5]
FluShadow{
radius: 4
}
color: FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(248/255,250/255,253/255,1)
ListView{ ListView{
id:list_view id:list_view
anchors.fill: parent anchors.fill: parent
@ -97,10 +93,13 @@ FluTextBox{
radius:4 radius:4
} }
color: { color: {
if(hovered){ if(pressed){
return FluTheme.dark ? Qt.rgba(63/255,60/255,61/255,1) : Qt.rgba(237/255,237/255,242/255,1) return FluTheme.itemPressColor
} }
return FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(0,0,0,0) if(hovered){
return FluTheme.itemHoverColor
}
return FluTheme.itemNormalColor
} }
} }
contentItem: FluText{ contentItem: FluText{
@ -112,22 +111,28 @@ FluTextBox{
} }
} }
} }
background: Item{ background:Rectangle{
id:container id: rect_background
implicitWidth: control.width implicitWidth: control.width
implicitHeight: 38*Math.min(Math.max(list_view.count,1),8) implicitHeight: 38*Math.min(Math.max(list_view.count,1),8)
radius: 5
color: FluTheme.dark ? Qt.rgba(43/255,43/255,43/255,1) : Qt.rgba(1,1,1,1)
border.color: FluTheme.dark ? Qt.rgba(26/255,26/255,26/255,1) : Qt.rgba(191/255,191/255,191/255,1)
FluShadow{
radius: 5
}
} }
} }
onTextChanged: { onTextChanged: {
d.loadData() d.loadData()
if(d.flagVisible){ if(d.flagVisible){
var pos = control.mapToItem(null, 0, 0) var pos = control.mapToItem(null, 0, 0)
if(d.window.height>pos.y+control.height+container.implicitHeight){ if(d.window.height>pos.y+control.height+rect_background.implicitHeight){
control_popup.y = control.height control_popup.y = control.height
} else if(pos.y>container.implicitHeight){ } else if(pos.y>rect_background.implicitHeight){
control_popup.y = -container.implicitHeight control_popup.y = -rect_background.implicitHeight
} else { } else {
control_popup.y = d.window.height-(pos.y+container.implicitHeight) control_popup.y = d.window.height-(pos.y+rect_background.implicitHeight) - 1
} }
control_popup.visible = true control_popup.visible = true
} }

View File

@ -23,16 +23,27 @@ FluControlBackground{
GradientStop { position: 1 - d.offsetSize/control.height; color: d.startColor } GradientStop { position: 1 - d.offsetSize/control.height; color: d.startColor }
GradientStop { position: 1.0; color: d.endColor } GradientStop { position: 1.0; color: d.endColor }
} }
bottomMargin: inputItem && inputItem.activeFocus ? 2 : 1 bottomMargin: 1
QtObject{ QtObject{
id:d id:d
property int offsetSize : inputItem && inputItem.activeFocus ? 2 : 3 property int offsetSize : 3
property color startColor : FluTheme.dark ? Qt.rgba(66/255,66/255,66/255,1) : Qt.rgba(232/255,232/255,232/255,1) property color startColor : FluTheme.dark ? Qt.rgba(66/255,66/255,66/255,1) : Qt.rgba(232/255,232/255,232/255,1)
property color endColor: { property color endColor: {
if(!control.enabled){ if(!control.enabled){
return d.startColor return d.startColor
} }
return inputItem && inputItem.activeFocus ? FluTheme.primaryColor : FluTheme.dark ? Qt.rgba(123/255,123/255,123/255,1) : Qt.rgba(132/255,132/255,132/255,1) return FluTheme.dark ? Qt.rgba(123/255,123/255,123/255,1) : Qt.rgba(132/255,132/255,132/255,1)
}
}
FluClip{
anchors.fill: parent
radius: [control.radius,control.radius,control.radius,control.radius]
visible: inputItem && inputItem.activeFocus
Rectangle{
width: parent.width
height: 2
anchors.bottom: parent.bottom
color: FluTheme.primaryColor
} }
} }
} }

View File

@ -330,6 +330,12 @@ Window {
function showMaximized(){ function showMaximized(){
frameless.showMaximized() frameless.showMaximized()
} }
function showMinimized(){
frameless.showMinimized()
}
function showNormal(){
frameless.showNormal()
}
function showLoading(text = "",cancel = true){ function showLoading(text = "",cancel = true){
if(text===""){ if(text===""){
text = qsTr("Loading...") text = qsTr("Loading...")

View File

@ -58,12 +58,8 @@ FluTextBox{
duration: FluTheme.animationEnabled ? 83 : 0 duration: FluTheme.animationEnabled ? 83 : 0
} }
} }
contentItem: FluRectangle{ contentItem: FluClip{
radius: [4,4,4,4] radius: [5,5,5,5]
FluShadow{
radius: 4
}
color: FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(248/255,250/255,253/255,1)
ListView{ ListView{
id:list_view id:list_view
anchors.fill: parent anchors.fill: parent
@ -96,10 +92,13 @@ FluTextBox{
radius:4 radius:4
} }
color: { color: {
if(hovered){ if(pressed){
return FluTheme.dark ? Qt.rgba(63/255,60/255,61/255,1) : Qt.rgba(237/255,237/255,242/255,1) return FluTheme.itemPressColor
} }
return FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(0,0,0,0) if(hovered){
return FluTheme.itemHoverColor
}
return FluTheme.itemNormalColor
} }
} }
contentItem: FluText{ contentItem: FluText{
@ -111,22 +110,28 @@ FluTextBox{
} }
} }
} }
background: Item{ background:Rectangle{
id:container id: rect_background
implicitWidth: control.width implicitWidth: control.width
implicitHeight: 38*Math.min(Math.max(list_view.count,1),8) implicitHeight: 38*Math.min(Math.max(list_view.count,1),8)
radius: 5
color: FluTheme.dark ? Qt.rgba(43/255,43/255,43/255,1) : Qt.rgba(1,1,1,1)
border.color: FluTheme.dark ? Qt.rgba(26/255,26/255,26/255,1) : Qt.rgba(191/255,191/255,191/255,1)
FluShadow{
radius: 5
}
} }
} }
onTextChanged: { onTextChanged: {
d.loadData() d.loadData()
if(d.flagVisible){ if(d.flagVisible){
var pos = control.mapToItem(null, 0, 0) var pos = control.mapToItem(null, 0, 0)
if(d.window.height>pos.y+control.height+container.implicitHeight){ if(d.window.height>pos.y+control.height+rect_background.implicitHeight){
control_popup.y = control.height control_popup.y = control.height
} else if(pos.y>container.implicitHeight){ } else if(pos.y>rect_background.implicitHeight){
control_popup.y = -container.implicitHeight control_popup.y = -rect_background.implicitHeight
} else { } else {
control_popup.y = d.window.height-(pos.y+container.implicitHeight) control_popup.y = d.window.height-(pos.y+rect_background.implicitHeight) - 1
} }
control_popup.visible = true control_popup.visible = true
} }

View File

@ -23,16 +23,27 @@ FluControlBackground{
GradientStop { position: 1 - d.offsetSize/control.height; color: d.startColor } GradientStop { position: 1 - d.offsetSize/control.height; color: d.startColor }
GradientStop { position: 1.0; color: d.endColor } GradientStop { position: 1.0; color: d.endColor }
} }
bottomMargin: inputItem && inputItem.activeFocus ? 2 : 1 bottomMargin: 1
QtObject{ QtObject{
id:d id:d
property int offsetSize : inputItem && inputItem.activeFocus ? 2 : 3 property int offsetSize : 3
property color startColor : FluTheme.dark ? Qt.rgba(66/255,66/255,66/255,1) : Qt.rgba(232/255,232/255,232/255,1) property color startColor : FluTheme.dark ? Qt.rgba(66/255,66/255,66/255,1) : Qt.rgba(232/255,232/255,232/255,1)
property color endColor: { property color endColor: {
if(!control.enabled){ if(!control.enabled){
return d.startColor return d.startColor
} }
return inputItem && inputItem.activeFocus ? FluTheme.primaryColor : FluTheme.dark ? Qt.rgba(123/255,123/255,123/255,1) : Qt.rgba(132/255,132/255,132/255,1) return FluTheme.dark ? Qt.rgba(123/255,123/255,123/255,1) : Qt.rgba(132/255,132/255,132/255,1)
}
}
FluClip{
anchors.fill: parent
radius: [control.radius,control.radius,control.radius,control.radius]
visible: inputItem && inputItem.activeFocus
Rectangle{
width: parent.width
height: 2
anchors.bottom: parent.bottom
color: FluTheme.primaryColor
} }
} }
} }

View File

@ -329,6 +329,12 @@ Window {
function showMaximized(){ function showMaximized(){
frameless.showMaximized() frameless.showMaximized()
} }
function showMinimized(){
frameless.showMinimized()
}
function showNormal(){
frameless.showNormal()
}
function showLoading(text = "",cancel = true){ function showLoading(text = "",cancel = true){
if(text===""){ if(text===""){
text = qsTr("Loading...") text = qsTr("Loading...")