mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-11 01:10:13 +00:00
Sort colors by hue distance.
This commit is contained in:
parent
9cb5423d40
commit
529ef64257
@ -234,6 +234,8 @@ private:
|
||||
}
|
||||
void applyEditing(const QString &name, const QString ©Of, QColor value);
|
||||
|
||||
void sortByAccentDistance();
|
||||
|
||||
EditorBlock::Context _context;
|
||||
|
||||
QString _path;
|
||||
@ -332,6 +334,11 @@ Fn<void()> Editor::Inner::exportCallback() {
|
||||
}
|
||||
|
||||
void Editor::Inner::filterRows(const QString &query) {
|
||||
if (query == ":sort-by-accent-distance") {
|
||||
sortByAccentDistance();
|
||||
filterRows(QString());
|
||||
return;
|
||||
}
|
||||
_existingRows->filterRows(query);
|
||||
_newRows->filterRows(query);
|
||||
}
|
||||
@ -416,8 +423,8 @@ bool Editor::Inner::readData() {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto rows = style::main_palette::data();
|
||||
for_const (auto &row, rows) {
|
||||
const auto rows = style::main_palette::data();
|
||||
for (const auto &row : rows) {
|
||||
auto name = bytesToUtf8(row.name);
|
||||
auto description = bytesToUtf8(row.description);
|
||||
if (!_existingRows->feedDescription(name, description)) {
|
||||
@ -442,9 +449,16 @@ bool Editor::Inner::readData() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Editor::Inner::sortByAccentDistance() {
|
||||
const auto accent = *_existingRows->find("windowBgActive");
|
||||
_existingRows->sortByDistance(accent);
|
||||
_newRows->sortByDistance(accent);
|
||||
}
|
||||
|
||||
bool Editor::Inner::readExistingRows() {
|
||||
QFile f(_path);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
|
@ -394,6 +394,20 @@ bool EditorBlock::feedDescription(const QString &name, const QString &descriptio
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorBlock::sortByDistance(const QColor &to) {
|
||||
auto toHue = qreal();
|
||||
auto toSaturation = qreal();
|
||||
auto toLightness = qreal();
|
||||
to.getHsvF(&toHue, &toSaturation, &toLightness);
|
||||
ranges::sort(_data, ranges::less(), [&](const Row &row) {
|
||||
auto fromHue = qreal();
|
||||
auto fromSaturation = qreal();
|
||||
auto fromLightness = qreal();
|
||||
row.value().getHsvF(&fromHue, &fromSaturation, &fromLightness);
|
||||
return (toSaturation > 0.01) ? std::abs(fromHue - toHue) : 1.;
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
void EditorBlock::enumerateRows(Callback callback) {
|
||||
if (isSearch()) {
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
|
||||
bool feedDescription(const QString &name, const QString &description);
|
||||
|
||||
void sortByDistance(const QColor &to);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
Loading…
Reference in New Issue
Block a user