File indexing completed on 2024-05-12 05:14:58

0001 /*
0002  *  sounddlg.h  -  sound file selection and configuration dialog and widget
0003  *  Program:  kalarm
0004  *  SPDX-FileCopyrightText: 2005-2022 David Jarvie <djarvie@kde.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include <QUrl>
0012 #include <QDialog>
0013 #include <QString>
0014 
0015 class QPushButton;
0016 class QShowEvent;
0017 class QResizeEvent;
0018 namespace Phonon { class MediaObject; }
0019 class GroupBox;
0020 class PushButton;
0021 class CheckBox;
0022 class SpinBox;
0023 class Slider;
0024 class LineEdit;
0025 class QDialogButtonBox;
0026 class QAbstractButton;
0027 
0028 
0029 class SoundWidget : public QWidget
0030 {
0031     Q_OBJECT
0032 public:
0033     SoundWidget(bool showPlay, const QString& repeatWhatsThis, QWidget* parent);
0034     ~SoundWidget() override;
0035     void           set(const QString& file, float volume, float fadeVolume = -1, int fadeSeconds = 0, int repeatPause = -1);
0036     void           setReadOnly(bool);
0037     bool           isReadOnly() const    { return mReadOnly; }
0038     void           setAllowEmptyFile()   { mEmptyFileAllowed = true; }
0039     QString        fileName() const;
0040     bool           file(QUrl&, bool showErrorMessage = true) const;
0041     void           getVolume(float& volume, float& fadeVolume, int& fadeSeconds) const;
0042     int            repeatPause() const;   // -1 if none, else seconds between repeats
0043     QString        defaultDir() const    { return mDefaultDir; }
0044     bool           validate(bool showErrorMessage) const;
0045 
0046     static QString i18n_chk_Repeat();      // text of Repeat checkbox
0047     static QString i18n_chk_SetVolume();   // text of Set volume checkbox
0048 
0049 Q_SIGNALS:
0050     void           changed();      // emitted whenever any contents change
0051 
0052 protected:
0053     void           showEvent(QShowEvent*) override;
0054     void           resizeEvent(QResizeEvent*) override;
0055 
0056 private Q_SLOTS:
0057     void           slotPickFile();
0058     void           slotVolumeToggled(bool on);
0059     void           slotFadeToggled(bool on);
0060     void           playSound();
0061     void           playFinished();
0062 
0063 private:
0064     static QString       mDefaultDir;     // current default directory for mFileEdit
0065     const QString        mRepeatWhatsThis;
0066     QPushButton*         mFilePlay {nullptr};
0067     LineEdit*            mFileEdit;
0068     PushButton*          mFileBrowseButton;
0069     GroupBox*            mRepeatGroupBox {nullptr};
0070     SpinBox*             mRepeatPause {nullptr};
0071     CheckBox*            mVolumeCheckbox;
0072     Slider*              mVolumeSlider;
0073     CheckBox*            mFadeCheckbox {nullptr};
0074     QWidget*             mFadeBox {nullptr};
0075     SpinBox*             mFadeTime {nullptr};
0076     QWidget*             mFadeVolumeBox {nullptr};
0077     Slider*              mFadeSlider {nullptr};
0078     mutable QUrl         mUrl;
0079     mutable QString      mValidatedFile;
0080     Phonon::MediaObject* mPlayer {nullptr};
0081     bool                 mReadOnly {false};
0082     bool                 mEmptyFileAllowed {false};
0083 };
0084 
0085 
0086 class SoundDlg : public QDialog
0087 {
0088     Q_OBJECT
0089 public:
0090     SoundDlg(const QString& file, float volume, float fadeVolume, int fadeSeconds, int repeatPause,
0091              const QString& caption, QWidget* parent);
0092     void    setReadOnly(bool);
0093     bool    isReadOnly() const    { return mReadOnly; }
0094     QUrl    getFile() const;
0095     void    getVolume(float& volume, float& fadeVolume, int& fadeSeconds) const
0096                                   { mSoundWidget->getVolume(volume, fadeVolume, fadeSeconds); }
0097     int     repeatPause() const   { return mSoundWidget->repeatPause(); }
0098     QString defaultDir() const    { return mSoundWidget->defaultDir(); }
0099 
0100 protected:
0101     void    resizeEvent(QResizeEvent*) override;
0102 
0103 protected Q_SLOTS:
0104     void    slotButtonClicked(QAbstractButton*);
0105 
0106 private:
0107     SoundWidget*      mSoundWidget;
0108     QDialogButtonBox* mButtonBox;
0109     bool              mReadOnly {false};
0110 };
0111 
0112 // vim: et sw=4: