src/widgets/colorindexinput.cpp

Wed, 15 Jun 2022 13:05:53 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Wed, 15 Jun 2022 13:05:53 +0300
changeset 230
a1f3f7d9078b
parent 214
8e1fe64ce4e3
child 258
fe094d0687ad
permissions
-rw-r--r--

rename LibraryManager -> LibrariesModel

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

ColorIndexInput::ColorIndexInput(ColorTable *colorTable, ColorIndex color, QWidget *parent) :
	QWidget{parent},
	colorTable{colorTable},
	ui{*new Ui_ColorIndexInput}
{
	this->ui.setupUi(this);
	connect(this->ui.button, &QPushButton::clicked, [this]()
	{
		ColorSelectDialog dialog{*this->colorTable, this};
		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)
	{
		const opt<QString> displayName = colorDisplayName({value}, *this->colorTable);
		const opt<QColor> face = colorFace({value}, *this->colorTable);
		this->ui.button->setText(displayName.value_or(tr("???")));
		if (face.has_value()) {
			uiutilities::colorizeWidget(this->ui.button, *face);
		}
		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