Formatting

This commit is contained in:
Jonas Kvinge 2024-06-27 18:00:44 +02:00
parent 6446942e73
commit 93660bfc81
4 changed files with 16 additions and 25 deletions

View File

@ -26,12 +26,8 @@
namespace { namespace {
static const int sBarkBands[] = { constexpr int sBarkBands[] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500 };
100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, constexpr int sBarkBandCount = arraysize(sBarkBands);
2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500
};
static const int sBarkBandCount = arraysize(sBarkBands);
} // namespace } // namespace

View File

@ -43,10 +43,12 @@
#include "moodbarrenderer.h" #include "moodbarrenderer.h"
#include "settings/moodbarsettingspage.h" #include "settings/moodbarsettingspage.h"
const int MoodbarProxyStyle::kMarginSize = 3; namespace {
const int MoodbarProxyStyle::kBorderSize = 1; constexpr int kMarginSize = 3;
const int MoodbarProxyStyle::kArrowWidth = 17; constexpr int kBorderSize = 1;
const int MoodbarProxyStyle::kArrowHeight = 13; constexpr int kArrowWidth = 17;
constexpr int kArrowHeight = 13;
} // namespace
MoodbarProxyStyle::MoodbarProxyStyle(Application *app, QSlider *slider, QObject*) MoodbarProxyStyle::MoodbarProxyStyle(Application *app, QSlider *slider, QObject*)
: QProxyStyle(nullptr), : QProxyStyle(nullptr),
@ -145,8 +147,7 @@ void MoodbarProxyStyle::NextState() {
fade_target_ = QPixmap(); fade_target_ = QPixmap();
} }
else { else {
// Stop an existing fade and start fading the other direction from the // Stop an existing fade and start fading the other direction from the same place.
// same place.
fade_timeline_->stop(); fade_timeline_->stop();
fade_timeline_->setDirection(direction); fade_timeline_->setDirection(direction);
fade_timeline_->resume(); fade_timeline_->resume();
@ -291,8 +292,7 @@ QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionCom
const QStyleOptionSlider *slider_opt = qstyleoption_cast<const QStyleOptionSlider*>(opt); const QStyleOptionSlider *slider_opt = qstyleoption_cast<const QStyleOptionSlider*>(opt);
int x_offset = 0; int x_offset = 0;
/* slider_opt->{maximum,minimum} can have the value 0 (their default // slider_opt->{maximum,minimum} can have the value 0 (their default values), so this check avoids a division by 0.
values), so this check avoids a division by 0. */
if (slider_opt->maximum > slider_opt->minimum) { if (slider_opt->maximum > slider_opt->minimum) {
qint64 slider_delta = slider_opt->sliderValue - slider_opt->minimum; qint64 slider_delta = slider_opt->sliderValue - slider_opt->minimum;
qint64 slider_range = slider_opt->maximum - slider_opt->minimum; qint64 slider_range = slider_opt->maximum - slider_opt->minimum;
@ -311,6 +311,7 @@ QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionCom
} }
return QProxyStyle::subControlRect(cc, opt, sc, widget); return QProxyStyle::subControlRect(cc, opt, sc, widget);
} }
void MoodbarProxyStyle::DrawArrow(const QStyleOptionSlider *option, QPainter *painter) const { void MoodbarProxyStyle::DrawArrow(const QStyleOptionSlider *option, QPainter *painter) const {

View File

@ -65,11 +65,6 @@ class MoodbarProxyStyle : public QProxyStyle {
void SetMoodbarEnabled(const bool enabled); void SetMoodbarEnabled(const bool enabled);
private: private:
static const int kMarginSize;
static const int kBorderSize;
static const int kArrowWidth;
static const int kArrowHeight;
enum class State { enum class State {
MoodbarOn, MoodbarOn,
MoodbarOff, MoodbarOff,

View File

@ -87,16 +87,13 @@ ColorVector MoodbarRenderer::Colors(const QByteArray &data, const MoodbarStyle s
total = qMax(total, 1); total = qMax(total, 1);
// Remap the hue values to be between rangeStart and // Remap the hue values to be between rangeStart and rangeStart + rangeDelta.
// rangeStart + rangeDelta. Every time we see an input hue // Every time we see an input hue above the threshold, increment the output hue by (1/total) * rangeDelta.
// above the threshold, increment the output hue by
// (1/total) * rangeDelta.
for (int i = 0, n = 0; i < 360; i++) { for (int i = 0, n = 0; i < 360; i++) {
hue_distribution[i] = ((hue_distribution[i] > properties.threshold_ ? n++ : n) * properties.range_delta_ / total + properties.range_start_) % 360; hue_distribution[i] = ((hue_distribution[i] > properties.threshold_ ? n++ : n) * properties.range_delta_ / total + properties.range_start_) % 360;
} }
// Now huedist is a hue mapper: huedist[h] is the new hue value // Now huedist is a hue mapper: huedist[h] is the new hue value for a bar with hue h
// for a bar with hue h
for (ColorVector::iterator it = colors.begin(); it != colors.end(); ++it) { for (ColorVector::iterator it = colors.begin(); it != colors.end(); ++it) {
const int hue = qMax(0, it->hue()); const int hue = qMax(0, it->hue());
@ -104,6 +101,7 @@ ColorVector MoodbarRenderer::Colors(const QByteArray &data, const MoodbarStyle s
} }
return colors; return colors;
} }
void MoodbarRenderer::Render(const ColorVector &colors, QPainter *p, const QRect rect) { void MoodbarRenderer::Render(const ColorVector &colors, QPainter *p, const QRect rect) {
@ -148,6 +146,7 @@ void MoodbarRenderer::Render(const ColorVector &colors, QPainter *p, const QRect
p->drawPoint(rect.left() + x, rect.top() + rect.height() - 1 - y); p->drawPoint(rect.left() + x, rect.top() + rect.height() - 1 - y);
} }
} }
} }
QImage MoodbarRenderer::RenderToImage(const ColorVector &colors, const QSize size) { QImage MoodbarRenderer::RenderToImage(const ColorVector &colors, const QSize size) {