mirror of https://github.com/procxx/kepka.git
				
				
				
			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 applyEditing(const QString &name, const QString ©Of, QColor value); | ||||||
| 
 | 
 | ||||||
|  | 	void sortByAccentDistance(); | ||||||
|  | 
 | ||||||
| 	EditorBlock::Context _context; | 	EditorBlock::Context _context; | ||||||
| 
 | 
 | ||||||
| 	QString _path; | 	QString _path; | ||||||
|  | @ -332,6 +334,11 @@ Fn<void()> Editor::Inner::exportCallback() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Editor::Inner::filterRows(const QString &query) { | void Editor::Inner::filterRows(const QString &query) { | ||||||
|  | 	if (query == ":sort-by-accent-distance") { | ||||||
|  | 		sortByAccentDistance(); | ||||||
|  | 		filterRows(QString()); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
| 	_existingRows->filterRows(query); | 	_existingRows->filterRows(query); | ||||||
| 	_newRows->filterRows(query); | 	_newRows->filterRows(query); | ||||||
| } | } | ||||||
|  | @ -416,8 +423,8 @@ bool Editor::Inner::readData() { | ||||||
| 		return false; | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	auto rows = style::main_palette::data(); | 	const auto rows = style::main_palette::data(); | ||||||
| 	for_const (auto &row, rows) { | 	for (const auto &row : rows) { | ||||||
| 		auto name = bytesToUtf8(row.name); | 		auto name = bytesToUtf8(row.name); | ||||||
| 		auto description = bytesToUtf8(row.description); | 		auto description = bytesToUtf8(row.description); | ||||||
| 		if (!_existingRows->feedDescription(name, description)) { | 		if (!_existingRows->feedDescription(name, description)) { | ||||||
|  | @ -442,9 +449,16 @@ bool Editor::Inner::readData() { | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Editor::Inner::sortByAccentDistance() { | ||||||
|  | 	const auto accent = *_existingRows->find("windowBgActive"); | ||||||
|  | 	_existingRows->sortByDistance(accent); | ||||||
|  | 	_newRows->sortByDistance(accent); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool Editor::Inner::readExistingRows() { | bool Editor::Inner::readExistingRows() { | ||||||
| 	QFile f(_path); | 	QFile f(_path); | ||||||
| 	if (!f.open(QIODevice::ReadOnly)) { | 	if (!f.open(QIODevice::ReadOnly)) { | ||||||
|  |  | ||||||
|  | @ -394,6 +394,20 @@ bool EditorBlock::feedDescription(const QString &name, const QString &descriptio | ||||||
| 	return false; | 	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> | template <typename Callback> | ||||||
| void EditorBlock::enumerateRows(Callback callback) { | void EditorBlock::enumerateRows(Callback callback) { | ||||||
| 	if (isSearch()) { | 	if (isSearch()) { | ||||||
|  |  | ||||||
|  | @ -72,6 +72,8 @@ public: | ||||||
| 
 | 
 | ||||||
| 	bool feedDescription(const QString &name, const QString &description); | 	bool feedDescription(const QString &name, const QString &description); | ||||||
| 
 | 
 | ||||||
|  | 	void sortByDistance(const QColor &to); | ||||||
|  | 
 | ||||||
| protected: | protected: | ||||||
| 	void paintEvent(QPaintEvent *e) override; | 	void paintEvent(QPaintEvent *e) override; | ||||||
| 	int resizeGetHeight(int newWidth) override; | 	int resizeGetHeight(int newWidth) override; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue