src/widgets/colorindexinput.cpp

Fri, 01 Jul 2022 16:46:43 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Fri, 01 Jul 2022 16:46:43 +0300
changeset 312
2637134bc37c
parent 264
76a025db4948
permissions
-rw-r--r--

Fix right click to delete not really working properly
Instead of removing the point that had been added, it would remove
the point that is being drawn, which would cause it to overwrite the
previous point using the new point, causing a bit of a delay

#include <ui_colorindexinput.h>
#include "src/uiutilities.h"
#include "src/widgets/colorindexinput.h"
#include "src/widgets/colorselectdialog.h"

ColorIndexInput::ColorIndexInput(QWidget *parent) :
	QWidget{parent},
	ui{*new Ui_ColorIndexInput}
{
	static const ColorTable emptyColorTable;
	this->colorTable = &emptyColorTable;
	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(MAIN_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