add presets for color chooser (bar color) and fix typo
This commit is contained in:
+66
-16
@@ -6,12 +6,55 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
static QVector<QColor> makePreset4(const QColor &c0, const QColor &c1,
|
||||||
|
const QColor &c2, const QColor &c3,
|
||||||
|
const QColor &c4)
|
||||||
|
{
|
||||||
|
return { c0, c2, c3, c4 };
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Preset {
|
||||||
|
QString name;
|
||||||
|
QVector<QColor> colors;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Presets are defined in a Vector for simplicity of adding new ones
|
||||||
|
static const QVector<Preset> PRESETS = {
|
||||||
|
{ "Default",
|
||||||
|
{ QColor("#078D70"), QColor("#26CEAA"), QColor("#98E8C1"), QColor("#FFFFFF") } },
|
||||||
|
|
||||||
|
{ "Pastels",
|
||||||
|
makePreset4(QColor("#92ccdd"), QColor("#c7eff0"),
|
||||||
|
QColor("#f5d5fd"), QColor("#fdc4ec"), QColor("#ffc2cb")) },
|
||||||
|
|
||||||
|
{ "Raddish",
|
||||||
|
makePreset4(QColor("#ff0000"), QColor("#b40000"),
|
||||||
|
QColor("#890000"), QColor("#540000"), QColor("#240000")) },
|
||||||
|
|
||||||
|
{ "Blau",
|
||||||
|
makePreset4(QColor("#72c8dd"), QColor("#43b5d2"),
|
||||||
|
QColor("#14a3c7"), QColor("#1293b3"), QColor("#10829f")) },
|
||||||
|
|
||||||
|
{ "Turquoise",
|
||||||
|
makePreset4(QColor("#d8f2f6"), QColor("#8bd9ef"),
|
||||||
|
QColor("#3ec1d5"), QColor("#319aaa"), QColor("#25737f")) },
|
||||||
|
|
||||||
|
{ "Aqua",
|
||||||
|
makePreset4(QColor("#2278FB"), QColor("#3A9AF0"),
|
||||||
|
QColor("#53BDE6"), QColor("#6BDFDB"), QColor("#1A5BB8")) },
|
||||||
|
|
||||||
|
{ "Peaches",
|
||||||
|
makePreset4(QColor("#FFCAA6"), QColor("#FDA8A0"),
|
||||||
|
QColor("#FA879A"), QColor("#F86594"), QColor("#FFE0CC")) }
|
||||||
|
};
|
||||||
|
|
||||||
GradientDialog::GradientDialog(const QVector<QColor> &stops,
|
GradientDialog::GradientDialog(const QVector<QColor> &stops,
|
||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
: QDialog(parent), m_stops(stops)
|
: QDialog(parent), m_stops(stops)
|
||||||
{
|
{
|
||||||
setWindowTitle("Bar Colour Gradient");
|
setWindowTitle("Spectrogram Colors");
|
||||||
setMinimumSize(420, 180);
|
setMinimumSize(420, 180);
|
||||||
|
|
||||||
auto *mainLay = new QVBoxLayout(this);
|
auto *mainLay = new QVBoxLayout(this);
|
||||||
@@ -22,11 +65,13 @@ GradientDialog::GradientDialog(const QVector<QColor> &stops,
|
|||||||
m_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
m_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
mainLay->addWidget(m_preview);
|
mainLay->addWidget(m_preview);
|
||||||
|
|
||||||
// Colour stop buttons
|
|
||||||
auto *btnLay = new QHBoxLayout;
|
auto *btnLay = new QHBoxLayout;
|
||||||
QStringList labels = { "Low", "Mid", "High", "Peak" };
|
QStringList labels = { "Low", "Mid", "High", "Peak" };
|
||||||
for (int i = 0; i < m_stops.size(); ++i) {
|
if (m_stops.size() != 4) {
|
||||||
auto *btn = new QPushButton(labels.value(i, QString::number(i)));
|
m_stops = PRESETS[0].colors;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
auto *btn = new QPushButton(labels[i]);
|
||||||
btn->setFixedSize(70, 30);
|
btn->setFixedSize(70, 30);
|
||||||
connect(btn, &QPushButton::clicked, this, [this, i]{ onStopClicked(i); });
|
connect(btn, &QPushButton::clicked, this, [this, i]{ onStopClicked(i); });
|
||||||
btnLay->addWidget(btn);
|
btnLay->addWidget(btn);
|
||||||
@@ -34,15 +79,23 @@ GradientDialog::GradientDialog(const QVector<QColor> &stops,
|
|||||||
}
|
}
|
||||||
mainLay->addLayout(btnLay);
|
mainLay->addLayout(btnLay);
|
||||||
|
|
||||||
// Action buttons
|
|
||||||
auto *dialogBtns = new QHBoxLayout;
|
auto *dialogBtns = new QHBoxLayout;
|
||||||
auto *resetBtn = new QPushButton("Reset to Default");
|
|
||||||
connect(resetBtn, &QPushButton::clicked, this, &GradientDialog::onResetToDefault);
|
auto *presetLabel = new QLabel("Preset:");
|
||||||
dialogBtns->addWidget(resetBtn);
|
m_presetCombo = new QComboBox;
|
||||||
|
for (const auto &p : PRESETS) {
|
||||||
|
m_presetCombo->addItem(p.name);
|
||||||
|
}
|
||||||
|
connect(m_presetCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
|
this, &GradientDialog::onPresetSelected);
|
||||||
|
dialogBtns->addWidget(presetLabel);
|
||||||
|
dialogBtns->addWidget(m_presetCombo);
|
||||||
dialogBtns->addStretch();
|
dialogBtns->addStretch();
|
||||||
|
|
||||||
auto *ok = new QPushButton("Apply");
|
auto *ok = new QPushButton("Apply");
|
||||||
connect(ok, &QPushButton::clicked, this, &QDialog::accept);
|
connect(ok, &QPushButton::clicked, this, &QDialog::accept);
|
||||||
dialogBtns->addWidget(ok);
|
dialogBtns->addWidget(ok);
|
||||||
|
|
||||||
mainLay->addLayout(dialogBtns);
|
mainLay->addLayout(dialogBtns);
|
||||||
|
|
||||||
updatePreview();
|
updatePreview();
|
||||||
@@ -58,21 +111,18 @@ void GradientDialog::onStopClicked(int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GradientDialog::onResetToDefault()
|
void GradientDialog::onPresetSelected(int index)
|
||||||
{
|
{
|
||||||
m_stops = {
|
if (index < 0 || index >= PRESETS.size())
|
||||||
QColor("#078D70"), // Low
|
return;
|
||||||
QColor("#26CEAA"), // Mid
|
m_stops = PRESETS[index].colors;
|
||||||
QColor("#98E8C1"), // High
|
|
||||||
QColor("#FFFFFF") // Peak
|
|
||||||
};
|
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GradientDialog::updatePreview()
|
void GradientDialog::updatePreview()
|
||||||
{
|
{
|
||||||
QPixmap pix(m_preview->size());
|
QPixmap pix(m_preview->size());
|
||||||
if (pix.width() == 0) pix = QPixmap(400, 40); // fallback size
|
if (pix.width() == 0) pix = QPixmap(400, 40);
|
||||||
pix.fill(Qt::transparent);
|
pix.fill(Qt::transparent);
|
||||||
QPainter p(&pix);
|
QPainter p(&pix);
|
||||||
QLinearGradient grad(0, 0, pix.width(), 0);
|
QLinearGradient grad(0, 0, pix.width(), 0);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
class GradientDialog : public QDialog
|
class GradientDialog : public QDialog
|
||||||
{
|
{
|
||||||
@@ -19,12 +20,13 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onStopClicked(int index);
|
void onStopClicked(int index);
|
||||||
void onResetToDefault();
|
void onPresetSelected(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<QColor> m_stops;
|
QVector<QColor> m_stops;
|
||||||
QVector<QPushButton*> m_buttons;
|
QVector<QPushButton*> m_buttons;
|
||||||
QLabel *m_preview;
|
QLabel *m_preview;
|
||||||
|
QComboBox *m_presetCombo;
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user