From d93aac3518f9c6f6a6ddb376e7435e2eeff0f73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sun, 28 Apr 2024 15:56:37 +0800 Subject: [PATCH] update --- example/example_en_US.ts | 22 ++++----- example/example_zh_CN.ts | 4 +- example/qml/page/T_TableView.qml | 16 +++---- src/FluFrameless.cpp | 45 +++++++++++++------ src/FluTableSortProxyModel.cpp | 4 ++ src/FluTableSortProxyModel.h | 2 + .../FluentUI/Controls/FluTableView.qml | 19 ++++++++ .../imports/FluentUI/Controls/FluWindow.qml | 2 +- .../FluentUI/Controls/FluTableView.qml | 19 ++++++++ .../imports/FluentUI/Controls/FluWindow.qml | 2 +- 10 files changed, 98 insertions(+), 37 deletions(-) diff --git a/example/example_en_US.ts b/example/example_en_US.ts index ceabe270..e88eb62c 100644 --- a/example/example_en_US.ts +++ b/example/example_en_US.ts @@ -1998,7 +1998,17 @@ Some contents... - + + Delete Selection + + + + + Add a row of Data + + + + Insert a Row @@ -2042,16 +2052,6 @@ Some contents... Next> - - - Delete Selection - - - - - Add a row of Data - - T_Text diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts index c86300be..f6d98a5e 100644 --- a/example/example_zh_CN.ts +++ b/example/example_zh_CN.ts @@ -2140,7 +2140,7 @@ Some contents... 清除所有 - + Insert a Row 插入一行 @@ -2190,7 +2190,7 @@ Some contents... 删除选中 - + Add a row of Data 添加一行数据 diff --git a/example/qml/page/T_TableView.qml b/example/qml/page/T_TableView.qml index b309c369..8dee3a97 100644 --- a/example/qml/page/T_TableView.qml +++ b/example/qml/page/T_TableView.qml @@ -442,15 +442,15 @@ FluContentPage{ var data = [] var rows = [] for (var i = 0; i < table_view.rows; i++) { - var item = table_view.getRow(i); + var item = table_view.getRow(i) rows.push(item) if (!item.checkbox.options.checked) { data.push(item); } } - var sourceModel = table_view.sourceModel; + var sourceModel = table_view.sourceModel for (i = 0; i < sourceModel.rowCount; i++) { - var sourceItem = sourceModel.getRow(i); + var sourceItem = sourceModel.getRow(i) const foundItem = rows.find(item=> item._key === sourceItem._key) if (!foundItem) { data.push(sourceItem); @@ -459,7 +459,6 @@ FluContentPage{ table_view.dataSource = data } } - FluButton{ text: qsTr("Add a row of Data") onClicked: { @@ -470,10 +469,11 @@ FluContentPage{ text: qsTr("Insert a Row") onClicked: { if(typeof table_view.current !== 'undefined'){ - var newLine = genTestObject() - var currentLine = dataSource.findIndex(obj => obj._key === table_view.current._key) - root.dataSource.splice(currentLine, 0, newLine); - table_view.dataSource = root.dataSource + var index = table_view.currentIndex() + if(index !== -1){ + var testObj = genTestObject() + table_view.insertRow(index,testObj) + } }else{ showWarning(qsTr("Focus not acquired: Please click any item in the form as the target for insertion!")) } diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index 6f92e2c7..0c2a2337 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -35,6 +35,22 @@ static inline bool isCompositionEnabled() { return false; } +static inline void setShadow(HWND hwnd){ + const MARGINS shadow = { 1, 1, 1, 1 }; + typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); + HMODULE module = LoadLibraryW(L"dwmapi.dll"); + if (module) + { + DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_; + dwm_extendframe_into_client_area_= reinterpret_cast(GetProcAddress(module, "DwmExtendFrameIntoClientArea")); + if (dwm_extendframe_into_client_area_) + { + dwm_extendframe_into_client_area_(hwnd, &shadow); + } + } +} + + #endif bool containsCursorToItem(QQuickItem *item) { @@ -106,6 +122,7 @@ void FluFrameless::componentComplete() { ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER); ::RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); }); + setShadow(hwnd); #endif h = qRound(h + _appbar->height()); if (_fixSize) { @@ -147,20 +164,22 @@ void FluFrameless::componentComplete() { } else if (uMsg == WM_NCCALCSIZE) { const auto clientRect = ((wParam == FALSE) ? reinterpret_cast(lParam) : &(reinterpret_cast(lParam))->rgrc[0]); bool isMaximum = ::IsZoomed(hwnd); + const LONG originalTop = clientRect->top; + const LONG originalLeft = clientRect->left; + const LONG originalBottom = clientRect->bottom; + const LONG originalRight = clientRect->right; + const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); + if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { + *result = static_cast(hitTestResult); + return true; + } if (!isMaximum){ - if (clientRect->top != 0) - { - clientRect->top -= 1; - clientRect->bottom -= 1; - } + clientRect->top = originalTop; + clientRect->bottom = originalBottom; + clientRect->left = originalLeft; + clientRect->right = originalRight; } else{ - const LONG originalTop = clientRect->top; - const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam); - if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) { - *result = static_cast(hitTestResult); - return true; - } - clientRect->top = originalTop-originalTop; + clientRect->top = 0; } _setMaximizeHovered(false); *result = WVR_REDRAW; @@ -244,8 +263,6 @@ void FluFrameless::componentComplete() { _setMaximizePressed(false); return true; } - } else if (uMsg == WM_ERASEBKGND) { - return true; } else if (uMsg == WM_NCRBUTTONDOWN) { if (wParam == HTCAPTION) { _showSystemMenu(QCursor::pos()); diff --git a/src/FluTableSortProxyModel.cpp b/src/FluTableSortProxyModel.cpp index 644f652a..1723a678 100644 --- a/src/FluTableSortProxyModel.cpp +++ b/src/FluTableSortProxyModel.cpp @@ -67,6 +67,10 @@ bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QMod QMetaObject::invokeMethod(_model, "setRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val)); } +[[maybe_unused]] void FluTableSortProxyModel::insertRow(int rowIndex, const QVariant &val) { + QMetaObject::invokeMethod(_model, "insertRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val)); +} + [[maybe_unused]] void FluTableSortProxyModel::removeRow(int rowIndex, int rows) { QMetaObject::invokeMethod(_model, "removeRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(int, rows)); } diff --git a/src/FluTableSortProxyModel.h b/src/FluTableSortProxyModel.h index 7a959f41..05fb1d9e 100644 --- a/src/FluTableSortProxyModel.h +++ b/src/FluTableSortProxyModel.h @@ -23,6 +23,8 @@ public: [[maybe_unused]] Q_INVOKABLE void setRow(int rowIndex, const QVariant &val); + [[maybe_unused]] Q_INVOKABLE void insertRow(int rowIndex, const QVariant &val); + [[maybe_unused]] Q_INVOKABLE void removeRow(int rowIndex, int rows); [[maybe_unused]] Q_INVOKABLE void setComparator(const QJSValue &comparator); diff --git a/src/Qt5/imports/FluentUI/Controls/FluTableView.qml b/src/Qt5/imports/FluentUI/Controls/FluTableView.qml index b09cab1b..31f81191 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluTableView.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluTableView.qml @@ -873,6 +873,25 @@ Rectangle { table_view.model.removeRow(rowIndex,rows) } } + function insertRow(rowIndex,obj){ + if(rowIndex>=0 && rowIndex=0 && rowIndex