Rename colorbutton.cpp -> coloredit.cpp

Sat, 08 Apr 2023 15:15:20 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 08 Apr 2023 15:15:20 +0300
changeset 348
98776f54a8d0
parent 347
5c655cc006de
child 349
673b8dffbe14

Rename colorbutton.cpp -> coloredit.cpp

widgets/CMakeLists.txt file | annotate | diff | comparison | revisions
widgets/colorbutton.cpp file | annotate | diff | comparison | revisions
widgets/colorbutton.h file | annotate | diff | comparison | revisions
widgets/coloredit.cpp file | annotate | diff | comparison | revisions
widgets/coloredit.h file | annotate | diff | comparison | revisions
widgets/designerplugins.cpp file | annotate | diff | comparison | revisions
--- a/widgets/CMakeLists.txt	Sat Apr 08 15:11:39 2023 +0300
+++ b/widgets/CMakeLists.txt	Sat Apr 08 15:15:20 2023 +0300
@@ -7,8 +7,8 @@
 )
 
 add_library(${WIDGETLIB} SHARED
-	colorbutton.cpp
-	colorbutton.h
+	coloredit.cpp
+	coloredit.h
 	designerplugins.cpp
 	designerplugins.h
 	doublespinbox.cpp
--- a/widgets/colorbutton.cpp	Sat Apr 08 15:11:39 2023 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-#include <QColorDialog>
-#include <QHBoxLayout>
-#include "widgets/colorbutton.h"
-
-ColorEdit::ColorEdit(const QColor& color, QWidget* parent) :
-	ColorEdit{parent}
-{
-	this->setColor(color);
-}
-
-ColorEdit::ColorEdit(QWidget* parent) :
-	QWidget{parent},
-	lineEdit{new QLineEdit{this}},
-	button{new QPushButton{"…", this}}
-{
-	auto*const layout = new QHBoxLayout{};
-	layout->addWidget(this->lineEdit);
-	layout->addWidget(this->button);
-	layout->setStretch(0, 1);
-	layout->setStretch(1, 0);
-	this->setLayout(layout);
-	connect(this->button, &QPushButton::clicked, [&](){
-		const QColor color = QColorDialog::getColor(this->color(), this->parentWidget());
-		if (color.isValid()) {
-			this->setColor(color);
-		}
-	});
-	connect(this->lineEdit, &QLineEdit::textChanged, [&]{
-		const QColor color = this->color();
-		const qreal lightness = color.lightnessF();
-		const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black;
-		this->setStyleSheet(
-			QStringLiteral("QLineEdit{background-color: %1; color: %2;}")
-				.arg(color.name())
-				.arg(foreground.name()));
-		Q_EMIT this->colorChanged(this->color());
-	});
-	this->setColor(Qt::black);
-}
-
-QColor ColorEdit::color() const
-{
-	return QColor{this->lineEdit->text()};
-}
-
-void ColorEdit::setColor(const QColor& color)
-{
-	if (color.isValid() and this->color() != color) {
-		this->lineEdit->setText(color.name());
-	}
-}
--- a/widgets/colorbutton.h	Sat Apr 08 15:11:39 2023 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#pragma once
-#include <QPushButton>
-#include <QLineEdit>
-
-/**
- * @brief A button that can be used to select a color
- */
-class ColorEdit : public QWidget
-{
-	Q_OBJECT
-	Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
-	QLineEdit* lineEdit;
-	QPushButton* button;
-public:
-	ColorEdit(const QColor& color = {}, QWidget* parent = nullptr);
-	ColorEdit(QWidget* parent = nullptr);
-	QColor color() const;
-	Q_SLOT void setColor(const QColor& color);
-	Q_SIGNAL void colorChanged(const QColor& color);
-};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/coloredit.cpp	Sat Apr 08 15:15:20 2023 +0300
@@ -0,0 +1,51 @@
+#include <QColorDialog>
+#include <QHBoxLayout>
+#include "widgets/coloredit.h"
+
+ColorEdit::ColorEdit(const QColor& color, QWidget* parent) :
+	ColorEdit{parent}
+{
+	this->setColor(color);
+}
+
+ColorEdit::ColorEdit(QWidget* parent) :
+	QWidget{parent},
+	lineEdit{new QLineEdit{this}},
+	button{new QPushButton{"…", this}}
+{
+	auto*const layout = new QHBoxLayout{};
+	layout->addWidget(this->lineEdit);
+	layout->addWidget(this->button);
+	layout->setStretch(0, 1);
+	layout->setStretch(1, 0);
+	this->setLayout(layout);
+	connect(this->button, &QPushButton::clicked, [&](){
+		const QColor color = QColorDialog::getColor(this->color(), this->parentWidget());
+		if (color.isValid()) {
+			this->setColor(color);
+		}
+	});
+	connect(this->lineEdit, &QLineEdit::textChanged, [&]{
+		const QColor color = this->color();
+		const qreal lightness = color.lightnessF();
+		const QColor foreground = lightness < 0.4 ? Qt::white : Qt::black;
+		this->setStyleSheet(
+			QStringLiteral("QLineEdit{background-color: %1; color: %2;}")
+				.arg(color.name())
+				.arg(foreground.name()));
+		Q_EMIT this->colorChanged(this->color());
+	});
+	this->setColor(Qt::black);
+}
+
+QColor ColorEdit::color() const
+{
+	return QColor{this->lineEdit->text()};
+}
+
+void ColorEdit::setColor(const QColor& color)
+{
+	if (color.isValid() and this->color() != color) {
+		this->lineEdit->setText(color.name());
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/coloredit.h	Sat Apr 08 15:15:20 2023 +0300
@@ -0,0 +1,20 @@
+#pragma once
+#include <QPushButton>
+#include <QLineEdit>
+
+/**
+ * @brief A button that can be used to select a color
+ */
+class ColorEdit : public QWidget
+{
+	Q_OBJECT
+	Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+	QLineEdit* lineEdit;
+	QPushButton* button;
+public:
+	ColorEdit(const QColor& color = {}, QWidget* parent = nullptr);
+	ColorEdit(QWidget* parent = nullptr);
+	QColor color() const;
+	Q_SLOT void setColor(const QColor& color);
+	Q_SIGNAL void colorChanged(const QColor& color);
+};
--- a/widgets/designerplugins.cpp	Sat Apr 08 15:11:39 2023 +0300
+++ b/widgets/designerplugins.cpp	Sat Apr 08 15:15:20 2023 +0300
@@ -1,7 +1,7 @@
 #include "widgets/designerplugins.h"
 #include "widgets/vec3editor.h"
 #include "widgets/matrixeditor.h"
-#include "widgets/colorbutton.h"
+#include "widgets/coloredit.h"
 
 PluginCollection::PluginCollection(QObject* parent) :
 	QObject{parent}
@@ -99,7 +99,7 @@
 
 QString ColorButtonPlugin::name() const
 {
-	return "ColorButton";
+	return "ColorEdit";
 }
 
 QString ColorButtonPlugin::group() const
@@ -119,7 +119,7 @@
 
 QString ColorButtonPlugin::includeFile() const
 {
-	return "widgets/colorbutton.h";
+	return "widgets/coloredit.h";
 }
 
 QIcon ColorButtonPlugin::icon() const

mercurial