From 48c4dce96fce831aa529c52127f87edf8e17be19 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 2 Jun 2024 12:34:59 +0200 Subject: [PATCH] More prominent recording option Make the option to record samples more prominent by providing a pixmap button that is always shown and that can be used to turn recording on or off. The corresponding widget which constitutes of the button and a label is always positioned at the bottom left of the sample clip. Technical details ------------------ The recording widget is built in the private method `buildRecordWidget`. The method `adjustRecordWidget` is used to move the recording widget to the correct position relative to the sample view. It is called after construction and whenever the sample clip is resized (see `resizeEvent`). Add the method `SampleClip::getRecordModel` so that the pixmap button can be configured to act on it. --- include/SampleClip.h | 2 + include/SampleClipView.h | 9 ++++ src/gui/clips/SampleClipView.cpp | 71 ++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/include/SampleClip.h b/include/SampleClip.h index 3beca338b..5efdc5ed7 100644 --- a/include/SampleClip.h +++ b/include/SampleClip.h @@ -81,6 +81,8 @@ public: void setIsPlaying(bool isPlaying); void setSampleBuffer(std::shared_ptr sb); + BoolModel& getRecordModel() { return m_recordModel; } + public slots: void setSampleFile(const QString& sf); void updateLength(); diff --git a/include/SampleClipView.h b/include/SampleClipView.h index 4ff218fb0..73ed474e7 100644 --- a/include/SampleClipView.h +++ b/include/SampleClipView.h @@ -27,10 +27,13 @@ #include "ClipView.h" +class QWidget; + namespace lmms { class SampleClip; +class BoolModel; namespace gui { @@ -59,12 +62,18 @@ protected: void dropEvent( QDropEvent * _de ) override; void mouseDoubleClickEvent( QMouseEvent * ) override; void paintEvent( QPaintEvent * ) override; + void resizeEvent(QResizeEvent *event) override; +private: + QWidget* buildRecordWidget(BoolModel& recordModel); + void adjustRecordWidget(); private: SampleClip * m_clip; QPixmap m_paintPixmap; bool splitClip( const TimePos pos ) override; + + QWidget* m_recordWidget; } ; diff --git a/src/gui/clips/SampleClipView.cpp b/src/gui/clips/SampleClipView.cpp index bb0937381..ca8ec0978 100644 --- a/src/gui/clips/SampleClipView.cpp +++ b/src/gui/clips/SampleClipView.cpp @@ -25,6 +25,8 @@ #include "SampleClipView.h" #include +#include +#include #include #include @@ -33,6 +35,7 @@ #include "embed.h" #include "gui_templates.h" #include "PathUtil.h" +#include "PixmapButton.h" #include "SampleClip.h" #include "SampleLoader.h" #include "SampleWaveform.h" @@ -57,6 +60,11 @@ SampleClipView::SampleClipView( SampleClip * _clip, TrackView * _tv ) : connect(m_clip, SIGNAL(wasReversed()), this, SLOT(update())); setStyle( QApplication::style() ); + + m_recordWidget = buildRecordWidget(_clip->getRecordModel()); + m_recordWidget->setVisible(true); + + adjustRecordWidget(); } void SampleClipView::updateSample() @@ -306,36 +314,6 @@ void SampleClipView::paintEvent( QPaintEvent * pe ) { p.drawLine(m_markerPos, rect().bottom(), m_markerPos, rect().top()); } - // recording sample tracks is not possible at the moment - - if (m_clip->isRecord()) - { - p.setFont(adjustedToPixelSize(p.font(), 10)); - - const auto fontHeight = p.fontMetrics().height(); - - const auto baseLine = height() - 3; - - const int recordSymbolRadius = 3; - const int recordSymbolCenterX = recordSymbolRadius + 4; - const int recordSymbolCenterY = baseLine - fontHeight / 2 + 1; - - const int textStartX = recordSymbolCenterX + recordSymbolRadius + 4; - - auto textPos = QPoint(textStartX, baseLine); - - const auto rec = tr("Rec"); - - p.setPen(textShadowColor()); - p.drawText(textPos + QPoint(1, 1), rec); - - p.setPen(textColor()); - p.drawText(textPos, rec); - - p.setBrush(QBrush(textColor())); - - p.drawEllipse(QPoint(recordSymbolCenterX, recordSymbolCenterY), recordSymbolRadius, recordSymbolRadius); - } p.end(); @@ -343,6 +321,12 @@ void SampleClipView::paintEvent( QPaintEvent * pe ) } +void SampleClipView::resizeEvent(QResizeEvent *event) +{ + adjustRecordWidget(); + + ClipView::resizeEvent(event); +} void SampleClipView::reverseSample() @@ -393,5 +377,32 @@ bool SampleClipView::splitClip( const TimePos pos ) else { return false; } } +QWidget* SampleClipView::buildRecordWidget(BoolModel& recordModel) +{ + auto recordWidget = new QWidget(this); + + auto recordButton = new PixmapButton(recordWidget); + recordButton->setActiveGraphic(embed::getIconPixmap("led_red")); + recordButton->setToolTip(tr("Enable/disable recording")); + recordButton->setCheckable(true); + recordButton->setModel(&recordModel); + + auto recordLabel = new QLabel(tr("Rec"), recordWidget); + recordLabel->setFont(adjustedToPixelSize(recordLabel->font(), 10)); + + // Now layout everything + QHBoxLayout* recordLayout = new QHBoxLayout(recordWidget); + recordLayout->setContentsMargins(0, 0, 0, 0); + + recordLayout->addWidget(recordButton); + recordLayout->addWidget(recordLabel); + + return recordWidget; +} + +void SampleClipView::adjustRecordWidget() +{ + m_recordWidget->move(1, height() - m_recordWidget->height() - 1); +} } // namespace lmms::gui