diff --git a/containments/desktop/package/contents/config/main.xml b/containments/desktop/package/contents/config/main.xml --- a/containments/desktop/package/contents/config/main.xml +++ b/containments/desktop/package/contents/config/main.xml @@ -81,6 +81,9 @@ imagethumbnail,jpegthumbnail + + 0 + 4 diff --git a/containments/desktop/package/contents/ui/ConfigIcons.qml b/containments/desktop/package/contents/ui/ConfigIcons.qml --- a/containments/desktop/package/contents/ui/ConfigIcons.qml +++ b/containments/desktop/package/contents/ui/ConfigIcons.qml @@ -52,6 +52,7 @@ property alias cfg_popups: popups.checked property alias cfg_previews: previews.checked property alias cfg_previewPlugins: previewPluginsDialog.previewPlugins + property alias cfg_viewMode: viewMode.currentIndex property alias cfg_iconSize: iconSize.value property alias cfg_textLines: textLines.value @@ -238,14 +239,27 @@ Layout.fillWidth: true - visible: !isPopup - title: i18n("Appearance") flat: true ColumnLayout { RowLayout { + visible: isPopup + + Label { + text: i18nc("whether to use icon or list view", "View Mode:") + } + + ComboBox { + id: viewMode + model: [i18n("List"), i18n("Icons")] + } + } + + RowLayout { + visible: !isPopup || viewMode.currentIndex === 1 + Label { text: i18n("Size:") } @@ -270,6 +284,8 @@ } RowLayout { + visible: !isPopup || viewMode.currentIndex === 1 + Label { text: i18n("Text lines:") } diff --git a/containments/desktop/package/contents/ui/FolderItemDelegate.qml b/containments/desktop/package/contents/ui/FolderItemDelegate.qml --- a/containments/desktop/package/contents/ui/FolderItemDelegate.qml +++ b/containments/desktop/package/contents/ui/FolderItemDelegate.qml @@ -129,7 +129,7 @@ active: (plasmoid.configuration.toolTips && popupDialog == null && !model.blank) interactive: false - location: root.isPopup ? (plasmoid.location == PlasmaCore.Types.LeftEdge ? PlasmaCore.Types.LeftEdge : PlasmaCore.Types.RightEdge) : plasmoid.location + location: root.useListViewMode ? (plasmoid.location == PlasmaCore.Types.LeftEdge ? PlasmaCore.Types.LeftEdge : PlasmaCore.Types.RightEdge) : plasmoid.location onContainsMouseChanged: { if (containsMouse && !model.blank) { @@ -150,11 +150,11 @@ PlasmaCore.FrameSvgItem { id: frame - x: root.isPopup ? 0 : units.smallSpacing - y: root.isPopup ? 0 : units.smallSpacing + x: root.useListViewMode ? 0 : units.smallSpacing + y: root.useListViewMode ? 0 : units.smallSpacing width: { - if (root.isPopup) { + if (root.useListViewMode) { if (main.GridView.view.overflowing) { return parent.width - units.smallSpacing; } else { @@ -166,7 +166,7 @@ } height: { - if (root.isPopup) { + if (root.useListViewMode) { return parent.height; } @@ -188,19 +188,36 @@ PlasmaCore.IconItem { id: icon + states: [ + State { // icon view + when: !root.useListViewMode + + AnchorChanges { + target: icon + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + } + }, + State { // list view + when: root.useListViewMode + + AnchorChanges { + target: icon + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + } + } + ] + anchors { - top: root.isPopup ? undefined : parent.top topMargin: units.largeSpacing - left: root.isPopup ? parent.left : undefined leftMargin: units.smallSpacing - horizontalCenter: root.isPopup ? undefined : parent.horizontalCenter - verticalCenter: root.isPopup ? parent.verticalCenter : undefined } width: main.GridView.view.iconSize height: main.GridView.view.iconSize - opacity: root.isPopup ? (1.3 - selectionButton.opacity) : 1.0 + opacity: root.useListViewMode ? (1.3 - selectionButton.opacity) : 1.0 animated: false usesPlasmaTheme: false @@ -240,33 +257,49 @@ PlasmaComponents.Label { id: label - anchors { - top: root.isPopup ? undefined : icon.bottom - topMargin: 2 * units.smallSpacing - left: root.isPopup ? icon.right : undefined - leftMargin: units.smallSpacing * 2 - horizontalCenter: root.isPopup ? undefined : parent.horizontalCenter - verticalCenter: root.isPopup ? parent.verticalCenter : undefined - } - - width: { - if (root.isPopup) { - return parent.width - icon.width - (units.smallSpacing * 4); + states: [ + State { // icon view + when: !root.useListViewMode + + AnchorChanges { + target: label + anchors.top: icon.bottom + anchors.horizontalCenter: parent.horizontalCenter + } + PropertyChanges { + target: label + anchors.topMargin: 2 * units.smallSpacing + width: Math.min(labelMetrics.advanceWidth + units.smallSpacing, parent.width - units.smallSpacing * 8) + maximumLineCount: plasmoid.configuration.textLines + horizontalAlignment: Text.AlignHCenter + } + }, + State { // list view + when: root.useListViewMode + + AnchorChanges { + target: label + anchors.left: icon.right + anchors.verticalCenter: parent.verticalCenter + } + PropertyChanges { + target: label + anchors.leftMargin: units.smallSpacing * 2 + anchors.rightMargin: units.smallSpacing * 2 + width: parent.width - icon.width - (units.smallSpacing * 4) + maximumLineCount: 1 + horizontalAlignment: Text.AlignLeft + } } - - return Math.min(labelMetrics.advanceWidth + units.smallSpacing, parent.width - units.smallSpacing * 8); - } + ] height: undefined // Unset PlasmaComponents.Label's default. textFormat: Text.PlainText - maximumLineCount: root.isPopup ? 1 : plasmoid.configuration.textLines wrapMode: Text.Wrap elide: Text.ElideRight - horizontalAlignment: root.isPopup ? Text.AlignHLeft : Text.AlignHCenter - color: PlasmaCore.ColorScope.textColor text: model.blank ? "" : model.display @@ -282,7 +315,7 @@ y: units.smallSpacing * 3 anchors { - centerIn: root.isPopup ? icon : undefined + centerIn: root.useListViewMode ? icon : undefined } width: implicitWidth @@ -304,7 +337,7 @@ id: popupButtonComponent FolderItemActionButton { - visible: !root.isPopup + visible: !root.useListViewMode opacity: (plasmoid.configuration.popups && impl.hovered && impl.popupDialog == null) ? 1.0 : 0.0 diff --git a/containments/desktop/package/contents/ui/FolderView.qml b/containments/desktop/package/contents/ui/FolderView.qml --- a/containments/desktop/package/contents/ui/FolderView.qml +++ b/containments/desktop/package/contents/ui/FolderView.qml @@ -102,7 +102,7 @@ target: root onIsPopupChanged: { - if (upButton == null && root.isPopup) { + if (upButton == null && root.useListViewMode) { upButton = makeUpButton(); } else if (upButton != null) { upButton.destroy(); @@ -238,7 +238,7 @@ if (!(pos.x <= hoveredItem.actionsOverlay.width && pos.y <= hoveredItem.actionsOverlay.height)) { if (systemSettings.singleClick() || doubleClickInProgress) { - var func = root.isPopup && (mouse.button == Qt.LeftButton) && hoveredItem.isDir ? dir.cd : dir.run; + var func = root.useListViewMode && (mouse.button == Qt.LeftButton) && hoveredItem.isDir ? dir.cd : dir.run; func(positioner.map(gridView.currentIndex)); hoveredItem = null; @@ -318,7 +318,7 @@ clearPressState(); } else { // Disable rubberband in popup list view mode. - if (root.isPopup) { + if (root.useListViewMode) { return; } @@ -405,7 +405,7 @@ boundsBehavior: Flickable.StopAtBounds cellWidth: { - if (root.isPopup) { + if (root.useListViewMode) { return gridView.width; } @@ -413,7 +413,7 @@ } cellHeight: { - if (root.isPopup) { + if (root.useListViewMode) { return Math.ceil((Math.max(theme.mSize(theme.defaultFont).height, iconSize) + Math.max(highlightItemSvg.margins.top + highlightItemSvg.margins.bottom, listItemSvg.margins.top + listItemSvg.margins.bottom)) / 2) * 2; @@ -554,7 +554,7 @@ } function makeIconSize() { - if (root.isPopup) { + if (root.useListViewMode) { return units.iconSizes.small; } @@ -650,7 +650,7 @@ Keys.onReturnPressed: { if (currentIndex != -1 && dir.hasSelection()) { - var func = root.isPopup ? dir.cd : dir.run; + var func = root.useListViewMode ? dir.cd : dir.run; func(positioner.map(currentIndex)); } } @@ -977,7 +977,7 @@ } Component.onCompleted: { - if (upButton == null && root.isPopup) { + if (upButton == null && root.useListViewMode) { upButton = makeUpButton(); } } diff --git a/containments/desktop/package/contents/ui/main.qml b/containments/desktop/package/contents/ui/main.qml --- a/containments/desktop/package/contents/ui/main.qml +++ b/containments/desktop/package/contents/ui/main.qml @@ -20,6 +20,7 @@ ***************************************************************************/ import QtQuick 2.0 +import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore @@ -35,35 +36,16 @@ id: root objectName: isFolder ? "folder" : "desktop" - width: { - if (isContainment || !folderViewLayer.ready) { - return undefined; - } else if (isPopup) { - return units.gridUnit * 16; - } + width: isPopup ? undefined : preferredWidth() // for the initial size when placed on the desktop + Layout.preferredWidth: isPopup ? preferredWidth() : 0 // for the popup size to change at runtime when view mode changes - return (folderViewLayer.view.cellWidth * 3) + (units.largeSpacing * 2); - } - - height: { - if (isContainment || !folderViewLayer.ready) { - return undefined; - } else if (isPopup) { - var height = (folderViewLayer.view.cellHeight * 15) + units.smallSpacing; - } else { - var height = (folderViewLayer.view.cellHeight * 2) + units.largeSpacing - } - - if (plasmoid.configuration.labelMode != 0) { - height += folderViewLayer.item.labelHeight; - } - - return height - } + height: isPopup ? undefined : preferredHeight() + Layout.preferredHeight: isPopup ? preferredHeight() : 0 property bool isFolder: (plasmoid.pluginName == "org.kde.plasma.folder") property bool isContainment: ("containmentType" in plasmoid) property bool isPopup: (plasmoid.location != PlasmaCore.Types.Floating) + property bool useListViewMode: isPopup && plasmoid.configuration.viewMode === 0 property Item toolBox property var layoutManager: LayoutManager @@ -200,6 +182,32 @@ } } + function preferredWidth() { + if (isContainment || !folderViewLayer.ready) { + return undefined; + } else if (useListViewMode) { + return units.gridUnit * 16; + } + + return (folderViewLayer.view.cellWidth * 3) + (units.largeSpacing * 2); + } + + function preferredHeight() { + if (isContainment || !folderViewLayer.ready) { + return undefined; + } else if (useListViewMode) { + var height = (folderViewLayer.view.cellHeight * 15) + units.smallSpacing; + } else { + var height = (folderViewLayer.view.cellHeight * 2) + units.largeSpacing + } + + if (plasmoid.configuration.labelMode != 0) { + height += folderViewLayer.item.labelHeight; + } + + return height + } + onDragEnter: { if (isContainment && plasmoid.immutable) { event.ignore();