src/widgets/colorbutton.cpp

Mon, 20 Jun 2022 02:04:51 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 20 Jun 2022 02:04:51 +0300
changeset 232
8efa3a33172e
parent 39
caac957e9834
permissions
-rw-r--r--

Add base code for circular primitives

#include <QColorDialog>
#include "colorbutton.h"

ColorButton::ColorButton(const QColor& color, QWidget* parent) :
	ColorButton{parent}
{
	this->setSelectedColor(color);
}

ColorButton::ColorButton(QWidget* parent) :
	QPushButton{parent}
{
	connect(this, &QPushButton::clicked, [&]()
	{
		const QColor color = QColorDialog::getColor(this->storedSelectedColor, this->parentWidget());
		if (color.isValid())
		{
			this->setSelectedColor(color);
		}
	});
}

QColor ColorButton::selectedColor() const
{
	return this->storedSelectedColor;
}

void ColorButton::setSelectedColor(const QColor& newSelectedColor)
{
	this->storedSelectedColor = newSelectedColor;
	this->setStyleSheet(QString{"background-color: %1"}.arg(newSelectedColor.name()));
	this->setText(newSelectedColor.name());
}

mercurial