From b0dae7795ac3679a1ef87d1809a16a45fde36ed1 Mon Sep 17 00:00:00 2001 From: Person Date: Mon, 29 Jan 2018 22:14:48 -0800 Subject: [PATCH] --Bug fixes -Fix a variety of very strange bugs when clicking around on palettes in different files in the palette editor. --- Source/Ember/PaletteList.cpp | 13 +++++------ Source/Fractorium/DoubleSpinBox.cpp | 12 ++++++++-- .../PaletteEditor/PaletteEditor.cpp | 23 +++++++++++++++---- .../Fractorium/PaletteEditor/PaletteEditor.h | 1 + 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Source/Ember/PaletteList.cpp b/Source/Ember/PaletteList.cpp index b43ad0e..0d6d994 100644 --- a/Source/Ember/PaletteList.cpp +++ b/Source/Ember/PaletteList.cpp @@ -84,6 +84,7 @@ bool PaletteList::AddPaletteToFile(const string& filename, const Palette& if (auto p = GetPaletteListByFullPathOrFilename(filename)) { p->push_back(palette); + p->back().m_Filename = make_shared(filename);//Ensure the filename matches because this could have been duplicated from another palette file. p->back().m_Index = int(p->size()) - 1; Save(filename); return true; @@ -489,22 +490,20 @@ const string& PaletteList::Name(size_t index) } /// -/// Determines whether at least one palette in the passed in palette file is modifiable, +/// Determines whether all palettes in the passed in palette file are modifiable, /// meaning whether the source colors have at least one element in them. /// /// The full path to the existing palette file to search for a modifiable palette in -/// True if at least one palette in the file was modifiable, else false. +/// True if at all palettes in the file were modifiable, else false. template bool PaletteList::IsModifiable(const string& filename) { if (auto palFile = GetPaletteListByFullPathOrFilename(filename)) - { for (auto& pal : *palFile) - if (!pal.m_SourceColors.empty()) - return true; - } + if (pal.m_SourceColors.empty()) + return false; - return false; + return true; } /// diff --git a/Source/Fractorium/DoubleSpinBox.cpp b/Source/Fractorium/DoubleSpinBox.cpp index 14a0eb8..bcc6305 100644 --- a/Source/Fractorium/DoubleSpinBox.cpp +++ b/Source/Fractorium/DoubleSpinBox.cpp @@ -87,6 +87,7 @@ void DoubleSpinBox::DoubleClickNonZero(double val) /// /// Get the default step used when the user scrolls. /// +/// The default step as a double. double DoubleSpinBox::Step() { return m_Step; @@ -104,6 +105,7 @@ void DoubleSpinBox::Step(double step) /// /// Get the small step to be used when the user holds down shift while scrolling. /// +/// The small step as a double. double DoubleSpinBox::SmallStep() { return m_SmallStep; @@ -423,13 +425,19 @@ void VariationTreeDoubleSpinBox::FourOverPiActionTriggered(bool checked) { setV void VariationTreeDoubleSpinBox::SqrtTwoActionTriggered(bool checked) { setValue(M_SQRT2); } void VariationTreeDoubleSpinBox::SqrtThreeActionTriggered(bool checked) { setValue(std::sqrt(3.0)); } - +/// +/// Override which converts the passed in double to text. +/// +/// Text showing decimals() decimal places, or sometimes scientific notation. QString VariationTreeDoubleSpinBox::textFromValue(double value) const { return QWidget::locale().toString(value, 'g', decimals()); } - +/// +/// Override which converts the passed in text to a double +/// +/// The converted double double VariationTreeDoubleSpinBox::valueFromText(const QString& text) const { return QWidget::locale().toDouble(text); diff --git a/Source/Fractorium/PaletteEditor/PaletteEditor.cpp b/Source/Fractorium/PaletteEditor/PaletteEditor.cpp index 43c9dd0..28569ca 100644 --- a/Source/Fractorium/PaletteEditor/PaletteEditor.cpp +++ b/Source/Fractorium/PaletteEditor/PaletteEditor.cpp @@ -484,6 +484,7 @@ void PaletteEditor::EmitColorIndexChanged(size_t index, float value) /// Helper to lazily instantiate an open file dialog. /// Once created, it will remain alive for the duration of the program run. /// +/// The list of filenames selected QStringList PaletteEditor::SetupOpenImagesDialog() { QStringList filenames; @@ -555,6 +556,7 @@ void PaletteEditor::AddArrow(const QColor& color) /// /// The full path to the image file to get random colors from /// The number of colors to get +/// A map whose keys are the color indices from 0-1, and whose values are the gradient arrows containing the color for each key position. map PaletteEditor::GetRandomColorsFromImage(QString filename, int numPoints) { map colors; @@ -585,10 +587,11 @@ map PaletteEditor::GetRandomColorsFromImage(QString filena /// void PaletteEditor::EnablePaletteFileControls() { - bool b = m_PaletteList->IsModifiable(m_CurrentPaletteFilePath);//At least one in the file is not fixed. + bool b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable. ui->DeletePaletteButton->setEnabled(b); ui->CopyPaletteFileButton->setEnabled(b); ui->AppendPaletteButton->setEnabled(b); + ui->OverwritePaletteButton->setEnabled(b); } /// @@ -596,10 +599,11 @@ void PaletteEditor::EnablePaletteFileControls() /// void PaletteEditor::EnablePaletteControls() { - auto& palette = m_GradientColorView->GetPalette(256); - bool b = !palette.m_SourceColors.empty(); - bool any = m_PaletteList->IsModifiable(m_CurrentPaletteFilePath);//At least one in the file is not fixed. - ui->OverwritePaletteButton->setEnabled(b && any); + bool b = IsCurrentPaletteAndFileEditable();//Both the file and the current palette must be editable. + ui->DeletePaletteButton->setEnabled(b); + ui->CopyPaletteFileButton->setEnabled(b); + ui->AppendPaletteButton->setEnabled(b); + ui->OverwritePaletteButton->setEnabled(b && (GetFilename(m_CurrentPaletteFilePath) == GetFilename(*m_GradientColorView->GetPalette(256).m_Filename.get())));//Only allow overwrite if the palette is from the file it's overwriting a palette in. ui->AddColorButton->setEnabled(b); ui->DistributeColorsButton->setEnabled(b); ui->AutoDistributeCheckBox->setEnabled(b); @@ -609,4 +613,13 @@ void PaletteEditor::EnablePaletteControls() ui->ArrowsSpinBox->setEnabled(b); ui->CreatePaletteFromImageButton->setEnabled(b); ui->CreatePaletteAgainFromImageButton->setEnabled(b); +} + +/// +/// Determine whether the current file and the palette selected within it are both editable. +/// +/// True if both the currently selected palette is editable and if all palettes in the currently selected file are editable. +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 f9fc42a..7835330 100644 --- a/Source/Fractorium/PaletteEditor/PaletteEditor.h +++ b/Source/Fractorium/PaletteEditor/PaletteEditor.h @@ -73,6 +73,7 @@ private: map GetRandomColorsFromImage(QString filename, int numPoints); void EnablePaletteFileControls(); void EnablePaletteControls(); + bool IsCurrentPaletteAndFileEditable(); bool m_PaletteFileChanged = false; int m_PaletteIndex = 0; QString m_Filename;