src/widgets/colorbutton.cpp

Fri, 04 Mar 2022 11:37:50 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 04 Mar 2022 11:37:50 +0200
changeset 152
03f8e6d42e13
parent 39
caac957e9834
permissions
-rw-r--r--

Major refactoring
- Model now just stores objects
- Document contains business logic
- Model::EditContext is now ModelEditor, no longer a nested class

#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