From 9c2c2be8eb3e597e97463702212e5c1524fc3c5d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 28 Aug 2019 00:13:40 -0400 Subject: [PATCH] StatusBarWidget: Use std::array where applicable A fairly basic replacement to make the type of the array strongly typed. --- Editor/StatusBarWidget.cpp | 18 ++++++++++-------- Editor/StatusBarWidget.hpp | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Editor/StatusBarWidget.cpp b/Editor/StatusBarWidget.cpp index cf872e0..fe8ff67 100644 --- a/Editor/StatusBarWidget.cpp +++ b/Editor/StatusBarWidget.cpp @@ -14,10 +14,9 @@ StatusBarWidget::StatusBarWidget(QWidget* parent) m_killButton.setVisible(false); m_killButton.setToolTip(tr("Immediately kill active voices")); m_voiceCount.setVisible(false); - m_volumeIcons[0] = QIcon(QStringLiteral(":/icons/IconVolume0.svg")); - m_volumeIcons[1] = QIcon(QStringLiteral(":/icons/IconVolume1.svg")); - m_volumeIcons[2] = QIcon(QStringLiteral(":/icons/IconVolume2.svg")); - m_volumeIcons[3] = QIcon(QStringLiteral(":/icons/IconVolume3.svg")); + for (size_t i = 0; i < m_volumeIcons.size(); i++) { + m_volumeIcons[i] = QIcon(QStringLiteral(":/icons/IconVolume%1.svg").arg(i)); + } m_aIcon.setFixedSize(16, 16); m_aIcon.setPixmap(QIcon(QStringLiteral(":/icons/IconA.svg")).pixmap(16, 16)); QString aTip = tr("Aux A send level for all voices"); @@ -62,11 +61,14 @@ void StatusBarWidget::setVoiceCount(int voices) { } void StatusBarWidget::volumeChanged(int vol) { - int idx = int(std::round(vol * (3.f / 100.f))); - if (idx != m_lastVolIdx) { - m_lastVolIdx = idx; - m_volumeIcon.setPixmap(m_volumeIcons[idx].pixmap(16, 16)); + const int idx = int(std::round(vol * (3.f / 100.f))); + + if (idx == m_lastVolIdx) { + return; } + + m_lastVolIdx = idx; + m_volumeIcon.setPixmap(m_volumeIcons[idx].pixmap(16, 16)); } void StatusBarFocus::setMessage(const QString& message) { diff --git a/Editor/StatusBarWidget.hpp b/Editor/StatusBarWidget.hpp index 2bbee56..5526847 100644 --- a/Editor/StatusBarWidget.hpp +++ b/Editor/StatusBarWidget.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -24,7 +26,7 @@ class StatusBarWidget : public QStatusBar { QLabel m_normalMessage; QPushButton m_killButton; FXButton m_fxButton; - QIcon m_volumeIcons[4]; + std::array m_volumeIcons; QLabel m_volumeIcon; QSlider m_volumeSlider; QLabel m_aIcon;