#include "FractoriumPch.h" #include "Fractorium.h" /// /// Initialize the xforms selection UI. /// void Fractorium::InitXformsSelectUI() { m_XformsSelectionLayout = dynamic_cast(ui.XformsSelectGroupBoxScrollAreaWidget->layout()); connect(ui.XformsSelectAllButton, SIGNAL(clicked(bool)), this, SLOT(OnXformsSelectAllButtonClicked(bool)), Qt::QueuedConnection); connect(ui.XformsSelectNoneButton, SIGNAL(clicked(bool)), this, SLOT(OnXformsSelectNoneButtonClicked(bool)), Qt::QueuedConnection); ClearXformsSelections(); } /// /// Check all of the xform selection checkboxes. /// /// Ignored void Fractorium::OnXformsSelectAllButtonClicked(bool checked) { ForEachXformCheckbox([&](int i, QCheckBox * w, bool isFinal) { w->setChecked(true); }); } /// /// Uncheck all of the xform selection checkboxes. /// /// Ignored void Fractorium::OnXformsSelectNoneButtonClicked(bool checked) { ForEachXformCheckbox([&](int i, QCheckBox * w, bool isFinal) { w->setChecked(false); }); } /// /// Return whether the checkbox at the specified index is checked. /// /// The index of the xform to check for selection /// True if checked, else false. bool Fractorium::IsXformSelected(size_t i) { if (i < m_XformSelections.size()) if (const auto w = m_XformSelections[i]) return w->isChecked(); return false; } /// /// Return the number of xforms selected, optionally counting the final xform. /// /// Whether to include the final in the count if selected. /// The caption string int Fractorium::SelectedXformCount(bool includeFinal) { auto selCount = 0; ForEachXformCheckbox([&](int index, QCheckBox * cb, bool isFinal) { if (cb->isChecked()) { if (!isFinal || includeFinal) selCount++; } }); return selCount; } /// /// Clear all of the dynamically created xform checkboxes. /// void Fractorium::ClearXformsSelections() { QLayoutItem* child = nullptr; m_XformSelections.clear(); m_XformsSelectionLayout->blockSignals(true); while (m_XformsSelectionLayout->count() && (child = m_XformsSelectionLayout->takeAt(0))) { auto w = child->widget(); delete child; delete w; } m_XformsSelectionLayout->blockSignals(false); } /// /// Make a caption from an xform. /// The caption will be the xform count + 1, optionally followed by the xform's name. /// For final xforms, the string "Final" will be used in place of the count. /// /// The index of the xform to make a caption for /// The caption string template QString FractoriumEmberController::MakeXformCaption(size_t i) { const auto forceFinal = m_Fractorium->HaveFinal(); const auto isFinal = m_Ember.FinalXform() == m_Ember.GetTotalXform(i, forceFinal); QString caption = isFinal ? "Final" : QString::number(i + 1); if (const auto xform = m_Ember.GetTotalXform(i, forceFinal)) if (!xform->m_Name.empty()) caption += " (" + QString::fromStdString(xform->m_Name) + ")"; return caption; } /// /// Function to perform the specified operation on every dynamically created xform selection checkbox. /// /// The operation to perform which is a function taking the index of the xform, its checkbox, and a bool specifying whether it's final. void Fractorium::ForEachXformCheckbox(std::function func) { int i = 0; const auto haveFinal = HaveFinal(); for (auto& cb : m_XformSelections) func(i++, cb, haveFinal && cb == m_XformSelections.back()); } /// /// Function to perform the specified operation on one dynamically created xform selection checkbox. /// /// The index of the checkbox /// The operation to perform /// True if the checkbox was found, else false. template bool FractoriumEmberController::XformCheckboxAt(int i, std::function func) { if (i < m_Fractorium->m_XformSelections.size()) { if (const auto w = m_Fractorium->m_XformSelections[i]) { func(w); return true; } } return false; } /// /// Function to perform the specified operation on one dynamically created xform selection checkbox. /// The checkbox is specified by the xform it corresponds to, rather than its index. /// /// The xform that corresponds to the checkbox /// The operation to perform /// True if the checkbox was found, else false. template bool FractoriumEmberController::XformCheckboxAt(Xform* xform, std::function func) { const auto forceFinal = m_Fractorium->HaveFinal(); return XformCheckboxAt(m_Ember.GetTotalXformIndex(xform, forceFinal), func); } template class FractoriumEmberController; #ifdef DO_DOUBLE template class FractoriumEmberController; #endif