Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up MixerChannelView #7527

Merged
merged 13 commits into from
Nov 3, 2024
37 changes: 17 additions & 20 deletions include/MixerChannelView.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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>
Expand All @@ -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
{
Expand All @@ -65,25 +63,24 @@ class MixerChannelView : public QWidget
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);

QColor strokeOuterActive() const;
void setStrokeOuterActive(const QColor& c);
QBrush backgroundActive() const { return m_backgroundActive; }
void setBackgroundActive(const QBrush& c) { m_backgroundActive = c; }

QColor strokeOuterInactive() const;
void setStrokeOuterInactive(const QColor& c);
QColor strokeOuterActive() const { return m_strokeOuterActive; }
void setStrokeOuterActive(const QColor& c) { m_strokeOuterActive = c; }

QColor strokeInnerActive() const;
void setStrokeInnerActive(const QColor& c);
QColor strokeOuterInactive() const { return m_strokeOuterInactive; }
void setStrokeOuterInactive(const QColor& c) { m_strokeOuterInactive = c; }

QColor strokeInnerInactive() const;
void setStrokeInnerInactive(const QColor& c);
QColor strokeInnerActive() const { return m_strokeInnerActive; }
void setStrokeInnerActive(const QColor& c) { m_strokeInnerActive = c; }

void reset();
QColor strokeInnerInactive() const { return m_strokeInnerInactive; }
void setStrokeInnerInactive(const QColor& c) { m_strokeInnerInactive = c; }

public slots:
void renameChannel();
Expand Down Expand Up @@ -135,4 +132,4 @@ private slots:
};
} // namespace lmms::gui

#endif // MIXER_CHANNEL_VIEW_H
#endif // LMMS_GUI_MIXER_CHANNEL_VIEW_H
86 changes: 13 additions & 73 deletions src/gui/MixerChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,35 +186,30 @@ 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));
}
else { painter.fillRect(rect(), isActive ? backgroundActive().color() : painter.background().color()); }

// 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*)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -262,61 +252,6 @@ void MixerChannelView::setChannelIndex(int index)
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;
Expand Down Expand Up @@ -459,4 +394,9 @@ MixerChannel* MixerChannelView::mixerChannel() const
return Engine::mixer()->mixerChannel(m_channelIndex);
}

void MixerChannelView::reset()
{
m_peakIndicator->resetPeakToMinusInf();
}

} // namespace lmms::gui
Loading