📄 mediaselectorwidget.cpp
字号:
// Add actions to menu and toolbar d->tbPlay->addTo( d->bar ); d->tbInfo->addTo( d->bar ); d->tbUp->addTo( d->bar ); d->tbDown->addTo( d->bar ); d->tbLoop->addTo( d->optionsMenu ); if ( videoButtons ) { d->tbFull->addTo( d->optionsMenu ); d->tbScale->addTo( d->optionsMenu ); } d->tbShuffle->addTo( d->playlistMenu ); d->tbSort->addTo( d->playlistMenu ); d->tbSelect->addTo( d->playlistMenu ); d->tbAdd->addTo( d->playlistMenu ); QString skinPath = QPEApplication::qpeDir() + "pics/mediaplayer/skins/"; QDir skinDir( skinPath ); d->skinCount = 0; d->skinID.clear(); for ( unsigned int i = 0; i < skinDir.count(); i++ ) { if ( skinDir[i] != "." && skinDir[i] != ".." ) { QString cfgfile = skinPath + skinDir[i] + "/config"; Config cfg(cfgfile,Config::File); if ( cfg.isValid() ) { cfg.setGroup("Skin"); d->skinMenu->insertItem( cfg.readEntry("Name"), this, SLOT( skinChanged(int) ), 0, d->skinCount ); if ( skinDir[i] == mediaPlayerState->skin() ) d->skinMenu->setItemChecked( d->skinCount, TRUE ); d->skinID.append(skinDir[i]); d->skinCount++; } } }#endif connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), d->tbPlay, SLOT( setOn2(bool) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), d->tbLoop, SLOT( setOn2(bool) ) ); connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ), d->tbShuffle, SLOT( setOn2(bool) ) ); connect( mediaPlayerState, SIGNAL( fullscreenToggled(bool) ), d->tbFull, SLOT( setOn2(bool) ) ); connect( mediaPlayerState, SIGNAL( scaledToggled(bool) ), d->tbScale, SLOT( setOn2(bool) ) ); connect( mediaPlayerState, SIGNAL( viewChanged(View) ), this, SLOT( setView(View) ) ); connect( mediaPlayerState, SIGNAL( viewClosed() ), this, SLOT( viewClosed() ) ); connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); setCentralWidget(d->stack); initializeStates();}MediaSelectorWidget::~MediaSelectorWidget(){ Config cfg( "MediaPlayer" ); cfg.setGroup("PlayListSettings"); cfg.writeEntry("Category", d->catSel->currentCategoryId()); delete d;}void MediaSelectorWidget::selectAll(){ d->fileList->selectAll();}void MediaSelectorWidget::categorize(){ d->fileList->categorize();}void MediaSelectorWidget::selectCategory(){#ifdef QTOPIA_PHONE QPEApplication::execDialog((CategorySelectDialogX*)d->catSel);#endif}void MediaSelectorWidget::sort(){ d->fileList->setSorting(1); d->fileList->sort(); d->fileList->setSorting(-1);}void MediaSelectorWidget::shuffle(){ d->fileList->setSorting(-1); d->fileList->setUpdatesEnabled(false); QList<QListViewItem> shuffledList; QListViewItem *item = d->fileList->firstChild(); int count = 0; while (item) { unsigned int randomPos = (unsigned int)((double)rand() * count / RAND_MAX); randomPos = QMIN( randomPos, (unsigned int)count ); shuffledList.insert( randomPos, item ); count++; QListViewItem *nextItem = item->nextSibling(); d->fileList->takeItem(item); item = nextItem; } while (count--) d->fileList->insertItem(shuffledList.at(count)); d->fileList->setUpdatesEnabled(true); QTimer::singleShot(0,d->fileList,SLOT(updateContents()));}void MediaSelectorWidget::resizeEvent( QResizeEvent * ){#ifndef QTOPIA_PHONE QFontMetrics fm( qApp->font() ); int w = width() - fm.width( tr( "Playlist" ) + tr( "Options" ) + tr( "Skin" ) ); // Add it back in based on the width if ( w < 150 ) { if ( d->skinInMenu ) { d->menu->removeItem( d->skinMenuId ); d->skinMenuId = d->optionsMenu->insertItem( tr( "Skin" ), d->skinMenu ); d->skinInMenu = FALSE; } } else { if ( !d->skinInMenu ) { d->optionsMenu->removeItem( d->skinMenuId ); d->skinMenuId = d->menu->insertItem( tr( "Skin" ), d->skinMenu ); d->skinInMenu = TRUE; } }#endif}void MediaSelectorWidget::scanProgress(int percent){ int count = 0; d->loadingWidget->setProgress(percent); switch ( percent ) { case 0: d->stack->raiseWidget(0); d->fileList->setUpdatesEnabled(false); d->fileList->setSorting(-1); break; case 100: d->fileList->setUpdatesEnabled(true); d->stack->raiseWidget(1); count = d->fileList->childCount();#ifdef QTOPIA_PHONE if (count) ContextBar::setLabel( this, Key_Select, "play", tr("Play") ); else ContextBar::setLabel( this, Key_Select, ContextBar::NoLabel );#endif d->tbSelect->setEnabled( count ); d->tbAdd->setEnabled( count ); d->tbShuffle->setEnabled( count ); d->tbSort->setEnabled( count ); d->tbPlay->setEnabled( count ); d->tbInfo->setEnabled( count ); d->tbUp->setEnabled( count > 1 ); d->tbDown->setEnabled( count > 1 ); break; default: break; }}bool MediaSelectorWidget::listHasFocus(){ return d->fileList->hasFocus();}void MediaSelectorWidget::loadFiles() { d->list->start();}void MediaSelectorWidget::skinChanged( int id ){ // Already checked, therefore this is the current skin, do nothing if ( !d->skinMenu || d->skinMenu->isItemChecked( id ) ) return; // Update the checked menu item for ( int i = 0; i < (int)d->skinCount; i++ ) d->skinMenu->setItemChecked( i, (i == id) ); // Update the skin state mediaPlayerState->setSkin( d->skinID[id] );}void MediaSelectorWidget::initializeStates(){ d->tbPlay->setOn( mediaPlayerState->playing() ); d->tbLoop->setOn( mediaPlayerState->looping() ); d->tbShuffle->setOn( mediaPlayerState->shuffled() ); d->tbFull->setOn( mediaPlayerState->fullscreen() ); d->tbScale->setOn( mediaPlayerState->scaled() );}void MediaSelectorWidget::setDocument(const QString& fileref){ d->setDocumentActive = true; d->setDoc = DocLnk( fileref );}void MediaSelectorWidget::setActiveWindow(){ mediaPlayerState->setView( mediaPlayerState->view() );}const DocLnk *MediaSelectorWidget::current(){ if ( d->setDocumentActive ) return &d->setDoc; return d->fileList->current();}void MediaSelectorWidget::prev(){ mediaPlayerState->setPlaying(false); d->setDocumentActive = false; if ( d->fileList->prev() ) mediaPlayerState->setPlaying(true); else mediaPlayerState->setList();}void MediaSelectorWidget::next(){ mediaPlayerState->setPlaying(false); d->setDocumentActive = false; if ( d->fileList->next() ) mediaPlayerState->setPlaying(true); else mediaPlayerState->setList();}void MediaSelectorWidget::viewClosed(){ if ( d->setDocumentActive ) { mediaPlayerState->setPlaying(false); QTimer::singleShot(100, qApp, SLOT(quit())); } else { mediaPlayerState->setList(); }}void MediaSelectorWidget::setView( View view ){ if ( view == ListView ) { d->setDocumentActive = false; d->list->resume(); } else { d->list->pause(); }}void MediaSelectorWidget::showInfo(){ const DocLnk *cur = current(); if ( cur ) { MediaFileInfoWidget *infoWidget = new MediaFileInfoWidget( *cur, this ); QPEApplication::execDialog( infoWidget ); delete infoWidget; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -