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

📄 qmpositionbar.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
字号:
/* qmpositionbar.cpp * * $Id: qmpositionbar.cpp,v 1.10 2002/03/07 03:44:17 mariuss Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmpositionbar.h"#include "qmmainwindow.h"#include "qmstatusbar.h"#include "qmplayer.h"#include <qtoolbar.h>#include <qslider.h>#include <qlabel.h>#include <qtooltip.h>/** * @file qmpositionbar.cpp * @brief Shows the song position during play, drag to a specific time-position *//*!  \class QmPositionBar qmpositionbar.h  \brief Represents the position tracker.  This class provides functionality for showing and positioning song position in the  main window.*//*!*/QmPositionBar::QmPositionBar(	QmMainWindow *parent,	QmStatusBar *status,	QmPlayer *player)	: QToolBar(parent),	  m_pStatusBar(status),	  m_pPlayer(player),	  m_PositionPressed(false),      m_PosText(""){	setHorizontalStretchable(true);	(void) new QLabel(tr(" Position "), this);	m_pTracker = new QSlider(0, 0, 1000, 0, Horizontal, this);	connect(m_pTracker, SIGNAL(valueChanged(int)), this, SLOT(positionChanged(int)));	connect(m_pTracker, SIGNAL(sliderPressed()), this, SLOT(positionPressed()));	connect(m_pTracker, SIGNAL(sliderReleased()), this, SLOT(positionReleased()));// 	connect(m_pPlayer, SIGNAL(secondsCount(int)), this, SLOT(setTotalSeconds(int)));// 	connect(m_pPlayer, SIGNAL(secondsPlaying(int)), this, SLOT(setSecondsPlayed(int)));	initialize(m_pPlayer);}/*!*/QmPositionBar::~QmPositionBar(){}/*!  If the player crashes (e.g. mpg123), it can be respawned, but a new object  will be allocated and the signals will have to be reconnected.  Use this function  to re-initialize the positionbar with connections to the new player object. */voidQmPositionBar::initialize(	QmPlayer *player){	m_pPlayer = player;	connect(m_pPlayer, SIGNAL(secondsCount(int)), this, SLOT(setTotalSeconds(int)));	connect(m_pPlayer, SIGNAL(secondsPlaying(int)), this, SLOT(setSecondsPlayed(int)));// 	connect(m_pPlayer, SIGNAL(frameCount(int)), this, SLOT(setTrackerEnd(int)));// 	connect(m_pPlayer, SIGNAL(framesLeft(int)), this, SLOT(setTrackerValue(int)));}/*!  Sets the current value of the position tracker to \a s,  unless the user is currently moving the position bar.*/voidQmPositionBar::setSecondsPlayed(	int s){    if ( ! m_PositionPressed )    {        m_pTracker->blockSignals( true );        m_pTracker->setValue(s);        QToolTip::remove( m_pTracker );        QToolTip::add( m_pTracker, positionText()  );        m_pTracker->blockSignals( false );    }}/*!  Sets the end (upper) value of the position tracker to \a s.*/voidQmPositionBar::setTotalSeconds(	int s){    m_pTracker->blockSignals( true );	m_pTracker->setMaxValue(s);    QToolTip::remove( m_pTracker );    QToolTip::add( m_pTracker, positionText()  );    m_pTracker->blockSignals( false );}/*!  Returns a text string saying "Position: " and the current position setting  in percentage.  This is used for tooltips and status bars.*/QStringQmPositionBar::positionText() {    int s = m_pTracker->value();    int m = s/60;    s %= 60;    int h = m/60;    m %= 60;        if (h > 0)        m_PosText.sprintf("%dh%.2dm%.2ds", h, m, s);    else if (m > 0)        m_PosText.sprintf("%.2dm%.2ds", m, s);    else         m_PosText.sprintf("%ds", s);    return m_PosText;}/*!  Adjust the position to \a v, this is called whenever the position  slider changes.*/voidQmPositionBar::positionChanged(	int ){//      if ( !m_PositionPressed )//          m_pPositionTimer->blockSignals( true );//  	m_Mixer.setPosition(v);//      if ( !m_PositionPressed )//          m_pPositionTimer->blockSignals( false );	    if ( !m_PositionPressed )        m_pPlayer->jump( m_pTracker->value() );    QToolTip::remove( m_pTracker );    QToolTip::add( m_pTracker, positionText()  );    m_pStatusBar->showMessage( positionText(), 2000 );}/*!  Updates the position information tooltip on the slider.  If \a in_status is true it will show show the position information  in the status bar as well using \a time as the timeout.*/voidQmPositionBar::updatePosition(	bool in_status,	int time){    QToolTip::remove( m_pTracker );    QToolTip::add( m_pTracker, positionText() );	    if ( in_status )        m_pStatusBar->showMessage( positionText(), time );    else        m_pStatusBar->showSongInfo();}/*!  This is called when the position slider is released.  This makes sure that  the position can be updated when it changes externally.  \sa updatePosition()*/voidQmPositionBar::positionReleased(){//      m_pPositionTimer->blockSignals( false );    m_PositionPressed = false;    m_pStatusBar->showNameStatus(true);    m_pPlayer->jump( m_pTracker->value() );    updatePosition( false );}/*!  This is called when the position slider is pressed.  This makes sure that  the position is not updated when it changes externally, i.e. the user can  change the position.    \sa updatePosition()*/voidQmPositionBar::positionPressed(){//      m_pPositionTimer->blockSignals( true );    m_PositionPressed = true;    updatePosition( true );}

⌨️ 快捷键说明

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