mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-04 03:08:04 +01:00
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;
|
||||
|
||||
try {
|
||||
auto rnd_color = QRandomGenerator::global()->bounded(0xFFFFFF);
|
||||
auto rnd_color_name = QSL("#%1").arg(QString::number(rnd_color, 16));
|
||||
auto rnd_color = TextFactory::generateRandomColor();
|
||||
|
||||
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());
|
||||
|
||||
DatabaseQueries::createLabel(db, new_lbl, m_account->accountId());
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "gui/reusable/colortoolbutton.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QMouseEvent>
|
||||
@ -37,8 +38,7 @@ void ColorToolButton::setColor(const QColor& color) {
|
||||
}
|
||||
|
||||
void ColorToolButton::setRandomColor() {
|
||||
int hue = QRandomGenerator::global()->generate() % 360;
|
||||
auto clr = QColor::fromHsv(hue, 200, 240);
|
||||
auto clr = TextFactory::generateRandomColor();
|
||||
|
||||
setColor(clr);
|
||||
emit colorChanged(clr);
|
||||
|
@ -43,6 +43,13 @@ QColor TextFactory::generateColorFromText(const QString& text) {
|
||||
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) {
|
||||
const int count_lines = string.split(QL1C('\n')).size();
|
||||
|
||||
|
@ -14,8 +14,10 @@ class TextFactory {
|
||||
TextFactory();
|
||||
|
||||
public:
|
||||
static QString extractUsernameFromEmail(const QString& email_address);
|
||||
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 stringWidth(const QString& string, const QFontMetrics& metrics);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user