// (C) 2005 Max Howell (max.howell@methylblue.com) // See COPYING file for licensing information #include #include #include #include #include #include #include "../debug.h" #include "volumeAction.h" #include "xineEngine.h" class VolumeSlider : public TQFrame { public: VolumeSlider( TQWidget *parent ) : TQFrame( parent ) { slider = new TQSlider( TQt::Vertical, this, "volume" ); label = new TQLabel( this ); TQBoxLayout *lay = new TQVBoxLayout( this ); lay->addWidget( slider, 0, TQt::AlignHCenter ); lay->addWidget( label, 0, TQt::AlignHCenter ); lay->setMargin( 4 ); slider->setRange( 0, 100 ); setFrameStyle( TQFrame::Plain | TQFrame::Box ); setSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred ); // Calculate width required for max label size label->setText( "100%" ); adjustSize(); requiredWidth = width(); hide(); } TQLabel *label; TQSlider *slider; int requiredWidth; }; VolumeAction::VolumeAction( TDEToolBar *bar, TDEActionCollection *ac ) : TDEToggleAction( i18n("Volume"), "volume", TQt::Key_1, 0, 0, ac, "volume" ) , m_anchor( 0 ) { m_widget = new VolumeSlider( bar->topLevelWidget() ); connect( this, SIGNAL(toggled( bool )), SLOT(toggled( bool )) ); connect( m_widget->slider, SIGNAL(sliderMoved( int )), SLOT(sliderMoved( int )) ); connect( m_widget->slider, SIGNAL(sliderMoved( int )), Codeine::engine(), SLOT(setStreamParameter( int )) ); connect( m_widget->slider, SIGNAL(sliderReleased()), SLOT(sliderReleased()) ); } int VolumeAction::plug( TQWidget *bar, int index ) { DEBUG_BLOCK int const id = TDEAction::plug( bar, index ); m_anchor = (TQWidget*)bar->child( "toolbutton_volume" ); //TDEAction creates it with this name m_anchor->installEventFilter( this ); //so we can keep m_widget anchored return id; } void VolumeAction::toggled( bool const b ) { DEBUG_BLOCK TQString t = TQString::number(100 - m_widget->slider->value()) + "%"; setToolTip( i18n( "Volume: %1" ).arg( t ) ); m_widget->label->setText( t ); m_widget->raise(); m_widget->setShown( b ); } void VolumeAction::sliderMoved( int v ) { v = 100 - v; //TQt sliders are wrong way round when vertical TQString t = TQString::number( v ) + '%'; setToolTip( i18n( "Volume: %1" ).arg( t ) ); m_widget->label->setText( t ); } bool VolumeAction::eventFilter( TQObject *o, TQEvent *e ) { switch (e->type()) { case TQEvent::Move: case TQEvent::Resize: { TQWidget const * const &a = m_anchor; m_widget->resize( m_widget->requiredWidth, m_widget->sizeHint().height() ); m_widget->move( a->mapTo( m_widget->parentWidget(), TQPoint( a->width() - m_widget->width(), a->height() ) ) ); return false; } //TODO one click method, flawed currently in fullscreen mode by palette change in mainwindow.cpp /* case TQEvent::MouseButtonPress: m_widget->show(); break; case TQEvent::MouseButtonRelease: m_widget->hide(); break;*/ default: return false; } } #include "volumeAction.moc"