Skip to content

Commit

Permalink
Merge pull request #5 from aleixpol/master
Browse files Browse the repository at this point in the history
Small cleanups
  • Loading branch information
m-pilia authored Jan 21, 2018
2 parents 7b7ff90 + 01cff0b commit f8a31f6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 126 deletions.
29 changes: 0 additions & 29 deletions plasmoid/contents/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,3 @@ function computeVolume(componentVolume) {
QtMultimedia.LogarithmicVolumeScale,
QtMultimedia.LinearVolumeScale);
}

/*!
* Play all the audio streams for the noise components.
* @param value Boolean, play if true, stop if false, toggle if undefined.
*/
function play(value) {

// If no noise component is available, reset everything to not playing,
// otherwise perform the selected action (play/pause/toggle).
if (noiseComponentsModel.count < 1) {
main.playing = false;
}
else {
main.playing = (value === undefined) ? !main.playing : value;
}

// Set the right icon for the Play button
if (main.playing) {
main.playButtonIconName = "media-playback-pause";
}
else {
main.playButtonIconName = "media-playback-start";
}

// Play/pause all available noise components
Object.keys(main.playableList).forEach(function(key, index) {
main.playableList[key].play(main.playing);
});
}
81 changes: 35 additions & 46 deletions plasmoid/contents/ui/AddNoisePopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,49 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.plasmoid 2.0
import "../js/scripts.js" as Js

ColumnLayout {
anchors.fill: parent

// Button to go back
PlasmaComponents.ToolButton {
iconName: "draw-arrow-back"
Layout.alignment: Qt.AlignVCenter
onClicked: {
stack.pop();
ScrollView {
ListView {
header: PlasmaComponents.ToolButton {
iconName: "draw-arrow-back"
Layout.alignment: Qt.AlignVCenter
onClicked: {
stack.pop();
}
}
}

ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true

ListView {

model: FolderListModel {
id: folderModel
folder: Js.dataDirectory()
nameFilters: ["*.ogg", "*.flac", "*.mp3", "*.wav"]
showDirs: false
}
model: FolderListModel {
id: folderModel
folder: Js.dataDirectory()
nameFilters: ["*.ogg", "*.flac", "*.mp3", "*.wav"]
showDirs: false
}

delegate: PlasmaComponents.ListItem {
separatorVisible: true
delegate: PlasmaComponents.ListItem {
separatorVisible: true

RowLayout {
RowLayout {

Image {
source: Js.toImageName(fileName)
fillMode: Image.PreserveAspectFit
Layout.preferredHeight: units.iconSizes.medium
Layout.preferredWidth: units.iconSizes.medium
Layout.alignment: Qt.AlignVCenter
}
Image {
source: Js.toImageName(fileName)
fillMode: Image.PreserveAspectFit
Layout.preferredHeight: units.iconSizes.medium
Layout.preferredWidth: units.iconSizes.medium
Layout.alignment: Qt.AlignVCenter
}

PlasmaComponents.Label {
id: fileText
text: Js.toPrettyName(fileName)
Layout.alignment: Qt.AlignVCenter
}
PlasmaComponents.Label {
id: fileText
text: Js.toPrettyName(fileName)
Layout.alignment: Qt.AlignVCenter
}

MouseArea {
anchors.fill: parent
MouseArea {
anchors.fill: parent

onClicked: {
noiseComponentsModel.append({
"filename": fileName,
"tag": noiseComponentsModel.nextAdd
});
stack.pop()
}
onClicked: {
main.playing = true;
noiseComponentsModel.append({ "filename": fileName, });
stack.pop();
}
}
}
Expand Down
57 changes: 17 additions & 40 deletions plasmoid/contents/ui/NoiseListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,15 @@ PlasmaComponents.ListItem {
height: units.gridUnit * 4
separatorVisible: true

property string objectType: "NoiseListItem"
property int index: -1
property string noiseName: ""
property string audioSource: ""
property string imageSource: ""
property bool dynamic: false

// Fix index, register object in the playable list, and play.
Component.onCompleted: {
index = this.index;
main.playableList[index] = this;
main.playableList[noiseComponentsModel.nextAdd].play(main.playing);
noiseComponentsModel.nextAdd += 1;
Js.play(true);
}

// Play or pause the audio stream of this object.
function play(value) {
if (value) {
player.play()
}
else {
player.pause()
property alias noiseName: name.text
property alias audioSource: player.source
property alias imageSource: componentIcon.source
property bool playing: false
onPlayingChanged: {
if (playing) {
player.play();
} else {
player.pause();
}
}

Expand All @@ -63,10 +49,9 @@ PlasmaComponents.ListItem {
// Image for the noise component
Image {
id: componentIcon
source: root.imageSource
Layout.preferredHeight: .9 * root.height
Layout.fillHeight: true
Layout.preferredWidth: height
verticalAlignment: Image.AlignVCenter
fillMode: Image.PreserveAspectFit
}

ColumnLayout {
Expand All @@ -75,7 +60,7 @@ PlasmaComponents.ListItem {

// Name
Label {
text: root.noiseName
id: name
Layout.alignment: Qt.AlignLeft
}

Expand All @@ -92,17 +77,7 @@ PlasmaComponents.ListItem {
iconName: "delete"
Layout.alignment: Qt.AlignVCenter
onClicked: {
for (var i = 0; i < noiseComponentsModel.count; ++i) {
if (noiseComponentsModel.get(i).tag == index) {
noiseComponentsModel.remove(i);
delete main.playableList[index];
break;
}
}
if (noiseComponents.count < 1) {
Js.play(false);
return;
}
noiseComponentsModel.remove(index);
}
}

Expand All @@ -111,7 +86,9 @@ PlasmaComponents.ListItem {
id: muteButton
iconName: Js.volumeIcon(volume.value, volume.muted)
Layout.alignment: Qt.AlignVCenter
onClicked: {volume.muted = !volume.muted;}
onClicked: {
volume.muted = !volume.muted;
}
}

// Volume slider for this component
Expand Down Expand Up @@ -141,8 +118,8 @@ PlasmaComponents.ListItem {

Audio {
id: player
source: root.audioSource
loops: Audio.Infinite
volume: volume.muted ? 0.0 : Js.computeVolume(volume.value)
autoPlay: root.playing
}
}
18 changes: 7 additions & 11 deletions plasmoid/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,22 @@ Item {
Plasmoid.switchHeight: units.gridUnit * 12

Plasmoid.toolTipMainText: i18n("Ambient noise")
Plasmoid.toolTipSubText: playing ? i18n("Playing %1 elements", noiseComponentsModel.count) : i18n("Paused")

Plasmoid.icon: "ambientnoise"

property real maxVolume: 100.0
property real minVolume: 0.0
property real volumeStep: 5.
property real volumeStep: 5.0

property bool playing: false
property var playableList: []
property string playButtonIconName: "media-playback-start"
property bool playing: true

// List Model for the noise components
ListModel {
id: noiseComponentsModel
property int nextAdd: 0
}

function action_playpause() {
Js.play()
playing = !playing
}

Component.onCompleted: {
Expand All @@ -64,7 +61,6 @@ Item {
Plasmoid.compactRepresentation: PlasmaCore.IconItem {
source: plasmoid.icon
active: mouseArea.containsMouse
colorGroup: PlasmaCore.ColorScope.colorGroup

//TODO: add volume on wheel?
MouseArea {
Expand All @@ -75,7 +71,7 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onClicked: {
if (mouse.button == Qt.MiddleButton) {
action_playpause()
action_playpause();
} else if (mouse.button == Qt.LeftButton) {
plasmoid.expanded = !plasmoid.expanded;
}
Expand Down Expand Up @@ -106,7 +102,7 @@ Item {
// Play/Pause
PlasmaComponents.ToolButton {
id: playButton
iconName: playButtonIconName
iconName: playing ? "media-playback-pause" : "media-playback-start"
Layout.alignment: Qt.AlignVCenter
onClicked: {
action_playpause();
Expand Down Expand Up @@ -145,10 +141,10 @@ Item {
model: noiseComponentsModel

delegate: NoiseListItem {
playing: main.playing
audioSource: Js.toAudioName(filename)
imageSource: Js.toImageName(filename)
noiseName: Js.toPrettyName(filename)
index: tag
}
}
}
Expand Down

0 comments on commit f8a31f6

Please sign in to comment.