Commit 7e4f16e8 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Folder View Filter Config] Use TableView for mime types

* Implements proper keyboard navigation (up/down) as well as space to goggle check box
* Makes list sortable by name, comment, and "checked" (so you easily get an overview of
  types you enabled)
* Add mime type "comment" which is more user-friendly

Differential Revision: https://phabricator.kde.org/D8849
parent 9a32812a
......@@ -45,7 +45,10 @@ Item {
// SortFilterModel doesn't have a case-sensitivity option
// but filterRegExp always causes case-insensitive sorting.
filterRegExp: mimeFilter.text
filterRole: "display"
filterRole: "name"
sortRole: mimeTypesView.getColumn(mimeTypesView.sortIndicatorColumn).role
sortOrder: mimeTypesView.sortIndicatorOrder
}
ColumnLayout {
......@@ -94,50 +97,118 @@ Item {
Layout.fillWidth: true
Layout.fillHeight: true
ScrollView {
CheckBox { // Purely for metrics.
id: metricsCheckBox
visible: false
}
TableView {
id: mimeTypesView
// Signal the delegates listen to when user presses space to toggle current row.
signal toggleCurrent
Layout.fillWidth: true
Layout.fillHeight: true
frameVisible: true
enabled: (filterMode.currentIndex > 0)
ListView {
model: filderedMimeTypesModel
delegate: RowLayout {
CheckBox {
Layout.maximumWidth: 18 // FIXME HACK: Use actual radio button width.
model: filderedMimeTypesModel
checked: model.checked
onCheckedChanged: model.checked = checked
}
sortIndicatorVisible: true
sortIndicatorColumn: 2 // Default to sort by "File type".
PlasmaCore.IconItem {
anchors.verticalCenter: parent.verticalCenter
onSortIndicatorColumnChanged: { // Disallow sorting by icon.
if (sortIndicatorColumn === 1) {
sortIndicatorColumn = 2;
}
}
width: units.iconSizes.small
height: units.iconSizes.small
Keys.onSpacePressed: toggleCurrent()
Layout.maximumWidth: width
Layout.maximumHeight: height
function adjustColumns() {
// Resize description column to take whatever space is left.
var width = viewport.width;
for (var i = 0; i < columnCount - 1; ++i) {
width -= getColumn(i).width;
}
descriptionColumn.width = width;
}
source: model.decoration
onWidthChanged: adjustColumns()
// Component.onCompleted is too early to do this...
onRowCountChanged: adjustColumns()
TableViewColumn {
role: "checked"
width: metricsCheckBox.width
resizable: false
movable: false
delegate: CheckBox {
id: checkBox
checked: styleData.value
activeFocusOnTab: false // only let the TableView as a whole get focus
onClicked: {
model.checked = checked
// Clicking it breaks the binding to the model value which becomes
// an issue during sorting as TableView re-uses delegates.
checked = Qt.binding(function() {
return styleData.value;
});
}
Label {
Layout.fillWidth: true
text: model.display
Connections {
target: mimeTypesView
onToggleCurrent: {
if (styleData.row === mimeTypesView.currentRow) {
model.checked = !checkBox.checked
}
}
}
}
}
TableViewColumn {
role: "decoration"
width: units.iconSizes.small
resizable: false
movable: false
delegate: PlasmaCore.IconItem {
width: units.iconSizes.small
height: units.iconSizes.small
animated: false // TableView re-uses delegates, avoid animation when sorting/filtering.
source: styleData.value
}
}
TableViewColumn {
id: nameColumn
role: "name"
title: i18n("File type")
width: units.gridUnit * 10 // Assume somewhat reasonable default for mime type name.
onWidthChanged: mimeTypesView.adjustColumns()
movable: false
}
TableViewColumn {
id: descriptionColumn
role: "comment"
title: i18n("Description")
movable: false
resizable: false
}
}
ColumnLayout {
Layout.alignment: Qt.AlignTop
// Need to explicitly base the size off the button's implicitWidth
// to avoid the column from growing way too wide due to fillWidth...
Layout.maximumWidth: Math.max(selectAllButton.implicitWidth, deselectAllButton.implicitWidth)
Button {
id: selectAllButton
Layout.fillWidth: true
enabled: (filterMode.currentIndex > 0)
......@@ -150,6 +221,7 @@ Item {
}
Button {
id: deselectAllButton
Layout.fillWidth: true
enabled: (filterMode.currentIndex > 0)
......
......@@ -42,7 +42,8 @@ MimeTypesModel::~MimeTypesModel()
QHash<int, QByteArray> MimeTypesModel::roleNames() const
{
return {
{ Qt::DisplayRole, "display" },
{ Qt::DisplayRole, "comment" },
{ Qt::UserRole, "name" },
{ Qt::DecorationRole, "decoration" },
{ Qt::CheckStateRole, "checked" }
};
......@@ -56,6 +57,8 @@ QVariant MimeTypesModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::DisplayRole:
return m_mimeTypesList.at(index.row()).comment();
case Qt::UserRole:
return m_mimeTypesList.at(index.row()).name();
case Qt::DecorationRole:
......
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