-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [titlebar] connect qml with dpf events
Create crumbbar component, connent qml with dpf event, click item will send event and change titile. Log: Connect qml with dpf events
- Loading branch information
Showing
12 changed files
with
367 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/plugins/filemanager/core/dfmplugin-titlebar/models/quickcrumbmodel.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "quickcrumbmodel.h" | ||
|
||
namespace dfmplugin_titlebar { | ||
|
||
QuickCrumbModel::QuickCrumbModel(QObject *parent) | ||
: QAbstractListModel { parent } | ||
{ | ||
} | ||
|
||
void QuickCrumbModel::setCurrentUrl(const QUrl &url, const QList<CrumbData> &crumbDataList) | ||
{ | ||
beginResetModel(); | ||
fileUrl = url; | ||
crumbData = crumbDataList; | ||
endResetModel(); | ||
} | ||
|
||
int QuickCrumbModel::rowCount(const QModelIndex &) const | ||
{ | ||
return crumbData.size(); | ||
} | ||
|
||
QVariant QuickCrumbModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (index.row() < 0 || index.row() >= crumbData.size()) { | ||
return {}; | ||
} | ||
|
||
const CrumbData &data = crumbData.at(index.row()); | ||
switch (role) { | ||
case FileUrlRole: | ||
return data.url; | ||
case FullUrlRole: | ||
return fileUrl; | ||
case TextRole: | ||
return data.displayText; | ||
case IconRole: | ||
return data.iconName; | ||
case UseIconRole: | ||
return !data.iconName.isEmpty(); | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
QHash<int, QByteArray> QuickCrumbModel::roleNames() const | ||
{ | ||
QHash<int, QByteArray> roles; | ||
roles[FileUrlRole] = "fileUrl"; | ||
roles[FullUrlRole] = "fullUrl"; | ||
roles[TextRole] = "text"; | ||
roles[IconRole] = "icon"; | ||
roles[UseIconRole] = "useIcon"; | ||
return roles; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/plugins/filemanager/core/dfmplugin-titlebar/models/quickcrumbmodel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef QUICKCRUMBMODEL_H | ||
#define QUICKCRUMBMODEL_H | ||
|
||
#include "dfmplugin_titlebar_global.h" | ||
|
||
#include <QAbstractListModel> | ||
#include <QUrl> | ||
|
||
namespace dfmplugin_titlebar { | ||
|
||
class QuickCrumbModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
public: | ||
enum Roles { | ||
FileUrlRole = Qt::UserRole + 1, | ||
FullUrlRole, | ||
TextRole, | ||
IconRole, | ||
UseIconRole, | ||
}; | ||
Q_ENUM(Roles) | ||
|
||
explicit QuickCrumbModel(QObject *parent = nullptr); | ||
|
||
void setCurrentUrl(const QUrl &url, const QList<CrumbData> &crumbDataList); | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
private: | ||
QUrl fileUrl; | ||
QList<CrumbData> crumbData; | ||
}; | ||
|
||
} | ||
|
||
#endif // QUICKCRUMBMODEL_H |
86 changes: 86 additions & 0 deletions
86
src/plugins/filemanager/core/dfmplugin-titlebar/qml/CrumbBar.qml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import QtQuick | ||
import QtQuick.Controls | ||
import org.dfm.base | ||
import org.deepin.dtk | ||
import org.deepin.dtk.private 1.0 as P | ||
|
||
///! 面包屑导航栏 | ||
Item { | ||
id: breadcrumbs | ||
|
||
// 请求弹出同级文件夹列表 | ||
signal requsetQuickJumpMenu(var url, real x, real y) | ||
|
||
ListView { | ||
id: addressline | ||
|
||
anchors.fill: parent | ||
model: Containment.crumbModel | ||
orientation: ListView.Horizontal | ||
|
||
delegate: Button { | ||
id: addressBtn | ||
|
||
enabled: index !== (ListView.view.count - 1) | ||
icon.name: model.useIcon ? model.icon : undefined | ||
leftInset: 0 | ||
padding: 0 | ||
rightInset: 0 | ||
spacing: 0 | ||
text: model.useIcon ? undefined : model.text | ||
|
||
background: P.ButtonPanel { | ||
id: bkgPanel | ||
|
||
button: addressBtn | ||
implicitWidth: addressBtn.contentItem.implicitWidth | ||
visible: addressBtn.enabled && addressBtn.hovered | ||
} | ||
indicator: Item { | ||
implicitHeight: 20 | ||
implicitWidth: 10 | ||
|
||
Text { | ||
anchors.centerIn: parent | ||
font.bold: false | ||
font.family: "Noto Sans CJK TC" | ||
text: "/" | ||
visible: !bkgPanel.visible | ||
} | ||
|
||
Loader { | ||
enabled: bkgPanel.visible | ||
|
||
sourceComponent: Button { | ||
id: popupBtn | ||
|
||
height: 16 | ||
icon.height: 10 | ||
icon.name: "combobox_arrow" | ||
icon.width: 10 | ||
visible: bkgPanel.visible | ||
width: 16 | ||
|
||
onClicked: { | ||
breadcrumbs.requsetQuickJumpMenu(model.fileUrl, popupBtn.x, popupBtn.y + 20); | ||
} | ||
|
||
anchors { | ||
right: parent.right | ||
rightMargin: 10 | ||
verticalCenter: parent.verticalCenter | ||
} | ||
} | ||
} | ||
} | ||
|
||
onClicked: { | ||
Containment.currentUrl = model.fileUrl; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.