From 12d5f22475fdb247eb46de50fd45332238142f63 Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 6 Jul 2022 23:34:52 -0400 Subject: [PATCH] improve palette editor ui - remove redundant RGB label - in color picker, instruct user to press SPACE - add toggle between 15 and 24 bit depth displaying --- forms/colorpicker.ui | 255 +++--- forms/paletteeditor.ui | 1575 +++++++++++++++++------------------- include/ui/paletteeditor.h | 4 +- src/ui/paletteeditor.cpp | 172 +++- 4 files changed, 1019 insertions(+), 987 deletions(-) diff --git a/forms/colorpicker.ui b/forms/colorpicker.ui index 213116ee..a8cafe93 100644 --- a/forms/colorpicker.ui +++ b/forms/colorpicker.ui @@ -6,110 +6,47 @@ 0 0 - 357 - 186 + 383 + 243 Color Picker - + - + - QFrame::NoFrame + QFrame::Box QFrame::Plain - + - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 0 - 0 - - - - - 120 - 120 - - - - - 120 - 120 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - QFrame::NoFrame - - - QFrame::Plain - - - - + QFrame::NoFrame QFrame::Plain - + - + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 - + 0 @@ -118,39 +55,30 @@ - 50 - 50 + 120 + 120 - 50 - 50 + 120 + 120 - - - 50 - 50 - - - - QFrame::StyledPanel - - - QFrame::Raised + + - + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 @@ -159,32 +87,131 @@ - - - - Courier - + + + QFrame::NoFrame - - RGB (000, 000, 000) - - - - - - - - Courier - - - - #FFFFFF + + QFrame::Plain + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 50 + 50 + + + + + 50 + 50 + + + + + 50 + 50 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Courier + + + + RGB (000, 000, 000) + + + + + + + + Courier + + + + #FFFFFF + + + + + + + + + Courier + + + + press [SPACE] to capture color + + + Qt::AlignCenter + + + diff --git a/forms/paletteeditor.ui b/forms/paletteeditor.ui index a17e5dfd..35864675 100644 --- a/forms/paletteeditor.ui +++ b/forms/paletteeditor.ui @@ -6,60 +6,16 @@ 0 0 - 887 - 1013 + 907 + 886 - MainWindow + Palette Editor - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 16 - - - 16 - - - 16 - - - 16 - - - - - Palette - - - - - - - Qt::StrongFocus - - - - - - - + + @@ -317,49 +273,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -373,17 +287,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -637,49 +586,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -693,17 +600,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -957,49 +899,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -1013,17 +913,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -1277,49 +1212,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -1333,17 +1226,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -1597,49 +1525,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -1653,17 +1539,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -1917,49 +1838,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -1973,17 +1852,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -2237,49 +2151,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -2293,17 +2165,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -2557,49 +2464,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -2613,17 +2478,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -2877,49 +2777,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -2933,17 +2791,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -3197,49 +3090,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -3253,17 +3104,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -3517,49 +3403,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -3573,17 +3417,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -3837,49 +3716,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -3893,17 +3730,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -4157,49 +4029,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -4213,17 +4043,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -4477,49 +4342,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -4533,17 +4356,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -4797,49 +4655,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -4853,17 +4669,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -5117,49 +4968,7 @@ QFrame::Raised - - - 0 - - - 0 - - - 0 - - - 0 - - - - - rgb(00, 00, 00) - - - - - - - ... - - - - :/icons/pipette.ico:/icons/pipette.ico - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - + 0 @@ -5173,17 +4982,52 @@ 0 - - - # + + + QFrame::NoFrame - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + QFrame::Raised + + + 0 + + + 0 + + + 0 + + + 0 + + + + + # + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + - + + + ... + + + + :/icons/pipette.ico:/icons/pipette.ico + + @@ -5197,6 +5041,69 @@ + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + Palette + + + + + + + Qt::StrongFocus + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Bit Depth: + + + + + + + 15 + + + + + + + 24 + + + true + + + + + + @@ -5204,7 +5111,7 @@ 0 0 - 887 + 907 22 diff --git a/include/ui/paletteeditor.h b/include/ui/paletteeditor.h index 59f0c555..9b846d60 100644 --- a/include/ui/paletteeditor.h +++ b/include/ui/paletteeditor.h @@ -36,7 +36,6 @@ private: QList> sliders; QList> spinners; QList frames; - QList rgbLabels; QList pickButtons; QList hexEdits; @@ -59,6 +58,9 @@ private: void setRgbFromHexEdit(int colorIndex); void setRgbFromSpinners(int colorIndex); + void setBitDepth(int bits); + int bitDepth = 24; + class HexCodeValidator : public QValidator { virtual QValidator::State validate(QString &input, int &) const override { input = input.toUpper(); diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index 0dd7bc3f..ba128efa 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -10,6 +10,10 @@ #include static inline int rgb5(int rgb) { return round(static_cast(rgb * 31) / 255.0); } +static inline int rgb8(int rgb) { return round(rgb * 255. / 31.); } +static inline int gbaRed(int rgb) { return rgb & 0x1f; } +static inline int gbaGreen(int rgb) { return (rgb >> 5) & 0x1f; } +static inline int gbaBlue(int rgb) { return (rgb >> 10) & 0x1f; } PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset *secondaryTileset, int paletteId, QWidget *parent) : QMainWindow(parent), @@ -21,7 +25,7 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset this->ui->setupUi(this); this->ui->spinBox_PaletteId->setMinimum(0); this->ui->spinBox_PaletteId->setMaximum(Project::getNumPalettesTotal() - 1); - + this->sliders.clear(); for (int i = 0; i < 16; i++) { QList rgbSliders; @@ -51,13 +55,7 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset this->frames.clear(); for (int i = 0; i < 16; i++) { this->frames.append(this->ui->container->findChild("colorFrame_" + QString::number(i))); - this->frames[i]->setFrameStyle(QFrame::Box | QFrame::Plain); - } - - this->rgbLabels.clear(); - for (int i = 0; i < 16; i++) { - this->rgbLabels.append(this->ui->container->findChild("rgb_" + QString::number(i))); - this->rgbLabels[i]->setStyleSheet("QLabel { font-family: \"Courier\" }"); + this->frames[i]->setFrameStyle(QFrame::NoFrame); } this->pickButtons.clear(); @@ -70,8 +68,6 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset for (int i = 0; i < 16; i++) { this->hexEdits.append(this->ui->container->findChild("hex_" + QString::number(i))); this->hexEdits[i]->setValidator(hexValidator); - this->hexEdits[i]->setInputMask("HHHHHH"); - this->hexEdits[i]->setMaxLength(6); } // Connect to function that will update color when hex edit is changed @@ -91,6 +87,12 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset connect(this->pickButtons[i], &QToolButton::clicked, [this, i](){ this->pickColor(i); }); } + setBitDepth(24); + + // Connect bit depth buttons + connect(this->ui->bit_depth_15, &QRadioButton::toggled, [this](bool checked){ if (checked) this->setBitDepth(15); }); + connect(this->ui->bit_depth_24, &QRadioButton::toggled, [this](bool checked){ if (checked) this->setBitDepth(24); }); + this->setPaletteId(paletteId); this->commitEditHistory(this->ui->spinBox_PaletteId->value()); this->restoreWindowState(); @@ -108,31 +110,41 @@ void PaletteEditor::updateColorUi(int colorIndex, QRgb rgb) { int red = qRed(rgb); int green = qGreen(rgb); int blue = qBlue(rgb); - - // sliders - this->sliders[colorIndex][0]->setValue(rgb5(red)); - this->sliders[colorIndex][1]->setValue(rgb5(green)); - this->sliders[colorIndex][2]->setValue(rgb5(blue)); - // hex - QColor color(red, green, blue); - QString hexcode = color.name().remove(0, 1).toUpper(); - this->hexEdits[colorIndex]->setText(hexcode); + if (this->bitDepth == 15) { + // sliders + this->sliders[colorIndex][0]->setValue(rgb5(red)); + this->sliders[colorIndex][1]->setValue(rgb5(green)); + this->sliders[colorIndex][2]->setValue(rgb5(blue)); - // spinners - this->spinners[colorIndex][0]->setValue(red); - this->spinners[colorIndex][1]->setValue(green); - this->spinners[colorIndex][2]->setValue(blue); + // hex + int hex15 = (rgb5(blue) << 10) | (rgb5(green) << 5) | rgb5(red); + QString hexcode = QString::number(hex15, 16).toUpper(); + + // spinners + this->spinners[colorIndex][0]->setValue(rgb5(red)); + this->spinners[colorIndex][1]->setValue(rgb5(green)); + this->spinners[colorIndex][2]->setValue(rgb5(blue)); + } else { + // sliders + this->sliders[colorIndex][0]->setValue(red); + this->sliders[colorIndex][1]->setValue(green); + this->sliders[colorIndex][2]->setValue(blue); + + // hex + QColor color(red, green, blue); + QString hexcode = color.name().remove(0, 1).toUpper(); + this->hexEdits[colorIndex]->setText(hexcode); + + // spinners + this->spinners[colorIndex][0]->setValue(red); + this->spinners[colorIndex][1]->setValue(green); + this->spinners[colorIndex][2]->setValue(blue); + } // frame QString stylesheet = QString("background-color: rgb(%1, %2, %3);").arg(red).arg(green).arg(blue); this->frames[colorIndex]->setStyleSheet(stylesheet); - - // rgb label - int w = 3; - QChar spc = ' '; - int base = 10; - this->rgbLabels[colorIndex]->setText(QString(" RGB(%1, %2, %3)").arg(red, w, base, spc).arg(green, w, base, spc).arg(blue, w, base, spc)); setSignalsEnabled(true); } @@ -156,6 +168,68 @@ void PaletteEditor::setSignalsEnabled(bool enabled) { } } +void PaletteEditor::setBitDepth(int bits) { + setSignalsEnabled(false); + switch (bits) { + case 15: + for (int i = 0; i < 16; i++) { + // sliders ranged [0, 31] with 1 single step and 4 page step + this->sliders[i][0]->setSingleStep(1); + this->sliders[i][1]->setSingleStep(1); + this->sliders[i][2]->setSingleStep(1); + this->sliders[i][0]->setPageStep(4); + this->sliders[i][1]->setPageStep(4); + this->sliders[i][2]->setPageStep(4); + this->sliders[i][0]->setMaximum(31); + this->sliders[i][1]->setMaximum(31); + this->sliders[i][2]->setMaximum(31); + + // spinners limited [0, 31] with 1 step + this->spinners[i][0]->setSingleStep(1); + this->spinners[i][1]->setSingleStep(1); + this->spinners[i][2]->setSingleStep(1); + this->spinners[i][0]->setMaximum(31); + this->spinners[i][1]->setMaximum(31); + this->spinners[i][2]->setMaximum(31); + + // hex box now 4 digits + this->hexEdits[i]->setInputMask("HHHH"); + this->hexEdits[i]->setMaxLength(4); + } + break; + case 24: + default: + for (int i = 0; i < 16; i++) { + // sliders ranged [0, 31] with 1 single step and 4 page step + this->sliders[i][0]->setSingleStep(8); + this->sliders[i][1]->setSingleStep(8); + this->sliders[i][2]->setSingleStep(8); + this->sliders[i][0]->setPageStep(24); + this->sliders[i][1]->setPageStep(24); + this->sliders[i][2]->setPageStep(24); + this->sliders[i][0]->setMaximum(255); + this->sliders[i][1]->setMaximum(255); + this->sliders[i][2]->setMaximum(255); + + // spinners limited [0, 31] with 1 step + this->spinners[i][0]->setSingleStep(8); + this->spinners[i][1]->setSingleStep(8); + this->spinners[i][2]->setSingleStep(8); + this->spinners[i][0]->setMaximum(255); + this->spinners[i][1]->setMaximum(255); + this->spinners[i][2]->setMaximum(255); + + // hex box now 4 digits + this->hexEdits[i]->setInputMask("HHHHHH"); + this->hexEdits[i]->setMaxLength(6); + } + break; + } + this->bitDepth = bits; + refreshColorUis(); + setSignalsEnabled(true); +} + void PaletteEditor::setRgb(int colorIndex, QRgb rgb) { int paletteNum = this->ui->spinBox_PaletteId->value(); @@ -172,23 +246,45 @@ void PaletteEditor::setRgb(int colorIndex, QRgb rgb) { } void PaletteEditor::setRgbFromSliders(int colorIndex) { - setRgb(colorIndex, qRgb(round(this->sliders[colorIndex][0]->value() * 255. / 31.), - round(this->sliders[colorIndex][1]->value() * 255. / 31.), - round(this->sliders[colorIndex][2]->value() * 255. / 31.))); + if (this->bitDepth == 15) { + setRgb(colorIndex, qRgb(rgb8(this->sliders[colorIndex][0]->value()), + rgb8(this->sliders[colorIndex][1]->value()), + rgb8(this->sliders[colorIndex][2]->value()))); + } else { + setRgb(colorIndex, qRgb(this->sliders[colorIndex][0]->value(), + this->sliders[colorIndex][1]->value(), + this->sliders[colorIndex][2]->value())); + } } void PaletteEditor::setRgbFromHexEdit(int colorIndex) { QString text = this->hexEdits[colorIndex]->text(); bool ok = false; - QRgb rgb = text.toInt(&ok, 16); - if (!ok) rgb = 0xFFFFFFFF; - setRgb(colorIndex, rgb); + if (this->bitDepth == 15) { + int rgb15 = text.toInt(&ok, 16); + int rc = gbaRed(rgb15); + int gc = gbaGreen(rgb15); + int bc = gbaBlue(rgb15); + QRgb rgb = qRgb(rc, gc, bc); + if (!ok) rgb = 0xFFFFFFFF; + setRgb(colorIndex, rgb); + } else { + QRgb rgb = text.toInt(&ok, 16); + if (!ok) rgb = 0xFFFFFFFF; + setRgb(colorIndex, rgb); + } } void PaletteEditor::setRgbFromSpinners(int colorIndex) { - setRgb(colorIndex, qRgb(this->spinners[colorIndex][0]->value(), - this->spinners[colorIndex][1]->value(), - this->spinners[colorIndex][2]->value())); + if (this->bitDepth == 15) { + setRgb(colorIndex, qRgb(rgb8(this->spinners[colorIndex][0]->value()), + rgb8(this->spinners[colorIndex][1]->value()), + rgb8(this->spinners[colorIndex][2]->value()))); + } else { + setRgb(colorIndex, qRgb(this->spinners[colorIndex][0]->value(), + this->spinners[colorIndex][1]->value(), + this->spinners[colorIndex][2]->value())); + } } void PaletteEditor::refreshColorUis() {