summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-14 17:10:18 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-04-14 17:10:18 +0300
commita5ebff594913e217ccac688fec803e9dcb6186d8 (patch)
tree7f05759c08945b4813e7fe155880f3899737af91 /src
parentUse light theme (diff)
downloadnheko-a5ebff594913e217ccac688fec803e9dcb6186d8.tar.xz
Use color generator for nick names
Diffstat (limited to 'src')
-rw-r--r--src/HistoryViewManager.cc77
-rw-r--r--src/LoginPage.cc4
-rw-r--r--src/RegisterPage.cc4
-rw-r--r--src/WelcomePage.cc8
4 files changed, 58 insertions, 35 deletions
diff --git a/src/HistoryViewManager.cc b/src/HistoryViewManager.cc
index a6cb3f6d..20a42f3b 100644
--- a/src/HistoryViewManager.cc
+++ b/src/HistoryViewManager.cc
@@ -126,38 +126,61 @@ void HistoryViewManager::setHistoryView(const RoomInfo &info)
 
 QMap<QString, QString> HistoryViewManager::NICK_COLORS;
 
-const QList<QString> HistoryViewManager::COLORS({"#FFF46E",
-						 "#A58BFF",
-						 "#50C9BA",
-						 "#9EE6CF",
-						 "#FFDD67",
-						 "#2980B9",
-						 "#FC993C",
-						 "#2772DB",
-						 "#CB8589",
-						 "#DDE8B9",
-						 "#55A44E",
-						 "#A9EEE6",
-						 "#53B759",
-						 "#9E3997",
-						 "#5D89D5",
-						 "#BB86B7",
-						 "#50a0cf",
-						 "#3C989F",
-						 "#5A4592",
-						 "#235e5b",
-						 "#d58247",
-						 "#e0a729",
-						 "#a2b636",
-						 "#4BBE2E"});
-
 QString HistoryViewManager::chooseRandomColor()
 {
 	std::random_device random_device;
 	std::mt19937 engine{random_device()};
-	std::uniform_int_distribution<int> dist(0, HistoryViewManager::COLORS.size() - 1);
+	std::uniform_real_distribution<float> dist(0, 1);
+
+	float hue = dist(engine);
+	float saturation = 0.9;
+	float value = 0.7;
+
+	int hue_i = hue * 6;
+
+	float f = hue * 6 - hue_i;
+
+	float p = value * (1 - saturation);
+	float q = value * (1 - f * saturation);
+	float t = value * (1 - (1 - f) * saturation);
+
+	float r = 0;
+	float g = 0;
+	float b = 0;
+
+	if (hue_i == 0) {
+		r = value;
+		g = t;
+		b = p;
+	} else if (hue_i == 1) {
+		r = q;
+		g = value;
+		b = p;
+	} else if (hue_i == 2) {
+		r = p;
+		g = value;
+		b = t;
+	} else if (hue_i == 3) {
+		r = p;
+		g = q;
+		b = value;
+	} else if (hue_i == 4) {
+		r = t;
+		g = p;
+		b = value;
+	} else if (hue_i == 5) {
+		r = value;
+		g = p;
+		b = q;
+	}
+
+	int ri = r * 256;
+	int gi = g * 256;
+	int bi = b * 256;
+
+	QColor color(ri, gi, bi);
 
-	return HistoryViewManager::COLORS[dist(engine)];
+	return color.name();
 }
 
 QString HistoryViewManager::getUserColor(const QString &userid)
diff --git a/src/LoginPage.cc b/src/LoginPage.cc
index 306b190a..f12bb8f8 100644
--- a/src/LoginPage.cc
+++ b/src/LoginPage.cc
@@ -84,8 +84,8 @@ LoginPage::LoginPage(QSharedPointer<MatrixClient> client, QWidget *parent)
 	button_layout_->setContentsMargins(0, 0, 0, 50);
 
 	login_button_ = new RaisedButton("LOGIN", this);
-	login_button_->setBackgroundColor(QColor("#acc7dc"));
-	login_button_->setForegroundColor(QColor("black"));
+	login_button_->setBackgroundColor(QColor("#171919"));
+	login_button_->setForegroundColor(QColor("white"));
 	login_button_->setMinimumSize(350, 65);
 	login_button_->setCursor(QCursor(Qt::PointingHandCursor));
 	login_button_->setFontSize(17);
diff --git a/src/RegisterPage.cc b/src/RegisterPage.cc
index e9cdbcd7..2b2fae8b 100644
--- a/src/RegisterPage.cc
+++ b/src/RegisterPage.cc
@@ -99,8 +99,8 @@ RegisterPage::RegisterPage(QSharedPointer<MatrixClient> client, QWidget *parent)
 	error_label_->setStyleSheet("margin-bottom: 20px; color: #E22826; font-size: 11pt;");
 
 	register_button_ = new RaisedButton("REGISTER", this);
-	register_button_->setBackgroundColor(QColor("#acc7dc"));
-	register_button_->setForegroundColor(QColor("black"));
+	register_button_->setBackgroundColor(QColor("#171919"));
+	register_button_->setForegroundColor(QColor("white"));
 	register_button_->setMinimumSize(350, 65);
 	register_button_->setCursor(QCursor(Qt::PointingHandCursor));
 	register_button_->setFontSize(17);
diff --git a/src/WelcomePage.cc b/src/WelcomePage.cc
index 5f1fc1e1..37efbd14 100644
--- a/src/WelcomePage.cc
+++ b/src/WelcomePage.cc
@@ -59,16 +59,16 @@ WelcomePage::WelcomePage(QWidget *parent)
 	button_layout_->setContentsMargins(0, 20, 0, 80);
 
 	register_button_ = new RaisedButton("REGISTER", this);
-	register_button_->setBackgroundColor(QColor("#acc7dc"));
-	register_button_->setForegroundColor(QColor("#171919"));
+	register_button_->setBackgroundColor(QColor("#555459"));
+	register_button_->setForegroundColor(QColor("white"));
 	register_button_->setMinimumSize(240, 60);
 	register_button_->setCursor(QCursor(Qt::PointingHandCursor));
 	register_button_->setFontSize(14);
 	register_button_->setCornerRadius(3);
 
 	login_button_ = new RaisedButton("LOGIN", this);
-	login_button_->setBackgroundColor(QColor("#acc7dc"));
-	login_button_->setForegroundColor(QColor("#171919"));
+	login_button_->setBackgroundColor(QColor("#555459"));
+	login_button_->setForegroundColor(QColor("white"));
 	login_button_->setMinimumSize(240, 60);
 	login_button_->setCursor(QCursor(Qt::PointingHandCursor));
 	login_button_->setFontSize(14);