Skip to content

Commit 98234a9

Browse files
qtui: Allow hiding the album art in info bar
Based on the patch by "sn0w sn0w" who suggested it here: https://redmine.audacious-media-player.org/boards/1/topics/2518
1 parent 98cce52 commit 98234a9

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

src/qtui/info_bar.cc

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ InfoBar::InfoBar(QWidget * parent)
192192
update_vis();
193193
setFixedHeight(ps.Height);
194194

195+
m_art_enabled = aud_get_bool("qtui", "infoarea_show_art");
196+
195197
for (SongData & d : sd)
196198
{
197199
d.title.setTextFormat(Qt::PlainText);
@@ -213,10 +215,7 @@ InfoBar::InfoBar(QWidget * parent)
213215

214216
void InfoBar::resizeEvent(QResizeEvent *)
215217
{
216-
// re-ellipsize text on next paintEvent
217-
for (SongData & d : sd)
218-
d.title.setText(QString());
219-
218+
reellipsize_title();
220219
m_vis->move(width() - ps.VisWidth, 0);
221220
}
222221

@@ -225,13 +224,15 @@ void InfoBar::paintEvent(QPaintEvent *)
225224
QPainter p(this);
226225

227226
int viswidth = m_vis->isVisible() ? ps.VisWidth : 0;
227+
int offset = m_art_enabled ? ps.Height : ps.Spacing;
228+
228229
p.fillRect(0, 0, width() - viswidth, ps.Height, m_vis->gradient());
229230

230231
for (SongData & d : sd)
231232
{
232233
p.setOpacity((qreal)d.alpha / FadeSteps);
233234

234-
if (!d.art.isNull())
235+
if (m_art_enabled && !d.art.isNull())
235236
{
236237
auto sz = d.art.size() / d.art.devicePixelRatio();
237238
int left = ps.Spacing + (ps.IconSize - sz.width()) / 2;
@@ -248,19 +249,19 @@ void InfoBar::paintEvent(QPaintEvent *)
248249
QFontMetrics metrics = p.fontMetrics();
249250
d.title = QStaticText(metrics.elidedText(
250251
d.orig_title, Qt::ElideRight,
251-
width() - viswidth - ps.Height - ps.Spacing));
252+
width() - viswidth - offset - ps.Spacing));
252253
}
253254

254255
p.setPen(QColor(255, 255, 255));
255-
p.drawStaticText(ps.Height, ps.Spacing, d.title);
256+
p.drawStaticText(offset, ps.Spacing, d.title);
256257

257258
font.setPointSize(9);
258259
p.setFont(font);
259260

260-
p.drawStaticText(ps.Height, ps.Spacing + ps.IconSize / 2, d.artist);
261+
p.drawStaticText(offset, ps.Spacing + ps.IconSize / 2, d.artist);
261262

262263
p.setPen(QColor(179, 179, 179));
263-
p.drawStaticText(ps.Height, ps.Spacing + ps.IconSize * 3 / 4, d.album);
264+
p.drawStaticText(offset, ps.Spacing + ps.IconSize * 3 / 4, d.album);
264265
}
265266
}
266267

@@ -331,12 +332,23 @@ void InfoBar::playback_stop_cb()
331332
fade_timer.start();
332333
}
333334

334-
void InfoBar::update_vis()
335+
void InfoBar::reellipsize_title()
335336
{
336337
// re-ellipsize text on next paintEvent
337338
for (SongData & d : sd)
338339
d.title.setText(QString());
340+
}
339341

342+
void InfoBar::update_vis()
343+
{
344+
reellipsize_title();
340345
m_vis->enable(aud_get_bool("qtui", "infoarea_show_vis"));
341346
update();
342347
}
348+
349+
void InfoBar::update_art()
350+
{
351+
reellipsize_title();
352+
m_art_enabled = aud_get_bool("qtui", "infoarea_show_art");
353+
update();
354+
}

src/qtui/info_bar.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ class InfoBar : public QWidget
4444

4545
void playback_ready_cb();
4646
void playback_stop_cb();
47+
void reellipsize_title();
4748
void update_vis();
49+
void update_art();
4850

49-
const HookReceiver<InfoBar> hook1{"tuple change", this,
50-
&InfoBar::update_title},
51+
const HookReceiver<InfoBar>
52+
hook1{"tuple change", this, &InfoBar::update_title},
5153
hook2{"playback ready", this, &InfoBar::playback_ready_cb},
5254
hook3{"playback stop", this, &InfoBar::playback_stop_cb},
53-
hook4{"qtui toggle infoarea_vis", this, &InfoBar::update_vis};
55+
hook4{"qtui toggle infoarea_vis", this, &InfoBar::update_vis},
56+
hook5{"qtui toggle infoarea_art", this, &InfoBar::update_art};
5457

5558
const Timer<InfoBar> fade_timer{TimerRate::Hz30, this, &InfoBar::do_fade};
5659

@@ -73,6 +76,7 @@ class InfoBar : public QWidget
7376

7477
SongData sd[2];
7578
bool m_stopped;
79+
bool m_art_enabled;
7680
};
7781

7882
#endif

src/qtui/menus.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ static void toggle_infoarea_vis()
9191
{
9292
hook_call("qtui toggle infoarea_vis", nullptr);
9393
}
94+
static void toggle_infoarea_art()
95+
{
96+
hook_call("qtui toggle infoarea_art", nullptr);
97+
}
9498
static void toggle_statusbar() { hook_call("qtui toggle statusbar", nullptr); }
9599
static void toggle_remaining_time()
96100
{
@@ -257,6 +261,8 @@ QMenuBar * qtui_build_menubar(QWidget * parent)
257261
{"qtui", "infoarea_visible"}, toggle_infoarea),
258262
audqt::MenuToggle({N_("Show Info Bar Vis_ualization")},
259263
{"qtui", "infoarea_show_vis"}, toggle_infoarea_vis),
264+
audqt::MenuToggle({N_("Show Info Bar _Album Art")},
265+
{"qtui", "infoarea_show_art"}, toggle_infoarea_art),
260266
audqt::MenuToggle({N_("Show _Status Bar"), nullptr, "Shift+Ctrl+S"},
261267
{"qtui", "statusbar_visible"}, toggle_statusbar),
262268
audqt::MenuSep(),

src/qtui/settings.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
const char * const qtui_defaults[] = {
3030
// clang-format off
3131
"infoarea_show_vis", "TRUE",
32+
"infoarea_show_art", "TRUE",
3233
"infoarea_visible", "TRUE",
3334
"menu_visible", "TRUE",
3435
"playlist_tabs_visible", aud::numeric_string<PlaylistTabVisibility::AutoHide>::str,

0 commit comments

Comments
 (0)