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
}
onClicked: {
grid_view.model = FluTheme.awesomeList(text_box.text)
grid_view.model = FluApp.iconDatas(text_box.text)
}
}
GridView{

View File

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

View File

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

View File

@ -59,12 +59,8 @@ FluTextBox{
duration: FluTheme.animationEnabled ? 83 : 0
}
}
contentItem: FluRectangle{
radius: [4,4,4,4]
FluShadow{
radius: 4
}
color: FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(248/255,250/255,253/255,1)
contentItem: FluClip{
radius: [5,5,5,5]
ListView{
id:list_view
anchors.fill: parent
@ -97,10 +93,13 @@ FluTextBox{
radius:4
}
color: {
if(hovered){
return FluTheme.dark ? Qt.rgba(63/255,60/255,61/255,1) : Qt.rgba(237/255,237/255,242/255,1)
if(pressed){
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{
@ -112,22 +111,28 @@ FluTextBox{
}
}
}
background: Item{
id:container
background:Rectangle{
id: rect_background
implicitWidth: control.width
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: {
d.loadData()
if(d.flagVisible){
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
} else if(pos.y>container.implicitHeight){
control_popup.y = -container.implicitHeight
} else if(pos.y>rect_background.implicitHeight){
control_popup.y = -rect_background.implicitHeight
} 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
}

View File

@ -23,16 +23,27 @@ FluControlBackground{
GradientStop { position: 1 - d.offsetSize/control.height; color: d.startColor }
GradientStop { position: 1.0; color: d.endColor }
}
bottomMargin: inputItem && inputItem.activeFocus ? 2 : 1
bottomMargin: 1
QtObject{
id:d
property int offsetSize : inputItem && inputItem.activeFocus ? 2 : 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 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 endColor: {
if(!control.enabled){
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(){
frameless.showMaximized()
}
function showMinimized(){
frameless.showMinimized()
}
function showNormal(){
frameless.showNormal()
}
function showLoading(text = "",cancel = true){
if(text===""){
text = qsTr("Loading...")

View File

@ -58,12 +58,8 @@ FluTextBox{
duration: FluTheme.animationEnabled ? 83 : 0
}
}
contentItem: FluRectangle{
radius: [4,4,4,4]
FluShadow{
radius: 4
}
color: FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(248/255,250/255,253/255,1)
contentItem: FluClip{
radius: [5,5,5,5]
ListView{
id:list_view
anchors.fill: parent
@ -96,10 +92,13 @@ FluTextBox{
radius:4
}
color: {
if(hovered){
return FluTheme.dark ? Qt.rgba(63/255,60/255,61/255,1) : Qt.rgba(237/255,237/255,242/255,1)
if(pressed){
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{
@ -111,22 +110,28 @@ FluTextBox{
}
}
}
background: Item{
id:container
background:Rectangle{
id: rect_background
implicitWidth: control.width
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: {
d.loadData()
if(d.flagVisible){
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
} else if(pos.y>container.implicitHeight){
control_popup.y = -container.implicitHeight
} else if(pos.y>rect_background.implicitHeight){
control_popup.y = -rect_background.implicitHeight
} 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
}

View File

@ -23,16 +23,27 @@ FluControlBackground{
GradientStop { position: 1 - d.offsetSize/control.height; color: d.startColor }
GradientStop { position: 1.0; color: d.endColor }
}
bottomMargin: inputItem && inputItem.activeFocus ? 2 : 1
bottomMargin: 1
QtObject{
id:d
property int offsetSize : inputItem && inputItem.activeFocus ? 2 : 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 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 endColor: {
if(!control.enabled){
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(){
frameless.showMaximized()
}
function showMinimized(){
frameless.showMinimized()
}
function showNormal(){
frameless.showNormal()
}
function showLoading(text = "",cancel = true){
if(text===""){
text = qsTr("Loading...")