Solving Gnome Palette Editor problem

This commit is contained in:
Michel Mastriani
2019-05-19 18:10:56 -03:00
parent 4550f9dc87
commit 2d2d561e29
5 changed files with 94 additions and 4 deletions

View File

@ -396,6 +396,12 @@ void FractoriumEmberController<T>::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
/// <summary>
/// Slot called when palette editor window is closed.
/// </summary>
template <typename T>
void FractoriumEmberController<T>::SyncPalette(bool accepted)
{
size_t i = 0;
auto ed = m_Fractorium->m_PaletteEditor;
Palette<float> edPal;
Palette<float> prevPal = m_PreviosTempPalette;
map<size_t, float> 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));
}
/// <summary>
/// Slot called every time a color is changed in the palette editor.
/// </summary>
@ -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.
/// </summary>
/// <param name="result">Cancel/OK action</param>
void Fractorium::OnPaletteEditorFinished(int result)
{
m_Controller->SyncPalette(result == QDialog::Accepted);
}
/// <summary>
/// Apply the text in the palette filter text box to only show palettes whose names
/// contain the substring.