diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index c777cf7..44fcd7e 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,7 @@ #include #include #include -#include +#include // Qt Quick #include @@ -70,9 +71,9 @@ FolderModel::FolderModel(QObject *parent) sort(m_sortMode, m_sortDesc ? Qt::DescendingOrder : Qt::AscendingOrder); createActions(); - connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SIGNAL(statusTextChanged())); - connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SIGNAL(statusTextChanged())); - connect(this, SIGNAL(modelReset()), SIGNAL(statusTextChanged())); + connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), SIGNAL(countChanged())); + connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), SIGNAL(countChanged())); + connect(this, SIGNAL(modelReset()), SIGNAL(countChanged())); } FolderModel::~FolderModel() @@ -106,8 +107,10 @@ QHash FolderModel::staticRoleNames() roleNames[IsDirRole] = "isDir"; roleNames[UrlRole] = "url"; roleNames[FileNameRole] = "fileName"; + roleNames[FileSizeRole] = "fileSize"; roleNames[IconNameRole] = "iconName"; roleNames[ThumbnailRole] = "thumbnail"; + roleNames[ModifiedRole] = "modified"; return roleNames; } @@ -128,6 +131,14 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const case FileNameRole: { return item.url().fileName(); } + case FileSizeRole: { + if (item.isDir()) { + uint count = QDir(item.url().toLocalFile()).count(); + return count == 1 ? tr("%1 item").arg(count) : tr("%1 items").arg(count); + } + + return KIO::convertSize(item.size()); + } case IconNameRole: return item.iconName(); case ThumbnailRole: { @@ -144,6 +155,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const return QVariant(); } + case ModifiedRole: { + return item.timeString(KFileItem::ModificationTime); + } default: break; } @@ -405,23 +419,9 @@ KFileItem FolderModel::rootItem() const return m_dirModel->dirLister()->rootItem(); } -QString FolderModel::statusText() +int FolderModel::count() const { - if (m_selectionModel && m_selectionModel->hasSelection()) { - if (m_selectionModel->selectedIndexes().size() == 1) { - KFileItem item = itemForIndex(m_selectionModel->selectedIndexes().first()); - return item.name(); - } - - return tr("%1 selected").arg(m_selectionModel->selectedIndexes().size()); - } - - if (m_dirModel->rowCount() == 1) { - return tr("%1 item").arg(m_dirModel->rowCount()); - } else if (m_dirModel->rowCount() <= 0) - return ""; - - return tr("%1 items").arg(m_dirModel->rowCount()); + return rowCount(); } int FolderModel::selectionCound() const @@ -909,8 +909,6 @@ void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSe updateActions(); - // 选中状态信息 - emit statusTextChanged(); emit selectionCoundChanged(); } diff --git a/model/foldermodel.h b/model/foldermodel.h index 3f7c507..405dc8e 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -25,8 +25,9 @@ class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus Q_PROPERTY(bool sortDirsFirst READ sortDirsFirst WRITE setSortDirsFirst NOTIFY sortDirsFirstChanged) Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged) Q_PROPERTY(QObject *viewAdapter READ viewAdapter WRITE setViewAdapter NOTIFY viewAdapterChanged) - Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged) Q_PROPERTY(bool isDesktop READ isDesktop WRITE setIsDesktop NOTIFY isDesktopChanged) + Q_PROPERTY(int selectionCound READ selectionCound NOTIFY selectionCoundChanged) + Q_PROPERTY(int count READ count NOTIFY countChanged) public: enum DataRole { @@ -35,8 +36,10 @@ public: IsDirRole, UrlRole, FileNameRole, + FileSizeRole, IconNameRole, - ThumbnailRole + ThumbnailRole, + ModifiedRole }; enum FilterMode { @@ -103,7 +106,7 @@ public: KFileItem rootItem() const; - QString statusText(); + int count() const; int selectionCound() const; Q_INVOKABLE QString homePath() const; @@ -164,9 +167,9 @@ signals: void requestRename(); void draggingChanged(); void viewAdapterChanged(); - void statusTextChanged(); void isDesktopChanged(); void selectionCoundChanged(); + void countChanged(); private slots: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); diff --git a/qml/FolderGridItem.qml b/qml/FolderGridItem.qml index cdd9321..6da0a59 100644 --- a/qml/FolderGridItem.qml +++ b/qml/FolderGridItem.qml @@ -13,7 +13,7 @@ Item { height: GridView.view.cellHeight property Item iconArea: _image.visible ? _image : _icon - property Item textArea: _label + property Item labelArea: _label property Item background: _background property int index: model.index @@ -96,7 +96,7 @@ Item { anchors.topMargin: Meui.Units.smallSpacing maximumLineCount: 2 horizontalAlignment: Text.AlignHCenter - width: parent.width - Meui.Units.largeSpacing * 2 + width: parent.width - Meui.Units.largeSpacing * 2 - Meui.Units.smallSpacing textFormat: Text.PlainText elide: Qt.ElideRight wrapMode: Text.Wrap diff --git a/qml/FolderGridView.qml b/qml/FolderGridView.qml index 7f8f669..56d998a 100644 --- a/qml/FolderGridView.qml +++ b/qml/FolderGridView.qml @@ -58,6 +58,7 @@ GridView { function cancelRename() { if (editor) { + editor.cancel() editor.targetItem = null; } } @@ -113,6 +114,14 @@ GridView { cPress = mapToItem(control.contentItem, pressX, pressY) } + onContentXChanged: { + cancelRename() + } + + onContentYChanged: { + cancelRename() + } + onCachedRectangleSelectionChanged: { if (cachedRectangleSelection === null) return @@ -360,8 +369,8 @@ GridView { continue } - var labelRect = Qt.rect(itemX + item.textArea.x, itemY + item.textArea.y, - item.textArea.width, item.textArea.height) + var labelRect = Qt.rect(itemX + item.labelArea.x, itemY + item.labelArea.y, + item.labelArea.width, item.labelArea.height) if (control.rubberBand.intersects(labelRect)) { indices.push(index) @@ -421,18 +430,20 @@ GridView { 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 + var pos = control.mapFromItem(targetItem, targetItem.labelArea.x, targetItem.labelArea.y) width = targetItem.width - Meui.Units.smallSpacing - height = Meui.Units.fontMetrics.height * 2 - text = targetItem.textArea.text - targetItem.textArea.visible = false + height = targetItem.labelArea.paintedHeight + Meui.Units.largeSpacing * 2 + x = targetItem.x + Math.abs(Math.min(control.contentX, control.originX)) + y = pos.y - Meui.Units.largeSpacing + text = targetItem.labelArea.text + targetItem.labelArea.visible = false _editor.select(0, folderModel.fileExtensionBoundary(targetItem.index)) visible = true } else { - x: 0 - y: 0 + x = 0 + y = 0 + width = 0 + height = 0 visible = false } } @@ -444,11 +455,7 @@ GridView { commit() break case Qt.Key_Escape: - if (targetItem) { - targetItem.textArea.visible = true - targetItem = null - event.accepted = true - } + cancel() break } } @@ -462,12 +469,19 @@ GridView { function commit() { if (targetItem) { - targetItem.textArea.visible = true + targetItem.labelArea.visible = true folderModel.rename(targetItem.index, text) control.currentIndex = targetItem.index targetItem = null } } + + function cancel() { + if (targetItem) { + targetItem.labelArea.visible = true + targetItem = null + } + } } } } diff --git a/qml/FolderListItem.qml b/qml/FolderListItem.qml index 8121749..825800d 100644 --- a/qml/FolderListItem.qml +++ b/qml/FolderListItem.qml @@ -6,13 +6,14 @@ import MeuiKit 1.0 as Meui Item { id: _listItem width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin - height: 40 + height: Meui.Units.fontMetrics.height * 2 + Meui.Units.largeSpacing Accessible.name: fileName Accessible.role: Accessible.Canvas property Item iconArea: _image.visible ? _image : _icon - property Item textArea: _label + property Item labelArea: _label + property Item labelArea2: _label2 property int index: model.index property bool hovered: ListView.view.hoveredItem === _listItem @@ -80,12 +81,28 @@ Item { } } + ColumnLayout { + spacing: 0 + + Label { + id: _label + text: model.fileName + Layout.fillWidth: true + color: Meui.Theme.textColor + elide: Qt.ElideMiddle + } + + Label { + id: _label2 + text: model.fileSize + color: Meui.Theme.disabledTextColor + Layout.fillWidth: true + } + } + Label { - id: _label - text: model.fileName - Layout.fillWidth: true - color: Meui.Theme.textColor - elide: Qt.ElideMiddle + text: model.modified + color: Meui.Theme.disabledTextColor } } } diff --git a/qml/FolderListView.qml b/qml/FolderListView.qml index 22c062a..1c60b59 100644 --- a/qml/FolderListView.qml +++ b/qml/FolderListView.qml @@ -88,8 +88,10 @@ ListView { } function cancelRename() { - if (control.editor) + if (control.editor) { + control.editor.cancel() control.editor = null + } } MouseArea { @@ -303,6 +305,7 @@ ListView { wrapMode: Text.NoWrap textMargin: 0 verticalAlignment: TextEdit.AlignVCenter + leftPadding: 0 property Item targetItem: null @@ -310,13 +313,14 @@ ListView { onTargetItemChanged: { if (targetItem != null) { - var pos = control.mapFromItem(targetItem, targetItem.textArea.x, control.contentY) + var pos = control.mapFromItem(targetItem, targetItem.labelArea.x, targetItem.labelArea.y) width = targetItem.width - targetItem.iconArea.width * 2 height = targetItem.height - x = pos.x + x = control.mapFromItem(targetItem.labelArea, 0, 0).x y = pos.y - text = targetItem.textArea.text - targetItem.textArea.visible = false + text = targetItem.labelArea.text + targetItem.labelArea.visible = false + targetItem.labelArea2.visible = false _editor.select(0, folderModel.fileExtensionBoundary(targetItem.index)) visible = true } else { @@ -333,11 +337,7 @@ ListView { commit() break case Qt.Key_Escape: - if (targetItem) { - targetItem.textArea.visible = true - targetItem = null - event.accepted = true - } + cancel() break } } @@ -351,12 +351,21 @@ ListView { function commit() { if (targetItem) { - targetItem.textArea.visible = true + targetItem.labelArea.visible = true + targetItem.labelArea2.visible = true folderModel.rename(targetItem.index, text) control.currentIndex = targetItem.index targetItem = null } } + + function cancel() { + if (targetItem) { + targetItem.labelArea.visible = true + targetItem.labelArea2.visible = true + targetItem = null + } + } } } } diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index d259aa4..e6f9d00 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -98,11 +98,22 @@ Item { anchors.leftMargin: Meui.Units.largeSpacing anchors.rightMargin: Meui.Units.largeSpacing anchors.bottomMargin: 1 + spacing: Meui.Units.largeSpacing Label { - text: folderModel.statusText Layout.alignment: Qt.AlignLeft - elide: Text.ElideMiddle + text: folderModel.count == 1 ? qsTr("%1 item").arg(folderModel.count) + : qsTr("%1 items").arg(folderModel.count) + } + + Label { + Layout.alignment: Qt.AlignLeft + text: qsTr("%1 selected").arg(folderModel.selectionCound) + visible: folderModel.selectionCound >= 1 + } + + Item { + Layout.fillWidth: true } Button { @@ -147,6 +158,7 @@ Item { id: _folderListView model: folderModel + topMargin: Meui.Units.largeSpacing leftMargin: Meui.Units.largeSpacing rightMargin: Meui.Units.largeSpacing + Meui.Theme.smallRadius spacing: Meui.Units.largeSpacing diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index f1dfda1..36ba2f4 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -14,12 +14,12 @@ 名称 - + Cancel 取消 - + OK 确定 @@ -35,82 +35,81 @@ FolderModel - %1 selected - 选中了 %1 项 + 选中了 %1 项 - + %1 item %1 项 - + %1 items %1 项 - + Select All 全选 - + Open 打开 - + Cut 剪切 - + Copy 复制 - + Paste 粘贴 - + New Folder 新建文件夹 - + Move To Trash 移动到回收站 - + Empty Trash 清空回收站 - + Delete 删除 - + Rename 重命名 - + Open in Terminal 在终端中打开 - + Set as Wallpaper 设置为壁纸 - + Properties 属性 @@ -123,7 +122,22 @@ 无文件 - + + %1 item + %1 项 + + + + %1 items + %1 项 + + + + %1 selected + 选中了 %1 项 + + + Empty Trash 清空回收站