src/widgets/colorselectdialog.cpp

changeset 178
a23024fc98e0
parent 139
72098474d362
child 205
1a4342d80de7
--- a/src/widgets/colorselectdialog.cpp	Wed Mar 09 14:22:22 2022 +0200
+++ b/src/widgets/colorselectdialog.cpp	Sun Mar 13 14:51:39 2022 +0200
@@ -1,7 +1,9 @@
 #include <QColorDialog>
 #include <QTableView>
+#include <QStyleFactory>
 #include "colorselectdialog.h"
 #include "ui_colorselectdialog.h"
+#include "uiutilities.h"
 
 ColorSelectDialog::ColorSelectDialog(const ldraw::ColorTable& colorTable, QWidget *parent) :
 	QDialog{parent},
@@ -29,14 +31,6 @@
 	return {button->property("_colorIndex").value<qint32>()};
 }
 
-QString styleSheetForColor(const QColor& color)
-{
-	QColor const textColor = (luma(color) < 0.4) ? Qt::white : Qt::black;
-	return QString{"background-color: %1; color: %2;"}
-		.arg(color.name())
-		.arg(textColor.name());
-}
-
 void ColorSelectDialog::makeColorButtons()
 {
 	this->buttons.reserve(this->colorTable.size());
@@ -48,8 +42,9 @@
 		const qint32 index = iterator->first;
 		const ldraw::ColorDefinition& colordef = iterator->second;
 		QPushButton* const button = new QPushButton{QString::number(index), this};
+		button->setMinimumSize({40, 40});
 		button->setToolTip(colordef.displayName);
-		button->setStyleSheet(styleSheetForColor(colordef.faceColor));
+		uiutilities::colorizeWidget(button, ldraw::colorFace({index}, colorTable));
 		button->setProperty("_colorIndex", index);
 		button->setCheckable(true);
 		connect(button, &QAbstractButton::clicked, this, &ColorSelectDialog::handleButtonClick);
@@ -95,17 +90,8 @@
 
 void ColorSelectDialog::updateSelectedColorTexts()
 {
-	if (ldraw::isDirectColor(this->selectedColor))
-	{
-		this->ui.selectedColorName->setText(ldraw::directColorFace(this->selectedColor).name());
-	}
-	else
-	{
-		const ldraw::ColorDefinition& colordef = this->colorTable[this->selectedColor];
-		this->ui.selectedColorName->setText(colordef.displayName);
-	}
-	const QColor colorFace = ldraw::colorFace(this->selectedColor, this->colorTable);
-	this->ui.selectedColorName->setStyleSheet(styleSheetForColor(colorFace));
+	this->ui.selectedColorName->setText(ldraw::colorDisplayName(this->selectedColor, this->colorTable));
+	uiutilities::colorizeWidget(this->ui.selectedColorName, ldraw::colorFace(this->selectedColor, colorTable));
 	this->ui.colorIndex->setValue(this->selectedColor.index);
 	for (QPushButton* button : this->buttons)
 	{
@@ -157,3 +143,8 @@
 	this->selectedColor = color;
 	this->updateSelectedColorTexts();
 }
+
+ldraw::Color ColorSelectDialog::currentColor() const
+{
+	return this->selectedColor;
+}

mercurial