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

main_view_mixer_simple.cpp

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

#include "main_view_mixer_simple.hpp"

#include <QCoreApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QStackedLayout>
#include <QWidgetAction>
#include <QFile>
#include <QIcon>

#include "config.hpp"

#include <iostream>


Main_View_Mixer_Simple::Main_View_Mixer_Simple (
      Mixer_Settings & settings_n,
      QSnd::Snd_Control_Address & ctl_n,
      QWidget * parent_n ) :
Main_View ( ctl_n, parent_n ),
_status_group_idx ( ~0 ),
_status_column_idx ( ~0 ),
_settings ( settings_n ),
_qsnd_mixer ( this ),
_act_grp_menu ( this ),
_act_grp_toolbar ( this ),
_act_grp_cmenu ( this )
{
      // Strings and icons
      _act_select_text[0] = tr ( "Show playback" );
      _act_select_text[1] = tr ( "Show capture" );
      _act_select_text[2] = tr ( "Show playback and capture" );
      _act_select_ttip[0] = tr ( "Show only playback elements" );
      _act_select_ttip[1] = tr ( "Show only capture elements" );
      _act_select_ttip[2] = tr ( "Show playback and capture elements" );

      _act_check_text[0] = _act_select_text[0];
      _act_check_text[1] = _act_select_text[1];
      _act_check_ttip[0] = tr ( "Show playback elements" );
      _act_check_ttip[1] = tr ( "Show capture elements" );

      { // Icons
            const char * fd_app[3] = {
                  "show-playback",
                  "show-capture"
            };
            const char * fd_def[3] = {
                  "media-playback-start",
                  "media-record"
            };

            QString icon_path_base ( INSTALL_DIR_APP_ICONS );
            icon_path_base.append ( "/" );
            for ( unsigned int ii=0; ii < 2; ++ii ) {
                  QIcon icon;
                  {
                        QString icon_path ( icon_path_base );
                        icon_path.append ( fd_app[ii] );
                        icon_path.append ( ".svg" );
                        if ( QFile::exists ( icon_path ) ) {
                              icon = QIcon ( icon_path );
                        } else {
                              icon = QIcon::fromTheme ( fd_def[ii] );
                        }
                  }
                  _act_check_icon[ii] = icon;
            }
      }


      connect ( &_qsnd_mixer, SIGNAL ( sig_mixer_reload_request() ),
            this, SLOT ( reload_delayed() ) );

      connect ( &_act_grp_menu, SIGNAL ( triggered ( QAction * ) ),
            this, SLOT ( stream_action_changed ( QAction * ) ) );

      connect ( &_act_grp_cmenu, SIGNAL ( triggered ( QAction * ) ),
            this, SLOT ( stream_action_changed ( QAction * ) ) );

      connect (
            _mixer_sliders.sliders_pad(),
            SIGNAL ( sig_footer_label_selected ( unsigned int, unsigned int ) ),
            this, SLOT ( footer_label_selected ( unsigned int, unsigned int ) ) );


      // Vertical splitter
      {
            _mixer_split.setOrientation ( Qt::Vertical );
            _mixer_split.addWidget ( &_mixer_sliders );
            _mixer_split.addWidget ( &_mixer_switches );
            _mixer_split.setCollapsible ( 0, false );
            _mixer_split.setCollapsible ( 1, false );
            _mixer_split.setStretchFactor ( 0, 1 );
            _mixer_split.setStretchFactor ( 1, 0 );
            lay_stack()->addWidget ( &_mixer_split );
      }

      // Adjust layout margins
      {
            QMargins mgs ( _mixer_sliders.contentsMargins() );
            mgs.setTop ( 0 );
            _mixer_sliders.setContentsMargins ( mgs );
      }

      if ( _mixer_sliders.layout() != 0 ) {
            QMargins mgs ( _mixer_sliders.layout()->contentsMargins() );
            mgs.setTop ( 0 );
            _mixer_sliders.layout()->setContentsMargins ( mgs );
      }

      apply_settings();
}


Main_View_Mixer_Simple::~Main_View_Mixer_Simple ( )
{
      if ( _status_wdg != 0 ) {
            delete _status_wdg;
      }
      _mixer_sliders.set_mixer_simple ( 0 );
      _mixer_switches.set_mixer_simple ( 0 );
      _qsnd_mixer.close();
}


void
Main_View_Mixer_Simple::set_mixer_style (
      QSnd::Mixer_Style * mstyle_n )
{
      if ( mstyle_n != 0 ) {
            _mixer_sliders.set_mixer_style ( mstyle_n );
      }
}


unsigned int
Main_View_Mixer_Simple::stream_mode ( ) const
{
      unsigned int idx ( 0 );
      {
            bool spb ( _settings.smixer.show_stream[0] );
            bool sca ( _settings.smixer.show_stream[1] );
            if ( spb && sca ) {
                  idx = 2;
            } else if ( sca ) {
                  idx = 1;
            }
      }
      return idx;
}


void
Main_View_Mixer_Simple::create_select_actions (
      QActionGroup * act_grp_n )
{
      if ( act_grp_n->actions().size() == 3 ) {
            return;
      }

      if ( act_grp_n->actions().size() > 0 ) {
            QList < QAction * > acts ( act_grp_n->actions() );
            for ( int ii=0; ii < acts.size(); ++ii ) {
                  delete acts[ii];
            }
      }

      {
            QAction * acts[3];
            for ( unsigned int ii=0; ii < 3; ++ii ) {
                  acts[ii] = new QAction ( act_grp_n );
                  acts[ii]->setCheckable ( true );
                  acts[ii]->setText ( _act_select_text[ii] );
                  acts[ii]->setToolTip ( _act_select_ttip[ii] );
                  acts[ii]->setData ( ii );
            }

            acts[stream_mode()]->setChecked ( true );
      }
}


void
Main_View_Mixer_Simple::create_check_actions (
      QActionGroup * act_grp_n )
{
      if ( act_grp_n->actions().size() == 2 ) {
            return;
      }

      if ( act_grp_n->actions().size() > 0 ) {
            QList < QAction * > acts ( act_grp_n->actions() );
            for ( int ii=0; ii < acts.size(); ++ii ) {
                  delete acts[ii];
            }
      }

      act_grp_n->setExclusive ( false );

      {
            QAction * acts[2];
            for ( unsigned int ii=0; ii < 2; ++ii ) {
                  acts[ii] = new QAction ( act_grp_n );
                  acts[ii]->setCheckable ( true );
                  acts[ii]->setText ( _act_check_text[ii] );
                  acts[ii]->setToolTip ( _act_check_ttip[ii] );
                  acts[ii]->setIcon ( _act_check_icon[ii] );
            }

            acts[0]->setChecked (  _settings.smixer.show_stream[0] );
            acts[1]->setChecked (  _settings.smixer.show_stream[1] );

            connect ( acts[0], SIGNAL ( triggered ( bool ) ),
                  this, SLOT ( show_playback ( bool ) ) );

            connect ( acts[1], SIGNAL ( triggered ( bool ) ),
                  this, SLOT ( show_capture ( bool ) ) );
      }
}


void
00235 Main_View_Mixer_Simple::acquire_menu_actions (
      QList < QAction * > & lst_n )
{
      create_select_actions ( &_act_grp_menu );
      lst_n.append ( _act_grp_menu.actions() );
}


void
00244 Main_View_Mixer_Simple::acquire_toolbar_actions (
      QList < QAction * > & lst_n )
{
      create_check_actions ( &_act_grp_toolbar );
      lst_n.append ( _act_grp_toolbar.actions() );
}


void
00253 Main_View_Mixer_Simple::acquire_context_actions (
      QList < QAction * > & lst_n )
{
      create_select_actions ( &_act_grp_cmenu );
      lst_n.append ( _act_grp_cmenu.actions() );
}


void
Main_View_Mixer_Simple::apply_settings ( )
{
      {
            const unsigned int idx ( stream_mode() );
            if ( _act_grp_menu.actions().size() == 3 ) {
                  _act_grp_menu.actions()[idx]->setChecked ( true );
            }
            if ( _act_grp_toolbar.actions().size() == 2 ) {
                  _act_grp_toolbar.actions()[0]->setChecked ( _settings.smixer.show_stream[0] );
                  _act_grp_toolbar.actions()[1]->setChecked ( _settings.smixer.show_stream[1] );
            }
            if ( _act_grp_cmenu.actions().size() == 3 ) {
                  _act_grp_cmenu.actions()[idx]->setChecked ( true );
            }
      }

      _mixer_split.hide();

      _mixer_sliders.set_mixer_settings ( _settings.smixer );
      _mixer_switches.set_mixer_settings ( _settings.smixer );
      _mixer_sliders.set_wheel_degrees ( _settings.wheel_degrees );

      update_mixer_visibility();
}


void
Main_View_Mixer_Simple::show_playback (
      bool flag_n )
{
      if ( flag_n != _settings.smixer.show_stream[0] ) {
            _settings.smixer.show_stream[0] = flag_n;
            if ( !_settings.smixer.show_stream[0] &&
                  !_settings.smixer.show_stream[1] )
            {
                  _settings.smixer.show_stream[1] = true;
            }
            emit sig_settings_changed();
      }
}


void
Main_View_Mixer_Simple::show_capture (
      bool flag_n )
{
      if ( flag_n != _settings.smixer.show_stream[1] ) {
            _settings.smixer.show_stream[1] = flag_n;
            if ( !_settings.smixer.show_stream[0] &&
                  !_settings.smixer.show_stream[1] )
            {
                  _settings.smixer.show_stream[0] = true;
            }
            emit sig_settings_changed();
      }
}


void
Main_View_Mixer_Simple::show_streams (
      unsigned int mode_n )
{
      if ( mode_n < 3 ) {
            bool changed ( false );
            bool sstr[2];
            sstr[0] = ( ( mode_n == 0 ) || ( mode_n == 2 ) );
            sstr[1] = ( ( mode_n == 1 ) || ( mode_n == 2 ) );
            for ( unsigned int ii=0; ii < 2; ++ii ) {
                  if ( _settings.smixer.show_stream[ii] != sstr[ii] ) {
                        _settings.smixer.show_stream[ii] = sstr[ii];
                        changed = true;
                  }
            }

            if ( changed ) {
                  emit sig_settings_changed();
            }
      }
}


void
Main_View_Mixer_Simple::show_slider_value_widget ( )
{
      if ( _status_wdg == 0 ) {
            QSnd::Mixer_Sliders_Status_Widget * swdg (
                  new QSnd::Mixer_Sliders_Status_Widget ( this ) );
            swdg->setAttribute ( Qt::WA_DeleteOnClose );
            swdg->set_sliders_pad ( _mixer_sliders.sliders_pad() );
            swdg->slider_focus_changed();

            _status_wdg = swdg;
            _status_wdg->show();
      }
}


void
Main_View_Mixer_Simple::footer_label_selected (
      unsigned int group_idx_n,
      unsigned int column_idx_n )
{
      //std::cout << "Footer label selected " << group_idx_n << " " << column_idx_n << "\n";
      bool keep_indices ( true );
      if ( _status_wdg == 0 ) {
            show_slider_value_widget();
      } else {
            if ( ( group_idx_n == _status_group_idx ) &&
                  ( column_idx_n == _status_column_idx ) )
            {
                  _status_group_idx = ~0;
                  _status_column_idx = ~0;
                  _status_wdg->close();
                  keep_indices = false;
            }
      }

      if ( keep_indices ) {
            _status_group_idx = group_idx_n;
            _status_column_idx = column_idx_n;
      }
}


void
Main_View_Mixer_Simple::stream_action_changed (
      QAction * act_n )
{
      const QVariant & vdata ( act_n->data() );
      if ( vdata.isValid() ) {
            if ( vdata.canConvert ( QVariant::UInt ) ) {
                  show_streams ( vdata.toUInt() );
            }
      }
}


void
Main_View_Mixer_Simple::reload ( )
{
      //std::cout << "Main_View_Mixer_Simple::reload()" << "\n";

      Main_View::reload();

      _mixer_split.hide();

      // Close mixer
      if ( _qsnd_mixer.is_open() ) {
            _mixer_sliders.set_mixer_simple ( 0 );
            _mixer_switches.set_mixer_simple ( 0 );
            _qsnd_mixer.close();
      }

      unsigned int stack_idx ( 0 );

      // Open mixer
      if ( !current_ctl().is_clear() ) {
            _qsnd_mixer.open ( current_ctl().ctl_id() );

            // Set mixer object
            if ( _qsnd_mixer.is_open() ) {
                  _mixer_sliders.set_mixer_simple ( &_qsnd_mixer );
                  _mixer_switches.set_mixer_simple ( &_qsnd_mixer );
                  stack_idx = 1;
            } else {
                  message_wdg().set_mixer_open_fail (
                        current_ctl().ctl_id(),
                        _qsnd_mixer.err_message(),
                        _qsnd_mixer.err_func() );
            }

      } else {
            message_wdg().set_no_device();
      }

      lay_stack()->setCurrentIndex ( stack_idx );
      if ( stack_idx == 1 ) {
            update_mixer_visibility();
      }
}


void
Main_View_Mixer_Simple::update_mixer_visibility ( )
{
      bool vis = ( _mixer_sliders.num_visible() > 0 );
      _mixer_sliders.setVisible ( vis );

      vis = ( _mixer_switches.num_visible() > 0 );
      _mixer_switches.setVisible ( vis );

      {
            QList<int> sizes;
            sizes.append ( 10000 );
            sizes.append ( 1 ); // Sets the switches area to it's minimum height
            _mixer_split.setSizes ( sizes );
      }

      _mixer_split.show();
}


void
Main_View_Mixer_Simple::showEvent (
      QShowEvent * event_n )
{
      Main_View::showEvent ( event_n );
      if ( _status_wdg != 0 ) {
            _status_wdg->show();
      }
}


void
Main_View_Mixer_Simple::hideEvent (
      QHideEvent * event_n )
{
      Main_View::hideEvent ( event_n );
      if ( _status_wdg != 0 ) {
            _status_wdg->hide();
      }
}

Generated by  Doxygen 1.6.0   Back to index