void RenderWindow::slotFractalSwap(int swapA, int swapB)
{
	// qDebug() << "swapping " << swapA << " with " << swapB;

	// read all data from ui
	gMainInterface->SynchronizeInterface(gPar, gParFractal, qInterface::read);

	// swap formula specific fields in gPar
	QStringList gParFormulaSpecificFields({"formula", "formula_iterations", "formula_weight",
		"formula_start_iteration", "formula_stop_iteration", "julia_mode", "julia_c",
		"fractal_constant_factor", "formula_position", "formula_rotation", "formula_repeat",
		"formula_scale", "dont_add_c_constant", "check_for_bailout"});

	for (int i = 0; i < gParFormulaSpecificFields.size(); i++)
	{
		cOneParameter formulaA =
			gPar->GetAsOneParameter(gParFormulaSpecificFields.at(i) + "_" + QString::number(swapA + 1));
		cOneParameter formulaB =
			gPar->GetAsOneParameter(gParFormulaSpecificFields.at(i) + "_" + QString::number(swapB + 1));
		gPar->SetFromOneParameter(
			gParFormulaSpecificFields.at(i) + "_" + QString::number(swapA + 1), formulaB);
		gPar->SetFromOneParameter(
			gParFormulaSpecificFields.at(i) + "_" + QString::number(swapB + 1), formulaA);
	}

	// swap formula specific fields in gParFractal by swapping whole container
	SynchronizeInterfaceWindow(fractalWidgets[swapA], &gParFractal->at(swapB), qInterface::read);
	SynchronizeInterfaceWindow(fractalWidgets[swapB], &gParFractal->at(swapA), qInterface::read);

	// write swapped changes to ui
	gMainInterface->SynchronizeInterface(gPar, gParFractal, qInterface::write);
}
void cDockFractal::SynchronizeInterfaceFractals(
	cParameterContainer *par, cFractalContainer *parFractal, qInterface::enumReadWrite mode) const
{
	WriteLog("cInterface::SynchronizeInterface: tabWidget_fractal_common", 3);
	SynchronizeInterfaceWindow(ui->tabWidget_fractal_common, par, mode);
	WriteLog("cInterface::SynchronizeInterface: tabWidget_fractal_hybrid", 3);
	SynchronizeInterfaceWindow(ui->tabWidget_fractal_hybrid, par, mode);
	WriteLog("cInterface::SynchronizeInterface: tab_primitives", 3);
	SynchronizeInterfaceWindow(ui->tab_primitives, par, mode);
	WriteLog("cInterface::SynchronizeInterface: tab_description", 3);
	SynchronizeInterfaceWindow(ui->tab_description, par, mode);

	WriteLog("cInterface::SynchronizeInterface: tabWidget_fractals", 3);
	SynchronizeInterfaceWindow(ui->tabWidget_fractals->tabBar(), par, mode);

	for (int i = 0; i < NUMBER_OF_FRACTALS; i++)
	{
		WriteLog("cInterface::SynchronizeInterface: fractalWidgets[i]", 3);
		fractalTabs[i]->SynchronizeFractal(&parFractal->at(i), mode);
		fractalTabs[i]->SynchronizeInterface(par, mode);
	}
}
void RenderWindow::slotMaterialEdited()
{
	SynchronizeInterfaceWindow(gMainInterface->materialEditor, gPar, qInterface::write);
}
void RenderWindow::slotChangedComboFractal(int indexInComboBox)
{
	QString comboName = this->sender()->objectName();
	int index = qobject_cast<QComboBox *>(this->sender())->itemData(indexInComboBox).toInt();
	int fractalNumber = comboName.right(1).toInt() - 1;

	QString fullFormulaName = fractalList[index].nameInComboBox;
	if (fractalList[index].internalID > 0)
	{
		QString formulaName = fractalList[index].internalName;
		QString uiFilename =
			systemData.sharedDir + "qt_data" + QDir::separator() + "fractal_" + formulaName + ".ui";

		if (fractalWidgets[fractalNumber]) delete fractalWidgets[fractalNumber];
		fractalWidgets[fractalNumber] = NULL;

		MyUiLoader loader;
		QFile uiFile(uiFilename);

		if (uiFile.exists())
		{
			uiFile.open(QFile::ReadOnly);
			fractalWidgets[fractalNumber] = loader.load(&uiFile);
			QVBoxLayout *layout = ui->dockWidget_fractal->findChild<QVBoxLayout *>(
				"verticalLayout_fractal_" + QString::number(fractalNumber + 1));
			layout->addWidget(fractalWidgets[fractalNumber]);
			uiFile.close();
			fractalWidgets[fractalNumber]->show();
			automatedWidgets->ConnectSignalsForSlidersInWindow(fractalWidgets[fractalNumber]);
			SynchronizeInterfaceWindow(
				fractalWidgets[fractalNumber], &gParFractal->at(fractalNumber), qInterface::write);

			QFrame *frame = ui->tabWidget_fractals->findChild<QFrame *>(
				"frame_iterations_formula_" + QString::number(fractalNumber + 1));
			MyCheckBox *caddCheckBoxframe = frame->findChild<MyCheckBox *>(
				QString("checkBox_dont_add_c_constant_") + QString::number(fractalNumber + 1));

			switch (fractalList[index].cpixelAddition)
			{
				case fractal::cpixelEnabledByDefault:
					caddCheckBoxframe->setText(QObject::tr("Don't add global C constant"));
					caddCheckBoxframe->setEnabled(true);
					break;

				case fractal::cpixelDisabledByDefault:
				{
					caddCheckBoxframe->setText(QObject::tr("Add global C constant"));
					caddCheckBoxframe->setEnabled(true);
					break;
				}

				case fractal::cpixelAlreadyHas:
				{
					caddCheckBoxframe->setText(QObject::tr("Don't add global C constant"));
					caddCheckBoxframe->setEnabled(false);
					break;
				}
			}

			fractal::enumCPixelAddition cPixelAddition = fractalList[index].cpixelAddition;
			bool boleanState = ui->groupCheck_boolean_operators->isChecked();
			if (cPixelAddition == fractal::cpixelAlreadyHas)
				ui->tabWidget_fractals
					->findChild<QGroupBox *>(
						"groupBox_c_constant_addition_" + QString::number(fractalNumber + 1))
					->setVisible(false);
			else
				ui->tabWidget_fractals
					->findChild<QGroupBox *>(
						"groupBox_c_constant_addition_" + QString::number(fractalNumber + 1))
					->setVisible(boleanState);

			if (fractalList[index].internalID == fractal::kaleidoscopicIFS)
			{
				QWidget *pushButton_preset_dodecahedron =
					fractalWidgets[fractalNumber]->findChild<QWidget *>("pushButton_preset_dodecahedron");
				QApplication::connect(pushButton_preset_dodecahedron, SIGNAL(clicked()), this,
					SLOT(slotPressedButtonIFSDefaultsDodecahedron()));
				QWidget *pushButton_preset_icosahedron =
					fractalWidgets[fractalNumber]->findChild<QWidget *>("pushButton_preset_icosahedron");
				QApplication::connect(pushButton_preset_icosahedron, SIGNAL(clicked()), this,
					SLOT(slotPressedButtonIFSDefaultsIcosahedron()));
				QWidget *pushButton_preset_octahedron =
					fractalWidgets[fractalNumber]->findChild<QWidget *>("pushButton_preset_octahedron");
				QApplication::connect(pushButton_preset_octahedron, SIGNAL(clicked()), this,
					SLOT(slotPressedButtonIFSDefaultsOctahedron()));
				QWidget *pushButton_preset_menger_sponge =
					fractalWidgets[fractalNumber]->findChild<QWidget *>("pushButton_preset_menger_sponge");
				QApplication::connect(pushButton_preset_menger_sponge, SIGNAL(clicked()), this,
					SLOT(slotPressedButtonIFSDefaultsMengerSponge()));
				QWidget *pushButton_preset_reset =
					fractalWidgets[fractalNumber]->findChild<QWidget *>("pushButton_preset_reset");
				QApplication::connect(pushButton_preset_reset, SIGNAL(clicked()), this,
					SLOT(slotPressedButtonIFSDefaultsReset()));
			}
		}
		else
		{
			cErrorMessage::showMessage(
				QString("Can't open file ") + uiFilename + QString("\nFractal ui file can't be loaded"),
				cErrorMessage::errorMessage, gMainInterface->mainWindow);
		}
	}
	else
	{
		if (fractalWidgets[fractalNumber]) delete fractalWidgets[fractalNumber];
		fractalWidgets[fractalNumber] = NULL;
	}
	ui->tabWidget_fractals->setTabText(
		fractalNumber, QString("#%1: %2").arg(fractalNumber + 1).arg(fullFormulaName));
	// ui->tabWidget_fractals->setTabIcon(fractalNumber, QIcon(fractalList[index].getIconName()));
}
void cDockFractal::SynchronizeInterfacePrimitives() const
{
	SynchronizeInterfaceWindow(ui->scrollArea_primitives, gPar, qInterface::write);
}
void cDockFractal::SynchronizeInterfaceJulia() const
{
	SynchronizeInterfaceWindow(ui->groupCheck_julia_mode, gPar, qInterface::write);
}