From 96a6d0e7fa085aa77e94b591e5a3bcfe48e934e2 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 20:22:05 +0800 Subject: [PATCH] update --- example/example_en_US.ts | 28 ++++---- example/example_zh_CN.ts | 28 ++++---- example/qml/page/T_TableView.qml | 3 +- src/FluApp.cpp | 3 +- src/FluApp.h | 2 +- src/FluFrameless.cpp | 70 +++++++++---------- src/FluTableModel.cpp | 36 +++++----- src/FluTableModel.h | 14 ++-- src/FluTableSortProxyModel.cpp | 12 ++-- src/FluTableSortProxyModel.h | 2 +- src/FluTools.h | 2 +- src/FluTreeModel.cpp | 10 +-- src/FluTreeModel.h | 2 +- .../imports/FluentUI/Controls/FluShadow.qml | 2 +- .../FluentUI/Controls/FluTableView.qml | 51 +++++++------- .../imports/FluentUI/Controls/FluShadow.qml | 2 +- .../FluentUI/Controls/FluTableView.qml | 51 +++++++------- 17 files changed, 158 insertions(+), 160 deletions(-) diff --git a/example/example_en_US.ts b/example/example_en_US.ts index 36ff648b..4ac68c4d 100644 --- a/example/example_en_US.ts +++ b/example/example_en_US.ts @@ -1968,7 +1968,7 @@ Some contents... - + Name @@ -1988,67 +1988,67 @@ Some contents... - + Age - + Clear All - + Delete Selection - + Add a row of Data - + Insert a Row - + Focus not acquired: Please click any item in the form as the target for insertion! - + Avatar - + Address - + Nickname - + Long String - + Options - + <Previous - + Next> diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts index 8d1b2571..5880157d 100644 --- a/example/example_zh_CN.ts +++ b/example/example_zh_CN.ts @@ -2110,7 +2110,7 @@ Some contents... - + Name 名称 @@ -2130,67 +2130,67 @@ Some contents... 全选 - + Age 年龄 - + Clear All 清除所有 - + Insert a Row 插入一行 - + Focus not acquired: Please click any item in the form as the target for insertion! 焦点未获取:请点击表格中的任意一项,作为插入的靶点! - + Avatar 头像 - + Address 地址 - + Nickname 昵称 - + Long String 长字符串 - + Options 操作 - + <Previous <上一页 - + Next> 下一页> - + Delete Selection 删除选中 - + Add a row of Data 添加一行数据 diff --git a/example/qml/page/T_TableView.qml b/example/qml/page/T_TableView.qml index 94a7aad0..fe0f6e93 100644 --- a/example/qml/page/T_TableView.qml +++ b/example/qml/page/T_TableView.qml @@ -244,7 +244,7 @@ FluContentPage{ clickListener: function(){ root.selectedAll = !root.selectedAll var checked = root.selectedAll - itemModel.display = table_view.customItem(com_column_checbox,{"checked":checked}) + model.display = table_view.customItem(com_column_checbox,{"checked":checked}) for(var i =0;i< table_view.rows ;i++){ var rowData = table_view.getRow(i) rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked}) @@ -293,6 +293,7 @@ FluContentPage{ }); items = result textbox.text= String(display) + selectAll() } onCommit: { editTextChaged(textbox.text) diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 36bfd3fa..82226782 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -1,6 +1,5 @@ #include "FluApp.h" -#include #include #include #include @@ -32,7 +31,7 @@ void FluApp::init(QObject *target, QLocale locale) { } } -[[maybe_unused]] QJsonArray FluApp::iconDatas(const QString &keyword) { +[[maybe_unused]] QJsonArray FluApp::iconData(const QString &keyword) { QJsonArray arr; QMetaEnum enumType = Fluent_Icons::staticMetaObject.enumerator(Fluent_Icons::staticMetaObject.indexOfEnumerator("Fluent_IconType")); for (int i = 0; i <= enumType.keyCount() - 1; ++i) { diff --git a/src/FluApp.h b/src/FluApp.h index 89934208..f691af61 100644 --- a/src/FluApp.h +++ b/src/FluApp.h @@ -36,7 +36,7 @@ SINGLETON(FluApp) Q_INVOKABLE void init(QObject *target, QLocale locale = QLocale::system()); - [[maybe_unused]] Q_INVOKABLE static QJsonArray iconDatas(const QString &keyword = ""); + [[maybe_unused]] Q_INVOKABLE static QJsonArray iconData(const QString &keyword = ""); private: QQmlEngine *_engine{}; diff --git a/src/FluFrameless.cpp b/src/FluFrameless.cpp index ec423f8a..8fec5f5e 100644 --- a/src/FluFrameless.cpp +++ b/src/FluFrameless.cpp @@ -35,16 +35,14 @@ static inline bool isCompositionEnabled() { return false; } -static inline void setShadow(HWND hwnd){ - const MARGINS shadow = { 1, 0, 0, 0 }; - typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); +static inline void setShadow(HWND hwnd) { + const MARGINS shadow = {1, 0, 0, 0}; + typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); HMODULE module = LoadLibraryW(L"dwmapi.dll"); - if (module) - { + 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_ = reinterpret_cast(GetProcAddress(module, "DwmExtendFrameIntoClientArea")); + if (dwm_extendframe_into_client_area_) { dwm_extendframe_into_client_area_(hwnd, &shadow); } } @@ -108,21 +106,21 @@ void FluFrameless::componentComplete() { HWND hwnd = reinterpret_cast(window()->winId()); DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE); if (_fixSize) { - ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_CAPTION); + ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_CAPTION); for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) { connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] { SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_FRAMECHANGED); }); } } else { - ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_CAPTION); + ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_CAPTION); } SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); connect(window(), &QQuickWindow::screenChanged, this, [hwnd] { ::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); }); - if(!window()->property("_hideShadow").toBool()){ + if (!window()->property("_hideShadow").toBool()) { setShadow(hwnd); } #endif @@ -175,12 +173,12 @@ void FluFrameless::componentComplete() { *result = static_cast(hitTestResult); return true; } - if (!isMaximum){ + if (!isMaximum) { clientRect->top = originalTop; clientRect->bottom = originalBottom; clientRect->left = originalLeft; clientRect->right = originalRight; - } else{ + } else { clientRect->top = 0; } _setMaximizeHovered(false); @@ -240,13 +238,13 @@ void FluFrameless::componentComplete() { *result = HTCLIENT; return true; } else if (uMsg == WM_NCPAINT) { - if(isCompositionEnabled()){ + if (isCompositionEnabled()) { return false; } *result = FALSE; return true; } else if (uMsg == WM_NCACTIVATE) { - if(isCompositionEnabled()){ + if (isCompositionEnabled()) { return false; } *result = TRUE; @@ -362,27 +360,27 @@ void FluFrameless::_setMaximizeHovered(bool val) { void FluFrameless::_updateCursor(int edges) { switch (edges) { - case 0: - window()->setCursor(Qt::ArrowCursor); - break; - case Qt::LeftEdge: - case Qt::RightEdge: - window()->setCursor(Qt::SizeHorCursor); - break; - case Qt::TopEdge: - case Qt::BottomEdge: - window()->setCursor(Qt::SizeVerCursor); - break; - case Qt::LeftEdge | Qt::TopEdge: - case Qt::RightEdge | Qt::BottomEdge: - window()->setCursor(Qt::SizeFDiagCursor); - break; - case Qt::RightEdge | Qt::TopEdge: - case Qt::LeftEdge | Qt::BottomEdge: - window()->setCursor(Qt::SizeBDiagCursor); - break; - default: - break; + case 0: + window()->setCursor(Qt::ArrowCursor); + break; + case Qt::LeftEdge: + case Qt::RightEdge: + window()->setCursor(Qt::SizeHorCursor); + break; + case Qt::TopEdge: + case Qt::BottomEdge: + window()->setCursor(Qt::SizeVerCursor); + break; + case Qt::LeftEdge | Qt::TopEdge: + case Qt::RightEdge | Qt::BottomEdge: + window()->setCursor(Qt::SizeFDiagCursor); + break; + case Qt::RightEdge | Qt::TopEdge: + case Qt::LeftEdge | Qt::BottomEdge: + window()->setCursor(Qt::SizeBDiagCursor); + break; + default: + break; } } diff --git a/src/FluTableModel.cpp b/src/FluTableModel.cpp index ac74bd67..1a0e9c7c 100644 --- a/src/FluTableModel.cpp +++ b/src/FluTableModel.cpp @@ -1,6 +1,6 @@ #include "FluTableModel.h" -FluTableModel::FluTableModel(QObject *parent) : QAbstractTableModel{parent}{ +FluTableModel::FluTableModel(QObject *parent) : QAbstractTableModel{parent} { } @@ -14,20 +14,20 @@ int FluTableModel::columnCount(const QModelIndex &parent) const { QVariant FluTableModel::data(const QModelIndex &index, int role) const { switch (role) { - case FluTableModel::RowModel: - return QVariant::fromValue(_rows.at(index.row())); - case FluTableModel::ColumnModel: - return QVariant::fromValue(_columnSource.at(index.column())); - default: - break; + case FluTableModel::RowModel: + return QVariant::fromValue(_rows.at(index.row())); + case FluTableModel::ColumnModel: + return QVariant::fromValue(_columnSource.at(index.column())); + default: + break; } return {}; } QHash FluTableModel::roleNames() const { return { - {FluTableModel::RowModel, "rowModel"}, - {FluTableModel::ColumnModel, "columnModel"} + {FluTableModel::RowModel, "rowModel"}, + {FluTableModel::ColumnModel, "columnModel"} }; } @@ -41,33 +41,33 @@ QModelIndex FluTableModel::index(int row, int column, const QModelIndex &parent) return createIndex(row, column); } -void FluTableModel::clear(){ +void FluTableModel::clear() { beginResetModel(); this->_rows.clear(); endResetModel(); } -QVariant FluTableModel::getRow(int rowIndex){ +QVariant FluTableModel::getRow(int rowIndex) { return _rows.at(rowIndex); } -void FluTableModel::setRow(int rowIndex,QVariant row){ - _rows.replace(rowIndex,row.toMap()); +void FluTableModel::setRow(int rowIndex, QVariant row) { + _rows.replace(rowIndex, row.toMap()); Q_EMIT dataChanged(index(rowIndex, 0), index(rowIndex, columnCount() - 1)); } -void FluTableModel::insertRow(int rowIndex,QVariant row){ +void FluTableModel::insertRow(int rowIndex, QVariant row) { beginInsertRows(QModelIndex(), rowIndex, rowIndex); - _rows.insert(rowIndex,row.toMap()); + _rows.insert(rowIndex, row.toMap()); endInsertRows(); } -void FluTableModel::removeRow(int rowIndex,int rows){ +void FluTableModel::removeRow(int rowIndex, int rows) { beginRemoveRows(QModelIndex(), rowIndex, rowIndex + rows - 1); _rows = _rows.mid(0, rowIndex) + _rows.mid(rowIndex + rows); endRemoveRows(); } -void FluTableModel::appendRow(QVariant row){ - insertRow(rowCount(),row); +void FluTableModel::appendRow(QVariant row) { + insertRow(rowCount(), row); } diff --git a/src/FluTableModel.h b/src/FluTableModel.h index 15b72435..e2cf8879 100644 --- a/src/FluTableModel.h +++ b/src/FluTableModel.h @@ -7,10 +7,10 @@ #include "stdafx.h" class FluTableModel : public QAbstractTableModel { - Q_OBJECT - Q_PROPERTY_AUTO(int, dataSourceSize) - Q_PROPERTY_AUTO(QList, columnSource) - Q_PROPERTY_AUTO(QList, rows) +Q_OBJECT +Q_PROPERTY_AUTO(int, dataSourceSize) +Q_PROPERTY_AUTO(QList, columnSource) +Q_PROPERTY_AUTO(QList, rows) Q_PROPERTY(int rowCount READ rowCount CONSTANT) QML_NAMED_ELEMENT(FluTableModel) public: @@ -37,11 +37,11 @@ public: Q_INVOKABLE QVariant getRow(int rowIndex); - Q_INVOKABLE void setRow(int rowIndex,QVariant row); + Q_INVOKABLE void setRow(int rowIndex, QVariant row); - Q_INVOKABLE void insertRow(int rowIndex,QVariant row); + Q_INVOKABLE void insertRow(int rowIndex, QVariant row); - Q_INVOKABLE void removeRow(int rowIndex,int rows = 1); + Q_INVOKABLE void removeRow(int rowIndex, int rows = 1); Q_INVOKABLE void appendRow(QVariant row); diff --git a/src/FluTableSortProxyModel.cpp b/src/FluTableSortProxyModel.cpp index 1723a678..796c8113 100644 --- a/src/FluTableSortProxyModel.cpp +++ b/src/FluTableSortProxyModel.cpp @@ -3,9 +3,8 @@ #include FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent) : QSortFilterProxyModel{parent} { - _model = nullptr; connect(this, &FluTableSortProxyModel::modelChanged, this, [=] { - setSourceModel(this->model()); + setSourceModel(this->model().value()); }); } @@ -59,19 +58,18 @@ bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QMod [[maybe_unused]] QVariant FluTableSortProxyModel::getRow(int rowIndex) { QVariant result; - QMetaObject::invokeMethod(_model, "getRow", Q_RETURN_ARG(QVariant, result), Q_ARG(int, mapToSource(index(rowIndex, 0)).row())); + QMetaObject::invokeMethod(_model.value(), "getRow", Q_RETURN_ARG(QVariant, result), Q_ARG(int, mapToSource(index(rowIndex, 0)).row())); return result; } [[maybe_unused]] void FluTableSortProxyModel::setRow(int rowIndex, const QVariant &val) { - QMetaObject::invokeMethod(_model, "setRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val)); + QMetaObject::invokeMethod(_model.value(), "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)); + QMetaObject::invokeMethod(_model.value(), "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)); + QMetaObject::invokeMethod(_model.value(), "removeRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(int, rows)); } - diff --git a/src/FluTableSortProxyModel.h b/src/FluTableSortProxyModel.h index 05fb1d9e..319dc118 100644 --- a/src/FluTableSortProxyModel.h +++ b/src/FluTableSortProxyModel.h @@ -8,7 +8,7 @@ class FluTableSortProxyModel : public QSortFilterProxyModel { Q_OBJECT -Q_PROPERTY_AUTO_P(QAbstractTableModel*, model) +Q_PROPERTY_AUTO_P(QVariant, model) QML_NAMED_ELEMENT(FluTableSortProxyModel) public: explicit FluTableSortProxyModel(QSortFilterProxyModel *parent = nullptr); diff --git a/src/FluTools.h b/src/FluTools.h index 2ba82887..a044c5d5 100644 --- a/src/FluTools.h +++ b/src/FluTools.h @@ -95,5 +95,5 @@ SINGLETON(FluTools) Q_INVOKABLE QString getWallpaperFilePath(); - Q_INVOKABLE QColor imageMainColor(const QImage& image, double bright = 1); + Q_INVOKABLE QColor imageMainColor(const QImage &image, double bright = 1); }; diff --git a/src/FluTreeModel.cpp b/src/FluTreeModel.cpp index 44b3ae2e..baaaf010 100644 --- a/src/FluTreeModel.cpp +++ b/src/FluTreeModel.cpp @@ -264,12 +264,12 @@ void FluTreeModel::allCollapse() { endResetModel(); } -QVariant FluTreeModel::selectionModel(){ +QVariant FluTreeModel::selectionModel() { QList data; - foreach (auto item, _dataSource) { - if (item->checked()) { - data.append(item); + foreach (auto item, _dataSource) { + if (item->checked()) { + data.append(item); + } } - } return QVariant::fromValue(data); } diff --git a/src/FluTreeModel.h b/src/FluTreeModel.h index 405e766c..0fc1b53c 100644 --- a/src/FluTreeModel.h +++ b/src/FluTreeModel.h @@ -50,7 +50,7 @@ public: } return true; }; - + Q_INVOKABLE bool hideLineFooter() { if (_parent) { auto childIndex = _parent->_children.indexOf(this); diff --git a/src/Qt5/imports/FluentUI/Controls/FluShadow.qml b/src/Qt5/imports/FluentUI/Controls/FluShadow.qml index 34c95753..11406b7c 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluShadow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluShadow.qml @@ -4,7 +4,7 @@ import FluentUI 1.0 Item { //高性能阴影!!!比DropShadow阴影性能高出数倍!!! - property color color: FluTheme.dark ? "#AAAAAA" : "#999999" + property color color: FluTheme.dark ? "#000000" : "#999999" property int elevation: 5 property int radius: 4 id:control diff --git a/src/Qt5/imports/FluentUI/Controls/FluTableView.qml b/src/Qt5/imports/FluentUI/Controls/FluTableView.qml index 029c4e10..9385d810 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluTableView.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluTableView.qml @@ -9,7 +9,9 @@ Rectangle { readonly property alias rows: table_view.rows readonly property alias columns: table_view.columns readonly property alias current: d.current - readonly property alias sourceModel: table_model + property var sourceModel:FluTableModel { + columnSource: control.columnSource + } property var columnSource: [] property var dataSource property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1) @@ -29,7 +31,7 @@ Rectangle { var columns= [] var headerRow = {} columnSource.forEach(function(item){ - var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',table_model); + var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',sourceModel); column.display = item.dataIndex columns.push(column) headerRow[item.dataIndex] = item.title @@ -58,12 +60,8 @@ Rectangle { } } onDataSourceChanged: { - table_model.clear() - table_model.rows = dataSource - } - FluTableModel { - id:table_model - columnSource: control.columnSource + sourceModel.clear() + sourceModel.rows = dataSource } TableModel{ id:header_column_model @@ -75,7 +73,7 @@ Rectangle { } FluTableSortProxyModel{ id:table_sort_model - model: table_model + model: control.sourceModel } Component{ id:com_edit @@ -191,6 +189,7 @@ Rectangle { id:com_table_delegate MouseArea{ id:item_table_mouse + property var _model: model property bool isRowSelected: { if(rowModel === null) return false @@ -283,6 +282,7 @@ Rectangle { } FluLoader{ id: item_table_loader + property var model: item_table_mouse._model property var display: rowModel[columnModel.dataIndex] property var rowModel : model.rowModel property var columnModel : model.columnModel @@ -446,7 +446,7 @@ Rectangle { id:column_item_control readonly property real cellPadding: 8 property bool canceled: false - property int columnIndex: column + property var _model: model readonly property var columnObject : control.columnSource[column] implicitWidth: { return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) @@ -503,22 +503,23 @@ Rectangle { } FluLoader{ id:item_column_loader - property var itemModel: model - property var modelData: model.display + property var model: column_item_control._model + property var display: model.display property var tableView: table_view - property var tableModel: table_model + property var sourceModel: control.sourceModel + property bool isObject: typeof(display) == "object" property var options:{ - if(typeof(modelData) == "object"){ - return modelData.options + if(isObject){ + return display.options } return {} } - property int column: column_item_control.columnIndex + property int column: model.column width: parent.width height: parent.height sourceComponent: { - if(typeof(modelData) == "object"){ - return modelData.comId + if(isObject){ + return display.comId } return com_column_text } @@ -686,7 +687,7 @@ Rectangle { id:com_column_text FluText { id: column_text - text: modelData + text: String(display) anchors.fill: parent horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter @@ -835,7 +836,7 @@ Rectangle { function sort(callback=undefined){ if(callback){ table_sort_model.setComparator(function(left,right){ - return callback(table_model.getRow(left),table_model.getRow(right)) + return callback(sourceModel.getRow(left),sourceModel.getRow(right)) }) }else{ table_sort_model.setComparator(undefined) @@ -844,7 +845,7 @@ Rectangle { function filter(callback=undefined){ if(callback){ table_sort_model.setFilter(function(index){ - return callback(table_model.getRow(index)) + return callback(sourceModel.getRow(index)) }) }else{ table_sort_model.setFilter(undefined) @@ -868,7 +869,7 @@ Rectangle { } function insertRow(rowIndex,obj){ if(rowIndex>=0 && rowIndex=0 && rowIndex