Tidy up MixerChannelView (#7527)

This commit is contained in:
saker
2024-11-03 02:13:55 -05:00
committed by GitHub
parent 9912fd88e3
commit 07baf9e27a
2 changed files with 31 additions and 93 deletions

View File

@@ -1,7 +1,7 @@
/*
* MixerChannelView.h - the mixer channel view
* MixerChannelView.h
*
* Copyright (c) 2022 saker <sakertooth@gmail.com>
* Copyright (c) 2024 saker
*
* This file is part of LMMS - https://lmms.io
*
@@ -22,8 +22,8 @@
*
*/
#ifndef MIXER_CHANNEL_VIEW_H
#define MIXER_CHANNEL_VIEW_H
#ifndef LMMS_GUI_MIXER_CHANNEL_VIEW_H
#define LMMS_GUI_MIXER_CHANNEL_VIEW_H
#include <QGraphicsView>
#include <QLabel>
@@ -46,8 +46,6 @@ class MixerChannel;
namespace lmms::gui {
class PeakIndicator;
constexpr int MIXER_CHANNEL_INNER_BORDER_SIZE = 3;
constexpr int MIXER_CHANNEL_OUTER_BORDER_SIZE = 1;
class MixerChannelView : public QWidget
{
@@ -65,25 +63,24 @@ public:
void mouseDoubleClickEvent(QMouseEvent*) override;
bool eventFilter(QObject* dist, QEvent* event) override;
int channelIndex() const;
void reset();
int channelIndex() const { return m_channelIndex; }
void setChannelIndex(int index);
QBrush backgroundActive() const;
void setBackgroundActive(const QBrush& c);
QBrush backgroundActive() const { return m_backgroundActive; }
void setBackgroundActive(const QBrush& c) { m_backgroundActive = c; }
QColor strokeOuterActive() const;
void setStrokeOuterActive(const QColor& c);
QColor strokeOuterActive() const { return m_strokeOuterActive; }
void setStrokeOuterActive(const QColor& c) { m_strokeOuterActive = c; }
QColor strokeOuterInactive() const;
void setStrokeOuterInactive(const QColor& c);
QColor strokeOuterInactive() const { return m_strokeOuterInactive; }
void setStrokeOuterInactive(const QColor& c) { m_strokeOuterInactive = c; }
QColor strokeInnerActive() const;
void setStrokeInnerActive(const QColor& c);
QColor strokeInnerActive() const { return m_strokeInnerActive; }
void setStrokeInnerActive(const QColor& c) { m_strokeInnerActive = c; }
QColor strokeInnerInactive() const;
void setStrokeInnerInactive(const QColor& c);
void reset();
QColor strokeInnerInactive() const { return m_strokeInnerInactive; }
void setStrokeInnerInactive(const QColor& c) { m_strokeInnerInactive = c; }
public slots:
void renameChannel();
@@ -135,4 +132,4 @@ private:
};
} // namespace lmms::gui
#endif // MIXER_CHANNEL_VIEW_H
#endif // LMMS_GUI_MIXER_CHANNEL_VIEW_H

View File

@@ -186,21 +186,18 @@ void MixerChannelView::contextMenuEvent(QContextMenuEvent*)
delete contextMenu;
}
void MixerChannelView::paintEvent(QPaintEvent* event)
void MixerChannelView::paintEvent(QPaintEvent*)
{
static constexpr auto innerBorderSize = 3;
static constexpr auto outerBorderSize = 1;
const auto channel = mixerChannel();
const bool muted = channel->m_muteModel.value();
const auto name = channel->m_name;
const auto elidedName = elideName(name);
const auto isActive = m_mixerView->currentMixerChannel() == this;
if (!m_inRename && m_renameLineEdit->text() != elidedName) { m_renameLineEdit->setText(elidedName); }
const auto width = rect().width();
const auto height = rect().height();
auto painter = QPainter{this};
if (channel->color().has_value() && !muted)
if (channel->color().has_value() && !channel->m_muteModel.value())
{
painter.fillRect(rect(), channel->color()->darker(isActive ? 120 : 150));
}
@@ -208,13 +205,11 @@ void MixerChannelView::paintEvent(QPaintEvent* event)
// inner border
painter.setPen(isActive ? strokeInnerActive() : strokeInnerInactive());
painter.drawRect(1, 1, width - MIXER_CHANNEL_INNER_BORDER_SIZE, height - MIXER_CHANNEL_INNER_BORDER_SIZE);
painter.drawRect(1, 1, width - innerBorderSize, height - innerBorderSize);
// outer border
painter.setPen(isActive ? strokeOuterActive() : strokeOuterInactive());
painter.drawRect(0, 0, width - MIXER_CHANNEL_OUTER_BORDER_SIZE, height - MIXER_CHANNEL_OUTER_BORDER_SIZE);
QWidget::paintEvent(event);
painter.drawRect(0, 0, width - outerBorderSize, height - outerBorderSize);
}
void MixerChannelView::mousePressEvent(QMouseEvent*)
@@ -227,7 +222,7 @@ void MixerChannelView::mouseDoubleClickEvent(QMouseEvent*)
renameChannel();
}
bool MixerChannelView::eventFilter(QObject* dist, QEvent* event)
bool MixerChannelView::eventFilter(QObject*, QEvent* event)
{
// If we are in a rename, capture the enter/return events and handle them
if (event->type() == QEvent::KeyPress)
@@ -246,11 +241,6 @@ bool MixerChannelView::eventFilter(QObject* dist, QEvent* event)
return false;
}
int MixerChannelView::channelIndex() const
{
return m_channelIndex;
}
void MixerChannelView::setChannelIndex(int index)
{
MixerChannel* mixerChannel = Engine::mixer()->mixerChannel(index);
@@ -259,64 +249,10 @@ void MixerChannelView::setChannelIndex(int index)
m_soloButton->setModel(&mixerChannel->m_soloModel);
m_effectRackView->setModel(&mixerChannel->m_fxChain);
m_channelNumberLcd->setValue(index);
m_renameLineEdit->setText(elideName(mixerChannel->m_name));
m_channelIndex = index;
}
QBrush MixerChannelView::backgroundActive() const
{
return m_backgroundActive;
}
void MixerChannelView::setBackgroundActive(const QBrush& c)
{
m_backgroundActive = c;
}
QColor MixerChannelView::strokeOuterActive() const
{
return m_strokeOuterActive;
}
void MixerChannelView::setStrokeOuterActive(const QColor& c)
{
m_strokeOuterActive = c;
}
QColor MixerChannelView::strokeOuterInactive() const
{
return m_strokeOuterInactive;
}
void MixerChannelView::setStrokeOuterInactive(const QColor& c)
{
m_strokeOuterInactive = c;
}
QColor MixerChannelView::strokeInnerActive() const
{
return m_strokeInnerActive;
}
void MixerChannelView::setStrokeInnerActive(const QColor& c)
{
m_strokeInnerActive = c;
}
QColor MixerChannelView::strokeInnerInactive() const
{
return m_strokeInnerInactive;
}
void MixerChannelView::setStrokeInnerInactive(const QColor& c)
{
m_strokeInnerInactive = c;
}
void MixerChannelView::reset()
{
m_peakIndicator->resetPeakToMinusInf();
}
void MixerChannelView::renameChannel()
{
m_inRename = true;
@@ -459,4 +395,9 @@ MixerChannel* MixerChannelView::mixerChannel() const
return Engine::mixer()->mixerChannel(m_channelIndex);
}
void MixerChannelView::reset()
{
m_peakIndicator->resetPeakToMinusInf();
}
} // namespace lmms::gui