Skip to content

Commit

Permalink
Added scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodmg committed Oct 27, 2023
1 parent 632ae2d commit 69d872a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
14 changes: 9 additions & 5 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "ui_desktopplayerwindow.h"
#include <QLabel>
#include <QVBoxLayout>
#include "scale.h"

const unsigned int WINDOW_W = 277 * UI_SCALE;
const unsigned int WINDOW_H = 117*UI_SCALE;

MainWindow::MainWindow(QWidget *parent)
: QMainWindow{parent}
Expand Down Expand Up @@ -72,11 +76,11 @@ MainWindow::MainWindow(QWidget *parent)

setCentralWidget(centralWidget);

resize(831, 351);
this->setMaximumWidth(831);
this->setMaximumHeight(351);
this->setMinimumWidth(831);
this->setMinimumHeight(351);
resize(WINDOW_W, WINDOW_H);
this->setMaximumWidth(WINDOW_W);
this->setMaximumHeight(WINDOW_H);
this->setMinimumWidth(WINDOW_W);
this->setMinimumHeight(WINDOW_H);
setWindowFlags(Qt::CustomizeWindowHint);
}

Expand Down
1 change: 1 addition & 0 deletions player.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ HEADERS = \
playerview.h \
playlistmodel.h \
playlistview.h \
scale.h \
scrolltext.h \
qmediaplaylist.h \
qmediaplaylist_p.h \
Expand Down
6 changes: 6 additions & 0 deletions scale.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef SCALE_H
#define SCALE_H

#define UI_SCALE 4

#endif // SCALE_H
30 changes: 18 additions & 12 deletions spectrumwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "fft.h"
#include <QPainter>
#include <QColor>
#include "scale.h"

#define VIS_DELAY 1 /* delay before falloff in frames */
#define VIS_FALLOFF 4 /* falloff in pixels per frame */
Expand Down Expand Up @@ -123,6 +124,9 @@ void SpectrumWidget::stop()
this->update();
}

const unsigned int BG_DOT_SIZE = 1 * UI_SCALE;
const unsigned int BG_DOT_SPACING = 1 * UI_SCALE;

void SpectrumWidget::paintBackground(QPainter & p)
{
// Paint the gray pixels behind the spectrum
Expand All @@ -132,29 +136,31 @@ void SpectrumWidget::paintBackground(QPainter & p)
const unsigned int cols = 38;

// Starting points
unsigned int x = 3;
unsigned int y = 6;
unsigned int x = BG_DOT_SIZE;
unsigned int y = BG_DOT_SIZE + BG_DOT_SPACING;

const QColor color = QColor::fromRgb(64, 64, 64);

for(unsigned int row = 0; row < rows; row++) {
for(unsigned int col = 0; col < cols; col++) {
p.fillRect(x, y, 3, 3, color);
x += 6; // Add pixel width + spacing
p.fillRect(x, y, BG_DOT_SIZE, BG_DOT_SIZE, color);
x += BG_DOT_SIZE + BG_DOT_SPACING; // Add pixel width + spacing
}
x = 3; // Go back to the start of the row
y += 6; // Add pixel height + spacing
x = BG_DOT_SIZE; // Go back to the start of the row
y += BG_DOT_SIZE + BG_DOT_SPACING; // Add pixel height + spacing
}
}

const unsigned int BAR_W = 3 * UI_SCALE;
const unsigned int BAR_SPACING = 1 * UI_SCALE;

void SpectrumWidget::paintSpectrum (QPainter & p)
{
for (int i = 0; i < N_BANDS; i++) {
// Bar measures 3px*3 wide, 1px*3 spacing
int x = (9 * i) + 3*i;
p.fillRect(x + 3, height() - (m_bandValues[i] * height() / 40),
9, (m_bandValues[i] * height() / 40), *getSpecBarGradient());
int x = (BAR_W * i) + BAR_SPACING*i;
p.fillRect(x + BAR_SPACING, height() - (m_bandValues[i] * height() / 40),
BAR_W, (m_bandValues[i] * height() / 40), *getSpecBarGradient());
}
}

Expand All @@ -163,9 +169,9 @@ void SpectrumWidget::paintPeaks (QPainter & p)
const QColor color = QColor::fromRgb(191, 191, 191);
for (int i = 0; i < N_BANDS; i++) {
// Peak rectangle measures 3px*3 wide, 1px*3 high, 1px*3 spacing
int x = (9 * i) + 3*i;
p.fillRect(x + 3, height() - (m_peakValues[i] * height() / 40),
9, 3, color);
int x = (BAR_W * i) + BAR_SPACING*i;
p.fillRect(x + BAR_SPACING, height() - (m_peakValues[i] * height() / 40),
BAR_W, BAR_SPACING, color);
}
}

Expand Down

0 comments on commit 69d872a

Please sign in to comment.