⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3mainwindow.cpp.bak

📁 这是一个自己开发的键盘驱动代码
💻 BAK
字号:
#include "mp3mainwindow.h"
#include "icons.h"
#include "../dirview/dirview.h"

#include <qsplitter.h>
#include <qtoolbar.h>
#include <qpixmap.h>
#include <qtoolbutton.h>
#include <qstringlist.h>
#include <stdlib.h>
#include <qheader.h>
#include <qvaluelist.h>
#include <qstring.h>
#include <qregexp.h>

Mp3MainWindow::Mp3MainWindow()
		: QMainWindow()
{
		pl_pa = true;
		QStringList fmt;
		fmt.append("MP3");

	  QSplitter *splitter = new QSplitter( this );
	  
	  playlist = new PlayList( splitter, "playlist" );
	  playlist->addColumn( "Name" );
    playlist->addColumn( "Path" );
    playlist->header()->hide();
    playlist->setSelectionMode( QListView::Extended );
    playlist->setColumnWidth( 1, 0 );
    playlist->setColumnWidthMode( 1, QListView::Manual );
/*    playlist->setFColor( yellow );
    playlist->setBColor( darkYellow );*/
		playlist->setEraseColor( darkYellow );

    dirlist = new DirectoryView( splitter, "dirlist", false, fmt );
    dirlist->addColumn( "Name" );
    dirlist->addColumn( "Type", 70 );
    dirlist->setColumnAlignment( 1, AlignRight );
    dirlist->setColumnWidth( 1, 0 );
    dirlist->setSelectionMode( QListView::Extended );
    Directory *root = new Directory( dirlist, "/" );
    root->setOpen( true );
    
    setCentralWidget( splitter );
    QValueList<int> sizeList;
		sizeList.append( 50 );
		splitter->setSizes( sizeList );
    splitter->setResizeMode( playlist, QSplitter::KeepSize );
    splitter->setOrientation( Horizontal );
    
		QToolBar *toolbar = new QToolBar( this, "toolbar" );
		QPixmap pix;
		pix = QPixmap( mp3_previous );
    preButton = new QToolButton( pix, "Previous Song", QString::null,
				this, SLOT( slotPause() ), toolbar, "previous" );
				
		pix = QPixmap( mp3_back );
    backButton = new QToolButton( pix, "Fast Backward", QString::null,
				this, SLOT( slotPause() ), toolbar, "back" );
				
		pix = QPixmap( mp3_play );
    playButton = new QToolButton( pix, "Play/Pause", QString::null,
				this, SLOT( slotMp3Play() ), toolbar, "play" );
				
		pix = QPixmap( mp3_forward );
    forwardButton = new QToolButton( pix, "Fast Forward", QString::null,
				this, SLOT( slotPause() ), toolbar, "forward" );
		
		pix = QPixmap( mp3_next );
    nextButton = new QToolButton( pix, "Next Song", QString::null,
				this, SLOT( slotPause() ), toolbar, "next" );
				
		pix = QPixmap( mp3_opendir );
    openButton = new QToolButton( pix, "Open/Hide Dirview", QString::null,
				this, SLOT( slotOpen_hide() ), toolbar, "open" );

	  connect( this, SIGNAL( openDirview() ), this, SLOT ( slotOpenDirview() ) );
	  
	  connect( this, SIGNAL( closeDirview() ), this, SLOT ( slotCloseDirview() ) );
	  
	  connect( playlist, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT ( slotMp3Play() ) );
	  
	  connect( dirlist, SIGNAL( fileSelected( const QString &, const QString & ) ),
	     playlist, SLOT( slotAddSong( const QString &, const QString & ) ) );
	  
	  emit openDirview();
}

void Mp3MainWindow::slotMp3Play()
{
	QPixmap pix;
	int er;
	QString commd, files, fntmp;
	
	QListViewItemIterator it( playlist ), it2( playlist );
  for ( ; it.current(); ++it ) {
  	if ( it.current()->isSelected() ) break;
  }
  if ( !it.current() )
  	for ( ; it2.current(); ++it2 )
  		files += spcCheck( it2.current()->text( 1 ) ) + " ";
  else
  	for ( ; it.current(); ++it )
  		files += spcCheck( it.current()->text( 1 ) ) + " ";
	commd = "/usr/mp3play " + files + "&";
	er = system( (const char *) commd );
	
	pl_pa = !pl_pa;
	if ( pl_pa ) pix = QPixmap( mp3_play );
	else pix = QPixmap( mp3_pause );
	playButton->setIconSet( pix );
	playlist->header()->hide();
	emit closeDirview();
}

void Mp3MainWindow::slotPause()
{
//	qwsServer->sendKeyEvent( 0, Qt::Key_P, 0, 1, false );
/*	int fd = open( "/dev/ttyS0", O_RDWR );
	write( fd, "p", 1 );*/
}

void Mp3MainWindow::slotOpen_hide()
{
	if ( !o_h ) emit openDirview();
	else emit closeDirview();
}

void Mp3MainWindow::slotOpenDirview()
{
	openButton->setIconSet( QPixmap( mp3_closedir ) );
	dirlist->show();
	o_h = true;
}

void Mp3MainWindow::slotCloseDirview()
{
	openButton->setIconSet( QPixmap( mp3_opendir ) );
	dirlist->hide();
	o_h = false;
}

QString Mp3MainWindow::spcCheck( const QString &orifn )
{
	QString tmp = orifn;
	tmp.replace( QRegExp( " " ) , "\\ " );
	return tmp;
}

PlayList::PlayList( QWidget * parent, const char * name )
    : QListView( parent, name ), timer( this )
{
	connect( &timer, SIGNAL( timeout() ), this, SLOT( slotRemoveSong() ) );
}

void PlayList::slotRemoveSong()
{
	takeItem( currentItem() );
}

void PlayList::contentsMousePressEvent( QMouseEvent * e )
{
	QListView::contentsMousePressEvent( e );
	timer.start( 500, TRUE );
}

void PlayList::contentsMouseReleaseEvent( QMouseEvent * e )
{
	QListView::contentsMouseReleaseEvent( e );
	timer.stop();
}

void PlayList::slotAddSong( const QString &fn, const QString &fp )
{
	QListViewItem item = new QListViewItem( this, fn, fp );
	insertItem( &item );
}

void PlayList::setFColor( const QColor & color )
{
    BackgroundMode mode = PaletteBackground;
    QPalette pal = palette();
    QColorGroup::ColorRole role = QPalette::foregroundRoleFromMode( mode );
    pal.setColor( QPalette::Active, role, color );
    pal.setColor( QPalette::Inactive, role, color );
    pal.setColor( QPalette::Disabled, role, color );
    setPalette( pal );
}

void PlayList::setBColor( const QColor & color )
{
    BackgroundMode mode = PaletteBackground;
		QPalette pal = palette();
		QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( mode );
		pal.setColor( QPalette::Active, role, color );
		pal.setColor( QPalette::Inactive, role, color );
		pal.setColor( QPalette::Disabled, role, color );
		setPalette( pal );
}

⌨️ 快捷键说明

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