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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
42 changes: 21 additions & 21 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 @@ -38,16 +38,14 @@
#include "LcdWidget.h"
#include "PixmapButton.h"
#include "SendButtonIndicator.h"
#include "PeakIndicator.h"

namespace lmms {
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 @@ -58,32 +56,34 @@ class MixerChannelView : public QWidget
Q_PROPERTY(QColor strokeInnerActive READ strokeInnerActive WRITE setStrokeInnerActive)
Q_PROPERTY(QColor strokeInnerInactive READ strokeInnerInactive WRITE setStrokeInnerInactive)
public:
static constexpr auto InnerBorderSize = 3;
static constexpr auto OuterBorderSize = 1;
sakertooth marked this conversation as resolved.
Show resolved Hide resolved

MixerChannelView(QWidget* parent, MixerView* mixerView, int channelIndex);
void paintEvent(QPaintEvent* event) override;
void contextMenuEvent(QContextMenuEvent*) override;
void mousePressEvent(QMouseEvent*) override;
void mouseDoubleClickEvent(QMouseEvent*) override;
bool eventFilter(QObject* dist, QEvent* event) override;

int channelIndex() const;
void reset() { m_peakIndicator->resetPeakToMinusInf(); }
sakertooth marked this conversation as resolved.
Show resolved Hide resolved
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 +135,4 @@ private slots:
};
} // namespace lmms::gui

#endif // MIXER_CHANNEL_VIEW_H
#endif // LMMS_GUI_MIXER_CHANNEL_VIEW_H
78 changes: 5 additions & 73 deletions src/gui/MixerChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,35 +186,27 @@ void MixerChannelView::contextMenuEvent(QContextMenuEvent*)
delete contextMenu;
}

void MixerChannelView::paintEvent(QPaintEvent* event)
void MixerChannelView::paintEvent(QPaintEvent*)
{
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 +219,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 +238,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 +249,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
Loading