sounddlg.h 4.36 KB
Newer Older
1
/*
2
 *  sounddlg.h  -  sound file selection and configuration dialog and widget
3
 *  Program:  kalarm
4
 *  Copyright © 2005-2007,2009-2012 by David Jarvie <djarvie@kde.org>
5 6 7 8 9 10 11 12 13 14 15
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
David Jarvie's avatar
David Jarvie committed
16 17 18
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 20 21 22 23
 */

#ifndef SOUNDDLG_H
#define SOUNDDLG_H

24
#include <kurl.h>
David Jarvie's avatar
David Jarvie committed
25
#include <kdialog.h>
26
#include <QString>
27

28
class QPushButton;
David Jarvie's avatar
David Jarvie committed
29 30
class QShowEvent;
class QResizeEvent;
31
namespace Phonon { class MediaObject; }
32
class GroupBox;
33 34 35 36 37 38 39
class PushButton;
class CheckBox;
class SpinBox;
class Slider;
class LineEdit;


40
class SoundWidget : public QWidget
41
{
42 43 44 45
        Q_OBJECT
    public:
        SoundWidget(bool showPlay, bool showRepeat, QWidget* parent);
        ~SoundWidget();
46
        void           set(const QString& file, float volume, float fadeVolume = -1, int fadeSeconds = 0, int repeatPause = -1);
47 48 49 50 51
        void           setReadOnly(bool);
        bool           isReadOnly() const    { return mReadOnly; }
        void           setAllowEmptyFile()   { mEmptyFileAllowed = true; }
        QString        fileName() const;
        bool           file(KUrl&, bool showErrorMessage = true) const;
52 53
        void           getVolume(float& volume, float& fadeVolume, int& fadeSeconds) const;
        int            repeatPause() const;   // -1 if none, else seconds between repeats
54 55 56 57 58
        QString        defaultDir() const    { return mDefaultDir; }
        bool           validate(bool showErrorMessage) const;

        static QString i18n_chk_Repeat();      // text of Repeat checkbox

Laurent Montel's avatar
Laurent Montel committed
59
    Q_SIGNALS:
60 61 62
        void           changed();      // emitted whenever any contents change

    protected:
David Jarvie's avatar
David Jarvie committed
63
        void   showEvent(QShowEvent*) Q_DECL_OVERRIDE;
Laurent Montel's avatar
Laurent Montel committed
64
        void   resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE;
65

Laurent Montel's avatar
Laurent Montel committed
66
    private Q_SLOTS:
67 68 69 70 71 72 73
        void           slotPickFile();
        void           slotVolumeToggled(bool on);
        void           slotFadeToggled(bool on);
        void           playSound();
        void           playFinished();

    private:
David Jarvie's avatar
Tidy up  
David Jarvie committed
74 75 76 77 78 79 80 81 82 83 84 85 86
        static QString       mDefaultDir;     // current default directory for mFileEdit
        QPushButton*         mFilePlay;
        LineEdit*            mFileEdit;
        PushButton*          mFileBrowseButton;
        GroupBox*            mRepeatGroupBox;
        SpinBox*             mRepeatPause;
        CheckBox*            mVolumeCheckbox;
        Slider*              mVolumeSlider;
        CheckBox*            mFadeCheckbox;
        QWidget*             mFadeBox;
        SpinBox*             mFadeTime;
        QWidget*             mFadeVolumeBox;
        Slider*              mFadeSlider;
87 88 89 90 91
        mutable KUrl         mUrl;
        mutable QString      mValidatedFile;
        Phonon::MediaObject* mPlayer;
        bool                 mReadOnly;
        bool                 mEmptyFileAllowed;
92 93 94 95 96
};


class SoundDlg : public KDialog
{
97 98
        Q_OBJECT
    public:
99
        SoundDlg(const QString& file, float volume, float fadeVolume, int fadeSeconds, int repeatPause,
100 101 102 103
                 const QString& caption, QWidget* parent);
        void           setReadOnly(bool);
        bool           isReadOnly() const    { return mReadOnly; }
        KUrl           getFile() const;
104 105 106
        void           getVolume(float& volume, float& fadeVolume, int& fadeSeconds) const
                                             { mSoundWidget->getVolume(volume, fadeVolume, fadeSeconds); }
        int            repeatPause() const   { return mSoundWidget->repeatPause(); }
107 108 109 110 111
        QString        defaultDir() const    { return mSoundWidget->defaultDir(); }

    protected:
        virtual void   resizeEvent(QResizeEvent*);

Laurent Montel's avatar
Laurent Montel committed
112
    protected Q_SLOTS:
113 114 115 116 117
        virtual void   slotButtonClicked(int button);

    private:
        SoundWidget*   mSoundWidget;
        bool           mReadOnly;
118 119 120
};

#endif
121 122

// vim: et sw=4: