Commit 6fc1cb84 authored by Ismael Asensio's avatar Ismael Asensio

[cuttlefish] Refactor Screenshot logic

Move all montage/screenshot logic to an unique non-visible item
(was `DualMontage`, now `Screenshot`). This frees up `Preview`
to just simpler on-screen behavior.

It fixes a bug where, after making a non-dual montage, `Kirigami.Theme`
bindings within `Preview` would break, stopping to follow the Theme combobox.
parent 9ea44349
......@@ -32,19 +32,19 @@ Item {
onTriggered: screenshotPopup.popup()
Kirigami.Action {
text: i18n("Breeze Colors")
onTriggered: previewPane.iconPreview.shot("normal")
onTriggered: cuttlefish.doScreenshot(Screenshot.MontageType.Normal)
}
Kirigami.Action {
text: i18n("Breeze Dark Colors")
onTriggered: previewPane.iconPreview.shot("dark")
onTriggered: cuttlefish.doScreenshot(Screenshot.MontageType.Dark)
}
Kirigami.Action {
onTriggered: previewPane.dualMont.shot()
text: i18n("Breeze (Normal) and Breeze Dark")
onTriggered: cuttlefish.doScreenshot(Screenshot.MontageType.Dual)
}
Kirigami.Action {
onTriggered: previewPane.iconPreview.shot("active")
text: i18n("Active Color Scheme")
onTriggered: cuttlefish.doScreenshot(Screenshot.MontageType.Active)
}
},
Kirigami.Action {
......
......@@ -21,19 +21,19 @@ MenuBar {
title: i18n("Export Montage with Color Scheme...")
MenuItem {
text: i18n("Active Color Scheme")
onTriggered: root.montage(0)
onTriggered: root.montage(Screenshot.MontageType.Active)
}
MenuItem {
text: i18n("Breeze (Normal)")
onTriggered: root.montage(1)
onTriggered: root.montage(Screenshot.MontageType.Normal)
}
MenuItem {
text: i18n("Breeze Dark")
onTriggered: root.montage(2)
onTriggered: root.montage(Screenshot.MontageType.Dark)
}
MenuItem {
text: i18n("Breeze (Normal) and Breeze Dark")
onTriggered: root.montage(3)
onTriggered: root.montage(Screenshot.MontageType.Dual)
}
}
MenuSeparator {}
......
......@@ -15,38 +15,9 @@ import org.kde.kirigami 2.8 as Kirigami
Rectangle {
property alias iconPreview: iconPreview
property alias dualMont: dualMont
color: Kirigami.Theme.backgroundColor
FileDialog {
id: ssPicker
selectExisting: false
selectMultiple: false
selectFolder: false
onAccepted: {
iconPreview.grabToImage(function(result) {
ssPicker.resetColors()
res = result.saveToFile(ssPicker.fileUrl.toString().slice(7))
});
}
onRejected: {
ssPicker.resetColors()
}
function resetColors() {
iconPreview.screenshotting = false
iconPreview.Kirigami.Theme.textColor = Kirigami.Theme.textColor
iconPreview.Kirigami.Theme.backgroundColor = Kirigami.Theme.backgroundColor
iconPreview.Kirigami.Theme.highlightColor = Kirigami.Theme.highlightColor
iconPreview.Kirigami.Theme.highlightedTextColor = Kirigami.Theme.highlightedTextColor
iconPreview.Kirigami.Theme.positiveTextColor = Kirigami.Theme.positiveTextColor
iconPreview.Kirigami.Theme.neutralTextColor = Kirigami.Theme.neutralTextColor
iconPreview.Kirigami.Theme.negativeTextColor = Kirigami.Theme.negativeTextColor
iconPreview.Kirigami.Theme.inherit = true
}
nameFilters: [ "PNG screenshot files (*.png)" ]
}
ColumnLayout {
anchors.fill: parent
spacing: Kirigami.Units.largeSpacing
......@@ -81,54 +52,10 @@ Rectangle {
}
IconMontage {
id: iconPreview
property bool screenshotting: false
columns: cuttlefish.iconSizes.length - 1
showWatermark: iconPreview.screenshotting
Behavior on color {
ColorAnimation {
duration: Kirigami.Units.longDuration
}
}
Behavior on Layout.preferredHeight {
NumberAnimation {
duration: Kirigami.Units.longDuration
}
}
Layout.fillWidth: true
Layout.preferredHeight: implicitHeight + (screenshotting ? (Kirigami.Units.gridUnit * 4) : 0)
Layout.topMargin: Kirigami.Units.largeSpacing
Layout.bottomMargin: Kirigami.Units.largeSpacing * 4
function shot(type) {
iconPreview.screenshotting = true
if (type == "normal") {
iconPreview.Kirigami.Theme.inherit = false
iconPreview.Kirigami.Theme.textColor = "#232629"
iconPreview.Kirigami.Theme.backgroundColor = "#eff0f1"
iconPreview.Kirigami.Theme.highlightColor = "#3daee9"
iconPreview.Kirigami.Theme.highlightedTextColor = "#eff0f1"
iconPreview.Kirigami.Theme.positiveTextColor = "#27ae60"
iconPreview.Kirigami.Theme.neutralTextColor = "#f67400"
iconPreview.Kirigami.Theme.negativeTextColor = "#da4453"
} else if (type == "dark") {
iconPreview.Kirigami.Theme.inherit = false
iconPreview.Kirigami.Theme.textColor = "#eff0f1"
iconPreview.Kirigami.Theme.backgroundColor = "#31363b"
iconPreview.Kirigami.Theme.highlightColor = "#3daee9"
iconPreview.Kirigami.Theme.highlightedTextColor = "#eff0f1"
iconPreview.Kirigami.Theme.positiveTextColor = "#27ae60"
iconPreview.Kirigami.Theme.neutralTextColor = "#f67400"
iconPreview.Kirigami.Theme.negativeTextColor = "#da4453"
} else if (type == "active") {
iconPreview.Kirigami.Theme.inherit = true
}
ssPicker.open()
}
}
Repeater {
model: cuttlefish.actions
......@@ -140,7 +67,6 @@ Rectangle {
Item {
Layout.fillHeight: true
}
DualMontage { id: dualMont }
}
Kirigami.Separator {
......
/*
SPDX-FileCopyrightText: 2019 Carson Black <uhhadd@gmail.com>
SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.2
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.3
import org.kde.kirigami 2.8 as Kirigami
Item {
id: dualMontage
id: screenshot
enum MontageType {
Active,
Normal,
Dark,
Dual
}
visible: false
height: 512
width: 512
signal finished
property int type: Screenshot.MontageType.Dual;
property Item selectedMontage: {
switch (type) {
case Screenshot.MontageType.Active:
return activeMontage
case Screenshot.MontageType.Normal:
return lightMontage
case Screenshot.MontageType.Dark:
return darkMontage
case Screenshot.MontageType.Dual:
return dualMontage
}
}
Kirigami.Theme.inherit: false
function shot() {
function shot(montageType) {
type = montageType
ssPicker.open()
}
FileDialog {
id: ssPicker
selectExisting: false
selectMultiple: false
selectFolder: false
onAccepted: {
dualMontage.grabToImage(function(result) {
res = result.saveToFile(ssPicker.fileUrl.toString().slice(7))
selectedMontage.grabToImage(function(result) {
result.saveToFile(ssPicker.fileUrl.toString().slice(7))
finished()
});
}
onRejected: {
finished()
}
nameFilters: [ "PNG screenshot files (*.png)" ]
}
IconMontage {
id: activeMontage
showWatermark: true
width: 512
height: 256
Kirigami.Theme.inherit: true
}
Column {
id:dualMontage
IconMontage {
height: 256
width: 512
id: lightMontage
showWatermark: true
width: 512
height: 256
Kirigami.Theme.inherit: false
Kirigami.Theme.textColor: "#232629"
Kirigami.Theme.backgroundColor: "#eff0f1"
......@@ -49,9 +93,11 @@ Item {
Kirigami.Theme.negativeTextColor: "#da4453"
}
IconMontage {
height: 256
id: darkMontage
showWatermark: screenshot.type == Screenshot.MontageType.Dark
width: 512
showWatermark: false
height: 256
Kirigami.Theme.inherit: false
Kirigami.Theme.textColor: "#eff0f1"
......
......@@ -32,6 +32,11 @@ Kirigami.ApplicationWindow {
Kirigami.Units.iconSizes.small, Kirigami.Units.iconSizes.smallMedium, Kirigami.Units.iconSizes.medium,
Kirigami.Units.iconSizes.large, Kirigami.Units.iconSizes.huge, Kirigami.Units.iconSizes.enormous]
function doScreenshot(montageType) {
ssLoader.type = montageType
ssLoader.active = true
}
Loader {
// Use a Loader instead of creating a GMB directly,
// so if the GMB errors, it doesn't affect Cuttlefish's operation
......@@ -57,20 +62,7 @@ Kirigami.ApplicationWindow {
function onZoomIn() { tools.slider.value += 1 }
function onZoomOut() { tools.slider.value -= 1 }
function onMontage(montageType) {
switch(montageType) {
case 0:
previewPane.iconPreview.shot("active")
break;
case 1:
previewPane.iconPreview.shot("normal")
break;
case 2:
previewPane.iconPreview.shot("dark")
break;
case 3:
previewPane.dualMont.shot()
break;
}
cuttlefish.doScreenshot(montageType)
}
}
......@@ -163,4 +155,20 @@ Kirigami.ApplicationWindow {
property variant sizes: []
property bool scalable: true
}
Loader {
id: ssLoader
sourceComponent: Screenshot {}
active: false
property int type: Screenshot.MontageType.Dual
onLoaded: {
ssLoader.item.shot(type)
}
Connections {
target: ssLoader.item
function onFinished() {
ssLoader.active = false
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment