Verified Commit 5ad0abb7 authored by Fushan Wen's avatar Fushan Wen
Browse files

wallpapers/image: Move components to individual files

This makes config.qml less crowded, and will install SlideshowComponent
only to slideshow folder to save some space.
parent 9d0a71d7
Pipeline #170995 passed with stage
in 5 minutes and 46 seconds
/*
SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Window 2.15 // for Screen
import org.kde.kcm 1.5 as KCM
import org.kde.kirigami 2.12 as Kirigami
Item {
id: thumbnailsComponent
anchors.fill: parent
readonly property var imageModel: (configDialog.currentWallpaper === "org.kde.image") ? imageWallpaper.wallpaperModel : imageWallpaper.slideFilterModel
KCM.GridView {
id: wallpapersGrid
anchors.fill: parent
function resetCurrentIndex() {
//that min is needed as the module will be populated in an async way
//and only on demand so we can't ensure it already exists
view.currentIndex = Qt.binding(() => Math.min(imageModel.indexOf(cfg_Image), imageModel.count - 1));
}
//kill the space for label under thumbnails
view.model: thumbnailsComponent.imageModel
Component.onCompleted: {
thumbnailsComponent.imageModel.usedInConfig = true;
resetCurrentIndex()
}
//set the size of the cell, depending on Screen resolution to respect the aspect ratio
view.implicitCellWidth: Screen.width / 10 + Kirigami.Units.smallSpacing * 2
view.implicitCellHeight: Screen.height / 10 + Kirigami.Units.smallSpacing * 2 + Kirigami.Units.gridUnit * 3
view.delegate: WallpaperDelegate {
color: cfg_Color
}
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - (Kirigami.Units.largeSpacing * 4)
visible: wallpapersGrid.view.count === 0
text: i18nd("plasma_wallpaper_org.kde.image", "There are no wallpapers in this slideshow")
}
KCM.SettingHighlighter {
target: wallpapersGrid
highlight: configDialog.currentWallpaper === "org.kde.image" && cfg_Image != cfg_ImageDefault
}
}
......@@ -77,14 +77,6 @@ ColumnLayout {
imageWallpaper.slideshowFoldersFirst = cfg_SlideshowFoldersFirst
}
property int hoursIntervalValue: Math.floor(cfg_SlideInterval / 3600)
property int minutesIntervalValue: Math.floor(cfg_SlideInterval % 3600) / 60
property int secondsIntervalValue: cfg_SlideInterval % 3600 % 60
property int hoursIntervalValueDefault: Math.floor(cfg_SlideIntervalDefault / 3600)
property int minutesIntervalValueDefault: Math.floor(cfg_SlideIntervalDefault % 3600) / 60
property int secondsIntervalValueDefault: cfg_SlideIntervalDefault % 3600 % 60
//Rectangle { color: "orange"; x: formAlignment; width: formAlignment; height: 20 }
Kirigami.FormLayout {
......@@ -167,282 +159,6 @@ ColumnLayout {
}
}
Component {
id: slideshowComponent
ColumnLayout {
Connections {
target: root
function onHoursIntervalValueChanged() {hoursInterval.value = root.hoursIntervalValue}
function onMinutesIntervalValueChanged() {minutesInterval.value = root.minutesIntervalValue}
function onSecondsIntervalValueChanged() {secondsInterval.value = root.secondsIntervalValue}
}
Kirigami.FormLayout {
twinFormLayouts: parentLayout
RowLayout {
id: slideshowModeRow
Kirigami.FormData.label: i18nd("plasma_wallpaper_org.kde.image", "Order:")
QtControls2.ComboBox {
id: slideshowModeComboBox
model: [
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Random"),
'slideshowMode': PlasmaWallpaper.SortingMode.Random
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "A to Z"),
'slideshowMode': PlasmaWallpaper.SortingMode.Alphabetical
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Z to A"),
'slideshowMode': PlasmaWallpaper.SortingMode.AlphabeticalReversed
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Date modified (newest first)"),
'slideshowMode': PlasmaWallpaper.SortingMode.ModifiedReversed
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Date modified (oldest first)"),
'slideshowMode': PlasmaWallpaper.SortingMode.Modified
}
]
textRole: "label"
onActivated: {
cfg_SlideshowMode = model[currentIndex]["slideshowMode"];
}
Component.onCompleted: setMethod();
function setMethod() {
for (var i = 0; i < model.length; i++) {
if (model[i]["slideshowMode"] === wallpaper.configuration.SlideshowMode) {
slideshowModeComboBox.currentIndex = i;
break;
}
}
}
KCM.SettingHighlighter {
highlight: cfg_SlideshowMode != cfg_SlideshowModeDefault
}
}
QtControls2.CheckBox {
id: slideshowFoldersFirstCheckBox
text: i18nd("plasma_wallpaper_org.kde.image", "Group by folders")
checked: root.cfg_SlideshowFoldersFirst
onToggled: cfg_SlideshowFoldersFirst = slideshowFoldersFirstCheckBox.checked
KCM.SettingHighlighter {
highlight: root.cfg_SlideshowFoldersFirst !== cfg_SlideshowFoldersFirstDefault
}
}
}
// FIXME: there should be only one spinbox: QtControls spinboxes are still too limited for it tough
RowLayout {
Kirigami.FormData.label: i18nd("plasma_wallpaper_org.kde.image", "Change every:")
QtControls2.SpinBox {
id: hoursInterval
value: root.hoursIntervalValue
from: 0
to: 24
editable: true
onValueChanged: cfg_SlideInterval = hoursInterval.value * 3600 + minutesInterval.value * 60 + secondsInterval.value
textFromValue: function(value, locale) {
return i18ndp("plasma_wallpaper_org.kde.image","%1 hour", "%1 hours", value)
}
valueFromText: function(text, locale) {
return parseInt(text);
}
KCM.SettingHighlighter {
highlight: root.hoursIntervalValue != root.hoursIntervalValueDefault
}
}
QtControls2.SpinBox {
id: minutesInterval
value: root.minutesIntervalValue
from: 0
to: 60
editable: true
onValueChanged: cfg_SlideInterval = hoursInterval.value * 3600 + minutesInterval.value * 60 + secondsInterval.value
textFromValue: function(value, locale) {
return i18ndp("plasma_wallpaper_org.kde.image","%1 minute", "%1 minutes", value)
}
valueFromText: function(text, locale) {
return parseInt(text);
}
KCM.SettingHighlighter {
highlight: root.minutesIntervalValue != root.minutesIntervalValueDefault
}
}
QtControls2.SpinBox {
id: secondsInterval
value: root.secondsIntervalValue
from: root.hoursIntervalValue === 0 && root.minutesIntervalValue === 0 ? 1 : 0
to: 60
editable: true
onValueChanged: cfg_SlideInterval = hoursInterval.value * 3600 + minutesInterval.value * 60 + secondsInterval.value
textFromValue: function(value, locale) {
return i18ndp("plasma_wallpaper_org.kde.image","%1 second", "%1 seconds", value)
}
valueFromText: function(text, locale) {
return parseInt(text);
}
KCM.SettingHighlighter {
highlight: root.secondsIntervalValue != root.secondsIntervalValueDefault
}
}
}
}
Kirigami.Heading {
text: i18nd("plasma_wallpaper_org.kde.image", "Folders")
level: 2
}
GridLayout {
columns: 2
Layout.fillWidth: true
Layout.fillHeight: true
columnSpacing: Kirigami.Units.largeSpacing
QtControls2.ScrollView {
id: foldersScroll
Layout.fillHeight: true
Layout.preferredWidth: 0.35 * parent.width
Layout.maximumWidth: Kirigami.Units.gridUnit * 16
Component.onCompleted: foldersScroll.background.visible = true;
ListView {
id: slidePathsView
model: imageWallpaper.slidePaths
delegate: Kirigami.SwipeListItem {
width: slidePathsView.width
// content item includes its own padding
padding: 0
// Don't need a highlight or hover effects
hoverEnabled: false
contentItem: Kirigami.BasicListItem {
// Don't need a highlight or hover effects
hoverEnabled: false
separatorVisible: false
// Header: the folder
label: {
var strippedPath = modelData.replace(/\/+$/, "");
return strippedPath.split('/').pop()
}
// Subtitle: the path to the folder
subtitle: {
var strippedPath = modelData.replace(/\/+$/, "");
return strippedPath.replace(/\/[^\/]*$/, '');;
}
QtControls2.ToolTip.text: modelData
QtControls2.ToolTip.visible: hovered
QtControls2.ToolTip.delay: 1000
QtControls2.ToolTip.timeout: 5000
}
actions: [
Kirigami.Action {
iconName: "list-remove"
tooltip: i18nd("plasma_wallpaper_org.kde.image", "Remove Folder")
onTriggered: imageWallpaper.removeSlidePath(modelData)
},
Kirigami.Action {
icon.name: "document-open-folder"
tooltip: i18nd("plasma_wallpaper_org.kde.image", "Open Folder")
onTriggered: imageWallpaper.openFolder(modelData)
}
]
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - (Kirigami.Units.largeSpacing * 4)
visible: slidePathsView.count === 0
text: i18nd("plasma_wallpaper_org.kde.image", "There are no wallpaper locations configured")
}
}
}
Loader {
sourceComponent: thumbnailsComponent
Layout.fillWidth: true
Layout.fillHeight: true
anchors.fill: undefined
}
QtControls2.Button {
Layout.alignment: Qt.AlignRight
icon.name: "list-add"
text: i18nd("plasma_wallpaper_org.kde.image","Add Folder…")
onClicked: imageWallpaper.showAddSlidePathsDialog()
}
NewStuff.Button {
Layout.alignment: Qt.AlignRight
configFile: Kirigami.Settings.isMobile ? "wallpaper-mobile.knsrc" : "wallpaper.knsrc"
text: i18nd("plasma_wallpaper_org.kde.image", "Get New Wallpapers…")
viewMode: NewStuff.Page.ViewMode.Preview
onEntryEvent: function(entry, event) {
if (event == NewStuff.Entry.StatusChangedEvent) {
imageWallpaper.newStuffFinished()
}
}
}
}
}
}
Component {
id: thumbnailsComponent
Item {
property var imageModel: (configDialog.currentWallpaper === "org.kde.image") ? imageWallpaper.wallpaperModel : imageWallpaper.slideFilterModel
KCM.GridView {
id: wallpapersGrid
anchors.fill: parent
function resetCurrentIndex() {
//that min is needed as the module will be populated in an async way
//and only on demand so we can't ensure it already exists
view.currentIndex = Qt.binding(function() { return Math.min(imageModel.indexOf(cfg_Image), imageModel.count - 1) });
}
//kill the space for label under thumbnails
view.model: imageModel
Component.onCompleted: {
imageModel.usedInConfig = true;
resetCurrentIndex()
}
//set the size of the cell, depending on Screen resolution to respect the aspect ratio
view.implicitCellWidth: Screen.width / 10 + Kirigami.Units.smallSpacing * 2
view.implicitCellHeight: Screen.height / 10 + Kirigami.Units.smallSpacing * 2 + Kirigami.Units.gridUnit * 3
view.delegate: WallpaperDelegate {
color: cfg_Color
}
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - (Kirigami.Units.largeSpacing * 4)
visible: wallpapersGrid.view.count === 0
text: i18nd("plasma_wallpaper_org.kde.image", "There are no wallpapers in this slideshow")
}
KCM.SettingHighlighter {
target: wallpapersGrid
highlight: configDialog.currentWallpaper === "org.kde.image" && cfg_Image != cfg_ImageDefault
}
}
}
DropArea {
Layout.fillWidth: true
Layout.fillHeight: true
......@@ -467,8 +183,8 @@ ColumnLayout {
Loader {
anchors.fill: parent
sourceComponent: (configDialog.currentWallpaper == "org.kde.image") ? thumbnailsComponent :
((configDialog.currentWallpaper == "org.kde.slideshow") ? slideshowComponent : undefined)
source: (configDialog.currentWallpaper == "org.kde.image") ? "ThumbnailsComponent.qml" :
((configDialog.currentWallpaper == "org.kde.slideshow") ? "SlideshowComponent.qml" : "")
}
}
......
/*
SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15
import org.kde.newstuff 1.91 as NewStuff
import org.kde.kcm 1.5 as KCM
import org.kde.kirigami 2.12 as Kirigami
import org.kde.plasma.wallpapers.image 2.0 as PlasmaWallpaper
ColumnLayout {
id: slideshowComponent
property int hoursIntervalValue: Math.floor(cfg_SlideInterval / 3600)
property int minutesIntervalValue: Math.floor(cfg_SlideInterval % 3600) / 60
property int secondsIntervalValue: cfg_SlideInterval % 3600 % 60
property int hoursIntervalValueDefault: Math.floor(cfg_SlideIntervalDefault / 3600)
property int minutesIntervalValueDefault: Math.floor(cfg_SlideIntervalDefault % 3600) / 60
property int secondsIntervalValueDefault: cfg_SlideIntervalDefault % 3600 % 60
onHoursIntervalValueChanged: hoursInterval.value = hoursIntervalValue
onMinutesIntervalValueChanged: minutesInterval.value = minutesIntervalValue
onSecondsIntervalValueChanged: secondsInterval.value = secondsIntervalValue
Kirigami.FormLayout {
twinFormLayouts: parentLayout
RowLayout {
id: slideshowModeRow
Kirigami.FormData.label: i18nd("plasma_wallpaper_org.kde.image", "Order:")
QQC2.ComboBox {
id: slideshowModeComboBox
model: [
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Random"),
'slideshowMode': PlasmaWallpaper.SortingMode.Random
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "A to Z"),
'slideshowMode': PlasmaWallpaper.SortingMode.Alphabetical
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Z to A"),
'slideshowMode': PlasmaWallpaper.SortingMode.AlphabeticalReversed
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Date modified (newest first)"),
'slideshowMode': PlasmaWallpaper.SortingMode.ModifiedReversed
},
{
'label': i18nd("plasma_wallpaper_org.kde.image", "Date modified (oldest first)"),
'slideshowMode': PlasmaWallpaper.SortingMode.Modified
}
]
textRole: "label"
onActivated: {
cfg_SlideshowMode = model[currentIndex]["slideshowMode"];
}
Component.onCompleted: setMethod();
function setMethod() {
for (var i = 0; i < model.length; i++) {
if (model[i]["slideshowMode"] === wallpaper.configuration.SlideshowMode) {
slideshowModeComboBox.currentIndex = i;
break;
}
}
}
KCM.SettingHighlighter {
highlight: cfg_SlideshowMode != cfg_SlideshowModeDefault
}
}
QQC2.CheckBox {
id: slideshowFoldersFirstCheckBox
text: i18nd("plasma_wallpaper_org.kde.image", "Group by folders")
checked: root.cfg_SlideshowFoldersFirst
onToggled: cfg_SlideshowFoldersFirst = slideshowFoldersFirstCheckBox.checked
KCM.SettingHighlighter {
highlight: root.cfg_SlideshowFoldersFirst !== cfg_SlideshowFoldersFirstDefault
}
}
}
// FIXME: there should be only one spinbox: QtControls spinboxes are still too limited for it tough
RowLayout {
Kirigami.FormData.label: i18nd("plasma_wallpaper_org.kde.image", "Change every:")
QQC2.SpinBox {
id: hoursInterval
value: slideshowComponent.hoursIntervalValue
from: 0
to: 24
editable: true
onValueChanged: cfg_SlideInterval = hoursInterval.value * 3600 + minutesInterval.value * 60 + secondsInterval.value
textFromValue: function(value, locale) {
return i18ndp("plasma_wallpaper_org.kde.image","%1 hour", "%1 hours", value)
}
valueFromText: function(text, locale) {
return parseInt(text);
}
KCM.SettingHighlighter {
highlight: slideshowComponent.hoursIntervalValue != slideshowComponent.hoursIntervalValueDefault
}
}
QQC2.SpinBox {
id: minutesInterval
value: slideshowComponent.minutesIntervalValue
from: 0
to: 60
editable: true
onValueChanged: cfg_SlideInterval = hoursInterval.value * 3600 + minutesInterval.value * 60 + secondsInterval.value
textFromValue: function(value, locale) {
return i18ndp("plasma_wallpaper_org.kde.image","%1 minute", "%1 minutes", value)
}
valueFromText: function(text, locale) {
return parseInt(text);
}
KCM.SettingHighlighter {
highlight: slideshowComponent.minutesIntervalValue != slideshowComponent.minutesIntervalValueDefault
}
}
QQC2.SpinBox {
id: secondsInterval
value: slideshowComponent.secondsIntervalValue
from: slideshowComponent.hoursIntervalValue === 0 && slideshowComponent.minutesIntervalValue === 0 ? 1 : 0
to: 60
editable: true
onValueChanged: cfg_SlideInterval = hoursInterval.value * 3600 + minutesInterval.value * 60 + secondsInterval.value
textFromValue: function(value, locale) {
return i18ndp("plasma_wallpaper_org.kde.image","%1 second", "%1 seconds", value)
}
valueFromText: function(text, locale) {
return parseInt(text);
}
KCM.SettingHighlighter {
highlight: slideshowComponent.secondsIntervalValue != slideshowComponent.secondsIntervalValueDefault
}
}
}
}
Kirigami.Heading {
text: i18nd("plasma_wallpaper_org.kde.image", "Folders")
level: 2
}
GridLayout {
columns: 2
Layout.fillWidth: true
Layout.fillHeight: true
columnSpacing: Kirigami.Units.largeSpacing
QQC2.ScrollView {
id: foldersScroll
Layout.fillHeight: true
Layout.preferredWidth: 0.35 * parent.width
Layout.maximumWidth: Kirigami.Units.gridUnit * 16
Component.onCompleted: foldersScroll.background.visible = true;
ListView {
id: slidePathsView
model: imageWallpaper.slidePaths
delegate: Kirigami.SwipeListItem {
width: slidePathsView.width
// content item includes its own padding
padding: 0
// Don't need a highlight or hover effects
hoverEnabled: false
contentItem: Kirigami.BasicListItem {
// Don't need a highlight or hover effects
hoverEnabled: false
separatorVisible: false
// Header: the folder
label: {
var strippedPath = modelData.replace(/\/+$/, "");
return strippedPath.split('/').pop()
}
// Subtitle: the path to the folder
subtitle: {
var strippedPath = modelData.replace(/\/+$/, "");
return strippedPath.replace(/\/[^\/]*$/, '');;
}
QQC2.ToolTip.text: modelData
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: 1000
QQC2.ToolTip.timeout: 5000
}
actions: [
Kirigami.Action {
iconName: "list-remove"
tooltip: i18nd("plasma_wallpaper_org.kde.image", "Remove Folder")