--User changes

Add the ability to set the current xform by pressing F1 - F32.
 Add the ability to toggle an entire row or column of xaos values.

--Bug fixes
 Prevent xform index flickering whenever changing the number of xforms.

--Code changes
 Remove ForEach() wrappers and replace with range based for loops with auto.
 Replace every regular for loop with a range based one where applicable. Note this doesn't work everywhere.
 Make event filter application wide.
 Add parameter to FillXforms() to specify the index to select, default 0.
 Rename some scroll areas and layouts to names that make sense, rather than their designer defaults.
This commit is contained in:
mfeemster
2015-05-03 17:13:14 -07:00
parent cd5669d0ef
commit e005b4c20e
29 changed files with 282 additions and 212 deletions

View File

@ -385,8 +385,8 @@ void FractoriumFinalRenderDialog::OnPlatformComboCurrentIndexChanged(int index)
ui.FinalRenderDeviceCombo->clear();
for (size_t i = 0; i < devices.size(); i++)
ui.FinalRenderDeviceCombo->addItem(QString::fromStdString(devices[i]));
for (auto& device : devices)
ui.FinalRenderDeviceCombo->addItem(QString::fromStdString(device));
}
/// <summary>

View File

@ -522,8 +522,8 @@ void FinalRenderEmberController<T>::SyncGuiToEmbers(size_t widthOverride, size_t
{
if (m_FinalRenderDialog->ApplyToAll())
{
for (size_t i = 0; i < m_EmberFile.Size(); i++)
SyncGuiToEmber(m_EmberFile.m_Embers[i], widthOverride, heightOverride);
for (auto& ember : m_EmberFile.m_Embers)
SyncGuiToEmber(ember, widthOverride, heightOverride);
}
else
{

View File

@ -139,7 +139,7 @@ Fractorium::Fractorium(QWidget* p)
ui.GeometryTable->setStyleSheet("QTableWidget::item { padding: 1px; }");
ui.FilterTable->setStyleSheet("QTableWidget::item { padding: 1px; }");
ui.IterationTable->setStyleSheet("QTableWidget::item { padding: 1px; }");
ui.AffineTab->setStyleSheet("QTableWidget::item { padding: 1px; }");
ui.XformAffineTab->setStyleSheet("QTableWidget::item { padding: 1px; }");
ui.XformWeightNameTable->setStyleSheet("QTableWidget::item { padding: 0px; }");
ui.XformColorIndexTable->setStyleSheet("QTableWidget::item { padding: 1px; }");
ui.XformColorValuesTable->setStyleSheet("QTableWidget::item { padding: 1px; }");
@ -153,8 +153,6 @@ Fractorium::Fractorium(QWidget* p)
SetCoordinateStatus(0, 0, 0, 0);
SetTabOrders();
ui.GLParentScrollArea->installEventFilter(this);
//At this point, everything has been setup except the renderer. Shortly after
//this constructor exits, GLWidget::InitGL() will create the initial flock and start the rendering timer
//which executes whenever the program is idle. Upon starting the timer, the renderer
@ -278,11 +276,17 @@ bool Fractorium::eventFilter(QObject* o, QEvent* e)
{
m_WidthSpin->DoubleClickNonZero(ui.GLParentScrollArea->width());
m_HeightSpin->DoubleClickNonZero(ui.GLParentScrollArea->height());
//qDebug() << "scroll area resized";
}
else if (o == ui.LibraryTree)
else if (QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e))
{
if (QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e))
if (ke->key() >= Qt::Key_F1 && ke->key() <= Qt::Key_F32)
{
int val = ke->key() - (int)Qt::Key_F1;
if (val < ui.CurrentXformCombo->count())
ui.CurrentXformCombo->setCurrentIndex(val);
}
else if (o == ui.LibraryTree)
{
if (ke->key() == Qt::Key_Delete && e->type() == QEvent::KeyRelease)
{
@ -401,10 +405,10 @@ void Fractorium::dropEvent(QDropEvent* e)
/// <param name="signal">The signal the combo box emits</param>
/// <param name="slot">The slot to receive the signal</param>
/// <param name="connectionType">Type of the connection. Default: Qt::QueuedConnection.</param>
void Fractorium::SetupCombo(QTableWidget* table, const QObject* receiver, int& row, int col, StealthComboBox*& comboBox, vector<string>& vals, const char* signal, const char* slot, Qt::ConnectionType connectionType)
void Fractorium::SetupCombo(QTableWidget* table, const QObject* receiver, int& row, int col, StealthComboBox*& comboBox, const vector<string>& vals, const char* signal, const char* slot, Qt::ConnectionType connectionType)
{
comboBox = new StealthComboBox(table);
ForEach(vals, [&](const string& s) { comboBox->addItem(s.c_str()); });
for (auto& s : vals) comboBox->addItem(s.c_str());
table->setCellWidget(row, col, comboBox);
connect(comboBox, signal, receiver, slot, connectionType);
row++;

View File

@ -249,6 +249,8 @@ public slots:
void OnXaosChanged(double d);
void OnClearXaosButtonClicked(bool checked);
void OnRandomXaosButtonClicked(bool checked);
void OnXaosRowDoubleClicked(int logicalIndex);
void OnXaosColDoubleClicked(int logicalIndex);
//Palette.
void OnPaletteFilenameComboChanged(const QString& text);
@ -271,7 +273,7 @@ public:
//template<typename spinType, typename valType>//See below.
//static void SetupSpinner(QTableWidget* table, const QObject* receiver, int& row, int col, spinType*& spinBox, int height, valType min, valType max, valType step, const char* signal, const char* slot, bool incRow = true, valType val = 0, valType doubleClickZero = -999, valType doubleClickNonZero = -999);
static void SetupAffineSpinner(QTableWidget* table, const QObject* receiver, int row, int col, DoubleSpinBox*& spinBox, int height, double min, double max, double step, double prec, const char* signal, const char* slot);
static void SetupCombo(QTableWidget* table, const QObject* receiver, int& row, int col, StealthComboBox*& comboBox, vector<string>& vals, const char* signal, const char* slot, Qt::ConnectionType connectionType = Qt::QueuedConnection);
static void SetupCombo(QTableWidget* table, const QObject* receiver, int& row, int col, StealthComboBox*& comboBox, const vector<string>& vals, const char* signal, const char* slot, Qt::ConnectionType connectionType = Qt::QueuedConnection);
static void SetFixedTableHeader(QHeaderView* header, QHeaderView::ResizeMode mode = QHeaderView::Fixed);
static int FlipDet(Affine2D<float>& affine);

View File

@ -239,7 +239,7 @@
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="DockWidgetHLayout">
<property name="spacing">
<number>4</number>
</property>
@ -379,7 +379,7 @@
<number>4</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_4">
<widget class="QScrollArea" name="LibraryTabScrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
@ -392,7 +392,7 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_5">
<widget class="QWidget" name="LibraryTabScrollWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
@ -489,7 +489,7 @@
<number>4</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<widget class="QScrollArea" name="FlameTabScrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
@ -499,7 +499,7 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<widget class="QWidget" name="FlameTabScrollWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
@ -1509,7 +1509,7 @@
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<spacer name="FlameTabVerticalSpacer1">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -1525,7 +1525,7 @@
</spacer>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_2">
<spacer name="FlameTabVerticalSpacer2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -1831,7 +1831,7 @@
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer_3">
<spacer name="FlameTabVerticalSpacer3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -1847,7 +1847,7 @@
</spacer>
</item>
<item row="11" column="0">
<spacer name="verticalSpacer_8">
<spacer name="FlameTabVerticalSpacer4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -1954,7 +1954,7 @@ SpinBox
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="ColorTab">
<widget class="QWidget" name="XformColorTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -2509,7 +2509,7 @@ SpinBox
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="CurvesGroupBox">
<property name="title">
<string>Curve</string>
</property>
@ -2575,7 +2575,7 @@ SpinBox
</item>
</layout>
</widget>
<widget class="QWidget" name="AffineTab">
<widget class="QWidget" name="XformAffineTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -2608,7 +2608,7 @@ SpinBox
<number>5</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_3">
<widget class="QScrollArea" name="AffineTabScrollArea">
<property name="autoFillBackground">
<bool>true</bool>
</property>
@ -2621,7 +2621,7 @@ SpinBox
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<widget class="QWidget" name="AffineTabScrollWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
@ -3921,7 +3921,7 @@ SpinBox
</widget>
</item>
<item>
<spacer name="verticalSpacer_10">
<spacer name="AffineTabVerticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -3942,7 +3942,7 @@ SpinBox
</item>
</layout>
</widget>
<widget class="QWidget" name="VariationsTab">
<widget class="QWidget" name="XformVariationsTab">
<property name="toolTip">
<string>Full list of available variations and their weights for the currently selected xform.</string>
</property>
@ -3963,7 +3963,7 @@ SpinBox
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11" stretch="0,0">
<layout class="QHBoxLayout" name="VariationsTabHLayout" stretch="0,0">
<property name="spacing">
<number>5</number>
</property>
@ -4015,7 +4015,7 @@ SpinBox
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
<enum>Qt::WheelFocus</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
@ -4173,10 +4173,13 @@ SpinBox
</item>
</layout>
</widget>
<widget class="QWidget" name="XformsSelectTab">
<widget class="QWidget" name="XformSelectTab">
<property name="toolTip">
<string>Select multiple xforms to apply operations to.</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<attribute name="title">
<string>Select</string>
</attribute>
@ -4218,6 +4221,9 @@ SpinBox
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="title">
<string>Select Xforms</string>
</property>
@ -4248,6 +4254,9 @@ SpinBox
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
@ -4320,7 +4329,7 @@ SpinBox
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<layout class="QHBoxLayout" name="XformTabHLayout">
<property name="spacing">
<number>2</number>
</property>
@ -4845,7 +4854,7 @@ SpinBox
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="XaosTabHLayout">
<item>
<widget class="QPushButton" name="ClearXaosButton">
<property name="toolTip">
@ -5186,7 +5195,7 @@ SpinBox
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="PaletteTabHLayout">
<property name="spacing">
<number>4</number>
</property>
@ -5280,7 +5289,7 @@ SpinBox
<number>4</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_5">
<widget class="QScrollArea" name="InfoTabScrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
@ -5302,7 +5311,7 @@ SpinBox
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_6">
<widget class="QWidget" name="InfoTabScrollWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
@ -6127,7 +6136,7 @@ SpinBox
<tabstop>SaveCurrentToOpenedFileButton</tabstop>
<tabstop>ParamsTabWidget</tabstop>
<tabstop>LibraryTree</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>FlameTabScrollArea</tabstop>
<tabstop>CurrentXformCombo</tabstop>
<tabstop>AddXformButton</tabstop>
<tabstop>DuplicateXformButton</tabstop>
@ -6140,7 +6149,7 @@ SpinBox
<tabstop>XformColorScroll</tabstop>
<tabstop>XformColorValuesTable</tabstop>
<tabstop>SoloXformCheckBox</tabstop>
<tabstop>scrollArea_3</tabstop>
<tabstop>AffineTabScrollArea</tabstop>
<tabstop>PreAffineTable</tabstop>
<tabstop>PreFlipVerticalButton</tabstop>
<tabstop>PreResetButton</tabstop>
@ -6186,13 +6195,13 @@ SpinBox
<tabstop>VariationsTree</tabstop>
<tabstop>PaletteAdjustTable</tabstop>
<tabstop>PaletteListTable</tabstop>
<tabstop>scrollArea_5</tabstop>
<tabstop>InfoTabScrollArea</tabstop>
<tabstop>InfoFileOpeningGroupBox</tabstop>
<tabstop>InfoFileOpeningTextEdit</tabstop>
<tabstop>InfoRenderingGroupBox</tabstop>
<tabstop>InfoRenderingTextEdit</tabstop>
<tabstop>PreAffineGroupBox</tabstop>
<tabstop>scrollArea_4</tabstop>
<tabstop>LibraryTabScrollArea</tabstop>
<tabstop>InfoBoundsGroupBox</tabstop>
</tabstops>
<resources>

View File

@ -158,7 +158,7 @@ public:
virtual void XformWeightChanged(double d) { }
virtual void EqualizeWeights() { }
virtual void XformNameChanged(int row, int col) { }
virtual void FillXforms() { }
virtual void FillXforms(int index = 0) { }
//Xforms Affine.
virtual void AffineSetHelper(double d, int index, bool pre) { }
@ -387,7 +387,7 @@ public:
virtual void XformWeightChanged(double d) override;
virtual void EqualizeWeights() override;
virtual void XformNameChanged(int row, int col) override;
virtual void FillXforms() override;
virtual void FillXforms(int index = 0) override;
void FillWithXform(Xform<T>* xform);
Xform<T>* CurrentXform();
@ -421,7 +421,7 @@ public:
virtual void XaosChanged(DoubleSpinBox* sender) override;
virtual void ClearXaos() override;
virtual void RandomXaos() override;
//Palette.
virtual int InitPaletteList(const string& s) override;
virtual bool FillPaletteTable(const string& s) override;

View File

@ -51,6 +51,6 @@ void Fractorium::ErrorReportToQTextEdit(const vector<string>& errors, QTextEdit*
if (clear)
QMetaObject::invokeMethod(textEdit, "clear", Qt::QueuedConnection);
for (size_t i = 0; i < errors.size(); i++)
QMetaObject::invokeMethod(textEdit, "append", Qt::QueuedConnection, Q_ARG(const QString&, QString::fromStdString(errors[i]) + "\n"));
for (auto& error : errors)
QMetaObject::invokeMethod(textEdit, "append", Qt::QueuedConnection, Q_ARG(const QString&, QString::fromStdString(error) + "\n"));
}

View File

@ -9,7 +9,6 @@ void Fractorium::InitLibraryUI()
connect(ui.LibraryTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(OnEmberTreeItemChanged(QTreeWidgetItem*, int)), Qt::QueuedConnection);
connect(ui.LibraryTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(OnEmberTreeItemDoubleClicked(QTreeWidgetItem*, int)), Qt::QueuedConnection);
connect(ui.LibraryTree, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(OnEmberTreeItemDoubleClicked(QTreeWidgetItem*, int)), Qt::QueuedConnection);
ui.LibraryTree->installEventFilter(this);//Needed for keypress events other than enter.
}

View File

@ -323,8 +323,8 @@ void FractoriumEmberController<T>::SaveEntireFileAsXml()
SaveCurrentToOpenedFile();//Save the current ember back to the opened file before writing to disk.
emberFile = m_EmberFile;
for (size_t i = 0; i < emberFile.Size(); i++)
ApplyXmlSavingTemplate(emberFile.m_Embers[i]);
for (auto& ember : emberFile.m_Embers)
ApplyXmlSavingTemplate(ember);
if (writer.Save(filename.toStdString().c_str(), emberFile.m_Embers, 0, true, false, true))
{
@ -479,9 +479,9 @@ void FractoriumEmberController<T>::CopyAllXml()
os << "<flames>\n";
for (size_t i = 0; i < m_EmberFile.Size(); i++)
for (auto& e : m_EmberFile.m_Embers)
{
Ember<T> ember = m_EmberFile.m_Embers[i];
Ember<T> ember = e;
ApplyXmlSavingTemplate(ember);
os << emberToXml.ToString(ember, "", 0, false, false, true);
@ -621,8 +621,8 @@ void FractoriumEmberController<T>::AddReflectiveSymmetry()
Update([&]()
{
m_Ember.AddSymmetry(-1, m_Rand);
FillXforms();
combo->setCurrentIndex(combo->count() - (m_Fractorium->HaveFinal() ? 2 : 1));//Set index to the last item before final.
int index = m_Ember.TotalXformCount() - (m_Ember.UseFinalXform() ? 2 : 1);//Set index to the last item before final.
FillXforms(index);
});
}
@ -640,8 +640,8 @@ void FractoriumEmberController<T>::AddRotationalSymmetry()
Update([&]()
{
m_Ember.AddSymmetry(2, m_Rand);
FillXforms();
combo->setCurrentIndex(combo->count() - (m_Fractorium->HaveFinal() ? 2 : 1));//Set index to the last item before final.
int index = m_Ember.TotalXformCount() - (m_Ember.UseFinalXform() ? 2 : 1);//Set index to the last item before final.
FillXforms(index);
});
}
@ -659,8 +659,8 @@ void FractoriumEmberController<T>::AddBothSymmetry()
Update([&]()
{
m_Ember.AddSymmetry(-2, m_Rand);
FillXforms();
combo->setCurrentIndex(combo->count() - (m_Fractorium->HaveFinal() ? 2 : 1));//Set index to the last item before final.
int index = m_Ember.TotalXformCount() - (m_Ember.UseFinalXform() ? 2 : 1);//Set index to the last item before final.
FillXforms(index);
});
}
@ -705,7 +705,6 @@ void FractoriumEmberController<T>::ClearFlame()
}
FillXforms();
m_Fractorium->ui.CurrentXformCombo->setCurrentIndex(0);
});
}

View File

@ -212,9 +212,9 @@ eProcessAction FractoriumEmberControllerBase::CondenseAndClearProcessActions()
m_Cs.Enter();
eProcessAction action = NOTHING;
for (size_t i = 0; i < m_ProcessActions.size(); i++)
if (m_ProcessActions[i] > action)
action = m_ProcessActions[i];
for (auto a : m_ProcessActions)
if (a > action)
action = a;
m_ProcessActions.clear();
m_Cs.Leave();
@ -492,6 +492,7 @@ bool FractoriumEmberController<T>::Render()
//Upon finishing, or having nothing to do, rest.
if (ProcessState() == ACCUM_DONE)
QThread::msleep(1);
//QApplication::processEvents();
m_Rendering = false;
return success;

View File

@ -6,8 +6,15 @@
/// </summary>
void Fractorium::InitXaosUI()
{
ui.XaosTable->verticalHeader()->setVisible(true);
ui.XaosTable->horizontalHeader()->setVisible(true);
ui.XaosTable->verticalHeader()->setSectionsClickable(true);
ui.XaosTable->horizontalHeader()->setSectionsClickable(true);
connect(ui.ClearXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnClearXaosButtonClicked(bool)), Qt::QueuedConnection);
connect(ui.RandomXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnRandomXaosButtonClicked(bool)), Qt::QueuedConnection);
connect(ui.XaosTable->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosRowDoubleClicked(int)), Qt::QueuedConnection);
connect(ui.XaosTable->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosColDoubleClicked(int)), Qt::QueuedConnection);
}
/// <summary>
@ -92,11 +99,6 @@ void Fractorium::FillXaosTable()
ui.XaosTable->setRowCount(count);//This will grow or shrink the number of rows and call the destructor for previous DoubleSpinBoxes.
ui.XaosTable->setColumnCount(count);
ui.XaosTable->verticalHeader()->setVisible(true);
ui.XaosTable->horizontalHeader()->setVisible(true);
ui.XaosTable->verticalHeader()->setSectionsClickable(false);
ui.XaosTable->horizontalHeader()->setSectionsClickable(false);
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
@ -159,7 +161,6 @@ void Fractorium::OnClearXaosButtonClicked(bool checked) { m_Controller->ClearXao
/// 50% that they're 0-3.
/// Resets the rendering process.
/// </summary>
/// <param name="checked">Ignored</param>
template <typename T>
void FractoriumEmberController<T>::RandomXaos()
{
@ -185,6 +186,78 @@ void FractoriumEmberController<T>::RandomXaos()
void Fractorium::OnRandomXaosButtonClicked(bool checked) { m_Controller->RandomXaos(); }
/// <summary>
/// Toggle all xaos values in one row.
/// The logic is:
/// If any cell in the row is non zero, set all cells to zero, else 1.
/// If shift is held down, reverse the logic.
/// Resets the rendering process.
/// </summary>
/// <param name="logicalIndex">The index of the row that was double clicked</param>
void Fractorium::OnXaosRowDoubleClicked(int logicalIndex)
{
bool allZero = true;
int cols = ui.XaosTable->columnCount();
bool shift = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
for (int i = 0; i < cols; i++)
{
if (auto* spinBox = dynamic_cast<DoubleSpinBox*>(ui.XaosTable->cellWidget(logicalIndex, i)))
{
if (!IsNearZero(spinBox->value()))
{
allZero = false;
break;
}
}
}
if (shift)
allZero = !allZero;
double val = allZero ? 1.0 : 0.0;
for (int i = 0; i < cols; i++)
if (auto* spinBox = dynamic_cast<DoubleSpinBox*>(ui.XaosTable->cellWidget(logicalIndex, i)))
spinBox->setValue(val);
}
/// <summary>
/// Toggle all xaos values in one column.
/// The logic is:
/// If any cell in the column is non zero, set all cells to zero, else 1.
/// If shift is held down, reverse the logic.
/// Resets the rendering process.
/// </summary>
/// <param name="logicalIndex">The index of the column that was double clicked</param>
void Fractorium::OnXaosColDoubleClicked(int logicalIndex)
{
bool allZero = true;
int rows = ui.XaosTable->rowCount();
bool shift = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
for (int i = 0; i < rows; i++)
{
if (auto* spinBox = dynamic_cast<DoubleSpinBox*>(ui.XaosTable->cellWidget(i, logicalIndex)))
{
if (!IsNearZero(spinBox->value()))
{
allZero = false;
break;
}
}
}
if (shift)
allZero = !allZero;
double val = allZero ? 1.0 : 0.0;
for (int i = 0; i < rows; i++)
if (auto* spinBox = dynamic_cast<DoubleSpinBox*>(ui.XaosTable->cellWidget(i, logicalIndex)))
spinBox->setValue(val);
}
template class FractoriumEmberController<float>;
#ifdef DO_DOUBLE

View File

@ -109,8 +109,8 @@ void FractoriumEmberController<T>::AddXform()
newXform.m_Weight = 0.25;
newXform.m_ColorX = m_Rand.Frand01<T>();
m_Ember.AddXform(newXform);
FillXforms();
combo->setCurrentIndex(combo->count() - (m_Fractorium->HaveFinal() ? 2 : 1));//Set index to the last item before final.
int index = m_Ember.TotalXformCount() - (m_Ember.UseFinalXform() ? 2 : 1);//Set index to the last item before final.
FillXforms(index);
});
}
@ -141,8 +141,8 @@ void FractoriumEmberController<T>::DuplicateXform()
for (auto& it : vec)
m_Ember.AddXform(it);
FillXforms();//Handles xaos.
combo->setCurrentIndex(combo->count() - (m_Fractorium->HaveFinal() ? 2 : 1));//Set index to the last item before final.
int index = m_Ember.TotalXformCount() - (m_Ember.UseFinalXform() ? 2 : 1);//Set index to the last item before final.
FillXforms(index);//Handles xaos.
});
}
@ -224,8 +224,8 @@ void FractoriumEmberController<T>::DeleteXforms()
if (offset)
{
FillXforms();
combo->setCurrentIndex(combo->count() - (m_Ember.UseFinalXform() ? 2 : 1));//Set index to the last item before final. Note final is requeried one last time.
int index = m_Ember.TotalXformCount() - (m_Ember.UseFinalXform() ? 2 : 1);//Set index to the last item before final. Note final is requeried one last time.
FillXforms(index);
UpdateRender();
}
}
@ -252,8 +252,8 @@ void FractoriumEmberController<T>::AddFinalXform()
final.AddVariation(new LinearVariation<T>());//Just a placeholder so other parts of the code don't see it as being empty.
m_Ember.SetFinalXform(final);
FillXforms();
combo->setCurrentIndex(combo->count() - 1);//Set index to the last item.
int index = m_Ember.TotalXformCount() - 1;//Set index to the last item.
FillXforms(index);
});
}
}
@ -374,12 +374,13 @@ bool FractoriumEmberController<T>::IsFinal(Xform<T>* xform)
/// <summary>
/// Fill the xforms combo box with the xforms in the current ember.
/// Select the first one and fill all widgets with its values.
/// Select the index passed in and fill all widgets with its values.
/// Also dynamically generate a checkbox for each xform which will allow the user
/// to select which xforms to apply operations to.
/// </summary>
/// <param name="index">The index to select after populating, default 0.</param>
template <typename T>
void FractoriumEmberController<T>::FillXforms()
void FractoriumEmberController<T>::FillXforms(int index)
{
int i = 0, count = int(XformCount());
auto combo = m_Fractorium->ui.CurrentXformCombo;
@ -435,11 +436,13 @@ void FractoriumEmberController<T>::FillXforms()
m_Fractorium->m_XformsSelectionLayout->blockSignals(false);
combo->blockSignals(false);
combo->setCurrentIndex(0);
if (index < combo->count())
combo->setCurrentIndex(index);
m_Fractorium->FillXaosTable();
m_Fractorium->OnSoloXformCheckBoxStateChanged(Qt::Unchecked);
m_Fractorium->OnCurrentXformComboChanged(0);//Make sure the event gets called, because it won't if the zero index is already selected.
m_Fractorium->OnCurrentXformComboChanged(index);//Make sure the event gets called, because it won't if the zero index is already selected.
}
template class FractoriumEmberController<float>;

View File

@ -64,7 +64,7 @@ void FractoriumEmberController<T>::SetupVariationTree()
{
ParamWithName<T>* params = parVar->Params();
for (size_t j = 0; j< parVar->ParamCount(); j++)
for (size_t j = 0; j < parVar->ParamCount(); j++)
{
if (!params[j].IsPrecalc())
{

View File

@ -46,6 +46,7 @@ int main(int argc, char *argv[])
Fractorium w;
w.show();
a.installEventFilter(&w);
return a.exec();
}

View File

@ -134,8 +134,8 @@ void FractoriumOptionsDialog::OnPlatformComboCurrentIndexChanged(int index)
ui.DeviceCombo->clear();
for (size_t i = 0; i < devices.size(); i++)
ui.DeviceCombo->addItem(QString::fromStdString(devices[i]));
for (auto& device : devices)
ui.DeviceCombo->addItem(QString::fromStdString(device));
if (ui.PlatformCombo->currentIndex() == m_Settings->PlatformIndex())
ui.DeviceCombo->setCurrentIndex(m_Settings->DeviceIndex());