From 314f1d5db53ae3a122ee4d5e2ed679775c76cfb8 Mon Sep 17 00:00:00 2001
From: sn0w <sn0w@sn0w.sh>
Date: Sat, 25 Apr 2020 03:12:13 +0200
Subject: [PATCH] Add support for toggling infobar album-art

---
 src/qtui/info_bar.cc | 22 ++++++++++++++++++----
 src/qtui/info_bar.h  |  5 ++++-
 src/qtui/menus.cc    |  6 ++++++
 src/qtui/settings.cc |  1 +
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/qtui/info_bar.cc b/src/qtui/info_bar.cc
index ea338e496..105a18cf2 100644
--- a/src/qtui/info_bar.cc
+++ b/src/qtui/info_bar.cc
@@ -188,10 +188,12 @@ InfoBar::InfoBar(QWidget * parent)
       m_stopped(true)
 {
     update_vis();
     setFixedHeight(ps.Height);
 
+    m_art_enabled = aud_get_bool("qtui", "infoarea_show_art");
+
     for (SongData & d : sd)
     {
         d.title.setTextFormat(Qt::PlainText);
         d.artist.setTextFormat(Qt::PlainText);
         d.album.setTextFormat(Qt::PlainText);
@@ -225,11 +227,11 @@ void InfoBar::paintEvent(QPaintEvent *)
 
     for (SongData & d : sd)
     {
         p.setOpacity((qreal)d.alpha / FadeSteps);
 
-        if (!d.art.isNull())
+        if (m_art_enabled && !d.art.isNull())
         {
             auto sz = d.art.size() / d.art.devicePixelRatio();
             int left = ps.Spacing + (ps.IconSize - sz.width()) / 2;
             int top = ps.Spacing + (ps.IconSize - sz.height()) / 2;
             p.drawPixmap(left, top, d.art);
@@ -245,20 +247,26 @@ void InfoBar::paintEvent(QPaintEvent *)
             d.title = QStaticText(metrics.elidedText(
                 d.orig_title, Qt::ElideRight,
                 width() - ps.VisWidth - ps.Height - ps.Spacing));
         }
 
+        int height = ps.Height;
+        if (!m_art_enabled)
+        {
+            height -= ps.IconSize;
+        }
+
         p.setPen(QColor(255, 255, 255));
-        p.drawStaticText(ps.Height, ps.Spacing, d.title);
+        p.drawStaticText(height, ps.Spacing, d.title);
 
         font.setPointSize(9);
         p.setFont(font);
 
-        p.drawStaticText(ps.Height, ps.Spacing + ps.IconSize / 2, d.artist);
+        p.drawStaticText(height, ps.Spacing + ps.IconSize / 2, d.artist);
 
         p.setPen(QColor(179, 179, 179));
-        p.drawStaticText(ps.Height, ps.Spacing + ps.IconSize * 3 / 4, d.album);
+        p.drawStaticText(height, ps.Spacing + ps.IconSize * 3 / 4, d.album);
     }
 }
 
 void InfoBar::update_title()
 {
@@ -329,5 +337,11 @@ void InfoBar::playback_stop_cb()
 
 void InfoBar::update_vis()
 {
     m_vis->enable(aud_get_bool("qtui", "infoarea_show_vis"));
 }
+
+void InfoBar::update_art()
+{
+    m_art_enabled = aud_get_bool("qtui", "infoarea_show_art");
+    update();
+}
diff --git a/src/qtui/info_bar.h b/src/qtui/info_bar.h
index 25941cf71..6ab21a3b6 100644
--- a/src/qtui/info_bar.h
+++ b/src/qtui/info_bar.h
@@ -43,16 +43,18 @@ private:
     void do_fade();
 
     void playback_ready_cb();
     void playback_stop_cb();
     void update_vis();
+    void update_art();
 
     const HookReceiver<InfoBar> hook1{"tuple change", this,
                                       &InfoBar::update_title},
         hook2{"playback ready", this, &InfoBar::playback_ready_cb},
         hook3{"playback stop", this, &InfoBar::playback_stop_cb},
-        hook4{"qtui toggle infoarea_vis", this, &InfoBar::update_vis};
+        hook4{"qtui toggle infoarea_vis", this, &InfoBar::update_vis},
+        hook5{"qtui toggle infoarea_art", this, &InfoBar::update_art};
 
     const Timer<InfoBar> fade_timer{TimerRate::Hz30, this, &InfoBar::do_fade};
 
     InfoVis * m_vis;
     const PixelSizes & ps;
@@ -71,8 +73,9 @@ private:
         Cur = 1
     }; /* index into SongData array */
 
     SongData sd[2];
     bool m_stopped;
+    bool m_art_enabled;
 };
 
 #endif
diff --git a/src/qtui/menus.cc b/src/qtui/menus.cc
index dcefed973..7ab174815 100644
--- a/src/qtui/menus.cc
+++ b/src/qtui/menus.cc
@@ -89,10 +89,14 @@ static void toggle_menubar() { hook_call("qtui toggle menubar", nullptr); }
 static void toggle_infoarea() { hook_call("qtui toggle infoarea", nullptr); }
 static void toggle_infoarea_vis()
 {
     hook_call("qtui toggle infoarea_vis", nullptr);
 }
+static void toggle_infoarea_art()
+{
+    hook_call("qtui toggle infoarea_art", nullptr);
+}
 static void toggle_statusbar() { hook_call("qtui toggle statusbar", nullptr); }
 static void toggle_remaining_time()
 {
     hook_call("qtui toggle remaining time", nullptr);
 }
@@ -247,10 +251,12 @@ QMenuBar * qtui_build_menubar(QWidget * parent)
                           {"qtui", "menu_visible"}, toggle_menubar),
         audqt::MenuToggle({N_("Show I_nfo Bar"), nullptr, "Shift+Ctrl+I"},
                           {"qtui", "infoarea_visible"}, toggle_infoarea),
         audqt::MenuToggle({N_("Show Info Bar Vis_ualization")},
                           {"qtui", "infoarea_show_vis"}, toggle_infoarea_vis),
+        audqt::MenuToggle({N_("Show Info Bar Album Art")},
+                          {"qtui", "infoarea_show_art"}, toggle_infoarea_art),
         audqt::MenuToggle({N_("Show _Status Bar"), nullptr, "Shift+Ctrl+S"},
                           {"qtui", "statusbar_visible"}, toggle_statusbar),
         audqt::MenuSep(),
         audqt::MenuToggle(
             {N_("Show _Remaining Time"), nullptr, "Shift+Ctrl+R"},
diff --git a/src/qtui/settings.cc b/src/qtui/settings.cc
index 0bbcff330..5ef5fce96 100644
--- a/src/qtui/settings.cc
+++ b/src/qtui/settings.cc
@@ -27,10 +27,11 @@
 #include <QDesktopWidget>
 
 const char * const qtui_defaults[] = {
     // clang-format off
     "infoarea_show_vis", "TRUE",
+    "infoarea_show_art", "TRUE",
     "infoarea_visible", "TRUE",
     "menu_visible", "TRUE",
     "playlist_tabs_visible", aud::numeric_string<PlaylistTabVisibility::AutoHide>::str,
     "statusbar_visible", "TRUE",
     "entry_count_visible", "FALSE",
-- 
2.26.2

