diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 518f7e0..1dbdfce 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -123,8 +123,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const return m_selectionModel->isSelected(index); case UrlRole: return item.url(); - case FileNameRole: + case FileNameRole: { return item.url().fileName(); + } case IconNameRole: return item.iconName(); case ThumbnailRole: { @@ -932,7 +933,7 @@ bool FolderModel::isSupportThumbnails(const QString &mimeType) const { const QStringList supportsMimetypes = {"image/bmp", "image/png", "image/gif", "image/jpeg", "image/web", "application/pdf", "application/rtf", "application/doc", "application/odf", - "audio/mpeg"}; + "audio/mpeg", "video/mp4"}; if (supportsMimetypes.contains(mimeType)) return true; diff --git a/model/placesmodel.cpp b/model/placesmodel.cpp index 50555b7..2eb70b1 100644 --- a/model/placesmodel.cpp +++ b/model/placesmodel.cpp @@ -87,7 +87,6 @@ PlacesModel::PlacesModel(QObject *parent) trashItem->setIconPath("qrc:/images/user-trash.svg"); m_items.append(trashItem); - Solid::Predicate predicate; QString predicateStr( QString::fromLatin1("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]" " OR " @@ -96,14 +95,14 @@ PlacesModel::PlacesModel(QObject *parent) "OpticalDisc.availableContent & 'Audio' ]" " OR " "StorageAccess.ignored == false ]")); - predicate = Solid::Predicate::fromString(predicateStr); + m_predicate = Solid::Predicate::fromString(predicateStr); Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance(); connect(notifier, &Solid::DeviceNotifier::deviceAdded, this, &PlacesModel::onDeviceAdded); connect(notifier, &Solid::DeviceNotifier::deviceRemoved, this, &PlacesModel::onDeviceRemoved); // Init devices - const QList &deviceList = Solid::Device::listFromQuery(predicate); + const QList &deviceList = Solid::Device::listFromQuery(m_predicate); for (const Solid::Device &device : deviceList) { PlacesItem *deviceItem = new PlacesItem; deviceItem->setUdi(device.udi()); @@ -239,11 +238,13 @@ void PlacesModel::requestEject(const int &index) void PlacesModel::onDeviceAdded(const QString &udi) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - PlacesItem *deviceItem = new PlacesItem; - deviceItem->setUdi(udi); - m_items.append(deviceItem); - endInsertRows(); + if (m_predicate.matches(Solid::Device(udi))) { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + PlacesItem *deviceItem = new PlacesItem; + deviceItem->setUdi(udi); + m_items.append(deviceItem); + endInsertRows(); + } } void PlacesModel::onDeviceRemoved(const QString &udi) diff --git a/model/placesmodel.h b/model/placesmodel.h index b833ee2..a372908 100644 --- a/model/placesmodel.h +++ b/model/placesmodel.h @@ -21,6 +21,7 @@ #define PLACESMODEL_H #include +#include #include "placesitem.h" class PlacesModel : public QAbstractItemModel @@ -61,6 +62,7 @@ private slots: private: QList m_items; + Solid::Predicate m_predicate; }; #endif diff --git a/qml/FolderGridItem.qml b/qml/FolderGridItem.qml index ee41daa..2cfef75 100644 --- a/qml/FolderGridItem.qml +++ b/qml/FolderGridItem.qml @@ -24,15 +24,14 @@ Item { Rectangle { id: _background - width: Math.max(_iconItem.width + Meui.Units.smallSpacing, - _label.paintedWidth + Meui.Units.largeSpacing) + width: Math.max(_iconItem.width, _label.paintedWidth) height: _iconItem.height + _label.paintedHeight + Meui.Units.largeSpacing x: (parent.width - width) / 2 y: _iconItem.y color: selected || hovered ? Meui.Theme.highlightColor : "transparent" radius: Meui.Theme.mediumRadius visible: selected || hovered - opacity: selected ? 0.9 : 0.4 + opacity: selected ? 1.0 : 0.4 } Item { @@ -45,7 +44,6 @@ Item { width: parent.width - Meui.Units.largeSpacing * 2 height: control.GridView.view.iconSize - opacity: selected || !hovered ? 1.0 : 0.95 Image { id: _icon diff --git a/qml/FolderGridView.qml b/qml/FolderGridView.qml index 98675dc..66f794b 100644 --- a/qml/FolderGridView.qml +++ b/qml/FolderGridView.qml @@ -41,6 +41,25 @@ GridView { signal keyPress(var event) + function rename() { + if (control.currentIndex != -1) { + var renameAction = control.model.action("rename") + if (renameAction && !renameAction.enabled) + return + + if (!editor) + editor = editorComponent.createObject(control) + + editor.targetItem = control.currentItem + } + } + + function cancelRename() { + if (editor) { + editor.targetItem = null; + } + } + highlightMoveDuration: 0 keyNavigationEnabled : true keyNavigationWraps : true @@ -115,6 +134,9 @@ GridView { onPressed: { control.forceActiveFocus() + if (control.editor && childAt(mouse.x, mouse.y) !== control.editor) + control.editor.commit() + pressX = mouse.x pressY = mouse.y @@ -353,4 +375,68 @@ GridView { } return Math.floor(extraSpacing) } + + Component { + id: editorComponent + + TextField { + id: _editor + visible: false + wrapMode: TextEdit.Wrap + horizontalAlignment: TextEdit.AlignHCenter + z: 999 + + property Item targetItem: null + + onTargetItemChanged: { + if (targetItem != null) { + var pos = control.mapFromItem(targetItem, targetItem.textArea.x, targetItem.textArea.y) + x = targetItem.x + Math.abs(Math.min(control.contentX, control.originX)) + y = pos.y + Meui.Units.smallSpacing + width = targetItem.width - Meui.Units.smallSpacing + height = Meui.Units.fontMetrics.height * 2 + text = targetItem.textArea.text + targetItem.textArea.visible = false + _editor.select(0, folderModel.fileExtensionBoundary(targetItem.index)) + visible = true + } else { + x: 0 + y: 0 + visible = false + } + } + + Keys.onPressed: { + switch (event.key) { + case Qt.Key_Return: + case Qt.Key_Enter: + commit() + break + case Qt.Key_Escape: + if (targetItem) { + targetItem.textArea.visible = true + targetItem = null + event.accepted = true + } + break + } + } + + onVisibleChanged: { + if (visible) + _editor.forceActiveFocus() + else + control.forceActiveFocus() + } + + function commit() { + if (targetItem) { + targetItem.textArea.visible = true + folderModel.rename(targetItem.index, text) + control.currentIndex = targetItem.index + targetItem = null + } + } + } + } } diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index c574321..660af43 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -75,6 +75,14 @@ Item { } } + function rename() { + _viewLoader.item.rename() + } + + Component.onCompleted: { + folderModel.requestRename.connect(rename) + } + Component { id: _statusBar @@ -121,6 +129,10 @@ Item { onCountChanged: { _fileTips.visible = count === 0 } + +// Component.onCompleted: { +// folderModel.requestRename.connect(rename) +// } } } @@ -140,10 +152,6 @@ Item { } delegate: FolderListItem {} - - Component.onCompleted: { - folderModel.requestRename.connect(rename) - } } } diff --git a/qml/SideBar.qml b/qml/SideBar.qml index 8d18346..1d14f9d 100644 --- a/qml/SideBar.qml +++ b/qml/SideBar.qml @@ -20,9 +20,12 @@ ListView { leftMargin: Meui.Units.smallSpacing rightMargin: Meui.Units.smallSpacing + bottomMargin: Meui.Units.smallSpacing spacing: Meui.Units.largeSpacing - ScrollBar.vertical: ScrollBar {} + ScrollBar.vertical: ScrollBar { + bottomPadding: Meui.Units.smallSpacing + } highlightFollowsCurrentItem: true highlightMoveDuration: 0