diff --git a/cuttlefish/package/contents/ui/ResponsivePreview.qml b/cuttlefish/package/contents/ui/Actions.qml copy from cuttlefish/package/contents/ui/ResponsivePreview.qml copy to cuttlefish/package/contents/ui/Actions.qml --- a/cuttlefish/package/contents/ui/ResponsivePreview.qml +++ b/cuttlefish/package/contents/ui/Actions.qml @@ -1,6 +1,7 @@ /*************************************************************************** * * * Copyright 2019 Carson Black * + * Copyright 2019 David Redondo * * * * 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 * @@ -20,44 +21,20 @@ ***************************************************************************/ import QtQuick 2.5 +import QtQuick.Dialogs 1.3 import QtQuick.Controls 2.5 as QQC2 -import QtQuick.Layouts 1.0 - import org.kde.kirigami 2.8 as Kirigami -Kirigami.GlobalDrawer { - id: root - edge: Qt.RightEdge - - handleOpenIcon.source: "dialog-close" - handleClosedIcon.source: "view-preview" - - Kirigami.Theme.textColor: cuttlefish.textcolor - Kirigami.Theme.backgroundColor: cuttlefish.bgcolor - Kirigami.Theme.highlightColor: cuttlefish.highlightcolor - Kirigami.Theme.highlightedTextColor: cuttlefish.highlightedtextcolor - Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor - Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor - Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - - focus: false - - function clipboard(text) { - if (!pickerMode) { - clipboardHelper.text = text; - clipboardHelper.selectAll(); - clipboardHelper.copy(); - } else { - iconModel.output(text); +Item { + property QQC2.Action screenshotAction: QQC2.Action { + enabled: !iconPreview.screenshotting + icon.name: "camera-web-symbolic" + text: i18n("Create screenshot of icon") + onTriggered: { + screenshotPopup.popup() } } - - TextEdit { - id: clipboardHelper - visible: false - } - - actions: [ + property list actions:[ Kirigami.Action { text: i18n("Open icon with external program") iconName: "document-open" @@ -67,27 +44,29 @@ text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard") iconName: "edit-copy" onTriggered: { - root.clipboard(preview.iconName) + clipboard(preview.iconName) cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short") } }, Kirigami.Action { + id: screenshotAction iconName: "camera-web-symbolic" text: i18n("Create screenshot of icon with...") + onTriggered: screenshotPopup.popup() Kirigami.Action { text: i18n("Breeze Colors") - onTriggered: iconPreview.shot("normal") + onTriggered: previewPane.iconPreview.shot("normal") } Kirigami.Action { text: i18n("Breeze Dark Colors") - onTriggered: iconPreview.shot("dark") + onTriggered: previewPane.iconPreview.shot("dark") } Kirigami.Action { - onTriggered: dualMont.shot() + onTriggered: previewPane.dualMont.shot() text: i18n("Breeze (Normal) and Breeze Dark") } Kirigami.Action { - onTriggered: iconPreview.shot("active") + onTriggered: previewPane.iconPreview.shot("active") text: i18n("Active Color Scheme") } }, @@ -97,58 +76,29 @@ onTriggered: comparison.sheetOpen = true } ] - Kirigami.Heading { - level: 1 - Layout.fillWidth: true - wrapMode: Text.Wrap - horizontalAlignment: Text.AlignHCenter - elide: Text.ElideRight - text: preview.iconName - } - Kirigami.FormLayout { - Layout.fillWidth: true - Layout.topMargin: Kirigami.Units.largeSpacing - QQC2.Label { - Layout.maximumWidth: Kirigami.Units.gridUnit * 10 - Kirigami.FormData.label: i18n("File name:") - elide: Text.ElideRight - text: preview.fileName - } - QQC2.Label { - Kirigami.FormData.label: i18n("Category:") - font.capitalization: Font.Capitalize - text: preview.category - } - QQC2.Label { - Kirigami.FormData.label: i18n("Scalable:") - text: preview.scalable ? i18n("yes") : i18n("no") - font.capitalization: Font.Capitalize - } - } - GridLayout { - id: grid - columns: 2 - property var sizes: [8, 16, 22, 32, 48, 64] - Layout.alignment: Qt.AlignHCenter + + QQC2.Menu { + id: screenshotPopup Repeater { - model: parent.sizes.length - delegate: ColumnLayout { - Kirigami.Icon { - Layout.alignment: Qt.AlignBottom - source: preview.iconName - width: grid.sizes[index] - height: grid.sizes[index] - } - QQC2.Label { - Layout.alignment: Qt.AlignTop | Qt.AlignHCenter - text: grid.sizes[index] - Behavior on color { - ColorAnimation { - duration: Kirigami.Units.longDuration - } - } - } + model: screenshotAction.visibleChildren + delegate: QQC2.MenuItem { + action: modelData } } } + + function clipboard(text) { + if (!pickerMode) { + clipboardHelper.text = text; + clipboardHelper.selectAll(); + clipboardHelper.copy(); + } else { + iconModel.output(text); + } + } + TextEdit { + id: clipboardHelper + visible: false + } + } diff --git a/cuttlefish/package/contents/ui/Menu.qml b/cuttlefish/package/contents/ui/Menu.qml --- a/cuttlefish/package/contents/ui/Menu.qml +++ b/cuttlefish/package/contents/ui/Menu.qml @@ -1,6 +1,8 @@ /*************************************************************************** * * + * Copyright 2018 Aleix Pol Gonzalez * * Copyright 2019 Carson Black * + * Copyright 2019 David Redondo * * * * 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 * @@ -20,29 +22,63 @@ ***************************************************************************/ import QtQuick 2.5 -import Qt.labs.platform 1.0 +import QtQuick.Controls 2.5 as QQC2 +import org.kde.kirigami 2.8 as Kirigami -Menu { - id: root - Connections { - target: cuttlefish - onItemRightClicked: { - root.open() +Item { + Loader { + id:menuLoader + sourceComponent: actionsMenu + onLoaded: { + item.actions = cuttlefish.actions } - } - MenuItem { - iconName: "edit-copy" - text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard") - onTriggered: { - previewPane.clipboard(preview.iconName) - cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short") + Connections { + target: cuttlefish + onItemRightClicked: { + menuLoader.item.popup() + } } } - MenuItem { - iconName: "document-open" - text: i18n("Open icon with external program") - onTriggered: { - Qt.openUrlExternally(preview.fullPath) + Component { + id: actionsMenu + QQC2.Menu { + id: theMenu + property Component submenuComponent: actionsMenu + property Component itemDelegate: QQC2.MenuItem { } + property Component seperatorDelegate: Kirigami.Separator {} + property alias actions: actionsInstantiator.model + Item { + id: invisibleItems + visible: false + } + Instantiator { + id: actionsInstantiator + active: theMenu.visible + delegate: QtObject { + readonly property var action: modelData + property QtObject item: null + function create() { + if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { + item = theMenu.itemDelegate.createObject(null, { action: action }); + theMenu.addItem(item) + } else { + item = theMenu.submenuComponent.createObject(null, { actions: action.children, title: action.text}); + theMenu.insertMenu(theMenu.count, item) + var menuitem = theMenu.contentData[theMenu.contentData.length-1] + menuitem.icon = action.icon + } + } + function remove() { + if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { + theMenu.removeItem(item) + } else if (theMenu.submenuComponent) { + theMenu.removeMenu(item) + } + } + } + onObjectAdded: object.create() + onObjectRemoved: object.remove() + } } } } diff --git a/cuttlefish/package/contents/ui/Preview.qml b/cuttlefish/package/contents/ui/Preview.qml --- a/cuttlefish/package/contents/ui/Preview.qml +++ b/cuttlefish/package/contents/ui/Preview.qml @@ -41,21 +41,6 @@ color: Kirigami.Theme.backgroundColor - function clipboard(text) { - if (!pickerMode) { - clipboardHelper.text = text; - clipboardHelper.selectAll(); - clipboardHelper.copy(); - } else { - iconModel.output(text); - } - - } - TextEdit { - id: clipboardHelper - visible: false - } - FileDialog { id: ssPicker selectExisting: false @@ -252,65 +237,13 @@ ssPicker.open() } } - QQC2.Button { - Layout.alignment: Qt.AlignHCenter - text: i18n("Open icon with external program") - icon.name: "document-open" - onClicked: Qt.openUrlExternally(preview.fullPath) - } - QQC2.Button { - Layout.alignment: Qt.AlignHCenter - text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard") - icon.name: "edit-copy" - onClicked: { - clipboard(preview.iconName) - cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short") - } - } - QQC2.Button { - Layout.alignment: Qt.AlignHCenter - visible: !iconPreview.screenshotting - icon.name: "camera-web-symbolic" - text: i18n("Create screenshot of icon") - - onClicked: { - screenshotActions.popup() - } - - QQC2.Menu { - id: screenshotActions - QQC2.MenuItem { - text: i18n("Screenshot with Breeze Colors") - onTriggered: { - iconPreview.shot("normal") - } - } - QQC2.MenuItem { - text: i18n("Screenshot with Breeze Dark Colors") - onTriggered: { - iconPreview.shot("dark") - } - } - QQC2.MenuItem { - text: i18n("Screenshot with Breeze (Normal) and Breeze Dark") - onTriggered: { - dualMont.shot() - } - } - QQC2.MenuItem { - text: i18n("Screenshot with Active Color Scheme") - onTriggered: { - iconPreview.shot("active") - } - } + Repeater { + model: cuttlefish.actions + delegate: QQC2.Button { + Layout.alignment: Qt.AlignHCenter + action: modelData } } - QQC2.Button { - Layout.alignment: Qt.AlignCenter - text: i18n("View icon in other themes") - icon.name: "document-equal" - onClicked: comparison.sheetOpen = true - } Item { Layout.fillHeight: true } diff --git a/cuttlefish/package/contents/ui/ResponsivePreview.qml b/cuttlefish/package/contents/ui/ResponsivePreview.qml --- a/cuttlefish/package/contents/ui/ResponsivePreview.qml +++ b/cuttlefish/package/contents/ui/ResponsivePreview.qml @@ -42,61 +42,8 @@ focus: false - function clipboard(text) { - if (!pickerMode) { - clipboardHelper.text = text; - clipboardHelper.selectAll(); - clipboardHelper.copy(); - } else { - iconModel.output(text); - } - } + actions: cuttlefish.actions - TextEdit { - id: clipboardHelper - visible: false - } - - actions: [ - Kirigami.Action { - text: i18n("Open icon with external program") - iconName: "document-open" - onTriggered: Qt.openUrlExternally(preview.fullPath) - }, - Kirigami.Action { - text: pickerMode ? i18n("Insert icon name") : i18n("Copy icon name to clipboard") - iconName: "edit-copy" - onTriggered: { - root.clipboard(preview.iconName) - cuttlefish.showPassiveNotification(i18n("Icon name copied to clipboard"), "short") - } - }, - Kirigami.Action { - iconName: "camera-web-symbolic" - text: i18n("Create screenshot of icon with...") - Kirigami.Action { - text: i18n("Breeze Colors") - onTriggered: iconPreview.shot("normal") - } - Kirigami.Action { - text: i18n("Breeze Dark Colors") - onTriggered: iconPreview.shot("dark") - } - Kirigami.Action { - onTriggered: dualMont.shot() - text: i18n("Breeze (Normal) and Breeze Dark") - } - Kirigami.Action { - onTriggered: iconPreview.shot("active") - text: i18n("Active Color Scheme") - } - }, - Kirigami.Action { - text: i18n("View icon in other themes") - icon.name: "document-equal" - onTriggered: comparison.sheetOpen = true - } - ] Kirigami.Heading { level: 1 Layout.fillWidth: true diff --git a/cuttlefish/package/contents/ui/cuttlefish.qml b/cuttlefish/package/contents/ui/cuttlefish.qml --- a/cuttlefish/package/contents/ui/cuttlefish.qml +++ b/cuttlefish/package/contents/ui/cuttlefish.qml @@ -43,6 +43,8 @@ property bool usesPlasmaTheme: true property var schemeStash + property alias actions: actions.actions + property color textcolor: Kirigami.Theme.textColor property color bgcolor: Kirigami.Theme.backgroundColor property color highlightcolor: Kirigami.Theme.highlightColor @@ -59,16 +61,19 @@ Kirigami.Theme.positiveTextColor: cuttlefish.positivetextcolor Kirigami.Theme.neutralTextColor: cuttlefish.neutraltextcolor Kirigami.Theme.negativeTextColor: cuttlefish.negativetextcolor - + Loader { // Use a Loader instead of creating a GMB directly, // so if the GMB errors, it doesn't affect Cuttlefish's operation id: loader source: "GlobalMenuBar.qml" } - Loader { - // Ditto for the right click context menu. - source: "Menu.qml" + Actions { + id: actions + } + + Menu { + id: menu } Settings { property alias x: cuttlefish.x