Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Improve asset tree navigation

parent 264cadda
......@@ -34,6 +34,7 @@ void AssetFilter::setFilterName(bool enabled, const QString &pattern)
m_name_enabled = enabled;
m_name_value = pattern;
invalidateFilter();
sort(0);
}
bool AssetFilter::filterName(TreeItem *item) const
......@@ -84,14 +85,10 @@ QModelIndex AssetFilter::getNextChild(const QModelIndex &current)
if (!folder.isValid()) {
return current;
}
TreeItem *folderItem = static_cast<TreeItem *>(mapToSource(folder).internalPointer());
while (folder.isValid() && folderItem->childCount() == 0) {
while (folder.isValid() && rowCount(folder) == 0) {
folder = folder.sibling(folder.row() + 1, folder.column());
if (folder.isValid()) {
folderItem = static_cast<TreeItem *>(mapToSource(folder).internalPointer());
}
}
if (folder.isValid() && folderItem->childCount() > 0) {
if (folder.isValid() && rowCount(folder) > 0) {
return index(0, current.column(), folder);
} else {
nextItem = current;
......@@ -108,18 +105,38 @@ QModelIndex AssetFilter::getPreviousChild(const QModelIndex &current)
if (!folder.isValid()) {
return current;
}
TreeItem *folderItem = static_cast<TreeItem *>(mapToSource(folder).internalPointer());
while (folder.isValid() && folderItem->childCount() == 0) {
while (folder.isValid() && rowCount(folder) == 0) {
folder = folder.sibling(folder.row() - 1, folder.column());
if (folder.isValid()) {
folderItem = static_cast<TreeItem *>(mapToSource(folder).internalPointer());
}
}
if (folder.isValid() && folderItem->childCount() > 0) {
return index(folderItem->childCount() - 1, current.column(), folder);
if (folder.isValid() && rowCount(folder) > 0) {
return index(rowCount(folder) - 1, current.column(), folder);
} else {
nextItem = current;
}
}
return nextItem;
}
QModelIndex AssetFilter::firstVisibleItem(const QModelIndex &current)
{
if (current.isValid() && isVisible(mapToSource(current))) {
return current;
}
QModelIndex folder = index(0, 0, QModelIndex());
if (!folder.isValid()) {
return current;
}
while (folder.isValid() && rowCount(folder) == 0) {
folder = index(folder.row() + 1, 0, QModelIndex());
}
if (rowCount(folder) > 0) {
return index(0, 0, folder);
}
return current;
}
QModelIndex AssetFilter::getCategory(int catRow)
{
QModelIndex cat = index(catRow, 0, QModelIndex());
return cat;
}
......@@ -47,6 +47,8 @@ public:
bool isVisible(const QModelIndex &sourceIndex);
Q_INVOKABLE QModelIndex getNextChild(const QModelIndex &current);
Q_INVOKABLE QModelIndex getPreviousChild(const QModelIndex &current);
Q_INVOKABLE QModelIndex firstVisibleItem(const QModelIndex &current);
Q_INVOKABLE QModelIndex getCategory(int catRow);
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
......
......@@ -40,6 +40,18 @@ Rectangle {
treeView.expand(indexes[i]);
}
}
function rowPosition(model, index) {
var pos = 0;
for(var i = 0; i < index.parent.row; i++) {
var catIndex = model.getCategory(i);
if (treeView.isExpanded(catIndex)) {
pos += model.rowCount(catIndex);
}
pos ++;
}
pos += index.row + 2;
return pos;
}
ColumnLayout {
anchors.fill: parent
......@@ -172,7 +184,27 @@ Rectangle {
}
]
onTextChanged: {
var current = sel.currentIndex
assetlist.setFilterName(text)
sel.setCurrentIndex(assetListModel.firstVisibleItem(current), ItemSelectionModel.ClearAndSelect)
treeView.__listView.positionViewAtIndex(rowPosition(assetListModel, sel.currentIndex), ListView.Visible)
}
onEditingFinished: {
searchList.checked = false
}
Keys.onDownPressed: {
sel.setCurrentIndex(assetListModel.getNextChild(sel.currentIndex), ItemSelectionModel.ClearAndSelect)
treeView.expand(sel.currentIndex.parent)
treeView.__listView.positionViewAtIndex(rowPosition(assetListModel, sel.currentIndex), ListView.Visible)
}
Keys.onUpPressed: {
sel.setCurrentIndex(assetListModel.getPreviousChild(sel.currentIndex), ItemSelectionModel.ClearAndSelect)
treeView.expand(sel.currentIndex.parent)
treeView.__listView.positionViewAtIndex(rowPosition(assetListModel, sel.currentIndex), ListView.Visible)
}
Keys.onReturnPressed: {
assetlist.activate(sel.currentIndex)
searchList.checked = false
}
}
ItemSelectionModel {
......@@ -261,10 +293,12 @@ Rectangle {
Keys.onDownPressed: {
sel.setCurrentIndex(assetListModel.getNextChild(sel.currentIndex), ItemSelectionModel.ClearAndSelect)
treeView.expand(sel.currentIndex.parent)
treeView.__listView.positionViewAtIndex(rowPosition(assetListModel, sel.currentIndex), ListView.Visible)
}
Keys.onUpPressed: {
sel.setCurrentIndex(assetListModel.getPreviousChild(sel.currentIndex), ItemSelectionModel.ClearAndSelect)
treeView.expand(sel.currentIndex.parent)
treeView.__listView.positionViewAtIndex(rowPosition(assetListModel, sel.currentIndex), ListView.Visible)
}
Keys.onReturnPressed: assetlist.activate(sel.currentIndex)
......
......@@ -3651,7 +3651,7 @@ void MainWindow::slotUpdateTimecodeFormat(int ix)
void MainWindow::slotRemoveFocus()
{
pCore->projectManager()->currentTimeline()->setFocus();
getMainTimeline()->setFocus();
}
void MainWindow::slotShutdown()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment