From d6da7fe02c8c52ae459a88c056fabbd7d98848a0 Mon Sep 17 00:00:00 2001 From: cutefishd Date: Mon, 29 Mar 2021 22:53:21 +0800 Subject: [PATCH] Some improvements --- model/foldermodel.cpp | 24 ++++++++++++++++++++---- model/foldermodel.h | 6 ++++++ model/placesitem.cpp | 10 ++++++++++ model/placesitem.h | 4 ++++ qml/Desktop/main.qml | 9 +++++++-- qml/FolderGridItem.qml | 16 ++++++++-------- qml/FolderGridView.qml | 9 +++------ qml/FolderPage.qml | 9 +++++++-- qml/GlobalSettings.qml | 2 ++ qml/main.qml | 14 -------------- 10 files changed, 67 insertions(+), 36 deletions(-) diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 6849622..2e3f551 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -44,6 +44,7 @@ FolderModel::FolderModel(QObject *parent) , m_sortDesc(false) , m_sortDirsFirst(true) , m_complete(false) + , m_isDesktop(false) , m_actionCollection(this) , m_dragInProgress(false) , m_viewAdapter(nullptr) @@ -642,10 +643,11 @@ void FolderModel::openSelected() return; const QList urls = selectedUrls(); - - if (urls.size() == 1 && KFileItem(urls.first()).isDir()) { - setUrl(urls.first().toLocalFile()); - return; + if (!m_isDesktop) { + if (urls.size() == 1 && KFileItem(urls.first()).isDir()) { + setUrl(urls.first().toLocalFile()); + return; + } } for (const QUrl &url : urls) { @@ -934,6 +936,20 @@ bool FolderModel::isSupportThumbnails(const QString &mimeType) const return false; } +bool FolderModel::isDesktop() const +{ + return m_isDesktop; +} + +void FolderModel::setIsDesktop(bool isDesktop) +{ + if (m_isDesktop == isDesktop) + return; + + m_isDesktop = isDesktop; + emit isDesktopChanged(); +} + void FolderModel::invalidateIfComplete() { if (!m_complete) diff --git a/model/foldermodel.h b/model/foldermodel.h index 5ed17db..d58ca1c 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -26,6 +26,7 @@ class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged) Q_PROPERTY(QObject *viewAdapter READ viewAdapter WRITE setViewAdapter NOTIFY viewAdapterChanged) Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) + Q_PROPERTY(bool isDesktop READ isDesktop WRITE setIsDesktop NOTIFY isDesktopChanged) public: enum DataRole { @@ -147,6 +148,9 @@ public: Q_INVOKABLE void openPropertiesDialog(); Q_INVOKABLE void openInTerminal(); + bool isDesktop() const; + void setIsDesktop(bool isDesktop); + signals: void urlChanged(); void resolvedUrlChanged(); @@ -158,6 +162,7 @@ signals: void draggingChanged(); void viewAdapterChanged(); void statusTextChanged(); + void isDesktopChanged(); private slots: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); @@ -186,6 +191,7 @@ private: bool m_sortDirsFirst; bool m_complete; + bool m_isDesktop; KActionCollection m_actionCollection; QHash m_dragImages; diff --git a/model/placesitem.cpp b/model/placesitem.cpp index 04d4082..cc6c5eb 100644 --- a/model/placesitem.cpp +++ b/model/placesitem.cpp @@ -73,3 +73,13 @@ QString PlacesItem::path() const { return m_url.toString(QUrl::PreferLocalFile); } + +QString PlacesItem::udi() const +{ + return m_udi; +} + +void PlacesItem::setUdi(const QString &udi) +{ + m_udi = udi; +} diff --git a/model/placesitem.h b/model/placesitem.h index 9789d54..ecb17fc 100644 --- a/model/placesitem.h +++ b/model/placesitem.h @@ -46,10 +46,14 @@ public: QString path() const; + QString udi() const; + void setUdi(const QString &udi); + private: QString m_displayName; QString m_iconName; QString m_iconPath; + QString m_udi; QUrl m_url; }; diff --git a/qml/Desktop/main.qml b/qml/Desktop/main.qml index 822951c..70a5805 100644 --- a/qml/Desktop/main.qml +++ b/qml/Desktop/main.qml @@ -14,6 +14,10 @@ Item { id: settings } + GlobalSettings { + id: globalSettings + } + Loader { id: backgroundLoader anchors.fill: parent @@ -58,11 +62,12 @@ Item { FolderGridView { anchors.fill: parent - cellHeight: 128 - cellWidth: 128 + cellHeight: globalSettings.desktopIconSize + cellWidth: globalSettings.desktopIconSize model: FolderModel { id: folderModel url: desktopPath() + isDesktop: true } leftMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.x : 0 diff --git a/qml/FolderGridItem.qml b/qml/FolderGridItem.qml index cf77e93..ee13099 100644 --- a/qml/FolderGridItem.qml +++ b/qml/FolderGridItem.qml @@ -27,7 +27,7 @@ Item { Item { id: _iconItem - Layout.preferredHeight: parent.height * 0.7 + Layout.preferredHeight: parent.height * 0.6 Layout.fillWidth: true Image { @@ -46,7 +46,7 @@ Item { anchors.leftMargin: Meui.Units.smallSpacing anchors.rightMargin: Meui.Units.smallSpacing - fillMode: Image.PreserveAspectCrop + fillMode: Image.PreserveAspectFit visible: status === Image.Ready horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter @@ -75,27 +75,27 @@ Item { Item { Layout.fillHeight: true + Layout.preferredHeight: Math.min(_label.implicitHeight, height) Layout.fillWidth: true - Layout.preferredHeight: Math.min(_label.implicitHeight, height) - Rectangle { + width: Math.min(_label.implicitWidth + Meui.Units.smallSpacing, parent.width) + height: Math.min(_label.implicitHeight + Meui.Units.smallSpacing, parent.height) anchors.centerIn: parent - width: Math.min(_label.implicitWidth + Meui.Units.largeSpacing, parent.width) - height: Math.min(_label.implicitHeight + Meui.Units.largeSpacing, parent.height) color: selected ? Meui.Theme.highlightColor : "transparent" radius: Meui.Theme.smallRadius } Label { id: _label - anchors.fill: parent horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter + anchors.fill: parent + anchors.margins: 0 elide: Qt.ElideRight wrapMode: Text.Wrap - color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor text: model.fileName + color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor } } } diff --git a/qml/FolderGridView.qml b/qml/FolderGridView.qml index 0e65587..bd7adfa 100644 --- a/qml/FolderGridView.qml +++ b/qml/FolderGridView.qml @@ -28,10 +28,10 @@ GridView { property Item editor: null property int anchorIndex: 0 - property var itemSize: 96 + Meui.Units.fontMetrics.height + property var itemSize: settings.gridIconSize - property var itemWidth: itemSize + Meui.Units.smallSpacing - property var itemHeight: itemSize + Meui.Units.largeSpacing + property var itemWidth: itemSize + Meui.Units.largeSpacing + property var itemHeight: itemSize + Meui.Units.fontMetrics.height * 2 property variant cachedRectangleSelection: null @@ -42,9 +42,6 @@ GridView { signal keyPress(var event) - leftMargin: Meui.Units.smallSpacing - rightMargin: Meui.Units.smallSpacing - highlightMoveDuration: 0 keyNavigationEnabled : true keyNavigationWraps : true diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index dbebb74..c1fd2af 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -12,7 +12,7 @@ Item { property alias currentUrl: folderModel.url property Item currentView: _viewLoader.item - property int statusBarHeight: 30 + Meui.Units.smallSpacing + property int statusBarHeight: 30 signal requestPathEditor() @@ -83,7 +83,7 @@ Item { anchors.fill: parent anchors.leftMargin: Meui.Units.largeSpacing anchors.rightMargin: Meui.Units.largeSpacing - anchors.bottomMargin: Meui.Units.smallSpacing + anchors.bottomMargin: 1 Label { text: folderModel.statusText @@ -110,6 +110,11 @@ Item { model: folderModel delegate: FolderGridItem {} + leftMargin: Meui.Units.largeSpacing + rightMargin: Meui.Units.largeSpacing + topMargin: Meui.Units.smallSpacing + bottomMargin: Meui.Units.smallSpacing + onCountChanged: { _fileTips.visible = count === 0 } diff --git a/qml/GlobalSettings.qml b/qml/GlobalSettings.qml index 8fb3d76..84d083f 100644 --- a/qml/GlobalSettings.qml +++ b/qml/GlobalSettings.qml @@ -9,4 +9,6 @@ Settings { property int desktopIconSize: 128 property int maximumIconSize: 256 property int minimumIconSize: 128 + + property int gridIconSize: 128 } diff --git a/qml/main.qml b/qml/main.qml index 80a7855..ffe603f 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -78,20 +78,6 @@ Meui.Window { settings.viewMethod = 1 } } - -// IconButton { -// Layout.fillHeight: true -// implicitWidth: height -// source: Meui.Theme.darkMode ? "qrc:/images/dark/grid.svg" : "qrc:/images/light/grid.svg" -// onClicked: settings.viewMethod = 1 -// } - -// IconButton { -// Layout.fillHeight: true -// implicitWidth: height -// source: Meui.Theme.darkMode ? "qrc:/images/dark/list.svg" : "qrc:/images/light/list.svg" -// onClicked: settings.viewMethod = 0 -// } } }