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

📄 qmstatusbar.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
字号:
/* qmstatusbar.cpp * * $Id: qmstatusbar.cpp,v 1.14 2002/03/30 11:49:07 kyllingstad 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 "qmstatusbar.h"#include "qmmainwindow.h"#include "qmplayer.h"#include "message.h"#include "util.h"#include <qtoolbar.h>#include <qlabel.h>#include <qtimer.h>#include <qfontmetrics.h>#include <qpainter.h>/* Disables false warning in Visual Studio about dynamic_cast */#ifdef _WS_WIN_#pragma warning(disable: 4541)#endif/** * @file qmstatusbar.cpp * @brief The text field below the toolbar showing playlist song etc. *//*!  \class QmStatusBar qmstatusbar.h  \brief Represents the status bar.  This class provides functionality for showing a status bar in the main window.  Note that, despite the name, this class is derived from QToolBar.  So, it's really  a tool bar, but it's used as a status bar.*//*!*/QmStatusBar::QmStatusBar(	QmMainWindow *parent,	QmPlayer *player)	: QToolBar(parent),	  m_pMainWindow(parent),	  m_ShowNameStatus(true),	  m_pPlayer(player){	setHorizontalStretchable(true);	    m_pStatus = new QLabel(this);    m_pStatus->setFrameStyle(QFrame::Panel | QFrame::Sunken);	m_pStatus->setFixedHeight(m_pStatus->sizeHint().height());	m_pStatus->setBackgroundColor(colorGroup().base());    m_pStatusTime = new QLabel(this);    m_pStatusTime->setFrameStyle(QFrame::Panel | QFrame::Sunken);	m_pStatusTime->setFixedHeight(m_pStatusTime->sizeHint().height());	m_pStatusTime->setBackgroundColor(colorGroup().base());	// width returns too small value, add 5	m_pStatusTime->setFixedWidth(fontMetrics().width("00:00/00:00")+5);     m_pStatusTimer = new QTimer( this );    connect( m_pStatusTimer, SIGNAL( timeout() ), this, SLOT( resetStatus() ) );	initialize(m_pPlayer);}/*!*/QmStatusBar::~QmStatusBar(){}/*!  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 statusbar with connections to the new player object. */voidQmStatusBar::initialize(	QmPlayer *player){	m_pPlayer = player;	connect(m_pPlayer, SIGNAL(secondsCount(int)), this, SLOT(secondsCount(int)));	connect(m_pPlayer, SIGNAL(secondsPlaying(int)), this, SLOT(secondsPlaying(int)));}/*!  Updates the window caption according to the song playing.*/voidQmStatusBar::updateCaption(){	// have song title first since it might be used in taskbars or small title bars    if ( m_pMainWindow->playingState() == QmMainWindow::Playing ||         m_pMainWindow->playingState() == QmMainWindow::Paused )    {		m_pMainWindow->setCaption( m_NameString + " (Apollo)" );    }	else		m_pMainWindow->setCaption( "Apollo" );}/*!  Updates the status bar.  Typically, playing info is shown, such as  time played and time remaining, but other messages may also be shown,  such as when adjusting the volume.*/voidQmStatusBar::updateStatus(){    if ( m_ShowNameStatus && !m_NameString.isEmpty())    {		m_pStatus->setText(m_NameString);        if ( (m_pMainWindow->playingState() == QmMainWindow::Playing ||			  m_pMainWindow->playingState() == QmMainWindow::Paused) &&			 (!m_TimeString.isEmpty() && !m_TimeTotalString.isEmpty() ) )		{			m_pStatusTime->setText(m_TimeString+"/"+m_TimeTotalString);        }    }    else        m_pStatus->setText( m_MessageString );}/*!  Shows a message in the status bar, this will replace any song info or earlier messages.  If \a msecs is negative the text is permanent(that is until the song info or another message is show),  if not this is used as a timer, when the timer times out it will display the song info again.*/voidQmStatusBar::showMessage(	const QString &msg,	int msecs ){    if ( msecs > 0 )        m_pStatusTimer->start( msecs, true );    m_MessageString = msg;    m_ShowNameStatus = false;    updateStatus();}/*!  Resets the status area to show the song info, the is called by the timer on timeout.  \sa showMessage(), showSongInfo()*/voidQmStatusBar::resetStatus(){    showSongInfo();}/*!  Displays the song info in the status area, any messages currently shown will be replaced.  \sa updateStatus()*/voidQmStatusBar::showSongInfo(){    m_ShowNameStatus = true;    updateStatus();}/*!  Updates the status bar with play info, that is, how many seconds  that has been played.*/voidQmStatusBar::secondsPlaying(	int s){	m_SecondsPlaying = s;	secondsToTimeString(s, m_TimeString);    updateStatus();}voidQmStatusBar::showNameStatus(	bool s){    m_ShowNameStatus = s;}voidQmStatusBar::clearTime(){    m_TimeString 	  = QString::null;    m_TimeTotalString = QString::null;}voidQmStatusBar::clearName(){    m_NameString 	  = QString::null;	m_pStatus->clear();}/*!  Called by the player whenever the second counter changes, this will update the status bar  song info with the new time.*/voidQmStatusBar::secondsCount(	int s){	m_TotalSeconds = s;	secondsToTimeString(s, m_TimeTotalString);	m_pStatusTime->setFixedWidth(fontMetrics().width(s>=60*60?"0:00:00/0:00:00":"00:00/00:00")+5);	// How can one get Toolbar insets?  Use 13 for now.	m_pStatus->setFixedWidth(width()-m_pStatusTime->width()-13);    updateStatus();}/*!  resize the labels*/voidQmStatusBar::resizeEvent ( QResizeEvent *e ){	m_pStatusTime->setFixedWidth(fontMetrics().width(m_TotalSeconds>=60*60?"0:00:00/0:00:00":"00:00/00:00")+5);	m_pStatus->setFixedWidth(width()-m_pStatusTime->width()-13);	QToolBar::resizeEvent(e);}/*!  Updates status bar and window caption with the song title  \a title.  \sa updateStatus(), updateCaption()*/voidQmStatusBar::setSongTitle(	const QString &title ){	m_NameString = title;		updateStatus();	updateCaption();}intQmStatusBar::secondsPlaying() const{	return m_pMainWindow->isPlaying() ? m_SecondsPlaying : -1;}// rk: width returned is too small// void// QmStatusBar::paintEvent(QPaintEvent *e)// {// 	if (m_TimeFieldDirty) {// 		m_TimeFieldDirty = false;// 		QPainter paint(this);// 		m_pStatusTime->setFixedWidth(paint.fontMetrics().width(m_TotalSeconds>=60*60?"0:00:00/0:00:00":"00:00/00:00")); // 	}// 	QToolBar::paintEvent(e);// }

⌨️ 快捷键说明

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