From 76f40a6265cf82f542c17ce068ffb6ac2e8759db Mon Sep 17 00:00:00 2001 From: jeffrey0326 <547913081@qq.com> Date: Wed, 21 Aug 2024 22:07:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwin11=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=95=88=E6=9E=9C=E5=B4=A9=E6=BA=83=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/qml/page/New_TableView.qml | 263 +++++++++++++++++++++++++++++ src/FluFrameless.cpp | 21 +++ 2 files changed, 284 insertions(+) create mode 100644 example/qml/page/New_TableView.qml diff --git a/example/qml/page/New_TableView.qml b/example/qml/page/New_TableView.qml new file mode 100644 index 00000000..0bef204a --- /dev/null +++ b/example/qml/page/New_TableView.qml @@ -0,0 +1,263 @@ +import QtQuick 2.15 +import FluentUI 1.0 +import "../component" + +FluPage{ + title:"表格测试" + TableView{ + columnSource: [ + { + title: "全选", + dataIndex: 'patientsex', + width:60, + readOnly:true, + position: 0, + delegate: com_checkbox, + headerDelegate: com_header_checkbox, + frozen: true + }, + + { + title: "检测日期", + dataIndex: 'testdate', + readOnly:true, + // width:150, + // delegate: com_action + }, + { + title: "条码号", + dataIndex: 'barcode', + width:80, + readOnly:true, + position: 0, + movable: false, + frozen: true + // delegate: com_checkbox, + // headerDelegate: com_header_checkbox + }, + { + title: "样本号", + dataIndex: 'sampleid', + width:100, + position: 1, + minimumWidth:100, + maximumWidth:100, + }, + { + title: "姓名", + dataIndex: 'patientname', + width:220, + minimumWidth:100, + maximumWidth:250 + }, + { + title:"操作", + dataIndex:"", + delegate:com_action, + frozen: true, + width: 250 + }, + { + title: "头像", + dataIndex: 'imageurl', + width:120, + minimumWidth:80, + maximumWidth:250, + delegate:com_avatar, + frozen: true + }, + { + title: "性别", + dataIndex: 'patientsex', + width:130, + minimumWidth:50, + maximumWidth:250, + // delegate:com_avatar + }, + + { + title: "年龄", + dataIndex: 'patientage', + width:100, + minimumWidth:80, + maximumWidth:330 + }, + { + title: "电话", + dataIndex: 'patienttel', + width:200, + minimumWidth:100, + maximumWidth:300, + editMultiline: true + }, + { + title: "身份证号", + dataIndex: 'patientidenno', + width:120, + minimumWidth:100, + maximumWidth:250 + }, + { + title: "检测项目", + dataIndex: 'hisitemnamelist', + width:120, + minimumWidth:100, + maximumWidth:250 + }, + { + title: "开单科室", + dataIndex: 'deptname', + width:150, + minimumWidth:100, + maximumWidth:250 + }, + { + title: "开单医生", + dataIndex: 'doctorname', + width:140, + minimumWidth:100, + maximumWidth:250 + } + , + { + title: "接收时间", + dataIndex: 'incepttime', + width:120, + minimumWidth:100, + maximumWidth:250 + }, + { + title: "核收时间", + dataIndex: 'accepttime', + width:220, + minimumWidth:100, + maximumWidth:250 + } + ] + model: ListModel{ + id: customModel + } + } + Component.onCompleted: { + // generateTestData(1000) // 生成100条测试数据 + for (var i = 0; i < 100000; i++) { + customModel.append(generateTestData(i)) + } + // uvRecord.setProperty() + } + Component{ + id:com_avatar + Item{ + anchors.fill: parent + FluClip{ + anchors.centerIn: parent + width: Math.min(parent.width,parent.height) + height: width + radius: [width/2,width/2,width/2,width/2] + Image{ + anchors.fill: parent + source: display + sourceSize: Qt.size(80,80) + fillMode: Image.PreserveAspectFit + } + } + } + } + Component { + id: com_checkbox + Item{ + FluCheckBox { + width: 15 + height: 15 + anchors.centerIn: parent + } + } + } + Component { + id: com_header_checkbox + Item{ + FluCheckBox { + width: 15 + height: 15 + anchors.centerIn: parent + } + } + } + Component{ + id: com_action + Item{ + Row{ + anchors.centerIn: parent + FluTextButton{ + text:"插入" + onClicked: { + // uvRecord.insertRecord(row) + uvRecord.insert(row,generateTestData(row)) + } + } + FluTextButton{ + text:"上移" + onClicked:{ + if (row > 0) { + uvRecord.move(row, row - 1, 1) + } + } + } + FluTextButton{ + text:"下移" + onClicked:{ + if (row < uvRecord.rowCount() - 1) { + uvRecord.move(row, row + 2, 1) // 注意这里是 row + 2 + } + } + } + FluTextButton{ + text:"查看" + onClicked: { + showSuccess(JSON.stringify(control.model.get(row))) + } + } + FluTextButton{ + text:"删除" + onClicked: { + uvRecord.remove(row) + } + } + } + } + } + + function generateTestData(i) { + var sexes = ["男", "女"] + var departments = ["内科", "外科", "儿科", "妇科", "眼科"] + var doctors = ["张医生", "李医生", "王医生", "刘医生", "陈医生"] + var images = [ + "qrc:/res/image/pages/exchange.png", + "qrc:/res/image/pages/nuclear.png", + "qrc:/res/image/pages/ocr.png", + "qrc:/res/image/pages/room-temperature.png", + "qrc:/res/image/pages/rt-pcr-machine.png" + ] + return { + testdate: new Date().toLocaleDateString(), + barcode: "BC" + (1000000 + i).toString(), + sampleid: "S" + (100000 + i).toString(), + patientname: "患者" + (i + 1), + patientsex: sexes[Math.floor(Math.random() * sexes.length)], + patientage: Math.floor(Math.random() * 80 + 1) + "岁", + patienttel: "1" + Math.floor(Math.random() * 9000000000 + 1000000000), + patientidenno: (310000000000000000 + i).toString(), + hisitemnamelist: "项目1,项目2,项目3", + deptname: departments[Math.floor(Math.random() * departments.length)], + doctorname: doctors[Math.floor(Math.random() * doctors.length)], + incepttime: new Date().toLocaleString(), + accepttime: new Date().toLocaleString(), + imageurl: images[Math.floor(Math.random() * images.length)], + _minimumHeight: 42, + _maximumHeight: 800, + height: 42 + } + + } + +} diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index 165f7212..bed322c7 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -136,6 +136,13 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en if (!isWin11OrGreater()) { return false; } + if(module && !pDwmSetWindowAttribute){ + pDwmSetWindowAttribute = reinterpret_cast( + GetProcAddress(module, "DwmSetWindowAttribute")); + if (!pDwmSetWindowAttribute) { + return false; + } + } if (enable) { pDwmExtendFrameIntoClientArea(hwnd, &extendedMargins); if (isWin1122H2OrGreater()) { @@ -163,6 +170,13 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en if (!isWin1122H2OrGreater()) { return false; } + if(module && !pDwmSetWindowAttribute){ + pDwmSetWindowAttribute = reinterpret_cast( + GetProcAddress(module, "DwmSetWindowAttribute")); + if (!pDwmSetWindowAttribute) { + return false; + } + } if (enable) { pDwmExtendFrameIntoClientArea(hwnd, &extendedMargins); const DWORD backdropType = _DWMSBT_TABBEDWINDOW; @@ -180,6 +194,13 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en if (!isWin11OrGreater()) { return false; } + if(module && !pDwmSetWindowAttribute){ + pDwmSetWindowAttribute = reinterpret_cast( + GetProcAddress(module, "DwmSetWindowAttribute")); + if (!pDwmSetWindowAttribute) { + return false; + } + } if (enable) { MARGINS margins{-1, -1, -1, -1}; pDwmExtendFrameIntoClientArea(hwnd, &margins); From f2eca9a2b9a800f7ff86557378dcf2e974e3d77b Mon Sep 17 00:00:00 2001 From: jeffrey0326 <547913081@qq.com> Date: Wed, 21 Aug 2024 22:08:13 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwin11=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=95=88=E6=9E=9C=E5=B4=A9=E6=BA=83=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/qml/page/New_TableView.qml | 263 ----------------------------- 1 file changed, 263 deletions(-) delete mode 100644 example/qml/page/New_TableView.qml diff --git a/example/qml/page/New_TableView.qml b/example/qml/page/New_TableView.qml deleted file mode 100644 index 0bef204a..00000000 --- a/example/qml/page/New_TableView.qml +++ /dev/null @@ -1,263 +0,0 @@ -import QtQuick 2.15 -import FluentUI 1.0 -import "../component" - -FluPage{ - title:"表格测试" - TableView{ - columnSource: [ - { - title: "全选", - dataIndex: 'patientsex', - width:60, - readOnly:true, - position: 0, - delegate: com_checkbox, - headerDelegate: com_header_checkbox, - frozen: true - }, - - { - title: "检测日期", - dataIndex: 'testdate', - readOnly:true, - // width:150, - // delegate: com_action - }, - { - title: "条码号", - dataIndex: 'barcode', - width:80, - readOnly:true, - position: 0, - movable: false, - frozen: true - // delegate: com_checkbox, - // headerDelegate: com_header_checkbox - }, - { - title: "样本号", - dataIndex: 'sampleid', - width:100, - position: 1, - minimumWidth:100, - maximumWidth:100, - }, - { - title: "姓名", - dataIndex: 'patientname', - width:220, - minimumWidth:100, - maximumWidth:250 - }, - { - title:"操作", - dataIndex:"", - delegate:com_action, - frozen: true, - width: 250 - }, - { - title: "头像", - dataIndex: 'imageurl', - width:120, - minimumWidth:80, - maximumWidth:250, - delegate:com_avatar, - frozen: true - }, - { - title: "性别", - dataIndex: 'patientsex', - width:130, - minimumWidth:50, - maximumWidth:250, - // delegate:com_avatar - }, - - { - title: "年龄", - dataIndex: 'patientage', - width:100, - minimumWidth:80, - maximumWidth:330 - }, - { - title: "电话", - dataIndex: 'patienttel', - width:200, - minimumWidth:100, - maximumWidth:300, - editMultiline: true - }, - { - title: "身份证号", - dataIndex: 'patientidenno', - width:120, - minimumWidth:100, - maximumWidth:250 - }, - { - title: "检测项目", - dataIndex: 'hisitemnamelist', - width:120, - minimumWidth:100, - maximumWidth:250 - }, - { - title: "开单科室", - dataIndex: 'deptname', - width:150, - minimumWidth:100, - maximumWidth:250 - }, - { - title: "开单医生", - dataIndex: 'doctorname', - width:140, - minimumWidth:100, - maximumWidth:250 - } - , - { - title: "接收时间", - dataIndex: 'incepttime', - width:120, - minimumWidth:100, - maximumWidth:250 - }, - { - title: "核收时间", - dataIndex: 'accepttime', - width:220, - minimumWidth:100, - maximumWidth:250 - } - ] - model: ListModel{ - id: customModel - } - } - Component.onCompleted: { - // generateTestData(1000) // 生成100条测试数据 - for (var i = 0; i < 100000; i++) { - customModel.append(generateTestData(i)) - } - // uvRecord.setProperty() - } - Component{ - id:com_avatar - Item{ - anchors.fill: parent - FluClip{ - anchors.centerIn: parent - width: Math.min(parent.width,parent.height) - height: width - radius: [width/2,width/2,width/2,width/2] - Image{ - anchors.fill: parent - source: display - sourceSize: Qt.size(80,80) - fillMode: Image.PreserveAspectFit - } - } - } - } - Component { - id: com_checkbox - Item{ - FluCheckBox { - width: 15 - height: 15 - anchors.centerIn: parent - } - } - } - Component { - id: com_header_checkbox - Item{ - FluCheckBox { - width: 15 - height: 15 - anchors.centerIn: parent - } - } - } - Component{ - id: com_action - Item{ - Row{ - anchors.centerIn: parent - FluTextButton{ - text:"插入" - onClicked: { - // uvRecord.insertRecord(row) - uvRecord.insert(row,generateTestData(row)) - } - } - FluTextButton{ - text:"上移" - onClicked:{ - if (row > 0) { - uvRecord.move(row, row - 1, 1) - } - } - } - FluTextButton{ - text:"下移" - onClicked:{ - if (row < uvRecord.rowCount() - 1) { - uvRecord.move(row, row + 2, 1) // 注意这里是 row + 2 - } - } - } - FluTextButton{ - text:"查看" - onClicked: { - showSuccess(JSON.stringify(control.model.get(row))) - } - } - FluTextButton{ - text:"删除" - onClicked: { - uvRecord.remove(row) - } - } - } - } - } - - function generateTestData(i) { - var sexes = ["男", "女"] - var departments = ["内科", "外科", "儿科", "妇科", "眼科"] - var doctors = ["张医生", "李医生", "王医生", "刘医生", "陈医生"] - var images = [ - "qrc:/res/image/pages/exchange.png", - "qrc:/res/image/pages/nuclear.png", - "qrc:/res/image/pages/ocr.png", - "qrc:/res/image/pages/room-temperature.png", - "qrc:/res/image/pages/rt-pcr-machine.png" - ] - return { - testdate: new Date().toLocaleDateString(), - barcode: "BC" + (1000000 + i).toString(), - sampleid: "S" + (100000 + i).toString(), - patientname: "患者" + (i + 1), - patientsex: sexes[Math.floor(Math.random() * sexes.length)], - patientage: Math.floor(Math.random() * 80 + 1) + "岁", - patienttel: "1" + Math.floor(Math.random() * 9000000000 + 1000000000), - patientidenno: (310000000000000000 + i).toString(), - hisitemnamelist: "项目1,项目2,项目3", - deptname: departments[Math.floor(Math.random() * departments.length)], - doctorname: doctors[Math.floor(Math.random() * doctors.length)], - incepttime: new Date().toLocaleString(), - accepttime: new Date().toLocaleString(), - imageurl: images[Math.floor(Math.random() * images.length)], - _minimumHeight: 42, - _maximumHeight: 800, - height: 42 - } - - } - -} From 50b89e7eb2dd44814891dd535a24bae5e2c1ed55 Mon Sep 17 00:00:00 2001 From: jeffrey0326 <547913081@qq.com> Date: Wed, 21 Aug 2024 22:50:43 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8Dwin11=E8=AE=BE=E7=BD=AE=E6=95=88?= =?UTF-8?q?=E6=9E=9C=E5=B4=A9=E6=BA=83=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FluFrameless.cpp | 141 ++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 83 deletions(-) diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index bed322c7..be2f239d 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -84,14 +84,57 @@ static inline QByteArray qtNativeEventType() { return result; } -static inline bool isCompositionEnabled() { - HMODULE module = ::LoadLibraryW(L"dwmapi.dll"); +static inline bool initializeFunctionPointers() { + HMODULE module = LoadLibraryW(L"dwmapi.dll"); if (module) { - BOOL composition_enabled = false; - pDwmIsCompositionEnabled = reinterpret_cast(::GetProcAddress(module, "DwmIsCompositionEnabled")); - if (pDwmIsCompositionEnabled) { - pDwmIsCompositionEnabled(&composition_enabled); + if (!pDwmSetWindowAttribute) { + pDwmSetWindowAttribute = reinterpret_cast( + GetProcAddress(module, "DwmSetWindowAttribute")); + if (!pDwmSetWindowAttribute) { + return false; + } + } + if (!pDwmExtendFrameIntoClientArea) { + pDwmExtendFrameIntoClientArea = reinterpret_cast( + GetProcAddress(module, "DwmExtendFrameIntoClientArea")); + if (!pDwmExtendFrameIntoClientArea) { + return false; + } + } + if (!pDwmIsCompositionEnabled) { + pDwmIsCompositionEnabled = reinterpret_cast( + ::GetProcAddress(module, "DwmIsCompositionEnabled")); + if (!pDwmIsCompositionEnabled) { + return false; + } + } + if (!pDwmEnableBlurBehindWindow) { + pDwmEnableBlurBehindWindow = + reinterpret_cast( + GetProcAddress(module, "DwmEnableBlurBehindWindow")); + if (!pDwmEnableBlurBehindWindow) { + return false; + } } + if (!pSetWindowCompositionAttribute) { + HMODULE user32 = LoadLibraryW(L"user32.dll"); + if (!user32) { + return false; + } + pSetWindowCompositionAttribute = reinterpret_cast( + GetProcAddress(user32, "SetWindowCompositionAttribute")); + if (!pSetWindowCompositionAttribute) { + return false; + } + } + } + return true; +} + +static inline bool isCompositionEnabled() { + if(initializeFunctionPointers()){ + BOOL composition_enabled = false; + pDwmIsCompositionEnabled(&composition_enabled); return composition_enabled; } return false; @@ -99,50 +142,24 @@ static inline bool isCompositionEnabled() { static inline void setShadow(HWND hwnd) { const MARGINS shadow = {1, 0, 0, 0}; - HMODULE module = LoadLibraryW(L"dwmapi.dll"); - if (module) { - pDwmExtendFrameIntoClientArea = reinterpret_cast(GetProcAddress(module, "DwmExtendFrameIntoClientArea")); - if (pDwmExtendFrameIntoClientArea) { - pDwmExtendFrameIntoClientArea(hwnd, &shadow); - } + if (initializeFunctionPointers()) { + pDwmExtendFrameIntoClientArea(hwnd, &shadow); } } static inline bool setWindowDarkMode(HWND hwnd, const BOOL enable) { - if (!pDwmSetWindowAttribute) { - HMODULE module = LoadLibraryW(L"dwmapi.dll"); - if (module) { - pDwmSetWindowAttribute = reinterpret_cast( - GetProcAddress(module, "DwmSetWindowAttribute")); - } - if (!pDwmSetWindowAttribute) { - return false; - } + if (!initializeFunctionPointers()) { + return false; } return bool(pDwmSetWindowAttribute(hwnd, 20, &enable, sizeof(BOOL))); } static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &enable) { static constexpr const MARGINS extendedMargins = {-1, -1, -1, -1}; - HMODULE module = LoadLibraryW(L"dwmapi.dll"); - if (module) { - pDwmExtendFrameIntoClientArea = reinterpret_cast( - GetProcAddress(module, "DwmExtendFrameIntoClientArea")); - if (!pDwmExtendFrameIntoClientArea) { - return false; - } - } if (key == QStringLiteral("mica")) { - if (!isWin11OrGreater()) { + if (!isWin11OrGreater() || !initializeFunctionPointers()) { return false; } - if(module && !pDwmSetWindowAttribute){ - pDwmSetWindowAttribute = reinterpret_cast( - GetProcAddress(module, "DwmSetWindowAttribute")); - if (!pDwmSetWindowAttribute) { - return false; - } - } if (enable) { pDwmExtendFrameIntoClientArea(hwnd, &extendedMargins); if (isWin1122H2OrGreater()) { @@ -167,16 +184,9 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en } if (key == QStringLiteral("mica-alt")) { - if (!isWin1122H2OrGreater()) { + if (!isWin1122H2OrGreater() || !initializeFunctionPointers()) { return false; } - if(module && !pDwmSetWindowAttribute){ - pDwmSetWindowAttribute = reinterpret_cast( - GetProcAddress(module, "DwmSetWindowAttribute")); - if (!pDwmSetWindowAttribute) { - return false; - } - } if (enable) { pDwmExtendFrameIntoClientArea(hwnd, &extendedMargins); const DWORD backdropType = _DWMSBT_TABBEDWINDOW; @@ -191,19 +201,11 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en } if (key == QStringLiteral("acrylic")) { - if (!isWin11OrGreater()) { + if (!isWin11OrGreater() || !initializeFunctionPointers()) { return false; } - if(module && !pDwmSetWindowAttribute){ - pDwmSetWindowAttribute = reinterpret_cast( - GetProcAddress(module, "DwmSetWindowAttribute")); - if (!pDwmSetWindowAttribute) { - return false; - } - } if (enable) { - MARGINS margins{-1, -1, -1, -1}; - pDwmExtendFrameIntoClientArea(hwnd, &margins); + pDwmExtendFrameIntoClientArea(hwnd, &extendedMargins); DWORD system_backdrop_type = _DWMSBT_TRANSIENTWINDOW; pDwmSetWindowAttribute(hwnd, 38, &system_backdrop_type, sizeof(DWORD)); } else { @@ -216,19 +218,11 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en } if (key == QStringLiteral("dwm-blur")) { - if (isWin7Only() && !isCompositionEnabled()) { + if ((isWin7Only() && !isCompositionEnabled()) || !initializeFunctionPointers()) { return false; } BOOL isDark = FluTheme::getInstance()->dark(); setWindowDarkMode(hwnd, isDark && enable); - if (isWin8OrGreater() && !pSetWindowCompositionAttribute) { - HMODULE module = LoadLibraryW(L"user32.dll"); - pSetWindowCompositionAttribute = reinterpret_cast( - GetProcAddress(module, "SetWindowCompositionAttribute")); - if (!pSetWindowCompositionAttribute) { - return false; - } - } if (enable) { if (isWin8OrGreater()) { ACCENT_POLICY policy{}; @@ -243,15 +237,6 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en DWM_BLURBEHIND bb{}; bb.fEnable = TRUE; bb.dwFlags = DWM_BB_ENABLE; - if (!pDwmEnableBlurBehindWindow) { - HMODULE module = LoadLibraryW(L"user32.dll"); - pDwmEnableBlurBehindWindow = - reinterpret_cast( - GetProcAddress(module, "DwmEnableBlurBehindWindowFunc")); - if (!pDwmEnableBlurBehindWindow) { - return false; - } - } pDwmEnableBlurBehindWindow(hwnd, &bb); } } else { @@ -268,21 +253,11 @@ static inline bool setWindowEffect(HWND hwnd, const QString &key, const bool &en DWM_BLURBEHIND bb{}; bb.fEnable = FALSE; bb.dwFlags = DWM_BB_ENABLE; - if (!pDwmEnableBlurBehindWindow) { - HMODULE module = LoadLibraryW(L"user32.dll"); - pDwmEnableBlurBehindWindow = - reinterpret_cast( - GetProcAddress(module, "DwmEnableBlurBehindWindowFunc")); - if (!pDwmEnableBlurBehindWindow) { - return false; - } - } pDwmEnableBlurBehindWindow(hwnd, &bb); } } return true; } - return false; }