/*
    This file is part of kenvy24 KDE multimedia utility
    Copyright (c) 2007  Valentin RUSU kenvy24@rusu.info

    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) version 3 or, at the discretion of KDE e.V. (which shall
    act as a proxy as in section 14 of the GPLv3), 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.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MixerPartChannel_h_
#define _MixerPartChannel_h_

#include "envystructs.h"

#include <QObject>

/**
 * The sliders  typically go from 0 to this maximum value
 * This is because of ALSA design
 */
#define VOLUME_MAX_VALUE_DEFAULT 96

class MixerPart;
class MixerPartMonoVuMeter;
class QSlider;
class QPushButton;
class EnvyCard;
class QToolButton;
class QGroupBox;
class KConfigGroup;

class MixerPartChannel : public QObject
{
    Q_OBJECT
    private:
        int                     channelIndex; // EnvyCard channel index
        MixerPartMonoVuMeter*   leftVu;
        MixerPartMonoVuMeter*   rightVu;
        QSlider*                leftVol;
        QSlider*                rightVol;
        bool                    inSlotFlag;
        bool                    inEventFlag;
        EnvyCard*               envyCard;
        int                     volumeMaxValue;
        QPushButton*            stereoLinkButton;
        QToolButton*            muteLeftButton;
        QToolButton*            muteRightButton;
        QGroupBox*              groupBox;
        QToolButton*            hideButton;

        struct ExclusiveFlag {
            bool& slotFlag;
            ExclusiveFlag( bool& flag ) : slotFlag( flag) { flag = true; }
            ~ExclusiveFlag() { slotFlag = false; }
        };

    public:
        MixerPartChannel( QGroupBox*, int index, MixerPart* parent );
        virtual ~MixerPartChannel();

    public:

        void setVuMeters( MixerPartMonoVuMeter* leftVu, MixerPartMonoVuMeter* rightVu );
        void setVolumes( QSlider* leftVol, QSlider* rightVol, int maxValue = VOLUME_MAX_VALUE_DEFAULT );
        void setStereoLinkButton( QPushButton* );
        void setMuteButtons( QToolButton*, QToolButton* );
        void setVisible( bool );
        void setTitle( const QString& );
        void setHideButton( QToolButton* );

        void parentResizeEvent();
        void setLeftVolume( int );
        void setRightVolume( int );

        void saveConfig( KConfigGroup* );
        void loadConfig( KConfigGroup* );

    private:
        QString configPrefix() const;
        bool readBoolConfigValue( KConfigGroup*, const char*, bool defVal = false ) const;

    Q_SIGNALS:
        /**
         * this signal is emmitted when the volume change
         */
        void volumeChange( int channelIndex, LeftRight, int, int );
        /**
         * this variant is convenient for cases where no channel index
         * is needed
         */
        void volumeChange( LeftRight, int );
        void muteChanged( int, LeftRight, bool );

    public Q_SLOTS:
        void levelUpdated( int, const StereoLevels& );
        void levelUpdated( const StereoLevels& );
        void timerTick();
        /**
         * This slot is used to receive notifications of volume change outside kenvy24
         * This may be done by, say, envy24control
         */
        void mixerUpdatePlaybackVolume( int, LeftRight, int );
        void mixerUpdatePlaybackVolume( int, LeftRight, int, int );
        void mixerUpdateMuteSwitch( int, LeftRight, bool );
        void setEnvyCard( EnvyCard* );

        // slots used to receive notification from our controls
    protected Q_SLOTS:
        void stereoLinkButtonToggle( bool );
        void leftVolumeChange( int );
        void rightVolumeChange( int );
        void muteLeftButtonToggle( bool );
        void muteRightButtonToggle( bool );
        void hideButtonToggle( bool );
};

#endif // _MixerPartChannel_h_

// kate: space-indent on; indent-width 4; replace-tabs on;
