refactoring random colors
This commit is contained in:
parent
48ed8497ea
commit
96910ee97d
@ -186,10 +186,9 @@ QString MessageObject::createLabelId(const QString& title, const QString& hex_co
|
|||||||
Label* new_lbl = nullptr;
|
Label* new_lbl = nullptr;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto rnd_color = QRandomGenerator::global()->bounded(0xFFFFFF);
|
auto rnd_color = TextFactory::generateRandomColor();
|
||||||
auto rnd_color_name = QSL("#%1").arg(QString::number(rnd_color, 16));
|
|
||||||
|
|
||||||
new_lbl = new Label(title, hex_color.isEmpty() ? rnd_color_name : hex_color);
|
new_lbl = new Label(title, hex_color.isEmpty() ? rnd_color : hex_color);
|
||||||
QSqlDatabase db = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
|
QSqlDatabase db = qApp->database()->driver()->threadSafeConnection(metaObject()->className());
|
||||||
|
|
||||||
DatabaseQueries::createLabel(db, new_lbl, m_account->accountId());
|
DatabaseQueries::createLabel(db, new_lbl, m_account->accountId());
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "gui/reusable/colortoolbutton.h"
|
#include "gui/reusable/colortoolbutton.h"
|
||||||
|
|
||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
|
#include "miscellaneous/textfactory.h"
|
||||||
|
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
@ -37,8 +38,7 @@ void ColorToolButton::setColor(const QColor& color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ColorToolButton::setRandomColor() {
|
void ColorToolButton::setRandomColor() {
|
||||||
int hue = QRandomGenerator::global()->generate() % 360;
|
auto clr = TextFactory::generateRandomColor();
|
||||||
auto clr = QColor::fromHsv(hue, 200, 240);
|
|
||||||
|
|
||||||
setColor(clr);
|
setColor(clr);
|
||||||
emit colorChanged(clr);
|
emit colorChanged(clr);
|
||||||
|
@ -43,6 +43,13 @@ QColor TextFactory::generateColorFromText(const QString& text) {
|
|||||||
return QColor::fromHsv(hue, 200, 240);
|
return QColor::fromHsv(hue, 200, 240);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QColor TextFactory::generateRandomColor() {
|
||||||
|
int hue = QRandomGenerator::global()->generate() % 360;
|
||||||
|
auto clr = QColor::fromHsv(hue, 200, 240);
|
||||||
|
|
||||||
|
return clr;
|
||||||
|
}
|
||||||
|
|
||||||
int TextFactory::stringHeight(const QString& string, const QFontMetrics& metrics) {
|
int TextFactory::stringHeight(const QString& string, const QFontMetrics& metrics) {
|
||||||
const int count_lines = string.split(QL1C('\n')).size();
|
const int count_lines = string.split(QL1C('\n')).size();
|
||||||
|
|
||||||
|
@ -14,8 +14,10 @@ class TextFactory {
|
|||||||
TextFactory();
|
TextFactory();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QString extractUsernameFromEmail(const QString& email_address);
|
|
||||||
static QColor generateColorFromText(const QString& text);
|
static QColor generateColorFromText(const QString& text);
|
||||||
|
static QColor generateRandomColor();
|
||||||
|
|
||||||
|
static QString extractUsernameFromEmail(const QString& email_address);
|
||||||
static int stringHeight(const QString& string, const QFontMetrics& metrics);
|
static int stringHeight(const QString& string, const QFontMetrics& metrics);
|
||||||
static int stringWidth(const QString& string, const QFontMetrics& metrics);
|
static int stringWidth(const QString& string, const QFontMetrics& metrics);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user