Skip to content

Commit

Permalink
Finish UI
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKauss committed Aug 14, 2024
1 parent 4d26b30 commit 4cce529
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 121 deletions.
20 changes: 11 additions & 9 deletions include/PluginView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@

#include <QWidget>

#include "Plugin.h"
#include "ModelView.h"
#include "Plugin.h"

namespace lmms::gui
{
namespace lmms::gui {

class LMMS_EXPORT PluginView : public QWidget, public ModelView
class LMMS_EXPORT PluginView : public QWidget, public ModelView
{
public:
PluginView( Plugin * _plugin, QWidget * _parent ) :
QWidget( _parent ),
ModelView( _plugin, this )
PluginView(Plugin* _plugin, QWidget* _parent)
: QWidget(_parent)
, ModelView(_plugin, this)
{
}
bool m_isResizable = false;

} ;
void setResizable(bool resizable) { m_isResizable = resizable; }
bool isResizable() { return m_isResizable; }

private:
bool m_isResizable = false;
};

} // namespace lmms::gui

Expand Down
2 changes: 1 addition & 1 deletion plugins/SlicerT/SlicerT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void SlicerT::findSlices()
if (noteSnap == 0) { sliceLock = 1; }
for (float& sliceValue : m_slicePoints)
{
sliceValue += sliceLock / 2;
sliceValue += sliceLock / 2.;
sliceValue -= static_cast<int>(sliceValue) % sliceLock;
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/SlicerT/SlicerT.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public slots:
void findSlices();
void findBPM();

QString getSampleName() { return m_originalSample.sampleFile(); }

QString nodeName() const override;
gui::PluginView* instantiateView(QWidget* parent) override;

Expand Down
144 changes: 102 additions & 42 deletions plugins/SlicerT/SlicerTView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@

#include <QDropEvent>
#include <QFileInfo>
#include <cmath>
#include <qlayout.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qsizepolicy.h>
#include <qwidget.h>

Expand All @@ -48,29 +51,29 @@ namespace gui {
SlicerTView::SlicerTView(SlicerT* instrument, QWidget* parent)
: InstrumentView(instrument, parent)
, m_slicerTParent(instrument)
, m_fullLogo(PLUGIN_NAME::getIconPixmap("full_logo"))
, m_background(PLUGIN_NAME::getIconPixmap("toolbox"))
{
// window settings
setAcceptDrops(true);
setAutoFillBackground(true);

setMaximumSize(QSize(500, 500));
setMinimumSize(QSize(250, 250));
m_isResizable = true;

// render background
QPalette pal;
pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork"));
setPalette(pal);
setMaximumSize(QSize(10000, 10000));
setMinimumSize(QSize(516, 400));
setResizable(true);

m_wf = new SlicerTWaveform(248, 128, instrument, this);
m_wf->move(2, 6);
m_wf->move(0, s_topBarHeight);

m_snapSetting = new ComboBox(this, tr("Slice snap"));
m_snapSetting->setGeometry(185, 200, 55, ComboBox::DEFAULT_HEIGHT);
m_snapSetting->setToolTip(tr("Set slice snapping for detection"));
m_snapSetting->setModel(&m_slicerTParent->m_sliceSnap);

m_syncToggle = new LedCheckBox("Sync", this, tr("SyncToggle"), LedCheckBox::LedColor::Green);
m_syncToggle = new PixmapButton(this, tr("Sync sample"));
m_syncToggle->setActiveGraphic(PLUGIN_NAME::getIconPixmap("sync_active"));
m_syncToggle->setInactiveGraphic(PLUGIN_NAME::getIconPixmap("sync_inactive"));
m_syncToggle->setCheckable(true);
m_syncToggle->setToolTip(tr("Enable BPM sync"));
m_syncToggle->setModel(&m_slicerTParent->m_enableSync);

Expand All @@ -91,9 +94,15 @@ SlicerTView::SlicerTView(SlicerT* instrument, QWidget* parent)
m_midiExportButton->setToolTip(tr("Copy midi pattern to clipboard"));
connect(m_midiExportButton, &PixmapButton::clicked, this, &SlicerTView::exportMidi);

m_folderButton = new PixmapButton(this);
m_folderButton->setActiveGraphic(PLUGIN_NAME::getIconPixmap("folder_icon"));
m_folderButton->setInactiveGraphic(PLUGIN_NAME::getIconPixmap("folder_icon"));
m_folderButton->setToolTip(tr("Open sample selector"));
connect(m_folderButton, &PixmapButton::clicked, this, &SlicerTView::openFiles);

m_resetButton = new QPushButton(this);
m_resetButton->setIcon(PLUGIN_NAME::getIconPixmap("reset_slices"));
m_resetButton->setToolTip(tr("Reset Slices"));
m_resetButton->setToolTip(tr("Reset slices"));
connect(m_resetButton, &PixmapButton::clicked, m_slicerTParent, &SlicerT::updateSlices);

update();
Expand Down Expand Up @@ -181,50 +190,101 @@ void SlicerTView::dropEvent(QDropEvent* de)
void SlicerTView::paintEvent(QPaintEvent* pe)
{
QPainter brush(this);
brush.setPen(QColor(255, 255, 255));
brush.setFont(QFont(brush.font().family(), 7, -1, false));

int y1_text = m_y1 + 22;
int y2_text = m_y2 + 22;
int boxTopY = height() - s_bottomBoxHeight;

// --- backgrounds and limiters
brush.drawPixmap(QRect(0, boxTopY, s_leftBoxWidth, s_bottomBoxHeight), m_background); // left
brush.fillRect(
QRect(s_leftBoxWidth, boxTopY, width() - s_leftBoxWidth, s_bottomBoxHeight), QColor(23, 26, 31)); // right
brush.fillRect(QRect(0, 0, width(), s_topBarHeight), QColor(20, 23, 27)); // top

// top bar dividers
brush.setPen(QColor(56, 58, 60));
brush.drawLine(0, s_topBarHeight - 1, width(), s_topBarHeight - 1);
brush.drawLine(0, 0, width(), 0);

brush.drawText(m_x1 - 12, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Reset"));
brush.drawText(m_x4 - 12, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Midi"));
// sample name divider
brush.setPen(QColor(56, 58, 60));
brush.drawLine(0, boxTopY, width(), boxTopY);

brush.drawText(m_x1 - 25, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Threshold"));
brush.drawText(m_x2 - 25, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Fade Out"));
brush.drawText(m_x3 - 16, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("BPM"));
brush.drawText(m_x4 - 8, y2_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Snap"));
// boxes divider
brush.setPen(QColor(56, 24, 94));
brush.drawLine(s_leftBoxWidth, boxTopY, s_leftBoxWidth, height());

// --- top bar
brush.drawPixmap(
QRect(10, (s_topBarHeight - m_fullLogo.height()) / 2, m_fullLogo.width(), m_fullLogo.height()), m_fullLogo);

int y1_text = m_y1 + 27;

// --- left box
brush.setPen(QColor(255, 255, 255));
brush.drawText(s_x1 - 25, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Threshold"));
brush.drawText(s_x2 - 25, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Fade Out"));
brush.drawText(s_x3 - 25, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Reset"));
brush.drawText(s_x4 - 8, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Midi"));
brush.drawText(s_x5 - 16, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("BPM"));
brush.drawText(s_x6 - 8, y1_text, s_textBoxWidth, s_textBoxHeight, Qt::AlignCenter, tr("Snap"));

int kor = 15; // knob outer radius
int kir = 9; // knob inner radius

// draw knob backgrounds
brush.setRenderHint(QPainter::Antialiasing);

// draw outer radius 2 times to make smooth
brush.setPen(QPen(QColor(159, 124, 223, 100), 4));
brush.drawArc(QRect(s_x1 - kor, m_y1, kor * 2, kor * 2), -45 * 16, 270 * 16);
brush.drawArc(QRect(s_x2 - kor, m_y1, kor * 2, kor * 2), -45 * 16, 270 * 16);

brush.setPen(QPen(QColor(159, 124, 223, 255), 2));
brush.drawArc(QRect(s_x1 - kor, m_y1, kor * 2, kor * 2), -45 * 16, 270 * 16);
brush.drawArc(QRect(s_x2 - kor, m_y1, kor * 2, kor * 2), -45 * 16, 270 * 16);

// inner knob circle
brush.setBrush(QColor(106, 90, 138));
brush.setPen(QColor(0, 0, 0, 0));
brush.drawEllipse(QPoint(s_x1, m_y1 + 15), kir, kir);
brush.drawEllipse(QPoint(s_x2, m_y1 + 15), kir, kir);

// current sample bar
brush.fillRect(QRect(0, boxTopY - s_sampleBoxHeight, width(), s_sampleBoxHeight), QColor(5, 5, 5));

brush.setPen(QColor(56, 58, 60));
brush.drawLine(width() - 24, boxTopY - s_sampleBoxHeight, width() - 24, boxTopY);

brush.setPen(QColor(255, 255, 255, 180));
brush.setFont(QFont(brush.font().family(), 8, -1, false));
QString sampleName = m_slicerTParent->getSampleName();
if (sampleName == "") { sampleName = "No sample loaded"; }

brush.drawText(5, boxTopY - s_sampleBoxHeight, width(), s_sampleBoxHeight, Qt::AlignLeft, sampleName);
}

void SlicerTView::resizeEvent(QResizeEvent * re)
void SlicerTView::resizeEvent(QResizeEvent* re)
{
QPalette pal = palette();
pal.setBrush(backgroundRole(), PLUGIN_NAME::getIconPixmap("artwork").scaled(size(), Qt::IgnoreAspectRatio));
setPalette(pal);
m_y1 = height() - s_bottomBoxOffset;

// left box
m_noteThresholdKnob->move(s_x1 - 25, m_y1);
m_fadeOutKnob->move(s_x2 - 25, m_y1);

m_y1 = height() - 100;
m_y2 = height() - 50;
m_resetButton->move(s_x3 - 15, m_y1 + 3);
m_midiExportButton->move(s_x4 + 2, m_y1 + 3);

m_x1 = width() * 0.2f;
m_x2 = width() * 0.4f;
m_x3 = width() * 0.6f;
m_x4 = width() * 0.8f;
m_bpmBox->move(s_x5 - 13, m_y1 + 4);
m_snapSetting->move(s_x6 - 8, m_y1 + 3);

// first row
m_resetButton->move(m_x1 - 12, m_y1);
m_midiExportButton->move(m_x4 - 12, m_y1);
// right box
m_syncToggle->move((width() - 100), m_y1 + 5);

// second row
m_noteThresholdKnob->move(m_x1 - 25, m_y2);
m_fadeOutKnob->move(m_x2 - 25, m_y2);

m_bpmBox->move(m_x3 - 16, m_y2);
m_syncToggle->move(m_x3 - 7, m_y2 - 16);
m_folderButton->move(width() - 20, height() - s_bottomBoxHeight - s_sampleBoxHeight + 1);

m_snapSetting->move(m_x4 - 8, m_y2);
int waveFormHeight = height() - s_bottomBoxHeight - s_topBarHeight - s_sampleBoxHeight;

m_wf->resize(width() - 2, height() - 125);
m_wf->updateSize(width() - 2, height() - 125);
m_wf->resize(width(), waveFormHeight);
}

} // namespace gui
Expand Down
34 changes: 24 additions & 10 deletions plugins/SlicerT/SlicerTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
#define LMMS_GUI_SLICERT_VIEW_H

#include <QPushButton>
#include <qpixmap.h>

#include "ComboBox.h"
#include "InstrumentView.h"
#include "Knob.h"
#include "LcdSpinBox.h"
#include "LedCheckBox.h"
#include "PixmapButton.h"
#include "SlicerTWaveform.h"

namespace lmms {
Expand All @@ -53,14 +55,26 @@ public slots:

static constexpr int s_textBoxHeight = 20;
static constexpr int s_textBoxWidth = 50;
static constexpr int s_topTextY = 170;
static constexpr int s_bottomTextY = 220;

static constexpr int s_topBarHeight = 50;
static constexpr int s_bottomBoxHeight = 97;
static constexpr int s_bottomBoxOffset = 65;
static constexpr int s_sampleBoxHeight = 14;
static constexpr int s_folderButtonWidth = 15;
static constexpr int s_leftBoxWidth = 400;


static constexpr int s_x1 = 35;
static constexpr int s_x2 = 85;
static constexpr int s_x3 = 160;
static constexpr int s_x4 = 190;
static constexpr int s_x5 = 275;
static constexpr int s_x6 = 325;
protected:
virtual void dragEnterEvent(QDragEnterEvent* dee) override;
virtual void dropEvent(QDropEvent* de) override;
void dragEnterEvent(QDragEnterEvent* dee) override;
void dropEvent(QDropEvent* de) override;

virtual void paintEvent(QPaintEvent* pe) override;
void paintEvent(QPaintEvent* pe) override;
/* QSize sizeHint() const override { return QSize(150, 150); } */
/* QSize minimumSizeHint() const override { return QSize(300, 300); } */
void resizeEvent(QResizeEvent* event) override;
Expand All @@ -72,7 +86,8 @@ public slots:
Knob* m_fadeOutKnob;
LcdSpinBox* m_bpmBox;
ComboBox* m_snapSetting;
LedCheckBox* m_syncToggle;
PixmapButton* m_syncToggle;
PixmapButton* m_folderButton;

QPushButton* m_resetButton;
QPushButton* m_midiExportButton;
Expand All @@ -81,10 +96,9 @@ public slots:

Knob* createStyledKnob();

int m_x1;
int m_x2;
int m_x3;
int m_x4;
QPixmap m_fullLogo;
QPixmap m_background;


int m_y1;
int m_y2;
Expand Down
Loading

0 comments on commit 4cce529

Please sign in to comment.