Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 87cf04a1 authored by Michael Pyne's avatar Michael Pyne

Port status label away from KHBox.

parent ec8d20a3
......@@ -16,11 +16,11 @@
#include "statuslabel.h"
#include <QAction>
#include <kiconloader.h>
#include <ksqueezedtextlabel.h>
#include <klocale.h>
#include <QAction>
#include <QMouseEvent>
#include <QLabel>
#include <QFrame>
......@@ -41,20 +41,23 @@ using namespace ActionCollection;
////////////////////////////////////////////////////////////////////////////////
StatusLabel::StatusLabel(PlaylistInterface *playlist, QWidget *parent) :
KHBox(parent),
QWidget(parent),
PlaylistObserver(playlist),
m_showTimeRemaining(false)
{
auto hboxLayout = new QHBoxLayout(this);
QFrame *trackAndPlaylist = new QFrame(this);
trackAndPlaylist->setFrameStyle(Box | Sunken);
hboxLayout->addWidget(trackAndPlaylist);
trackAndPlaylist->setFrameStyle(QFrame::Box | QFrame::Sunken);
trackAndPlaylist->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Make sure that we have enough of a margin to suffice for the borders,
// hence the "lineWidth() * 2"
QHBoxLayout *trackAndPlaylistLayout = new QHBoxLayout( trackAndPlaylist );
trackAndPlaylistLayout->setMargin( trackAndPlaylist->lineWidth() * 2 );
trackAndPlaylistLayout->setSpacing( 5 );
trackAndPlaylistLayout->setObjectName( QLatin1String( "trackAndPlaylistLayout" ));
QHBoxLayout *trackAndPlaylistLayout = new QHBoxLayout(trackAndPlaylist);
trackAndPlaylistLayout->setMargin(trackAndPlaylist->lineWidth() * 2);
trackAndPlaylistLayout->setSpacing(5);
trackAndPlaylistLayout->setObjectName(QLatin1String("trackAndPlaylistLayout"));
trackAndPlaylistLayout->addSpacing(5);
m_playlistLabel = new KSqueezedTextLabel(trackAndPlaylist);
......@@ -72,25 +75,30 @@ StatusLabel::StatusLabel(PlaylistInterface *playlist, QWidget *parent) :
trackAndPlaylistLayout->addSpacing(5);
m_itemTimeLabel = new QLabel(this);
hboxLayout->addWidget(m_itemTimeLabel);
QFontMetrics fontMetrics(font());
m_itemTimeLabel->setAlignment(Qt::AlignCenter);
m_itemTimeLabel->setMinimumWidth(fontMetrics.boundingRect("000:00 / 000:00").width());
m_itemTimeLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
m_itemTimeLabel->setFrameStyle(Box | Sunken);
m_itemTimeLabel->setFrameStyle(QFrame::Box | QFrame::Sunken);
m_itemTimeLabel->installEventFilter(this);
setItemTotalTime(0);
setItemCurrentTime(0);
KHBox *jumpBox = new KHBox(this);
jumpBox->setFrameStyle(Box | Sunken);
auto jumpBox = new QFrame(this);
hboxLayout->addWidget(jumpBox);
jumpBox->setFrameStyle(QFrame::Box | QFrame::Sunken);
jumpBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
auto jumpBoxHLayout = new QHBoxLayout(jumpBox);
QPushButton *jumpButton = new QPushButton(jumpBox);
jumpBoxHLayout->addWidget(jumpButton);
jumpButton->setIcon(SmallIcon("go-up"));
jumpButton->setFlat(true);
jumpButton->setToolTip( i18n("Jump to the currently playing item"));
jumpButton->setToolTip(i18n("Jump to the currently playing item"));
connect(jumpButton, SIGNAL(clicked()), action("showPlaying"), SLOT(trigger()));
installEventFilter(this);
......@@ -98,24 +106,21 @@ StatusLabel::StatusLabel(PlaylistInterface *playlist, QWidget *parent) :
updateData();
}
StatusLabel::~StatusLabel()
{
}
void StatusLabel::updateCurrent()
{
if(playlist()->playing()) {
FileHandle file = playlist()->currentFile();
if(!playlist()->playing()) {
return;
}
QString mid = file.tag()->artist().isEmpty() || file.tag()->title().isEmpty()
? QString::null : QString(" - "); //krazy:exclude=nullstrassign for old broken gcc
FileHandle file = playlist()->currentFile();
QString text = file.tag()->artist() + mid + file.tag()->title();
QString mid = file.tag()->artist().isEmpty() || file.tag()->title().isEmpty()
? QString::null : QString(" - "); //krazy:exclude=nullstrassign for old broken gcc
m_trackLabel->setText(text);
m_playlistLabel->setText(playlist()->name().simplified());
}
QString text = file.tag()->artist() + mid + file.tag()->title();
m_trackLabel->setText(text);
m_playlistLabel->setText(playlist()->name().simplified());
}
void StatusLabel::updateData()
......@@ -123,31 +128,33 @@ void StatusLabel::updateData()
updateCurrent();
if(!playlist()->playing()) {
setItemTotalTime(0);
setItemCurrentTime(0);
int time = playlist()->time();
return;
}
int days = time / (60 * 60 * 24);
int hours = time / (60 * 60) % 24;
int minutes = time / 60 % 60;
int seconds = time % 60;
setItemTotalTime(0);
setItemCurrentTime(0);
QString timeString;
int time = playlist()->time();
if(days > 0) {
timeString = i18np("1 day", "%1 days", days);
timeString.append(" ");
}
int days = time / (60 * 60 * 24);
int hours = time / (60 * 60) % 24;
int minutes = time / 60 % 60;
int seconds = time % 60;
if(days > 0 || hours > 0)
timeString.append(QString().sprintf("%1d:%02d:%02d", hours, minutes, seconds));
else
timeString.append(QString().sprintf("%1d:%02d", minutes, seconds));
QString timeString;
m_playlistLabel->setText(playlist()->name());
m_trackLabel->setText(i18np("1 item", "%1 items", playlist()->count()) + " - " + timeString);
if(days > 0) {
timeString = i18np("1 day", "%1 days", days);
timeString.append(" ");
}
if(days > 0 || hours > 0)
timeString.append(QString().sprintf("%1d:%02d:%02d", hours, minutes, seconds));
else
timeString.append(QString().sprintf("%1d:%02d", minutes, seconds));
m_playlistLabel->setText(playlist()->name());
m_trackLabel->setText(i18np("1 item", "%1 items", playlist()->count()) + " - " + timeString);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -197,6 +204,7 @@ bool StatusLabel::eventFilter(QObject *o, QEvent *e)
return false;
}
// TODO: Look at QLocale or KCoreAddons::format for showing time durations
QString StatusLabel::formatTime(int minutes, int seconds) // static
{
QString m = QString::number(minutes);
......
......@@ -14,27 +14,23 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STATUSLABEL_H
#define STATUSLABEL_H
#ifndef JUK_STATUSLABEL_H
#define JUK_STATUSLABEL_H
#include "playlistinterface.h"
#include <khbox.h>
//Added by qt3to4:
#include <QLabel>
#include <QEvent>
#include <QWidget>
class QEvent;
class QLabel;
class KSqueezedTextLabel;
class StatusLabel : public KHBox, public PlaylistObserver
class StatusLabel : public QWidget, public PlaylistObserver
{
Q_OBJECT
public:
explicit StatusLabel(PlaylistInterface *playlist, QWidget *parent = 0);
virtual ~StatusLabel();
explicit StatusLabel(PlaylistInterface *playlist, QWidget *parent = nullptr);
virtual void updateCurrent();
public slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment