File indexing completed on 2025-01-19 04:24:08

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Leo Franchi <lfranchi@gmail.com>                                  *
0003  * Copyright (c) 2008 Mark Kretschmann <kretschmann@kde.org>                            *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef AMAROK_LYRICS_ENGINE
0019 #define AMAROK_LYRICS_ENGINE
0020 
0021 #include "core/meta/Meta.h"
0022 
0023 #include <QObject>
0024 #include <QString>
0025 #include <QVariantList>
0026 
0027 class LyricsEngine : public QObject
0028 {
0029     Q_OBJECT
0030     Q_PROPERTY(QString text READ text NOTIFY lyricsChanged)
0031     Q_PROPERTY(bool fetching READ fetching NOTIFY fetchingChanged)
0032     Q_PROPERTY(QVariantList suggestions READ suggestions NOTIFY lyricsChanged)
0033     Q_PROPERTY(qreal position READ position NOTIFY positionChanged)
0034     Q_PROPERTY(qreal fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
0035     Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
0036     Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
0037 
0038 public:
0039     explicit LyricsEngine( QObject* parent = nullptr );
0040 
0041     void newLyrics( const Meta::TrackPtr &track );
0042     void newSuggestions( const QVariantList &suggest );
0043     void lyricsMessage( const QString& key, const QString& val );
0044 
0045     QString text() const { return m_lyrics; }
0046     QVariantList suggestions() const { return m_suggestions; }
0047     bool fetching() const { return m_fetching; }
0048     qreal position() const;
0049     qreal fontSize() const;
0050     void setFontSize( qreal fontSize );
0051     int alignment() const;
0052     void setAlignment( int alignment );
0053     QString font() const;
0054     void setFont( const QString &font );
0055 
0056     Q_INVOKABLE void refetchLyrics() const;
0057     Q_INVOKABLE QStringList availableFonts() const;
0058 
0059 Q_SIGNALS:
0060     void lyricsChanged();
0061     void newLyricsMessage( const QString& key, const QString &val );
0062     void positionChanged();
0063     void fetchingChanged();
0064     void fontSizeChanged();
0065     void alignmentChanged();
0066     void fontChanged();
0067 
0068 private Q_SLOTS:
0069     void update();
0070     void onTrackMetadataChanged( Meta::TrackPtr track );
0071 
0072 private:
0073     void clearLyrics();
0074 
0075     QString m_lyrics;
0076     QVariantList m_suggestions;
0077     bool m_fetching;
0078     bool m_isUpdateInProgress;
0079 
0080     struct trackMetadata {
0081         QString artist;
0082         QString title;
0083     } m_prevTrackMetadata;
0084 };
0085 
0086 #endif