Support shortcut keys to adjust desktop icon size

This commit is contained in:
cutefishd 2021-03-16 23:19:36 +08:00
parent 6d82581776
commit 2f4ad13357
6 changed files with 49 additions and 21 deletions

View file

@ -4,7 +4,7 @@ Name=File Manager
Name[zh_CN]=
GenericName=File Manager
Comment=Cutefish File Manager
Exec=cutefish-fm %U
Exec=cutefish-filemanager %U
MimeType=inode/directory;
Icon=file-system-manager
Categories=FileManager;Utility;Core;Qt;

View file

@ -84,7 +84,7 @@ Item {
FolderIconView {
id: _gridViewBrowser
anchors.fill: parent
model: dirModel
model: positioner
leftMargin: Meui.Units.largeSpacing
rightMargin: Meui.Units.largeSpacing

View file

@ -5,6 +5,7 @@ import QtQuick.Layouts 1.12
import Cutefish.FileManager 1.0 as FM
import MeuiKit 1.0 as Meui
import "../"
import "FolderTools.js" as FolderTools
FocusScope {
@ -104,6 +105,10 @@ FocusScope {
}
}
GlobalSettings {
id: settings
}
MouseArea {
id: listener
anchors.fill: parent
@ -133,6 +138,15 @@ FocusScope {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onWheel: {
if (wheel.modifiers & Qt.ControlModifier) {
if (wheel.angleDelta.y > 0)
gridView.increaseIconSize()
else
gridView.decreaseIconSize()
}
}
onPressed: {
gridView.focus = true
gridView.forceActiveFocus()
@ -382,7 +396,7 @@ FocusScope {
}
}
property var iconSize: 150 + Meui.Units.largeSpacing
property var iconSize: settings.desktopIconSize + Meui.Units.largeSpacing
cellWidth: {
var extraWidth = calcExtraSpacing(iconSize, gridView.width - leftMargin - rightMargin);
@ -394,6 +408,26 @@ FocusScope {
return iconSize + extraHeight;
}
function increaseIconSize() {
if (iconSize >= settings.maximumIconSize) {
iconSize = settings.maximumIconSize
return
}
iconSize += (iconSize * 0.1)
settings.desktopIconSize = iconSize
}
function decreaseIconSize() {
if (iconSize <= settings.minimumIconSize) {
iconSize = settings.minimumIconSize
return
}
iconSize -= (iconSize * 0.1)
settings.desktopIconSize = iconSize
}
function calcExtraSpacing(cellSize, containerSize) {
var availableColumns = Math.floor(containerSize / cellSize);
var extraSpacing = 0;

View file

@ -15,10 +15,6 @@ Window {
if (visible) updateWindowSize()
}
Component.onCompleted: {
updateWindowSize()
}
function updateWindowSize() {
if (visible) {
control.width = _mainLayout.implicitWidth + _mainLayout.anchors.leftMargin + _mainLayout.anchors.rightMargin
@ -77,6 +73,7 @@ Window {
Layout.alignment: Qt.AlignTop
onHeightChanged: updateWindowSize()
onImplicitHeightChanged: updateWindowSize()
Label {
text: qsTr("Type:")

View file

@ -6,4 +6,7 @@ Settings {
property bool showHidden: false
property int width: 1080
property int height: 645
property int desktopIconSize: 128
property int maximumIconSize: 256
property int minimumIconSize: 128
}

View file

@ -1648,6 +1648,9 @@ void FolderModel::createActions()
QAction *actOpen = new QAction(tr("&Open"), this);
connect(actOpen, &QAction::triggered, this, &FolderModel::openSelected);
QAction *propertiesAction = new QAction(tr("Properties"), this);
QObject::connect(propertiesAction, &QAction::triggered, this, &FolderModel::openPropertiesDialog);
m_actionCollection.addAction(QStringLiteral("open"), actOpen);
m_actionCollection.addAction(QStringLiteral("cut"), cut);
m_actionCollection.addAction(QStringLiteral("undo"), undo);
@ -1661,6 +1664,7 @@ void FolderModel::createActions()
m_actionCollection.addAction(QStringLiteral("emptyTrash"), emptyTrash);
m_actionCollection.addAction(QStringLiteral("new_folder"), newFolderAction);
m_actionCollection.addAction(QStringLiteral("new_documents"), newDocAction);
m_actionCollection.addAction(QStringLiteral("properties"), propertiesAction);
m_newMenu = new KNewFileMenu(&m_actionCollection, QStringLiteral("newMenu"), this);
m_newMenu->setModal(false);
@ -1819,13 +1823,8 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
menu->addAction(setWallpaper);
}
// Properties
if (KPropertiesDialog::canDisplay(KFileItemList() << rootItem())) {
menu->addSeparator();
QAction *act = new QAction(tr("Properties"), menu);
QObject::connect(act, &QAction::triggered, this, &FolderModel::openPropertiesDialog);
menu->addAction(act);
}
menu->addAction(m_actionCollection.action(QStringLiteral("properties")));
} else {
KFileItemList items;
QList<QUrl> urls;
@ -1875,13 +1874,8 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
menu->addAction(setAswallpaper);
}
// Properties
if (KPropertiesDialog::canDisplay(items)) {
menu->addSeparator();
QAction *act = new QAction(tr("&Properties"), menu);
QObject::connect(act, &QAction::triggered, this, &FolderModel::openPropertiesDialog);
menu->addAction(act);
}
menu->addAction(m_actionCollection.action(QStringLiteral("properties")));
}
if (visualParent) {