Commit f3606f83 authored by Michael Pyne's avatar Michael Pyne

Ensure Now Playing bar shows text even with hiDPI/big fonts.

Note the fix only applies to KDE4-based desktops as JuK is still not
ported to KF5.

BUG:350460
GUI:
FIXED-IN:16.04.1
parent e20fd7da
...@@ -51,7 +51,7 @@ static const char sho[] = I18N_NOOP("MPRIS2 Interface implementation."); ...@@ -51,7 +51,7 @@ static const char sho[] = I18N_NOOP("MPRIS2 Interface implementation.");
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
KAboutData aboutData("juk", 0, ki18n("JuK"), KAboutData aboutData("juk", 0, ki18n("JuK"),
"3.12", ki18n(description), KAboutData::License_GPL, "3.12.1", ki18n(description), KAboutData::License_GPL,
ki18n("© 2002–2014, Scott Wheeler, Michael Pyne, and others"), ki18n("© 2002–2014, Scott Wheeler, Michael Pyne, and others"),
KLocalizedString(), KLocalizedString(),
"http://www.kde.org/applications/multimedia/juk/"); "http://www.kde.org/applications/multimedia/juk/");
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <QUrl> #include <QUrl>
#include <QList> #include <QList>
#include <QTextDocument> #include <QTextDocument>
#include <QFontMetrics>
#include "playlistcollection.h" #include "playlistcollection.h"
#include "playlistitem.h" #include "playlistitem.h"
...@@ -47,11 +48,9 @@ ...@@ -47,11 +48,9 @@
#include "tag.h" #include "tag.h"
#include "collectionlist.h" #include "collectionlist.h"
static const int imageSize = 64; // Anon namespace to hide symbol from outside this translation unit
namespace {
struct Line : public QFrame static int g_imageSize = 64;
{
Line(QWidget *parent) : QFrame(parent) { setFrameShape(VLine); }
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -72,11 +71,17 @@ NowPlaying::NowPlaying(QWidget *parent, PlaylistCollection *collection) : ...@@ -72,11 +71,17 @@ NowPlaying::NowPlaying(QWidget *parent, PlaylistCollection *collection) :
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(3); layout->setSpacing(3);
setFixedHeight(imageSize + 2);
// With HiDPI the text might actually be bigger... try to account for
// that.
QFont defaultLargeFont(KGlobalSettings::largeFont(QLatin1String("XXXXXXX")));
const QFontMetrics fm(defaultLargeFont, this);
g_imageSize = qMax(g_imageSize, fm.lineSpacing());
setFixedHeight(g_imageSize + 2);
layout->addWidget(new CoverItem(this), 0); layout->addWidget(new CoverItem(this), 0);
layout->addWidget(new TrackItem(this), 2); layout->addWidget(new TrackItem(this), 2);
layout->addWidget(new Line(this), 0);
hide(); hide();
} }
...@@ -120,7 +125,7 @@ CoverItem::CoverItem(NowPlaying *parent) : ...@@ -120,7 +125,7 @@ CoverItem::CoverItem(NowPlaying *parent) :
QLabel(parent), QLabel(parent),
NowPlayingItem(parent) NowPlayingItem(parent)
{ {
setObjectName( QLatin1String("CoverItem" )); setObjectName(QLatin1String("CoverItem"));
setFixedHeight(parent->height() - parent->layout()->margin() * 2); setFixedHeight(parent->height() - parent->layout()->margin() * 2);
setMargin(1); setMargin(1);
setAcceptDrops(true); setAcceptDrops(true);
...@@ -134,7 +139,7 @@ void CoverItem::update(const FileHandle &file) ...@@ -134,7 +139,7 @@ void CoverItem::update(const FileHandle &file)
show(); show();
setPixmap( setPixmap(
file.coverInfo()->pixmap(CoverInfo::Thumbnail) file.coverInfo()->pixmap(CoverInfo::Thumbnail)
.scaled(imageSize, imageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); .scaled(g_imageSize, g_imageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
} }
else else
hide(); hide();
...@@ -237,7 +242,7 @@ TrackItem::TrackItem(NowPlaying *parent) : ...@@ -237,7 +242,7 @@ TrackItem::TrackItem(NowPlaying *parent) :
QWidget(parent), QWidget(parent),
NowPlayingItem(parent) NowPlayingItem(parent)
{ {
setObjectName( QLatin1String("TrackItem" )); setObjectName(QLatin1String("TrackItem"));
setFixedHeight(parent->height() - parent->layout()->margin() * 2); setFixedHeight(parent->height() - parent->layout()->margin() * 2);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
...@@ -249,7 +254,7 @@ TrackItem::TrackItem(NowPlaying *parent) : ...@@ -249,7 +254,7 @@ TrackItem::TrackItem(NowPlaying *parent) :
m_label->setTextInteractionFlags(Qt::LinksAccessibleByMouse|Qt::LinksAccessibleByKeyboard); m_label->setTextInteractionFlags(Qt::LinksAccessibleByMouse|Qt::LinksAccessibleByKeyboard);
layout->addStretch(); layout->addStretch();
layout->addWidget(m_label); layout->addWidget(m_label, 1);
layout->addStretch(); layout->addStretch();
connect(m_label, SIGNAL(linkActivated(QString)), this, connect(m_label, SIGNAL(linkActivated(QString)), this,
...@@ -269,7 +274,7 @@ void TrackItem::update(const FileHandle &file) ...@@ -269,7 +274,7 @@ void TrackItem::update(const FileHandle &file)
void TrackItem::slotOpenLink(const QString &link) void TrackItem::slotOpenLink(const QString &link)
{ {
PlaylistCollection *collection = NowPlayingItem::parent()->collection(); PlaylistCollection *collection = parentManager()->collection();
if(link == "artist") if(link == "artist")
collection->showMore(m_file.tag()->artist()); collection->showMore(m_file.tag()->artist());
...@@ -301,23 +306,26 @@ void TrackItem::slotUpdate() ...@@ -301,23 +306,26 @@ void TrackItem::slotUpdate()
"<br />" "<br />"
"<font size=\"+%3\"><b><a href=\"artist\">%4</a>%5<a href=\"album\">%6</a></b>"; "<font size=\"+%3\"><b><a href=\"artist\">%4</a>%5<a href=\"album\">%6</a></b>";
if(NowPlayingItem::parent()->collection()->showMoreActive()) if(parentManager()->collection()->showMoreActive())
format.append(QString(" (<a href=\"clear\">%1</a>)").arg(i18n("back to playlist"))); format.append(QString(" (<a href=\"clear\">%1</a>)").arg(i18n("back to playlist")));
format.append("</font>"); format.append("</font>");
int parentHeight = parentManager()->contentsRect().height();
int neededHeight = 0;
do { do {
m_label->setText(format.arg(size).arg(title).arg(size - 2) m_label->setText(format.arg(size).arg(title).arg(size - 2)
.arg(artist).arg(separator).arg(album)); .arg(artist).arg(separator).arg(album));
--size; --size;
} while(m_label->heightForWidth(m_label->width()) > imageSize && size >= 0); neededHeight = m_label->heightForWidth(m_label->width());
} while(neededHeight > parentHeight && size >= -1);
m_label->setFixedHeight(qMin(imageSize, m_label->heightForWidth(m_label->width()))); m_label->setFixedHeight(qMin(neededHeight, parentHeight));
} }
void TrackItem::slotClearShowMore() void TrackItem::slotClearShowMore()
{ {
PlaylistCollection *collection = NowPlayingItem::parent()->collection(); PlaylistCollection *collection = parentManager()->collection();
Q_ASSERT(collection); Q_ASSERT(collection);
collection->clearShowMore(); collection->clearShowMore();
} }
......
...@@ -81,7 +81,7 @@ class NowPlayingItem ...@@ -81,7 +81,7 @@ class NowPlayingItem
public: public:
virtual ~NowPlayingItem() {} virtual ~NowPlayingItem() {}
virtual void update(const FileHandle &file) = 0; virtual void update(const FileHandle &file) = 0;
NowPlaying *parent() const { return m_parent; } NowPlaying *parentManager() const { return m_parent; }
protected: protected:
NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); } NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); }
private: private:
......
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