[kde-doc-english] [juk/Applications/16.04] /: Ensure Now Playing bar shows text even with hiDPI/big fonts.

Michael Pyne mpyne at kde.org
Tue Apr 26 01:01:24 UTC 2016


Git commit f3606f835773627036e5e9e0513f2e3cecdb4f52 by Michael Pyne.
Committed on 26/04/2016 at 00:58.
Pushed by mpyne into branch 'Applications/16.04'.

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

M  +1    -1    main.cpp
M  +24   -16   nowplaying.cpp
M  +1    -1    nowplaying.h

http://commits.kde.org/juk/f3606f835773627036e5e9e0513f2e3cecdb4f52

diff --git a/main.cpp b/main.cpp
index ef3080a..2c3d5e2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -51,7 +51,7 @@ static const char sho[]         = I18N_NOOP("MPRIS2 Interface implementation.");
 int main(int argc, char *argv[])
 {
     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"),
                          KLocalizedString(),
                          "http://www.kde.org/applications/multimedia/juk/");
diff --git a/nowplaying.cpp b/nowplaying.cpp
index d5bf63b..ec3a51e 100644
--- a/nowplaying.cpp
+++ b/nowplaying.cpp
@@ -39,6 +39,7 @@
 #include <QUrl>
 #include <QList>
 #include <QTextDocument>
+#include <QFontMetrics>
 
 #include "playlistcollection.h"
 #include "playlistitem.h"
@@ -47,11 +48,9 @@
 #include "tag.h"
 #include "collectionlist.h"
 
-static const int imageSize = 64;
-
-struct Line : public QFrame
-{
-    Line(QWidget *parent) : QFrame(parent) { setFrameShape(VLine); }
+// Anon namespace to hide symbol from outside this translation unit
+namespace {
+    static int g_imageSize = 64;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -72,11 +71,17 @@ NowPlaying::NowPlaying(QWidget *parent, PlaylistCollection *collection) :
 
     layout->setMargin(0);
     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 TrackItem(this), 2);
-    layout->addWidget(new Line(this), 0);
 
     hide();
 }
@@ -120,7 +125,7 @@ CoverItem::CoverItem(NowPlaying *parent) :
     QLabel(parent),
     NowPlayingItem(parent)
 {
-    setObjectName( QLatin1String("CoverItem" ));
+    setObjectName(QLatin1String("CoverItem"));
     setFixedHeight(parent->height() - parent->layout()->margin() * 2);
     setMargin(1);
     setAcceptDrops(true);
@@ -134,7 +139,7 @@ void CoverItem::update(const FileHandle &file)
         show();
         setPixmap(
             file.coverInfo()->pixmap(CoverInfo::Thumbnail)
-            .scaled(imageSize, imageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+            .scaled(g_imageSize, g_imageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
     }
     else
         hide();
@@ -237,7 +242,7 @@ TrackItem::TrackItem(NowPlaying *parent) :
     QWidget(parent),
     NowPlayingItem(parent)
 {
-    setObjectName( QLatin1String("TrackItem" ));
+    setObjectName(QLatin1String("TrackItem"));
     setFixedHeight(parent->height() - parent->layout()->margin() * 2);
     setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
 
@@ -249,7 +254,7 @@ TrackItem::TrackItem(NowPlaying *parent) :
     m_label->setTextInteractionFlags(Qt::LinksAccessibleByMouse|Qt::LinksAccessibleByKeyboard);
 
     layout->addStretch();
-    layout->addWidget(m_label);
+    layout->addWidget(m_label, 1);
     layout->addStretch();
 
     connect(m_label, SIGNAL(linkActivated(QString)), this,
@@ -269,7 +274,7 @@ void TrackItem::update(const FileHandle &file)
 
 void TrackItem::slotOpenLink(const QString &link)
 {
-    PlaylistCollection *collection = NowPlayingItem::parent()->collection();
+    PlaylistCollection *collection = parentManager()->collection();
 
     if(link == "artist")
         collection->showMore(m_file.tag()->artist());
@@ -301,23 +306,26 @@ void TrackItem::slotUpdate()
         "<br />"
         "<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("</font>");
+    int parentHeight = parentManager()->contentsRect().height();
+    int neededHeight = 0;
 
     do {
         m_label->setText(format.arg(size).arg(title).arg(size - 2)
                          .arg(artist).arg(separator).arg(album));
         --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()
 {
-    PlaylistCollection *collection = NowPlayingItem::parent()->collection();
+    PlaylistCollection *collection = parentManager()->collection();
     Q_ASSERT(collection);
     collection->clearShowMore();
 }
diff --git a/nowplaying.h b/nowplaying.h
index a671f55..d77a86a 100644
--- a/nowplaying.h
+++ b/nowplaying.h
@@ -81,7 +81,7 @@ class NowPlayingItem
 public:
     virtual ~NowPlayingItem() {}
     virtual void update(const FileHandle &file) = 0;
-    NowPlaying *parent() const { return m_parent; }
+    NowPlaying *parentManager() const { return m_parent; }
 protected:
     NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); }
 private:


More information about the kde-doc-english mailing list