Warning, /graphics/optiimage/src/contents/ui/OptimizePage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 0004 import QtQuick 0005 import QtQuick.Controls as QQC2 0006 import org.kde.kirigami as Kirigami 0007 import org.kde.kirigamiaddons.delegates as Delegates 0008 import org.kde.kirigamiaddons.components as Components 0009 import QtQuick.Layouts 0010 import Qt.labs.platform 0011 import org.kde.optiimage 0012 import org.kde.coreaddons 0013 0014 Kirigami.ScrollablePage { 0015 id: root 0016 0017 title: i18n("Optimize your images") 0018 0019 readonly property SetupCheck setupCheck: SetupCheck { 0020 Component.onCompleted: check(); 0021 } 0022 0023 header: Components.Banner { 0024 visible: !setupCheck.isValidSetup 0025 0026 type: Kirigami.MessageType.Error 0027 width: parent.width 0028 0029 showCloseButton: true 0030 0031 actions: Kirigami.Action { 0032 text: i18nc("@action:button", "Re-check") 0033 icon.name: "view-refresh-symbolic" 0034 onTriggered: setupCheck.check() 0035 } 0036 text: { 0037 if (!visible) { 0038 return ''; 0039 } 0040 let result = i18nc("@info", "The following programs are missing for OptiImage to run correctly:"); 0041 result += "<ul>"; 0042 for (let program of setupCheck.missingPrograms) { 0043 result += `<li>${program}</li>` 0044 } 0045 result += "</ul>"; 0046 } 0047 } 0048 0049 actions: [ 0050 Kirigami.Action { 0051 id: addImages 0052 icon.name: "list-add" 0053 text: i18nc("@action:button", "Select Images") 0054 onTriggered: fileDialog.open() 0055 }, 0056 Kirigami.Action { 0057 icon.name: "settings-configure" 0058 text: i18n("Settings") 0059 onTriggered: pageStack.layers.push(settings); 0060 0061 } 0062 ] 0063 0064 Component { 0065 id: settings 0066 SettingsPage {} 0067 } 0068 0069 FileDialog { 0070 id: fileDialog 0071 folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) 0072 fileMode: FileDialog.OpenFiles 0073 onAccepted: imageModel.addImages(files) 0074 nameFilters: [i18n("Image files (*.jpg *.jpeg *.png *.svg *.webp)"), i18n("All files (*)")] 0075 } 0076 0077 ListView { 0078 id: imageView 0079 0080 currentIndex: -1 0081 0082 model: ImageModel { 0083 id: imageModel 0084 } 0085 0086 delegate: Delegates.RoundedItemDelegate { 0087 id: imageDelegate 0088 0089 required property int index 0090 required property string displayName 0091 required property string filename 0092 required property int size 0093 required property int newSize 0094 required property bool alreadyOptimized 0095 required property bool processed 0096 0097 readonly property string subtitle: if (alreadyOptimized) { 0098 return i18nc("Size information with no change", "%1 (No change)", Format.formatByteSize(size)); 0099 } else if (newSize != -1) { 0100 return i18nc("Size information", "%1 -> %2 (%3% decrease)", Format.formatByteSize(size), Format.formatByteSize(newSize), ((size - newSize) / size).toFixed(2) * 100); 0101 } else { 0102 return Format.formatByteSize(size); 0103 } 0104 0105 text: displayName 0106 icon { 0107 source: filename 0108 height: Kirigami.Units.iconSizes.large 0109 width: Kirigami.Units.iconSizes.large 0110 } 0111 0112 contentItem: RowLayout { 0113 spacing: Kirigami.Units.smallSpacing 0114 0115 Delegates.SubtitleContentItem { 0116 subtitle: imageDelegate.subtitle 0117 itemDelegate: imageDelegate 0118 } 0119 0120 Kirigami.Icon { 0121 Layout.preferredWidth: Kirigami.Units.iconSizes.medium 0122 Layout.preferredHeight: Kirigami.Units.iconSizes.medium 0123 source: 'checkbox-symbolic' 0124 visible: imageDelegate.processed 0125 } 0126 0127 TapHandler { 0128 acceptedButtons: Qt.RightButton 0129 onTapped: { 0130 menu.fileName = imageDelegate.filename; 0131 menu.popup(); 0132 } 0133 } 0134 0135 TapHandler { 0136 id: leftClickHandler 0137 acceptedButtons: Qt.LeftButton 0138 onTapped: imageModel.open(imageDelegate.filename) 0139 } 0140 } 0141 0142 background: null 0143 0144 QQC2.Menu { 0145 id: menu 0146 property string fileName 0147 QQC2.MenuItem { 0148 text: i18nc("@action:inmenu", "Open") 0149 icon.source: 'system-run-symbolic' 0150 onClicked: imageModel.open(menu.fileName) 0151 } 0152 0153 QQC2.MenuItem { 0154 text: i18nc("@action:inmenu", "Open Containing Folder") 0155 icon.source: 'system-file-manager-symbolic' 0156 onClicked: imageModel.highlightInFileManager(menu.fileName) 0157 } 0158 0159 QQC2.MenuItem { 0160 text: i18nc("@action:inmenu", "Properties") 0161 icon.source: 'document-properties-symbolic' 0162 onClicked: imageModel.openProperties(menu.fileName) 0163 } 0164 } 0165 } 0166 0167 Kirigami.PlaceholderMessage { 0168 visible: imageView.count === 0 0169 text: i18n("No images to optimize") 0170 helpfulAction: addImages 0171 width: parent.width - Kirigami.Units.gridUnit * 4 0172 icon.name: "org.kde.optiimage" 0173 anchors.centerIn: parent 0174 } 0175 } 0176 0177 data: Components.FloatingButton { 0178 anchors { 0179 right: parent.right 0180 rightMargin: Kirigami.Units.largeSpacing 0181 bottom: parent.bottom 0182 bottomMargin: Kirigami.Units.largeSpacing 0183 } 0184 0185 action: Kirigami.Action { 0186 visible: true 0187 icon.name: 'dialog-messages' 0188 onTriggered: applicationWindow().pageStack.layers.push(logOutputPage) 0189 } 0190 0191 Component { 0192 id: logOutputPage 0193 LogOutputPage {} 0194 } 0195 } 0196 }