Some improvements

This commit is contained in:
cutefishd 2021-03-29 22:53:21 +08:00
parent c3d7c6eedf
commit d6da7fe02c
10 changed files with 67 additions and 36 deletions

View file

@ -44,6 +44,7 @@ FolderModel::FolderModel(QObject *parent)
, m_sortDesc(false) , m_sortDesc(false)
, m_sortDirsFirst(true) , m_sortDirsFirst(true)
, m_complete(false) , m_complete(false)
, m_isDesktop(false)
, m_actionCollection(this) , m_actionCollection(this)
, m_dragInProgress(false) , m_dragInProgress(false)
, m_viewAdapter(nullptr) , m_viewAdapter(nullptr)
@ -642,10 +643,11 @@ void FolderModel::openSelected()
return; return;
const QList<QUrl> urls = selectedUrls(); const QList<QUrl> urls = selectedUrls();
if (!m_isDesktop) {
if (urls.size() == 1 && KFileItem(urls.first()).isDir()) { if (urls.size() == 1 && KFileItem(urls.first()).isDir()) {
setUrl(urls.first().toLocalFile()); setUrl(urls.first().toLocalFile());
return; return;
}
} }
for (const QUrl &url : urls) { for (const QUrl &url : urls) {
@ -934,6 +936,20 @@ bool FolderModel::isSupportThumbnails(const QString &mimeType) const
return false; 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() void FolderModel::invalidateIfComplete()
{ {
if (!m_complete) if (!m_complete)

View file

@ -26,6 +26,7 @@ class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus
Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged) Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged)
Q_PROPERTY(QObject *viewAdapter READ viewAdapter WRITE setViewAdapter NOTIFY viewAdapterChanged) Q_PROPERTY(QObject *viewAdapter READ viewAdapter WRITE setViewAdapter NOTIFY viewAdapterChanged)
Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
Q_PROPERTY(bool isDesktop READ isDesktop WRITE setIsDesktop NOTIFY isDesktopChanged)
public: public:
enum DataRole { enum DataRole {
@ -147,6 +148,9 @@ public:
Q_INVOKABLE void openPropertiesDialog(); Q_INVOKABLE void openPropertiesDialog();
Q_INVOKABLE void openInTerminal(); Q_INVOKABLE void openInTerminal();
bool isDesktop() const;
void setIsDesktop(bool isDesktop);
signals: signals:
void urlChanged(); void urlChanged();
void resolvedUrlChanged(); void resolvedUrlChanged();
@ -158,6 +162,7 @@ signals:
void draggingChanged(); void draggingChanged();
void viewAdapterChanged(); void viewAdapterChanged();
void statusTextChanged(); void statusTextChanged();
void isDesktopChanged();
private slots: private slots:
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
@ -186,6 +191,7 @@ private:
bool m_sortDirsFirst; bool m_sortDirsFirst;
bool m_complete; bool m_complete;
bool m_isDesktop;
KActionCollection m_actionCollection; KActionCollection m_actionCollection;
QHash<int, DragImage *> m_dragImages; QHash<int, DragImage *> m_dragImages;

View file

@ -73,3 +73,13 @@ QString PlacesItem::path() const
{ {
return m_url.toString(QUrl::PreferLocalFile); return m_url.toString(QUrl::PreferLocalFile);
} }
QString PlacesItem::udi() const
{
return m_udi;
}
void PlacesItem::setUdi(const QString &udi)
{
m_udi = udi;
}

View file

@ -46,10 +46,14 @@ public:
QString path() const; QString path() const;
QString udi() const;
void setUdi(const QString &udi);
private: private:
QString m_displayName; QString m_displayName;
QString m_iconName; QString m_iconName;
QString m_iconPath; QString m_iconPath;
QString m_udi;
QUrl m_url; QUrl m_url;
}; };

View file

@ -14,6 +14,10 @@ Item {
id: settings id: settings
} }
GlobalSettings {
id: globalSettings
}
Loader { Loader {
id: backgroundLoader id: backgroundLoader
anchors.fill: parent anchors.fill: parent
@ -58,11 +62,12 @@ Item {
FolderGridView { FolderGridView {
anchors.fill: parent anchors.fill: parent
cellHeight: 128 cellHeight: globalSettings.desktopIconSize
cellWidth: 128 cellWidth: globalSettings.desktopIconSize
model: FolderModel { model: FolderModel {
id: folderModel id: folderModel
url: desktopPath() url: desktopPath()
isDesktop: true
} }
leftMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.x : 0 leftMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.x : 0

View file

@ -27,7 +27,7 @@ Item {
Item { Item {
id: _iconItem id: _iconItem
Layout.preferredHeight: parent.height * 0.7 Layout.preferredHeight: parent.height * 0.6
Layout.fillWidth: true Layout.fillWidth: true
Image { Image {
@ -46,7 +46,7 @@ Item {
anchors.leftMargin: Meui.Units.smallSpacing anchors.leftMargin: Meui.Units.smallSpacing
anchors.rightMargin: Meui.Units.smallSpacing anchors.rightMargin: Meui.Units.smallSpacing
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectFit
visible: status === Image.Ready visible: status === Image.Ready
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
@ -75,27 +75,27 @@ Item {
Item { Item {
Layout.fillHeight: true Layout.fillHeight: true
Layout.preferredHeight: Math.min(_label.implicitHeight, height)
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: Math.min(_label.implicitHeight, height)
Rectangle { Rectangle {
width: Math.min(_label.implicitWidth + Meui.Units.smallSpacing, parent.width)
height: Math.min(_label.implicitHeight + Meui.Units.smallSpacing, parent.height)
anchors.centerIn: parent 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" color: selected ? Meui.Theme.highlightColor : "transparent"
radius: Meui.Theme.smallRadius radius: Meui.Theme.smallRadius
} }
Label { Label {
id: _label id: _label
anchors.fill: parent
horizontalAlignment: Qt.AlignHCenter horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter verticalAlignment: Qt.AlignVCenter
anchors.fill: parent
anchors.margins: 0
elide: Qt.ElideRight elide: Qt.ElideRight
wrapMode: Text.Wrap wrapMode: Text.Wrap
color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor
text: model.fileName text: model.fileName
color: selected ? Meui.Theme.highlightedTextColor : Meui.Theme.textColor
} }
} }
} }

View file

@ -28,10 +28,10 @@ GridView {
property Item editor: null property Item editor: null
property int anchorIndex: 0 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 itemWidth: itemSize + Meui.Units.largeSpacing
property var itemHeight: itemSize + Meui.Units.largeSpacing property var itemHeight: itemSize + Meui.Units.fontMetrics.height * 2
property variant cachedRectangleSelection: null property variant cachedRectangleSelection: null
@ -42,9 +42,6 @@ GridView {
signal keyPress(var event) signal keyPress(var event)
leftMargin: Meui.Units.smallSpacing
rightMargin: Meui.Units.smallSpacing
highlightMoveDuration: 0 highlightMoveDuration: 0
keyNavigationEnabled : true keyNavigationEnabled : true
keyNavigationWraps : true keyNavigationWraps : true

View file

@ -12,7 +12,7 @@ Item {
property alias currentUrl: folderModel.url property alias currentUrl: folderModel.url
property Item currentView: _viewLoader.item property Item currentView: _viewLoader.item
property int statusBarHeight: 30 + Meui.Units.smallSpacing property int statusBarHeight: 30
signal requestPathEditor() signal requestPathEditor()
@ -83,7 +83,7 @@ Item {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: Meui.Units.largeSpacing anchors.leftMargin: Meui.Units.largeSpacing
anchors.rightMargin: Meui.Units.largeSpacing anchors.rightMargin: Meui.Units.largeSpacing
anchors.bottomMargin: Meui.Units.smallSpacing anchors.bottomMargin: 1
Label { Label {
text: folderModel.statusText text: folderModel.statusText
@ -110,6 +110,11 @@ Item {
model: folderModel model: folderModel
delegate: FolderGridItem {} delegate: FolderGridItem {}
leftMargin: Meui.Units.largeSpacing
rightMargin: Meui.Units.largeSpacing
topMargin: Meui.Units.smallSpacing
bottomMargin: Meui.Units.smallSpacing
onCountChanged: { onCountChanged: {
_fileTips.visible = count === 0 _fileTips.visible = count === 0
} }

View file

@ -9,4 +9,6 @@ Settings {
property int desktopIconSize: 128 property int desktopIconSize: 128
property int maximumIconSize: 256 property int maximumIconSize: 256
property int minimumIconSize: 128 property int minimumIconSize: 128
property int gridIconSize: 128
} }

View file

@ -78,20 +78,6 @@ Meui.Window {
settings.viewMethod = 1 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
// }
} }
} }