Logo Search packages:      
Sourcecode: qasmixer version File versions  Download package

mixer_ctl.cpp

//
// C++ Implementation:
//
// Description:
//
//
// Author: Sebastian Holtermann <sebholt@xwmw.org>, (C) 2010-2011
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "mixer_ctl.hpp"

#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>

#include "mixer_ctl_editor_bool.hpp"
#include "mixer_ctl_editor_enum.hpp"
#include "mixer_ctl_editor_int.hpp"
#include "mixer_ctl_editor_unsupported.hpp"

#include <iostream>


namespace QSnd
{


Mixer_CTL::Mixer_CTL (
      QWidget * parent_n ) :
QWidget ( parent_n ),
_editor_pad ( 0 )
{
      {
            const QString dmask ( "<div>%1</div>\n<div>(%2)</div>" );
            _ttip_name_lbl_mask = dmask.arg ( tr ( "Element name" ) );
      }

      // Localized shared strings
      mx_data().str_joined = tr ( "Joined" );
      mx_data().ttip_grid_lbl_elem = tr ( "Element index" );
      mx_data().ttip_grid_lbl_channel = tr ( "Channel %1" );

      mx_data().str_list_channel = tr ( "Ch. %1" );
      mx_data().ttip_list_channel = tr ( "Channel %1" );
      {
            const QString dmask ( "<div>%1</div>" );
            QString txt[2];
            txt[0] = tr ( "Index: %1" );
            txt[1] = tr ( "Channel: %2" );
            mx_data().ttip_grid_widget += dmask.arg ( txt[0] );
            mx_data().ttip_grid_widget += "\n";
            mx_data().ttip_grid_widget += dmask.arg ( txt[1] );
      }

      // Pad widget layout
      {
            QVBoxLayout * lay_pad_wdg ( new QVBoxLayout );
            lay_pad_wdg->setContentsMargins ( 0, 0, 0, 0 );
            _pad_wdg.setLayout ( lay_pad_wdg );
      }

      // Info widget 1 layout
      {
            QHBoxLayout * lay_elem_name ( new QHBoxLayout );
            lay_elem_name->setContentsMargins ( 0, 0, 0, 0 );
            lay_elem_name->addWidget ( &_info_lbl_name );
            lay_elem_name->addStretch();

            QHBoxLayout * lay_info_items_1 ( new QHBoxLayout );
            lay_info_items_1->setContentsMargins ( 0, 0, 0, 0 );
            {
                  QGridLayout * lay_items ( new QGridLayout );
                  lay_items->setContentsMargins ( 0, 0, 0, 0 );

                  unsigned int row ( 0 );
                  unsigned int col ( 0 );
                  lay_items->addWidget ( &_info_lbl_count.name,   row, col++ );
                  lay_items->addWidget ( &_info_lbl_count.value,  row, col++ );
                  lay_items->addWidget ( &_info_lbl_flags.name,   row, col++ );
                  lay_items->addWidget ( &_info_lbl_flags.value,  row, col++ );

                  ++row;
                  col = 0;
                  lay_items->addWidget ( &_info_lbl_index.name,  row, col++ );
                  lay_items->addWidget ( &_info_lbl_index.value, row, col++ );
                  lay_items->addWidget ( &_info_lbl_dev.name,    row, col++ );
                  lay_items->addWidget ( &_info_lbl_dev.value,   row, col++ );
                  lay_items->addWidget ( &_info_lbl_numid.name,  row, col++ );
                  lay_items->addWidget ( &_info_lbl_numid.value, row, col++ );

                  lay_info_items_1->addLayout ( lay_items );
                  lay_info_items_1->addStretch();
            }

            QVBoxLayout * lay_info_wdg ( new QVBoxLayout );
            lay_info_wdg->setContentsMargins ( 0, 0, 0, 0 );
            lay_info_wdg->addLayout ( lay_elem_name );
            lay_info_wdg->addLayout ( lay_info_items_1 );

            _info_wdg.setLayout ( lay_info_wdg );
      }


      // Item name labels
      _info_lbl_index.name.setText ( tr ( "Index:" ) );
      _info_lbl_dev.name.setText ( tr ( "Device:" ) );
      _info_lbl_flags.name.setText ( tr ( "Flags:" ) );
      _info_lbl_count.name.setText ( tr ( "Channels:" ) );
      _info_lbl_numid.name.setText ( tr ( "Num. id:" ) );

      // Item name tooltips
      _info_lbl_index.name.setToolTip ( tr ( "Element index" ) );
      _info_lbl_dev.name.setToolTip ( tr ( "Device" ) );
      _info_lbl_flags.name.setToolTip ( tr ( "Flags" ) );
      _info_lbl_count.name.setToolTip ( tr ( "Channel count" ) );
      _info_lbl_numid.name.setToolTip ( tr ( "Numeric Id" ) );

      // Item values
      _info_dev_mask = "%1,%2";
      _info_lbl_index.value.set_min_text ( "1000" );
      _info_lbl_dev.value.set_min_text ( "99,99" );
      _info_lbl_flags.value.set_min_text ( "MMMM" );
      _info_lbl_count.value.set_min_text ( "1000" );
      _info_lbl_numid.value.set_min_text ( "1000" );

      // Item value tooltips
      {
            QString ttip_dev ( _info_dev_mask );
            ttip_dev = ttip_dev.arg ( tr ( "Device" ) );
            ttip_dev = ttip_dev.arg ( tr ( "Subdevice" ) );

            _info_lbl_index.value.setToolTip ( _info_lbl_index.name.toolTip() );
            _info_lbl_dev.value.setToolTip ( ttip_dev );

            _info_lbl_count.value.setToolTip ( _info_lbl_count.name.toolTip() );
            _info_lbl_numid.value.setToolTip ( _info_lbl_numid.name.toolTip() );
      }

      // Item alignment
      {
            const Qt::Alignment align_cc ( Qt::AlignHCenter | Qt::AlignVCenter );
            const Qt::Alignment align_lc ( Qt::AlignLeft | Qt::AlignVCenter );
            _info_lbl_index.value.setAlignment ( align_cc );
            _info_lbl_dev.value.setAlignment ( align_cc );
            _info_lbl_flags.value.setAlignment ( align_cc );
            _info_lbl_count.value.setAlignment ( align_cc );
            _info_lbl_numid.value.setAlignment ( align_cc );
      }

      // Set final layout
      {
            QVBoxLayout * lay_vbox ( new QVBoxLayout );
            lay_vbox->addWidget ( &_info_wdg, 0 );
            lay_vbox->addWidget ( &_pad_wdg, 1 );
            setLayout ( lay_vbox );
      }

      update_info();
}


Mixer_CTL::~Mixer_CTL ( )
{
      clear();
}


Snd_Mixer_CTL_Elem_Group *
Mixer_CTL::snd_elem_group ( ) const
{
      return mx_data().snd_elem_group;
}


unsigned int
Mixer_CTL::elem_idx ( ) const
{
      return mx_data().elem_idx;
}


const Snd_Mixer_CTL_Data *
Mixer_CTL::mixer_data ( ) const
{
      return mx_data().mixer_data;
}


void
Mixer_CTL::set_mixer_data (
      const Snd_Mixer_CTL_Data * data_n )
{
      mx_data().mixer_data = data_n;
}


Mixer_Style *
Mixer_CTL::mixer_style ( ) const
{
      return mx_data().mixer_style;
}


void
Mixer_CTL::set_mixer_style (
      Mixer_Style * mstyle_n )
{
      mx_data().mixer_style = mstyle_n;
}


unsigned int
Mixer_CTL::wheel_degrees ( ) const
{
      return mx_data().wheel_degrees;
}


void
Mixer_CTL::set_wheel_degrees (
      unsigned int degrees_n )
{
      if ( mx_data().wheel_degrees != degrees_n ) {
            mx_data().wheel_degrees = degrees_n;
            if ( _editor_pad != 0 ) {
                  _editor_pad->update_wheel_degrees();
            }
      }
}


void
Mixer_CTL::clear ( )
{
      if ( _editor_pad != 0 ) {
            delete _editor_pad;
            _editor_pad = 0;
      }

      mx_data().snd_elem_group = 0;
}


void
Mixer_CTL::set_snd_elem_group (
      Snd_Mixer_CTL_Elem_Group * elem_group_n,
      unsigned int index_n )
{
      if ( ( snd_elem_group() == elem_group_n ) &&
            ( elem_idx() == index_n ) )
      {
            return;
      }

      clear();

      mx_data().snd_elem_group = elem_group_n;
      mx_data().elem_idx = index_n;

      if ( snd_elem_group() != 0 ) {
            setup_widgets();
      }

      update_info();
}


void
Mixer_CTL::setup_widgets ( )
{
      if ( snd_elem_group() == 0 ) {
            return;
      }
      if ( snd_elem_group()->num_elems() == 0 ) {
            return;
      }

      Snd_Mixer_CTL_Elem * elem0 ( snd_elem_group()->elem ( 0 ) );
      if ( elem0->is_boolean() ) {
            _editor_pad = new Mixer_CTL_Editor_Bool ( mx_data(), this );
      } else if ( elem0->is_enumerated() ) {
            _editor_pad = new Mixer_CTL_Editor_Enum ( mx_data(), this );
      } else if ( elem0->is_integer() ) {
            _editor_pad = new Mixer_CTL_Editor_Int ( mx_data(), this );
      } else {
            _editor_pad = new Mixer_CTL_Editor_Unsupported ( mx_data(), this );
      }

      _pad_wdg.layout()->addWidget ( _editor_pad );
}


void
Mixer_CTL::update_info ( )
{
      QFont name_fnt ( font() );
      QString name_val;
      QString name_ttip;

      _info_wdg.setEnabled ( ( snd_elem_group() != 0 ) );

      // Clear
      {
            QString clear_txt ( "" );
            _info_lbl_name.setText ( clear_txt );
            _info_lbl_index.value.setText ( clear_txt );
            _info_lbl_dev.value.setText ( clear_txt );
            _info_lbl_flags.value.setText ( clear_txt );
            _info_lbl_count.value.setText ( clear_txt );
            _info_lbl_numid.value.setText ( clear_txt );
      }

      if ( snd_elem_group() == 0 ) {

            name_fnt.setItalic ( true );
            name_val = tr ( "No element selected" );

      } else {

            const Snd_Mixer_CTL_Elem * elem_first ( snd_elem_group()->elem ( 0 ) );

            const QString dname ( elem_first->display_name() );

            name_val = "<h3>%1</h3>";
            name_val = name_val.arg ( dname );

            // Tooltip
            name_ttip = _ttip_name_lbl_mask.arg ( elem_first->elem_name() );

            if ( elem_idx() < snd_elem_group()->num_elems() ) {

                  const QString val ( "%1" );
                  QString valc;

                  Snd_Mixer_CTL_Elem * elem ( snd_elem_group()->elem ( elem_idx() ) );

                  valc = val.arg ( elem->elem_index() );
                  _info_lbl_index.value.setText ( valc );

                  valc = _info_dev_mask;
                  valc = valc.arg ( elem->device() );
                  valc = valc.arg ( elem->subdevice() );
                  _info_lbl_dev.value.setText ( valc );

                  if ( mixer_data() != 0 ) {
                        const QString wrap ( "<div>%1</div>" );
                        QString txt;
                        QString accu;

                        accu = mixer_data()->flag_readable_char ( elem->is_readable() );
                        accu += mixer_data()->flag_writable_char ( elem->is_writable() );
                        accu += mixer_data()->flag_active_char ( elem->is_active() );
                        accu += mixer_data()->flag_volatile_char ( elem->is_volatile() );
                        _info_lbl_flags.value.setText ( accu );

                        txt = mixer_data()->flag_readable_text ( elem->is_readable() );
                        accu = wrap.arg ( txt );
                        txt = mixer_data()->flag_writable_text ( elem->is_writable() );
                        accu += wrap.arg ( txt );
                        txt = mixer_data()->flag_active_text ( elem->is_active() );
                        accu += wrap.arg ( txt );
                        txt = mixer_data()->flag_volatile_text ( elem->is_volatile() );
                        accu += wrap.arg ( txt );
                        _info_lbl_flags.value.setToolTip ( accu );
                  }

                  valc = val.arg ( elem->count() );
                  _info_lbl_count.value.setText ( valc );

                  valc = val.arg ( elem->elem_numid() );
                  _info_lbl_numid.value.setText ( valc );

            }
      }

      _info_lbl_name.setText ( name_val );
      _info_lbl_name.setToolTip ( name_ttip );
      _info_lbl_name.setFont ( name_fnt );
}


} // End of namespace

Generated by  Doxygen 1.6.0   Back to index