diff --git a/containments/desktop/package/contents/ui/FolderViewLayer.qml b/containments/desktop/package/contents/ui/FolderViewLayer.qml index ba4dc1e74..c0d78b3a0 100644 --- a/containments/desktop/package/contents/ui/FolderViewLayer.qml +++ b/containments/desktop/package/contents/ui/FolderViewLayer.qml @@ -1,418 +1,423 @@ /*************************************************************************** * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.0 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.private.desktopcontainment.folder 0.1 as Folder Item { id: folderViewLayerComponent property variant sharedActions: ["newMenu", "paste", "undo", "refresh", "emptyTrash"] property Component folderViewDialogComponent: Qt.createComponent("FolderViewDialog.qml", Qt.Asynchronous, root) property Item view: folderView property Item label: null property int labelHeight: theme.mSize(theme.defaultFont).height + (root.isPopup ? (units.smallSpacing * 2) : 0) property alias model: folderView.model property alias overflowing: folderView.overflowing property alias flow: folderView.flow function updateContextualActions() { folderView.model.updateActions(); var actionName = ""; var appletAction = null; var modelAction = null; for (var i = 0; i < sharedActions.length; i++) { actionName = sharedActions[i]; appletAction = plasmoid.action(actionName); modelAction = folderView.model.action(actionName); appletAction.text = modelAction.text; appletAction.enabled = modelAction.enabled; appletAction.visible = modelAction.visible; } } function cancelRename() { folderView.cancelRename(); } function goHome() { if (folderView.url != plasmoid.configuration.url) { folderView.url = Qt.binding(function() { return plasmoid.configuration.url; }); folderView.history = []; folderView.updateHistory(); } } PlasmaCore.Svg { id: actionOverlays imagePath: "widgets/action-overlays" multipleImages: true size: "16x16" } Binding { target: plasmoid property: "title" value: labelGenerator.displayLabel } Folder.LabelGenerator { id: labelGenerator folderModel: folderView.model rtl: (Qt.application.layoutDirection == Qt.RightToLeft) labelMode: plasmoid.configuration.labelMode || (isContainment ? 0 : 1) labelText: plasmoid.configuration.labelText } Folder.ViewPropertiesMenu { id: viewPropertiesMenu showLayoutActions: !isPopup showLockAction: isContainment showIconSizeActions: !root.useListViewMode onArrangementChanged: { plasmoid.configuration.arrangement = arrangement; } onAlignmentChanged: { plasmoid.configuration.alignment = alignment; } + onPreviewsChanged: { + plasmoid.configuration.previews = previews; + } + onLockedChanged: { plasmoid.configuration.locked = locked; } onSortModeChanged: { plasmoid.configuration.sortMode = sortMode; } onSortDescChanged: { plasmoid.configuration.sortDesc = sortDesc; } onSortDirsFirstChanged: { plasmoid.configuration.sortDirsFirst = sortDirsFirst; } onIconSizeChanged: { plasmoid.configuration.iconSize = iconSize; } Component.onCompleted: { arrangement = plasmoid.configuration.arrangement; alignment = plasmoid.configuration.alignment; + previews = plasmoid.configuration.previews; locked = plasmoid.configuration.locked; sortMode = plasmoid.configuration.sortMode; sortDesc = plasmoid.configuration.sortDesc; sortDirsFirst = plasmoid.configuration.sortDirsFirst; iconSize = plasmoid.configuration.iconSize; } } PlasmaComponents.Label { anchors.fill: parent text: folderView.errorString horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter wrapMode: Text.Wrap } Connections { target: plasmoid onExpandedChanged: { if (root.isPopup) { if (plasmoid.expanded) { folderView.currentIndex = -1; folderView.forceActiveFocus(); } else { goHome(); folderView.currentIndex = -1; folderView.model.clearSelection(); folderView.cancelRename(); } } } onExternalData: { plasmoid.configuration.url = data } } Connections { target: plasmoid.configuration onArrangementChanged: { viewPropertiesMenu.arrangement = plasmoid.configuration.arrangement; } onAlignmentChanged: { viewPropertiesMenu.alignment = plasmoid.configuration.alignment; } onLockedChanged: { viewPropertiesMenu.locked = plasmoid.configuration.locked; } onSortModeChanged: { folderView.sortMode = plasmoid.configuration.sortMode; viewPropertiesMenu.sortMode = plasmoid.configuration.sortMode; } onSortDescChanged: { viewPropertiesMenu.sortDesc = plasmoid.configuration.sortDesc; } onSortDirsFirstChanged: { viewPropertiesMenu.sortDirsFirst = plasmoid.configuration.sortDirsFirst; } onIconSizeChanged: { viewPropertiesMenu.iconSize = plasmoid.configuration.iconSize; } onPositionsChanged: { folderView.positions = plasmoid.configuration.positions; } } PlasmaCore.ColorScope { id: colorScope anchors.left: parent.left anchors.top: parent.top anchors.topMargin: folderViewLayerComponent.label != null ? folderViewLayerComponent.label.height : 0 anchors.right: parent.right anchors.bottom: parent.bottom colorGroup: (root.isContainment ? PlasmaCore.Theme.ComplementaryColorGroup : PlasmaCore.Theme.NormalColorGroup) FolderView { id: folderView anchors.fill: parent focus: true isRootView: true url: plasmoid.configuration.url locked: (plasmoid.configuration.locked || !isContainment) filterMode: plasmoid.configuration.filterMode filterPattern: plasmoid.configuration.filterPattern filterMimeTypes: plasmoid.configuration.filterMimeTypes flow: (plasmoid.configuration.arrangement == 0) ? GridView.FlowLeftToRight : GridView.FlowTopToBottom layoutDirection: (plasmoid.configuration.alignment == 0) ? Qt.LeftToRight : Qt.RightToLeft onSortModeChanged: { plasmoid.configuration.sortMode = sortMode; } onPositionsChanged: { plasmoid.configuration.positions = folderView.positions; } Component.onCompleted: { folderView.sortMode = plasmoid.configuration.sortMode; folderView.positions = plasmoid.configuration.positions; } } } Component { id: labelComponent Item { id: label // If we bind height to visible, it will be invisible initially (since "visible" // propagates recursively) and that confuses the Label, hence the temp property. readonly property bool active: (plasmoid.configuration.labelMode != 0) readonly property bool showPin: root.isPopup && plasmoid.compactRepresentationItem && plasmoid.compactRepresentationItem.visible width: parent.width height: active ? labelHeight : 0 visible: active property Item windowPin: null property Item homeButton: null onVisibleChanged: { if (root.isPopup && !visible) { plasmoid.hideOnWindowDeactivate = true; } } onShowPinChanged: { if (!windowPin && showPin) { windowPin = windowPinComponent.createObject(label); } else if (windowPin) { windowPin.destroy(); windowPin = null; } } Connections { target: folderView onUrlChanged: { if (!label.homeButton && folderView.url != plasmoid.configuration.url) { label.homeButton = homeButtonComponent.createObject(label); } else if (label.homeButton) { label.homeButton.destroy(); } } } PlasmaComponents.Label { id: text anchors { left: label.homeButton ? label.homeButton.right : parent.left right: label.windowPin ? label.windowPin.left : parent.right margins: units.smallSpacing } height: parent.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignTop elide: Text.ElideMiddle text: labelGenerator.displayLabel font.underline: labelMouseArea.containsMouse } MouseArea { id: labelMouseArea anchors { top: text.top horizontalCenter: text.horizontalCenter } width: text.contentWidth height: text.contentHeight hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: { var action = plasmoid.action("run associated application"); if (action) { action.trigger(); } } } Component { id: windowPinComponent PlasmaComponents.ToolButton { id: windowPin anchors.right: parent.right visible: label.showPin width: root.isPopup ? Math.round(units.gridUnit * 1.25) : 0 height: width checkable: true iconSource: "window-pin" onCheckedChanged: plasmoid.hideOnWindowDeactivate = !checked } } Component { id: homeButtonComponent PlasmaComponents.ToolButton { id: homeButton anchors.left: parent.left visible: root.isPopup && folderView.url != plasmoid.configuration.url width: root.isPopup ? Math.round(units.gridUnit * 1.25) : 0 height: width iconSource: "go-home" onClicked: goHome() } } Component.onCompleted: { if (root.showPin) { windowPin = windowPinComponent.createObject(label); } } } } Component.onCompleted: { if (!isContainment) { label = labelComponent.createObject(folderViewLayerComponent); } var actionName = ""; var modelAction = null; for (var i = 0; i < sharedActions.length; i++) { actionName = sharedActions[i]; modelAction = folderView.model.action(actionName); plasmoid.setAction(actionName, modelAction.text, Folder.MenuHelper.iconName(modelAction)); var plasmoidAction = plasmoid.action(actionName); plasmoidAction.shortcut = modelAction.shortcut; plasmoidAction.shortcutContext = Qt.WidgetShortcut; if (actionName == "newMenu") { Folder.MenuHelper.setMenu(plasmoidAction, folderView.model.newMenu); plasmoid.setActionSeparator("separator1"); plasmoid.setAction("viewProperties", i18n("Icons"), "preferences-desktop-icons"); Folder.MenuHelper.setMenu(plasmoid.action("viewProperties"), viewPropertiesMenu.menu); } else { plasmoidAction.triggered.connect(modelAction.trigger); } } plasmoid.setActionSeparator("separator2"); plasmoid.contextualActionsAboutToShow.connect(updateContextualActions); plasmoid.contextualActionsAboutToShow.connect(folderView.model.clearSelection); } } diff --git a/containments/desktop/plugins/folder/viewpropertiesmenu.cpp b/containments/desktop/plugins/folder/viewpropertiesmenu.cpp index e79d085db..5af10704d 100644 --- a/containments/desktop/plugins/folder/viewpropertiesmenu.cpp +++ b/containments/desktop/plugins/folder/viewpropertiesmenu.cpp @@ -1,258 +1,273 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "viewpropertiesmenu.h" #include #include #include ViewPropertiesMenu::ViewPropertiesMenu(QObject *parent) : QObject(parent) { m_menu = new QMenu(); m_arrangementMenu = m_menu->addMenu(i18n("Arrange In")); m_arrangement = new QActionGroup(this); connect(m_arrangement, &QActionGroup::triggered, this, &ViewPropertiesMenu::arrangementChanged); QAction *action = m_arrangementMenu->addAction(i18n("Rows")); action->setCheckable(true); action->setData(0); m_arrangement->addAction(action); action = m_arrangementMenu->addAction(i18n("Columns")); action->setData(1); action->setCheckable(true); m_arrangement->addAction(action); m_alignmentMenu = m_menu->addMenu(i18n("Align")); m_alignment = new QActionGroup(this); connect(m_alignment, &QActionGroup::triggered, this, &ViewPropertiesMenu::alignmentChanged); action = m_alignmentMenu->addAction(i18n("Left")); action->setCheckable(true); action->setData(0); m_alignment->addAction(action); action = m_alignmentMenu->addAction(i18n("Right")); action->setCheckable(true); action->setData(1); m_alignment->addAction(action); QMenu *menu = m_menu->addMenu(i18n("Sort By")); m_sortMode = new QActionGroup(this); connect(m_sortMode, &QActionGroup::triggered, this, &ViewPropertiesMenu::sortModeChanged); action = menu->addAction(i18n("Unsorted")); action->setCheckable(true); action->setData(-1); m_sortMode->addAction(action); action = menu->addAction(i18n("Name")); action->setCheckable(true); action->setData(int(KDirModel::Name)); m_sortMode->addAction(action); action = menu->addAction(i18n("Size")); action->setCheckable(true); action->setData(int(KDirModel::Size)); m_sortMode->addAction(action); action = menu->addAction(i18n("Type")); action->setCheckable(true); action->setData(int(KDirModel::Type)); m_sortMode->addAction(action); action = menu->addAction(i18n("Date")); action->setCheckable(true); action->setData(int(KDirModel::ModifiedTime)); m_sortMode->addAction(action); menu->addSeparator(); m_sortDesc = menu->addAction(i18n("Descending"), this, SIGNAL(sortDescChanged())); m_sortDesc->setCheckable(true); m_sortDirsFirst = menu->addAction(i18n("Folders First"), this, SIGNAL(sortDirsFirstChanged())); m_sortDirsFirst->setCheckable(true); m_iconSizeMenu = m_menu->addMenu(i18n("Icon Size")); m_iconSize = new QActionGroup(this); connect(m_iconSize, &QActionGroup::triggered, this, &ViewPropertiesMenu::iconSizeChanged); const QStringList iconSizes{ i18n("Tiny"), i18n("Small"), i18n("Small Medium"), i18n("Medium"), i18n("Large"), i18n("Huge") }; for (int i = 0; i < iconSizes.count(); ++i) { action = m_iconSizeMenu->addAction(iconSizes.at(i)); action->setCheckable(true); action->setData(i); m_iconSize->addAction(action); } + m_previews = m_menu->addAction(QIcon::fromTheme(QStringLiteral("view-preview")), i18n("Show Previews"), this, &ViewPropertiesMenu::previewsChanged); + m_previews->setCheckable(true); + m_locked = m_menu->addAction(i18n("Locked"), this, SIGNAL(lockedChanged())); m_locked->setCheckable(true); } ViewPropertiesMenu::~ViewPropertiesMenu() { delete m_menu; } QObject* ViewPropertiesMenu::menu() const { return m_menu; } bool ViewPropertiesMenu::showLayoutActions() const { return m_alignmentMenu->menuAction()->isVisible() && m_arrangementMenu->menuAction()->isVisible(); } void ViewPropertiesMenu::setShowLayoutActions(bool show) { if (showLayoutActions() != show) { m_arrangementMenu->menuAction()->setVisible(show); m_alignmentMenu->menuAction()->setVisible(show); emit showLayoutActionsChanged(); } } bool ViewPropertiesMenu::showLockAction() const { return m_locked->isVisible(); } void ViewPropertiesMenu::setShowLockAction(bool show) { if (m_locked->isVisible() != show) { m_locked->setVisible(show); emit showLockActionChanged(); } } bool ViewPropertiesMenu::showIconSizeActions() const { return m_iconSizeMenu->menuAction()->isVisible(); } void ViewPropertiesMenu::setShowIconSizeActions(bool show) { if (showIconSizeActions() != show) { m_iconSizeMenu->menuAction()->setVisible(show); emit showIconSizeActionsChanged(); } } int ViewPropertiesMenu::arrangement() const { return m_arrangement->checkedAction()->data().toInt(); } void ViewPropertiesMenu::setArrangement(int arrangement) { if (!m_arrangement->checkedAction() || m_arrangement->checkedAction()->data().toInt() != arrangement) { foreach (QAction *action, m_arrangement->actions()) { if (action->data().toInt() == arrangement) { action->setChecked(true); break; } } } } int ViewPropertiesMenu::alignment() const { return m_alignment->checkedAction()->data().toInt(); } void ViewPropertiesMenu::setAlignment(int alignment) { if (!m_alignment->checkedAction() || m_alignment->checkedAction()->data().toInt() != alignment) { foreach (QAction *action, m_alignment->actions()) { if (action->data().toInt() == alignment) { action->setChecked(true); break; } } } } +bool ViewPropertiesMenu::previews() const +{ + return m_previews->isChecked(); +} + +void ViewPropertiesMenu::setPreviews(bool previews) +{ + if (m_previews->isChecked() != previews) { + m_previews->setChecked(previews); + } +} + bool ViewPropertiesMenu::locked() const { return m_locked->isChecked(); } void ViewPropertiesMenu::setLocked(bool locked) { if (m_locked->isChecked() != locked) { m_locked->setChecked(locked); } } int ViewPropertiesMenu::sortMode() const { return m_sortMode->checkedAction()->data().toInt(); } void ViewPropertiesMenu::setSortMode(int sortMode) { if (!m_sortMode->checkedAction() || m_sortMode->checkedAction()->data().toInt() != sortMode) { foreach (QAction *action, m_sortMode->actions()) { if (action->data().toInt() == sortMode) { action->setChecked(true); break; } } } } bool ViewPropertiesMenu::sortDesc() const { return m_sortDesc->isChecked(); } void ViewPropertiesMenu::setSortDesc(bool sortDesc) { if (m_sortDesc->isChecked() != sortDesc) { m_sortDesc->setChecked(sortDesc); } } bool ViewPropertiesMenu::sortDirsFirst() const { return m_sortDirsFirst->isChecked(); } void ViewPropertiesMenu::setSortDirsFirst(bool sortDirsFirst) { if (m_sortDirsFirst->isChecked() != sortDirsFirst) { m_sortDirsFirst->setChecked(sortDirsFirst); } } int ViewPropertiesMenu::iconSize() const { return m_iconSize->checkedAction()->data().toInt(); } void ViewPropertiesMenu::setIconSize(int iconSize) { if (!m_iconSize->checkedAction() || m_iconSize->checkedAction()->data().toInt() != iconSize) { QAction *action = m_iconSize->actions().value(iconSize); if (action) { action->setChecked(true); } } } diff --git a/containments/desktop/plugins/folder/viewpropertiesmenu.h b/containments/desktop/plugins/folder/viewpropertiesmenu.h index 21d11ed77..8ec7ee1cd 100644 --- a/containments/desktop/plugins/folder/viewpropertiesmenu.h +++ b/containments/desktop/plugins/folder/viewpropertiesmenu.h @@ -1,110 +1,116 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef VIEWPROPERTIESMENU_H #define VIEWPROPERTIESMENU_H #include #include "folderplugin_private_export.h" class QAction; class QActionGroup; class QMenu; class FOLDERPLUGIN_TESTS_EXPORT ViewPropertiesMenu : public QObject { Q_OBJECT Q_PROPERTY(QObject* menu READ menu CONSTANT) Q_PROPERTY(bool showLayoutActions READ showLayoutActions WRITE setShowLayoutActions NOTIFY showLayoutActionsChanged) Q_PROPERTY(bool showLockAction READ showLockAction WRITE setShowLockAction NOTIFY showLockActionChanged) Q_PROPERTY(bool showIconSizeActions READ showIconSizeActions WRITE setShowIconSizeActions NOTIFY showIconSizeActionsChanged) Q_PROPERTY(int arrangement READ arrangement WRITE setArrangement NOTIFY arrangementChanged) Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) + Q_PROPERTY(bool previews READ previews WRITE setPreviews NOTIFY previewsChanged) Q_PROPERTY(bool locked READ locked WRITE setLocked NOTIFY lockedChanged) Q_PROPERTY(int sortMode READ sortMode WRITE setSortMode NOTIFY sortModeChanged) Q_PROPERTY(bool sortDesc READ sortDesc WRITE setSortDesc NOTIFY sortDescChanged) Q_PROPERTY(bool sortDirsFirst READ sortDirsFirst WRITE setSortDirsFirst NOTIFY sortDirsFirstChanged) Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) public: explicit ViewPropertiesMenu(QObject *parent = nullptr); ~ViewPropertiesMenu(); QObject* menu() const; bool showLayoutActions() const; void setShowLayoutActions(bool show); bool showLockAction() const; void setShowLockAction(bool show); bool showIconSizeActions() const; void setShowIconSizeActions(bool show); int arrangement() const; void setArrangement(int arrangement); int alignment() const; void setAlignment(int alignment); + bool previews() const; + void setPreviews(bool previews); + bool locked() const; void setLocked(bool locked); int sortMode() const; void setSortMode(int sortMode); bool sortDesc() const; void setSortDesc(bool sortDesc); bool sortDirsFirst() const; void setSortDirsFirst(bool sortDirsFirst); int iconSize() const; void setIconSize(int iconSize); Q_SIGNALS: void showLayoutActionsChanged() const; void showLockActionChanged() const; void showIconSizeActionsChanged(); void arrangementChanged() const; void alignmentChanged() const; + void previewsChanged() const; void lockedChanged() const; void sortModeChanged() const; void sortDescChanged() const; void sortDirsFirstChanged() const; void iconSizeChanged(); private: QMenu *m_menu; QMenu *m_arrangementMenu; QActionGroup *m_arrangement; QMenu *m_alignmentMenu; QActionGroup *m_alignment; QActionGroup *m_sortMode; QMenu *m_iconSizeMenu; QActionGroup *m_iconSize; QAction *m_sortDesc; QAction *m_sortDirsFirst; + QAction *m_previews; QAction *m_locked; }; #endif