diff --git a/Source/Fractorium/Fractorium.h b/Source/Fractorium/Fractorium.h index 5de0a75..0ecc8b0 100644 --- a/Source/Fractorium/Fractorium.h +++ b/Source/Fractorium/Fractorium.h @@ -21,6 +21,7 @@ class GLWidget; class QssDialog; +class PaletteEditor; // michel class FractoriumOptionsDialog; class FractoriumVariationsDialog; class FractoriumFinalRenderDialog; @@ -359,6 +360,7 @@ public slots: void OnPaletteEditorColorChanged(); void OnPaletteEditorFileChanged(); void OnPaletteEditorColorIndexChanged(size_t index, float value); + void OnPaletteEditorFinished(int result); // michel //Info. void OnSummaryTableHeaderResized(int logicalIndex, int oldSize, int newSize); diff --git a/Source/Fractorium/FractoriumEmberController.h b/Source/Fractorium/FractoriumEmberController.h index 918b464..0322aa9 100644 --- a/Source/Fractorium/FractoriumEmberController.h +++ b/Source/Fractorium/FractoriumEmberController.h @@ -249,6 +249,7 @@ public: virtual void SetBasePaletteAndAdjust(const Palette& palette) { } virtual void PaletteEditorButtonClicked() { } virtual void PaletteEditorColorChanged() { } + virtual void SyncPalette(bool accepted) { } // michel QImage& FinalPaletteImage() { return m_FinalPaletteImage; } //Info. @@ -310,7 +311,7 @@ protected: unique_ptr m_Renderer; QTIsaac m_Rand; Fractorium* m_Fractorium; - Palette m_TempPalette; + Palette m_TempPalette, m_PreviosTempPalette; // michel std::unique_ptr m_RenderTimer; std::unique_ptr m_RenderRestartTimer; shared_ptr> m_PaletteList; @@ -537,6 +538,7 @@ public: virtual void SetBasePaletteAndAdjust(const Palette& palette) override; virtual void PaletteEditorButtonClicked() override; virtual void PaletteEditorColorChanged() override; + virtual void SyncPalette(bool accepted) override; // michel //Info. virtual void FillSummary() override; diff --git a/Source/Fractorium/FractoriumPalette.cpp b/Source/Fractorium/FractoriumPalette.cpp index 37d9ae6..b349c98 100644 --- a/Source/Fractorium/FractoriumPalette.cpp +++ b/Source/Fractorium/FractoriumPalette.cpp @@ -396,6 +396,12 @@ void FractoriumEmberController::PaletteEditorButtonClicked() ed->SetColorIndices(colorIndices); ed->SetPaletteFile(m_CurrentPaletteFilePath); + // michel - waiting to be approved - may be used with IFDEF LINUX + m_PreviosTempPalette = m_TempPalette; + ed->SetPreviousColorIndices(colorIndices); + ed->show(); + return; + //ed->setpal if (ed->exec() == QDialog::Accepted) { @@ -444,10 +450,11 @@ void Fractorium::OnPaletteEditorButtonClicked(bool checked) { if (!m_PaletteEditor) { - m_PaletteEditor = new PaletteEditor(this); + m_PaletteEditor = new PaletteEditor(this); connect(m_PaletteEditor, SIGNAL(PaletteChanged()), this, SLOT(OnPaletteEditorColorChanged()), Qt::QueuedConnection); connect(m_PaletteEditor, SIGNAL(PaletteFileChanged()), this, SLOT(OnPaletteEditorFileChanged()), Qt::QueuedConnection); connect(m_PaletteEditor, SIGNAL(ColorIndexChanged(size_t, float)), this, SLOT(OnPaletteEditorColorIndexChanged(size_t, float)), Qt::QueuedConnection); + connect(m_PaletteEditor, SIGNAL(finished(int)), this, SLOT(OnPaletteEditorFinished(int)), Qt::QueuedConnection); // michel } m_PaletteChanged = false; @@ -455,6 +462,51 @@ void Fractorium::OnPaletteEditorButtonClicked(bool checked) m_Controller->PaletteEditorButtonClicked(); } +// michel +/// +/// Slot called when palette editor window is closed. +/// +template +void FractoriumEmberController::SyncPalette(bool accepted) +{ + size_t i = 0; + auto ed = m_Fractorium->m_PaletteEditor; + Palette edPal; + Palette prevPal = m_PreviosTempPalette; + map colorIndices; + bool forceFinal = m_Fractorium->HaveFinal(); + + if (accepted) + { + //Copy all just to be safe, because they may or may not have synced. + colorIndices = ed->GetColorIndices(); + + for (auto& index : colorIndices) + if (auto xform = m_Ember.GetTotalXform(index.first, forceFinal)) + xform->m_ColorX = index.second; + + edPal = ed->GetPalette(int(prevPal.Size())); + SetBasePaletteAndAdjust(edPal);//This will take care of updating the color index controls. + + if (edPal.m_Filename.get() && !edPal.m_Filename->empty()) + m_Fractorium->SetPaletteFileComboIndex(*edPal.m_Filename); + } + else if (m_Fractorium->PaletteChanged())//They clicked cancel, but synced at least once, restore the previous palette. + { + colorIndices = ed->GetPreviousColorIndices(); + + for (auto& index : colorIndices) + if (auto xform = m_Ember.GetTotalXform(index.first, forceFinal)) + xform->m_ColorX = index.second; + + SetBasePaletteAndAdjust(prevPal);//This will take care of updating the color index controls. + } + + //Whether the current palette file was changed or not, if it's modifiable then reload it just to be safe (even though it might be overkill). + if (m_PaletteList->IsModifiable(m_CurrentPaletteFilePath)) + m_Fractorium->OnPaletteFilenameComboChanged(QString::fromStdString(m_CurrentPaletteFilePath)); +} + /// /// Slot called every time a color is changed in the palette editor. /// @@ -497,6 +549,15 @@ void Fractorium::OnPaletteEditorColorIndexChanged(size_t index, float value) OnXformColorIndexChanged(value, true, true, true, eXformUpdate::UPDATE_SPECIFIC, index); } +// michel +/// Slot called after EditPallete is closed. +/// +/// Cancel/OK action +void Fractorium::OnPaletteEditorFinished(int result) +{ + m_Controller->SyncPalette(result == QDialog::Accepted); +} + /// /// Apply the text in the palette filter text box to only show palettes whose names /// contain the substring. diff --git a/Source/Fractorium/PaletteEditor/PaletteEditor.cpp b/Source/Fractorium/PaletteEditor/PaletteEditor.cpp index 2e5ebd6..a76c5ac 100644 --- a/Source/Fractorium/PaletteEditor/PaletteEditor.cpp +++ b/Source/Fractorium/PaletteEditor/PaletteEditor.cpp @@ -117,6 +117,17 @@ map PaletteEditor::GetColorIndices() const return m_GradientColorView->GetColorIndices(); } +// michel +/// +/// Return the previous xform color indices as a map. +/// The keys are the xform indices, and the values are the color indices. +/// +/// The color indices +map PaletteEditor::GetPreviousColorIndices() const +{ + return m_PreviousColorIndices; +} + /// /// Assign the values of the xform color indices to the arrows. /// This will clear out any existing values first. @@ -127,6 +138,16 @@ void PaletteEditor::SetColorIndices(const map& indices) m_GradientColorView->SetColorIndices(indices); } +// michel +/// +/// Backup xform color +/// +/// The color indices to backup +void PaletteEditor::SetPreviousColorIndices(const map& indices) +{ + m_PreviousColorIndices = indices; +} + /// /// Return the filename of the currently selected palette. /// Note this will only be filled in if the user has clicked in the palette @@ -636,4 +657,4 @@ void PaletteEditor::EnablePaletteControls() bool PaletteEditor::IsCurrentPaletteAndFileEditable() { return m_PaletteList->IsModifiable(m_CurrentPaletteFilePath) && !m_GradientColorView->GetPalette(256).m_SourceColors.empty(); -} \ No newline at end of file +} diff --git a/Source/Fractorium/PaletteEditor/PaletteEditor.h b/Source/Fractorium/PaletteEditor/PaletteEditor.h index 4893e30..24ffc3b 100644 --- a/Source/Fractorium/PaletteEditor/PaletteEditor.h +++ b/Source/Fractorium/PaletteEditor/PaletteEditor.h @@ -1,6 +1,7 @@ #pragma once #include "FractoriumPch.h" +#include "Fractorium.h" // michel #include "ColorPickerWidget.h" #include "GradientColorsView.h" #include "EmberFile.h" @@ -26,14 +27,16 @@ class PaletteEditor : public QDialog Q_OBJECT public: - explicit PaletteEditor(QWidget* p = nullptr); + explicit PaletteEditor(QWidget* p = nullptr); public: bool Sync(); Palette& GetPalette(int size); void SetPalette(const Palette& palette); map GetColorIndices() const; + map GetPreviousColorIndices() const; // michel void SetColorIndices(const map& indices); + void SetPreviousColorIndices(const map& indices); // michel string GetPaletteFile() const; void SetPaletteFile(const string& filename); @@ -77,6 +80,7 @@ private: bool IsCurrentPaletteAndFileEditable(); bool m_PaletteFileChanged = false; int m_PaletteIndex = 0; + map m_PreviousColorIndices; // michel QString m_Filename; string m_CurrentPaletteFilePath; ColorPickerWidget* m_ColorPicker = nullptr;