playerwindow.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 956 行 · 第 1/3 页

CPP
956
字号
            m_pSlider->setValue( 0 );            m_pSlider->setMinValue( 0 );            m_pSlider->setMaxValue( 0 );            m_pSlider->newBundle( MetaBundle() ); // Set an empty bundle for no moodbar            m_pTimeLabel->hide();            m_pTimeSign->hide();            m_rateString = QString::null;            m_pSlider->setEnabled( false );            setScroll( i18n( "Welcome to Amarok" ) );            update();            break;        case Engine::Playing:            if( !m_minimalView )            {                m_pTimeLabel->show();                m_pTimeSign->show();            }            m_pButtonPlay->setOn( true );            m_pButtonPause->setOn( false );            break;        case Engine::Paused:            m_pButtonPause->setOn( true );            break;        case Engine::Idle: //don't really want to do anything when idle            break;    }}void PlayerWidget::engineVolumeChanged( int percent ){    m_pVolSlider->setValue( percent );}void PlayerWidget::engineNewMetaData( const MetaBundle &bundle, bool ){    m_currentURL == bundle.url().path();    m_pSlider->setMinValue( 0 ); // Important. minValue could have been changed by bogus maxValues    m_pSlider->setMaxValue( bundle.length() * 1000 );    m_pSlider->setEnabled( bundle.length() > 0 );    m_pSlider->newBundle( bundle );    m_rateString     = bundle.prettyBitrate();    QString Hz = bundle.prettySampleRate( true );    if( !Hz.isEmpty() )    {        if( m_rateString.isEmpty() )            m_rateString = Hz;        else            m_rateString = i18n("%1 kBit - %2").arg( m_rateString, Hz );    }    QStringList list( bundle.prettyTitle() );    list << bundle.album();    if( bundle.length() ) list << bundle.prettyLength();    setScroll( list );    update(); //we need to update rateString}void PlayerWidget::engineTrackPositionChanged( long position, bool /*userSeek*/ ){    m_pSlider->setValue( position );    if( !m_pSlider->isEnabled() ) timeDisplay( position );}void PlayerWidget::engineTrackLengthChanged( long length ){    m_pSlider->setMaxValue( length * 1000 );}void PlayerWidget::timeDisplay( int ms ){    int seconds = ms / 1000;    const int songLength = EngineController::instance()->bundle().length();    const bool showRemaining = AmarokConfig::leftTimeDisplayRemaining() && songLength > 0;    if( showRemaining ) seconds = songLength - seconds;    m_timeBuffer.fill( backgroundColor() );    QPainter p( &m_timeBuffer );    p.setPen( foregroundColor() );    p.setFont( m_pTimeLabel->font() );    p.drawText( 0, 16, MetaBundle::prettyTime( seconds ) ); //FIXME remove padding, instead move()!    bitBlt( m_pTimeLabel, 0, 0, &m_timeBuffer );    m_pTimeSign->setPixmap( showRemaining ? m_minusPixmap : m_plusPixmap );}static inline QColor comodulate( int hue, QColor target ){    ///this function is only used by determineAmarokColors()    int ignore, s, v;    target.getHsv( &ignore, &s, &v );    return QColor( hue, s, v, QColor::Hsv );}void PlayerWidget::determineAmarokColors() //static{    int hue, s, v;    (!AmarokConfig::schemeKDE()        ? AmarokConfig::playlistWindowBgColor()        : KGlobalSettings::highlightColor()      ).getHsv( &hue, &s, &v );    using namespace Amarok::ColorScheme;    Text       = Qt::white;    Background = comodulate( hue, 0x002090 );    Foreground = comodulate( hue, 0x80A0FF );    //ensure the base colour does not conflict with the window decoration colour    //however generally it is nice to leave the other colours with the highlight hue    //because the scheme is then "complimentary"    //TODO schemes that have totally different active/inactive decoration colours need to be catered for too!    if ( AmarokConfig::schemeKDE() ) {        int h;        KGlobalSettings::activeTitleColor().getHsv( &h, &s, &v );        if( QABS( hue - h ) > 120 )           hue = h;    }    Base = comodulate( hue, Amarok::blue );}void PlayerWidget::setModifiedPalette(){    QPalette p = QApplication::palette();    QColorGroup cg = p.active();    cg.setColor( QColorGroup::Background, Amarok::ColorScheme::Base );    cg.setColor( QColorGroup::Foreground, Amarok::ColorScheme::Text );    setPalette( QPalette(cg, p.disabled(), cg) );}void PlayerWidget::applySettings(){    //NOTE DON'T use unsetFont(), we use custom font sizes (for now)    QFont phont = font();    phont.setFamily( AmarokConfig::useCustomFonts()        ? AmarokConfig::playerWidgetFont().family()        : QApplication::font().family() );    setFont( phont );    setModifiedPalette();    //update the scroller    switch( EngineController::engine()->state() ) {    case Engine::Empty:        m_scrollTextPixmap.fill( Amarok::ColorScheme::Base );        update();        break;    default:        engineNewMetaData( EngineController::instance()->bundle(), false );    }    if(m_pAnalyzer)        setMinimalView(m_minimalView);}void PlayerWidget::setMinimalView( bool enable ){    m_pAnalyzer->setHidden( enable );    m_pTimeLabel->setHidden( enable );    m_pTimeSign->setHidden( enable );    m_pDescription->setHidden( enable );    m_pButtonEq->setHidden( enable );    m_pPlaylistButton->setHidden( enable );    m_pVolSlider->setHidden( enable );    if( enable )    {        uint space = 2;        m_pScrollFrame->setGeometry ( 6,space,  m_pScrollFrame->width(), m_pScrollFrame->height() );        m_pSlider->setGeometry      ( 4,space + m_pScrollFrame->height(), 303, 12 );        m_pFrameButtons->setGeometry( 0,space + m_pScrollFrame->height() + m_pSlider->height(), 311,22 );        uint height = m_pFrameButtons->height() + m_pScrollFrame->height() + m_pSlider->height() + space;        setFixedSize( 311, height );        AmarokConfig::setPlayerWindowMinimalView( true );    }    else    {        m_pScrollFrame->setGeometry( 6,18, m_pScrollFrame->width(),m_pScrollFrame->height() );        m_pSlider->setGeometry( 4,103, 303,12 );        m_pFrameButtons->setGeometry(0,118, 311,22);        setFixedSize( 311, 140 );        AmarokConfig::setPlayerWindowMinimalView( false );    }    m_minimalView = enable;    update();}// EVENTS -----------------------------------------------------------------static bool dontChangeButtonState = false; //FIXME I hate this hackbool PlayerWidget::event( QEvent *e ){    switch( e->type() )    {    case QEvent::Wheel:    case QEvent::DragEnter:    case QEvent::Drop:    case QEvent::Close:        Amarok::genericEventHandler( this, e );        return true; //we handled it    case QEvent::ApplicationPaletteChange:        if( AmarokConfig::schemeKDE() )        {            determineAmarokColors();            applySettings();        }        return true;    case 6/*QEvent::KeyPress*/:        if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_D/* && (m_pAnalyzer->inherits("QGLWidget")*/)        {            if( m_pAnalyzer->parent() )            {                m_pAnalyzer->reparent( 0, QPoint(50,50), true );                m_pAnalyzer->setCaption( kapp->makeStdCaption( i18n("Analyzer") ) );                m_pAnalyzer->installEventFilter( this );                m_pAnalyzer->setPaletteBackgroundColor( paletteBackgroundColor() );                QToolTip::remove( m_pAnalyzer );            }            else                createAnalyzer( 0 );            return true; //eat event        }        return false; //don't eat event    case QEvent::Show:        m_pAnimTimer->start( ANIM_TIMER );        if( m_pPlaylistButton->isOn() )        {            //IMPORTANT! If the PlaylistButton is on then we MUST be shown            //we leave the PlaylistButton "on" to signify that we should restore it here            //we leave it on when we do a hidePlaylistWithPlayerWindow type action            //IMPORTANT - I beg of you! Please leave all this alone, it was hell to            //create! If you have an issue with the behaviour bring it up on the mailing            //list before you even think about committing. Thanks! (includes case Hide)            const WId id = parentWidget()->winId();            const uint desktop = KWin::windowInfo( winId() ).desktop();            const KWin::WindowInfo info = KWin::windowInfo( id );            //check the Playlist Window is on the correct desktop            if( !info.isOnDesktop( desktop ) ) KWin::setOnDesktop( id, desktop );            if( info.mappingState() == NET::Withdrawn )            {                //extern Atom qt_wm_state; //XAtom defined by Qt                //TODO prevent the active Window flicker from playlist to player window please!                //TODO look at code for QWidget::show();                //XDeleteProperty( qt_xdisplay(), id, qt_wm_state );                //parentWidget()->show();                //if( !parentWidget()->isShown() ) XMapWindow( qt_xdisplay(), id );//                 unsigned long data[2];//                 data[0] = (unsigned long) NormalState;//                 data[1] = (unsigned long) None;////                 XChangeProperty( qt_xdisplay(), id, qt_wm_state, qt_wm_state, 32,//                      PropModeReplace, (unsigned char *)data, 2);////                 KWin::clearState( id, NET::Hidden );////                 XMapWindow( qt_xdisplay(), id );//                //KWin::deIconifyWindow( id, false );                parentWidget()->show();            }            if( info.isMinimized() )            {                //then the user will expect us to deiconify the Playlist Window                //the PlaylistButton would be off otherwise (honest!)                KWin::deIconifyWindow( id, false );            }        }        return false;    case QEvent::Hide:        m_pAnimTimer->stop();        {            //this prevents the PlaylistButton being set to off (see the eventFilter)            //by leaving it on we ensure that we show the Playlist Window again when            //we are next shown (see Show event handler above)            if( parentWidget()->isShown() ) dontChangeButtonState = true;            if( e->spontaneous() ) //the window system caused the event            {                //if we have been iconified, iconify the Playlist Window too                //if we have been shaded, hide the PlaylistWindow

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?