Improve color slider edit history
This commit is contained in:
parent
eefa46a2a2
commit
4dc598455f
4 changed files with 24 additions and 3 deletions
|
@ -25,6 +25,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void colorChanged(QRgb color);
|
void colorChanged(QRgb color);
|
||||||
void bitDepthChanged(int bits);
|
void bitDepthChanged(int bits);
|
||||||
|
void editingFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ColorInputWidget *ui;
|
Ui::ColorInputWidget *ui;
|
||||||
|
|
|
@ -39,6 +39,7 @@ private:
|
||||||
|
|
||||||
Tileset* getTileset(int paletteId);
|
Tileset* getTileset(int paletteId);
|
||||||
void refreshColorInputs();
|
void refreshColorInputs();
|
||||||
|
void commitEditHistory();
|
||||||
void commitEditHistory(int paletteId);
|
void commitEditHistory(int paletteId);
|
||||||
void restoreWindowState();
|
void restoreWindowState();
|
||||||
void closeEvent(QCloseEvent*);
|
void closeEvent(QCloseEvent*);
|
||||||
|
|
|
@ -34,6 +34,7 @@ ColorInputWidget::ColorInputWidget(const QString &title, QWidget *parent) :
|
||||||
void ColorInputWidget::init() {
|
void ColorInputWidget::init() {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// Connect color change signals
|
||||||
connect(ui->slider_Red, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
connect(ui->slider_Red, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
||||||
connect(ui->slider_Green, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
connect(ui->slider_Green, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
||||||
connect(ui->slider_Blue, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
connect(ui->slider_Blue, &QSlider::valueChanged, this, &ColorInputWidget::setRgbFromSliders);
|
||||||
|
@ -46,6 +47,19 @@ void ColorInputWidget::init() {
|
||||||
ui->lineEdit_Hex->setValidator(&hexValidator);
|
ui->lineEdit_Hex->setValidator(&hexValidator);
|
||||||
connect(ui->lineEdit_Hex, &QLineEdit::textEdited, this, &ColorInputWidget::setRgbFromHexString);
|
connect(ui->lineEdit_Hex, &QLineEdit::textEdited, this, &ColorInputWidget::setRgbFromHexString);
|
||||||
|
|
||||||
|
// We have separate signals for when color input editing finishes.
|
||||||
|
// This is mostly useful for external commit histories, esp. for the sliders which can rapidly emit color change signals.
|
||||||
|
connect(ui->slider_Red, &QSlider::sliderReleased, this, &ColorInputWidget::editingFinished);
|
||||||
|
connect(ui->slider_Green, &QSlider::sliderReleased, this, &ColorInputWidget::editingFinished);
|
||||||
|
connect(ui->slider_Blue, &QSlider::sliderReleased, this, &ColorInputWidget::editingFinished);
|
||||||
|
|
||||||
|
connect(ui->spinBox_Red, &QSpinBox::editingFinished, this, &ColorInputWidget::editingFinished);
|
||||||
|
connect(ui->spinBox_Green, &QSpinBox::editingFinished, this, &ColorInputWidget::editingFinished);
|
||||||
|
connect(ui->spinBox_Blue, &QSpinBox::editingFinished, this, &ColorInputWidget::editingFinished);
|
||||||
|
|
||||||
|
connect(ui->lineEdit_Hex, &QLineEdit::editingFinished, this, &ColorInputWidget::editingFinished);
|
||||||
|
|
||||||
|
// Connect color picker
|
||||||
connect(ui->button_Eyedrop, &QToolButton::clicked, this, &ColorInputWidget::pickColor);
|
connect(ui->button_Eyedrop, &QToolButton::clicked, this, &ColorInputWidget::pickColor);
|
||||||
|
|
||||||
setBitDepth(24);
|
setBitDepth(24);
|
||||||
|
@ -210,5 +224,6 @@ void ColorInputWidget::pickColor() {
|
||||||
if (picker.exec() == QDialog::Accepted) {
|
if (picker.exec() == QDialog::Accepted) {
|
||||||
QColor c = picker.getColor();
|
QColor c = picker.getColor();
|
||||||
setColor(c.rgb());
|
setColor(c.rgb());
|
||||||
|
emit editingFinished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset
|
||||||
for (int i = 0; i < this->numColors; i++) {
|
for (int i = 0; i < this->numColors; i++) {
|
||||||
auto colorInput = new ColorInputWidget(QString("Color %1").arg(i));
|
auto colorInput = new ColorInputWidget(QString("Color %1").arg(i));
|
||||||
connect(colorInput, &ColorInputWidget::colorChanged, [this, i](QRgb color) { setRgb(i, color); });
|
connect(colorInput, &ColorInputWidget::colorChanged, [this, i](QRgb color) { setRgb(i, color); });
|
||||||
|
connect(colorInput, &ColorInputWidget::editingFinished, [this] { commitEditHistory(); });
|
||||||
this->colorInputs.append(colorInput);
|
this->colorInputs.append(colorInput);
|
||||||
ui->layout_Colors->addWidget(colorInput, i / numColorsPerRow, i % numColorsPerRow);
|
ui->layout_Colors->addWidget(colorInput, i / numColorsPerRow, i % numColorsPerRow);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset
|
||||||
connect(this->ui->bit_depth_24, &QRadioButton::toggled, [this](bool checked){ if (checked) this->setBitDepth(24); });
|
connect(this->ui->bit_depth_24, &QRadioButton::toggled, [this](bool checked){ if (checked) this->setBitDepth(24); });
|
||||||
|
|
||||||
this->setPaletteId(paletteId);
|
this->setPaletteId(paletteId);
|
||||||
this->commitEditHistory(this->ui->spinBox_PaletteId->value());
|
this->commitEditHistory();
|
||||||
this->restoreWindowState();
|
this->restoreWindowState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +77,6 @@ void PaletteEditor::setRgb(int colorIndex, QRgb rgb) {
|
||||||
tileset->palettes[paletteId][colorIndex] = rgb;
|
tileset->palettes[paletteId][colorIndex] = rgb;
|
||||||
tileset->palettePreviews[paletteId][colorIndex] = rgb;
|
tileset->palettePreviews[paletteId][colorIndex] = rgb;
|
||||||
|
|
||||||
commitEditHistory(paletteId);
|
|
||||||
emit changedPaletteColor();
|
emit changedPaletteColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +120,10 @@ void PaletteEditor::on_spinBox_PaletteId_valueChanged(int paletteId) {
|
||||||
emit this->changedPalette(paletteId);
|
emit this->changedPalette(paletteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaletteEditor::commitEditHistory() {
|
||||||
|
commitEditHistory(ui->spinBox_PaletteId->value());
|
||||||
|
}
|
||||||
|
|
||||||
void PaletteEditor::commitEditHistory(int paletteId) {
|
void PaletteEditor::commitEditHistory(int paletteId) {
|
||||||
QList<QRgb> colors;
|
QList<QRgb> colors;
|
||||||
for (int i = 0; i < this->numColors; i++) {
|
for (int i = 0; i < this->numColors; i++) {
|
||||||
|
|
Loading…
Reference in a new issue