Fix path bar model

This commit is contained in:
reven 2021-04-18 18:47:27 +08:00
parent 8dc6426b7e
commit abd619ac08
2 changed files with 24 additions and 25 deletions

View file

@ -18,7 +18,8 @@
*/ */
#include "pathbarmodel.h" #include "pathbarmodel.h"
#include<QDebug> #include <QDir>
#include <QDebug>
PathBarModel::PathBarModel(QObject *parent) PathBarModel::PathBarModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
@ -39,36 +40,34 @@ void PathBarModel::setUrl(const QString &url)
{ {
if (m_url != url) { if (m_url != url) {
beginResetModel(); beginResetModel();
m_url = url; m_url = url;
qDeleteAll(m_pathList); qDeleteAll(m_pathList);
m_pathList.clear(); m_pathList.clear();
QString _url = url; if (m_url.startsWith("trash:/")) {
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;
PathBarItem *item = new PathBarItem; PathBarItem *item = new PathBarItem;
item->name = m_url;
if (label.contains(":") && i == count - 1) { item->url = m_url;
item->name = "/";
item->url = QUrl(_url + "///");
} else {
item->name = label;
item->url = QUrl(_url);
}
m_pathList.append(item); 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()); std::reverse(m_pathList.begin(), m_pathList.end());

View file

@ -85,7 +85,7 @@ Item {
background: Rectangle { background: Rectangle {
radius: FishUI.Theme.smallRadius radius: FishUI.Theme.smallRadius
color: FishUI.Theme.darkMode ? Qt.darker(FishUI.Theme.backgroundColor, 1.1) : "white" 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 border.color: FishUI.Theme.highlightColor
} }