src/widgets/colorindexinput.cpp

Wed, 08 Jun 2022 19:33:00 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 08 Jun 2022 19:33:00 +0300
changeset 204
52e10e8d88cc
parent 200
ca23936b455b
child 205
1a4342d80de7
permissions
-rw-r--r--

Concentrate model editing into one coroutine inside main()

#include "colorindexinput.h"
#include "ui_colorindexinput.h"
#include "colorselectdialog.h"
#include "uiutilities.h"

ColorIndexInput::ColorIndexInput(EditorTabWidget *document, ldraw::Color color, QWidget *parent) :
	QWidget{parent},
	document{document},
	ui{*new Ui_ColorIndexInput}
{
	this->ui.setupUi(this);
	connect(this->ui.button, &QPushButton::clicked, [this]()
	{
		ColorSelectDialog dialog{this->document->colorTable, this->document};
		const int result = dialog.exec();
		if (result == QDialog::Accepted)
		{
			this->ui.index->setValue(dialog.currentColor().index);
		}
	});
	connect(this->ui.index, qOverload<int>(&QSpinBox::valueChanged), [this](int value)
	{
		this->ui.button->setText(ldraw::colorDisplayName({value}, this->document->colorTable));
		uiutilities::colorizeWidget(this->ui.button, ldraw::colorFace({value}, this->document->colorTable));
		Q_EMIT this->colorChanged({value});
	});
	this->ui.index->setValue(color.index);
}

ColorIndexInput::~ColorIndexInput()
{
	delete &this->ui;
}

ldraw::Color ColorIndexInput::selectedColor() const
{
	return {this->ui.index->value()};
}

void ColorIndexInput::setSelectedColor(ldraw::Color color)
{
	this->ui.index->setValue(color.index);
}

mercurial