File indexing completed on 2024-05-05 04:48:36

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Matěj Laitl <matej@laitl.cz>                                      *
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 #ifndef FADEOUTER_H
0018 #define FADEOUTER_H
0019 
0020 #include <amarok_export.h>
0021 
0022 #include <QObject>
0023 #include <QPointer>
0024 
0025 namespace Phonon {
0026     class MediaObject;
0027     class VolumeFaderEffect;
0028 }
0029 
0030 /**
0031  * A RAII approach to fadeout on track stop. Once created, it automatically
0032  * initiates fadeout. Fadeouter ensures that fadeoutFinished() is signalled when
0033  * fadeout is done. It also handles well situations where different track is played
0034  * while fadeout is still active.
0035  *
0036  * In each case, Fadeouter auto-deletes itself.
0037  */
0038 class AMAROK_EXPORT Fadeouter : public QObject
0039 {
0040     Q_OBJECT
0041 
0042     public:
0043         Fadeouter( const QPointer<Phonon::MediaObject> &media,
0044                    const QPointer<Phonon::VolumeFaderEffect> &fader,
0045                    int fadeOutLength );
0046 
0047         /**
0048          * Destructor ensures that fader volume is set back to normal
0049          */
0050         ~Fadeouter() override;
0051 
0052     Q_SIGNALS:
0053         /**
0054          * This signal is emitted when the fade-out is done. This signal may not
0055          * be emitted at all when Fadeouter is interrupted by new track playing.
0056          * Yuu should connect your track-finished-playing logic to this.
0057          */
0058         void fadeoutFinished();
0059 
0060     private Q_SLOTS:
0061         /**
0062          * Emits fadeoutFinished() and commits Fadeouter suicide.
0063          */
0064         void slotFinalizeFadeout();
0065 
0066     private:
0067         QPointer<Phonon::VolumeFaderEffect> m_fader;
0068 };
0069 
0070 #endif // FADEOUTER_H