Warning, /multimedia/amarok/src/context/applets/lyrics/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /****************************************************************************************
0002  * Copyright (c) 2017 Malte Veerman <malte.veerman@gmail.com>                           *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 import QtQuick 2.4
0018 import QtQuick.Controls 1.4
0019 import QtQuick.Layouts 1.3
0020 import org.kde.amarok.qml 1.0 as AmarokQml
0021 import org.kde.amarok.lyrics 1.0
0022 
0023 AmarokQml.Applet {
0024     id: applet
0025 
0026     property bool autoScroll: true
0027 
0028     configDialog: ConfigDialog {}
0029 
0030     Loader {
0031         id: loader
0032 
0033         width: parent.width
0034         height: parent.height
0035 
0036         sourceComponent: LyricsEngine.text === "" && LyricsEngine.suggestions.length > 0 ? suggestionsComponent : textComponent
0037 
0038         BusyIndicator {
0039             anchors.centerIn: parent
0040             running: LyricsEngine.fetching
0041         }
0042     }
0043 
0044     Component {
0045         id: textComponent
0046 
0047         TextArea {
0048             id: textArea
0049 
0050             text: LyricsEngine.text
0051             font.pointSize: LyricsEngine.fontSize
0052             font.family: LyricsEngine.font
0053             wrapMode: TextEdit.Wrap
0054             horizontalAlignment: LyricsEngine.alignment
0055             verticalAlignment: TextEdit.AlignTop
0056             textFormat: TextEdit.AutoText
0057             readOnly: true
0058 
0059             Connections {
0060                 target: LyricsEngine
0061                 onPositionChanged: {
0062                     if (applet.autoScroll) {
0063                         var middle = textArea.contentHeight * LyricsEngine.position;
0064                         var top = middle - textArea.height / 2;
0065                         var maxTop = textArea.contentHeight - textArea.height;
0066                         var boundTop = Math.min(maxTop, Math.max(0, top));
0067                         textArea.flickableItem.contentY = boundTop;
0068                     }
0069                 }
0070             }
0071 
0072             RowLayout {
0073                 id: buttonRow
0074 
0075                 y: applet.spacing
0076                 x: parent.effectiveHorizontalAlignment === TextEdit.AlignRight ? applet.spacing : parent.viewport.width - width - applet.spacing
0077 
0078                 Button {
0079                     Layout.alignment: Qt.AlignRight
0080                     checkable: true
0081                     checked: applet.autoScroll
0082                     iconName: "arrow-down"
0083                     tooltip: i18n("Toggle auto scroll")
0084 
0085                     onClicked: applet.autoScroll = !applet.autoScroll
0086                 }
0087                 Button {
0088                     Layout.alignment: Qt.AlignRight
0089                     iconName: "view-refresh"
0090                     tooltip: i18n("Reload lyrics")
0091 
0092                     onClicked: LyricsEngine.refetchLyrics()
0093                 }
0094             }
0095 
0096             Label {
0097                 anchors.centerIn: parent
0098                 text: i18n("No lyrics found")
0099                 visible: !textArea.text
0100                 font.pointSize: LyricsEngine.fontSize
0101                 font.family: LyricsEngine.font
0102             }
0103         }
0104     }
0105 
0106     // untested
0107     Component {
0108         id: suggestionsComponent
0109 
0110         ListView {
0111             model: LyricsEngine.suggestions
0112             header: Label {
0113                 text: i18n("Suggestions: ") + LyricsEngine.suggestions.length
0114             }
0115             delegate: Item {
0116                 width: parent.width
0117 
0118                 Column {
0119                     width: parent.width
0120 
0121                     Label {
0122                         text: '<b>' + i18n("Title:") + '</b> ' + modelData[0]
0123                     }
0124                     Label {
0125                         text: '<b>' + i18n("Artist:") + '</b> ' + modelData[1]
0126                     }
0127                 }
0128                 MouseArea {
0129                     anchors.fill: parent
0130 
0131                     onClicked: LyricsEngine.fetchLyrics(modelData[0], modelData[1], modelData[2])
0132                 }
0133             }
0134         }
0135     }
0136 }