Commit 1e83df7e authored by Michael Pyne's avatar Michael Pyne
Browse files

Merge commit 'd4bf5912' into release/21.04

This pulls in a batch of bugfixes applied to master into the 21.04
release branch. Further bugfixes will be cherry picked.

Conflicts:
	CMakeLists.txt
parents 150f2578 d4bf5912
......@@ -533,10 +533,11 @@ void CollectionListItem::repaint() const
// CollectionListItem protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionListItem::CollectionListItem(CollectionList *parent, const FileHandle &file) :
PlaylistItem(parent),
m_shuttingDown(false)
CollectionListItem::CollectionListItem(CollectionList *parent, const FileHandle &file)
: PlaylistItem(parent)
, m_shuttingDown(false)
{
PlaylistItem::m_collectionItem = this;
parent->addToDict(file.absFilePath(), this);
sharedData()->fileHandle = file;
......@@ -564,6 +565,8 @@ CollectionListItem::~CollectionListItem()
l->removeStringFromDict(file().tag()->artist(), ArtistColumn);
l->removeStringFromDict(file().tag()->genre(), GenreColumn);
}
m_collectionItem = nullptr;
}
void CollectionListItem::addChildItem(PlaylistItem *child)
......
......@@ -88,13 +88,13 @@ HistoryPlaylistItem::HistoryPlaylistItem(CollectionListItem *item, Playlist *par
PlaylistItem(item, parent, after),
m_dateTime(QDateTime::currentDateTime())
{
setText(0, m_dateTime.toString());
setText(0, m_dateTime.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss")));
}
void HistoryPlaylistItem::setDateTime(const QDateTime &dt)
{
m_dateTime = dt;
setText(0, m_dateTime.toString());
setText(0, m_dateTime.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss")));
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -1658,12 +1658,16 @@ void Playlist::slotUpdateColumnWidths()
// Make sure that the column weights have been initialized before trying to
// update the columns.
QList<int> visibleColumns;
QVector<int> visibleColumns;
for(int i = 0; i < columnCount(); i++) {
if(!isColumnHidden(i))
visibleColumns.append(i);
}
if(visibleColumns.isEmpty()) {
return;
}
// convenience handler for deprecated text metrics
const auto textWidth = [](const QFontMetrics &fm, const QString &text) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
......@@ -1725,6 +1729,11 @@ void Playlist::slotUpdateColumnWidths()
foreach(int column, visibleColumns)
totalWeight += m_columnWeights[column];
// This can happen during startup, before we have the tracks loaded.
if(qFuzzyIsNull(totalWeight)) {
return;
}
// Computed a "weighted width" for each visible column. This would be the
// width if we didn't have to handle the cases of minimum and maximum widths.
......
......@@ -187,6 +187,12 @@ PlaylistBox::~PlaylistBox()
Cache::savePlaylists(l);
saveConfig();
// Some view modes use event filters onto sibling widgets which may be
// destroyed before the view mode.
// Manually delete the view modes instead.
qDeleteAll(m_viewModes);
m_viewModes.clear();
}
void PlaylistBox::raise(Playlist *playlist)
......
......@@ -52,7 +52,9 @@ PlaylistItem::~PlaylistItem()
// stark advantage of working reliably. I'll tell anyone who tries to
// optimize this, the timing issues can be *hard*. -- mpyne
m_collectionItem->removeChildItem(this);
if(m_collectionItem) {
m_collectionItem->removeChildItem(this);
}
if(m_playingItems.contains(this)) {
m_playingItems.removeAll(this);
......@@ -233,12 +235,13 @@ PlaylistItem::PlaylistItem(CollectionListItem *item, Playlist *parent, QTreeWidg
// This constructor should only be used by the CollectionList subclass.
PlaylistItem::PlaylistItem(CollectionList *parent) :
QTreeWidgetItem(parent),
m_watched(0)
PlaylistItem::PlaylistItem(CollectionList *parent)
: QTreeWidgetItem(parent)
// We *will* be this but we aren't yet; subclass will fix
, m_collectionItem(nullptr)
, m_watched(false)
{
d = new Data;
m_collectionItem = static_cast<CollectionListItem *>(this);
setFlags(flags() | Qt::ItemIsEditable | Qt::ItemIsDragEnabled);
}
......
......@@ -163,11 +163,6 @@ protected:
PlaylistItem(CollectionListItem *item, Playlist *parent);
PlaylistItem(CollectionListItem *item, Playlist *parent, QTreeWidgetItem *after);
/**
* This is the constructor that should be used by subclasses.
*/
PlaylistItem(CollectionList *parent);
/**
* See the class documentation for an explanation of construction and deletion
* of PlaylistItems.
......@@ -200,6 +195,12 @@ protected:
private:
DataPtr d;
/**
* This is the constructor that should be used by CollectionList.
*/
PlaylistItem(CollectionList *parent);
friend class CollectionList;
void setup(CollectionListItem *item);
CollectionListItem *m_collectionItem;
......
......@@ -25,8 +25,7 @@
#include <QMouseEvent>
#include <QLabel>
#include <QIcon>
#include <QFrame>
#include <QEvent>
#include <QToolButton>
#include <QPushButton>
#include <QStatusBar>
......@@ -67,18 +66,17 @@ StatusLabel::StatusLabel(const PlaylistInterface &currentPlaylist, QStatusBar *p
m_trackLabel->setTextFormat(Qt::PlainText);
parent->addPermanentWidget(m_trackLabel);
m_itemTimeLabel = new QLabel(this);
m_itemTimeLabel = new QToolButton(this);
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(QFrame::Box | QFrame::Sunken);
m_itemTimeLabel->installEventFilter(this);
m_itemTimeLabel->setAutoRaise(true);
connect(m_itemTimeLabel, &QAbstractButton::clicked, this, [this]() {
m_showTimeRemaining = !m_showTimeRemaining;
updateTime();
});
parent->addPermanentWidget(m_itemTimeLabel);
setItemTotalTime(0);
setItemCurrentTime(0);
QPushButton *jumpButton = new QPushButton(this);
jumpButton->setIcon(QIcon::fromTheme("go-jump"));
jumpButton->setFlat(true);
......@@ -87,7 +85,6 @@ StatusLabel::StatusLabel(const PlaylistInterface &currentPlaylist, QStatusBar *p
connect(jumpButton, &QPushButton::clicked, action("showPlaying"), &QAction::trigger);
parent->addPermanentWidget(jumpButton);
installEventFilter(this);
slotCurrentPlaylistHasChanged(currentPlaylist);
}
......@@ -103,6 +100,7 @@ void StatusLabel::slotPlayingItemHasChanged(const FileHandle &file)
setItemCurrentTime(0);
m_trackLabel->setText(tag->artist() + mid + tag->title());
updateTime();
}
void StatusLabel::slotCurrentPlaylistHasChanged(const PlaylistInterface &currentPlaylist)
......@@ -117,6 +115,23 @@ void StatusLabel::slotCurrentPlaylistHasChanged(const PlaylistInterface &current
QStringLiteral(" - ") +
formatTime(qint64(1000) * currentPlaylist.time())
);
updateTime();
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
////////////////////////////////////////////////////////////////////////////////
void StatusLabel::mouseReleaseEvent(QMouseEvent *ev)
{
if(ev->button() != Qt::LeftButton) {
return;
}
m_showTimeRemaining = !m_showTimeRemaining;
updateTime();
ev->accept();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -134,25 +149,4 @@ void StatusLabel::updateTime()
m_itemTimeLabel->setText(timeString);
}
bool StatusLabel::eventFilter(QObject *o, QEvent *e)
{
if(!o || !e)
return false;
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
if(e->type() == QEvent::MouseButtonRelease &&
mouseEvent->button() == Qt::LeftButton)
{
if(o == m_itemTimeLabel) {
m_showTimeRemaining = !m_showTimeRemaining;
updateTime();
}
else
action("showPlaying")->trigger();
return true;
}
return false;
}
// vim: set et sw=4 tw=0 sta:
......@@ -17,13 +17,14 @@
#ifndef JUK_STATUSLABEL_H
#define JUK_STATUSLABEL_H
#include <QStatusBar>
#include <QWidget>
class KSqueezedTextLabel;
class QEvent;
class QLabel;
class QStatusBar;
class QToolButton;
class FileHandle;
class PlaylistInterface;
......@@ -46,13 +47,15 @@ public slots:
void setItemTotalTime(qint64 time_msec) { m_itemTotalTime = time_msec; }
void setItemCurrentTime(qint64 time_msec) { m_itemCurrentTime = time_msec; updateTime(); }
protected:
void mouseReleaseEvent(QMouseEvent *) override;
private:
void updateTime();
virtual bool eventFilter(QObject *o, QEvent *e) override;
KSqueezedTextLabel *m_playlistLabel = nullptr;
QLabel *m_trackLabel = nullptr;
QLabel *m_itemTimeLabel = nullptr;
QToolButton *m_itemTimeLabel = nullptr;
int m_itemTotalTime = 0;
int m_itemCurrentTime = 0;
......
......@@ -43,7 +43,7 @@ ViewMode::ViewMode(PlaylistBox *b) :
ViewMode::~ViewMode()
{
removeEventFilter(m_playlistBox->viewport());
}
bool ViewMode::eventFilter(QObject *watched, QEvent *e)
......
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