From abd619ac088540df62049275d05afdcec4440e8e Mon Sep 17 00:00:00 2001 From: reven Date: Sun, 18 Apr 2021 18:47:27 +0800 Subject: [PATCH] Fix path bar model --- model/pathbarmodel.cpp | 47 +++++++++++++++++++++--------------------- qml/PathBar.qml | 2 +- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/model/pathbarmodel.cpp b/model/pathbarmodel.cpp index cff9921..7bb1878 100644 --- a/model/pathbarmodel.cpp +++ b/model/pathbarmodel.cpp @@ -18,7 +18,8 @@ */ #include "pathbarmodel.h" -#include +#include +#include PathBarModel::PathBarModel(QObject *parent) : QAbstractItemModel(parent) @@ -39,36 +40,34 @@ void PathBarModel::setUrl(const QString &url) { if (m_url != url) { beginResetModel(); + m_url = url; qDeleteAll(m_pathList); m_pathList.clear(); - QString _url = url; - while (_url.endsWith("/")) - _url.chop(1); - _url += '/'; - - int count = _url.count("/"); - - for (int i = 0; i < count; ++i) { - _url = QString(_url).left(_url.lastIndexOf("/")); - QString label = QString(_url).right(_url.length() - _url.lastIndexOf("/") - 1); - - if (label.isEmpty()) - continue; - + if (m_url.startsWith("trash:/")) { PathBarItem *item = new PathBarItem; - - if (label.contains(":") && i == count - 1) { - item->name = "/"; - item->url = QUrl(_url + "///"); - } else { - item->name = label; - item->url = QUrl(_url); - } - + item->name = m_url; + item->url = m_url; m_pathList.append(item); + } else { + QDir dir(m_url); + while (true) { + if (dir.isRoot()) { + PathBarItem *item = new PathBarItem; + item->name = "/"; + item->url = "/"; + m_pathList.append(item); + break; + } + + PathBarItem *item = new PathBarItem; + item->name = dir.dirName(); + item->url = QUrl::fromLocalFile(dir.absolutePath()); + m_pathList.append(item); + dir.cdUp(); + } } std::reverse(m_pathList.begin(), m_pathList.end()); diff --git a/qml/PathBar.qml b/qml/PathBar.qml index 119dedf..e74420a 100644 --- a/qml/PathBar.qml +++ b/qml/PathBar.qml @@ -85,7 +85,7 @@ Item { background: Rectangle { radius: FishUI.Theme.smallRadius color: FishUI.Theme.darkMode ? Qt.darker(FishUI.Theme.backgroundColor, 1.1) : "white" - border.width: FishUI.Units.extendBorderWidth + border.width: 1 border.color: FishUI.Theme.highlightColor }