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,6 +18,7 @@
*/
#include "pathbarmodel.h"
#include <QDir>
#include <QDebug>
PathBarModel::PathBarModel(QObject *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 + "///");
item->name = m_url;
item->url = m_url;
m_pathList.append(item);
} else {
item->name = label;
item->url = QUrl(_url);
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());

View file

@ -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
}