add presets for color chooser (bar color) and fix typo
This commit is contained in:
+66
-16
@@ -6,12 +6,55 @@
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#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,
|
||||
QWidget *parent)
|
||||
: QDialog(parent), m_stops(stops)
|
||||
{
|
||||
setWindowTitle("Bar Colour Gradient");
|
||||
setWindowTitle("Spectrogram Colors");
|
||||
setMinimumSize(420, 180);
|
||||
|
||||
auto *mainLay = new QVBoxLayout(this);
|
||||
@@ -22,11 +65,13 @@ GradientDialog::GradientDialog(const QVector<QColor> &stops,
|
||||
m_preview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
mainLay->addWidget(m_preview);
|
||||
|
||||
// Colour stop buttons
|
||||
auto *btnLay = new QHBoxLayout;
|
||||
QStringList labels = { "Low", "Mid", "High", "Peak" };
|
||||
for (int i = 0; i < m_stops.size(); ++i) {
|
||||
auto *btn = new QPushButton(labels.value(i, QString::number(i)));
|
||||
if (m_stops.size() != 4) {
|
||||
m_stops = PRESETS[0].colors;
|
||||
}
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
auto *btn = new QPushButton(labels[i]);
|
||||
btn->setFixedSize(70, 30);
|
||||
connect(btn, &QPushButton::clicked, this, [this, i]{ onStopClicked(i); });
|
||||
btnLay->addWidget(btn);
|
||||
@@ -34,15 +79,23 @@ GradientDialog::GradientDialog(const QVector<QColor> &stops,
|
||||
}
|
||||
mainLay->addLayout(btnLay);
|
||||
|
||||
// Action buttons
|
||||
auto *dialogBtns = new QHBoxLayout;
|
||||
auto *resetBtn = new QPushButton("Reset to Default");
|
||||
connect(resetBtn, &QPushButton::clicked, this, &GradientDialog::onResetToDefault);
|
||||
dialogBtns->addWidget(resetBtn);
|
||||
|
||||
auto *presetLabel = new QLabel("Preset:");
|
||||
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();
|
||||
|
||||
auto *ok = new QPushButton("Apply");
|
||||
connect(ok, &QPushButton::clicked, this, &QDialog::accept);
|
||||
dialogBtns->addWidget(ok);
|
||||
|
||||
mainLay->addLayout(dialogBtns);
|
||||
|
||||
updatePreview();
|
||||
@@ -58,21 +111,18 @@ void GradientDialog::onStopClicked(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void GradientDialog::onResetToDefault()
|
||||
void GradientDialog::onPresetSelected(int index)
|
||||
{
|
||||
m_stops = {
|
||||
QColor("#078D70"), // Low
|
||||
QColor("#26CEAA"), // Mid
|
||||
QColor("#98E8C1"), // High
|
||||
QColor("#FFFFFF") // Peak
|
||||
};
|
||||
if (index < 0 || index >= PRESETS.size())
|
||||
return;
|
||||
m_stops = PRESETS[index].colors;
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void GradientDialog::updatePreview()
|
||||
{
|
||||
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);
|
||||
QPainter p(&pix);
|
||||
QLinearGradient grad(0, 0, pix.width(), 0);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
class QPushButton;
|
||||
class QLabel;
|
||||
class QComboBox;
|
||||
|
||||
class GradientDialog : public QDialog
|
||||
{
|
||||
@@ -19,12 +20,13 @@ public:
|
||||
|
||||
private slots:
|
||||
void onStopClicked(int index);
|
||||
void onResetToDefault();
|
||||
void onPresetSelected(int index);
|
||||
|
||||
private:
|
||||
QVector<QColor> m_stops;
|
||||
QVector<QPushButton*> m_buttons;
|
||||
QLabel *m_preview;
|
||||
QComboBox *m_presetCombo;
|
||||
void updatePreview();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user