7#include "absolutecolor.h"
8#include "genericcolor.h"
9#include "helperconversion.h"
10#include "initializelibraryresources.h"
11#include "rgbcolorspace.h"
16#include <qkeysequence.h>
21#include <qstringliteral.h>
23#include <qstyleoption.h>
26#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
29#include <qstringlist.h>
32#ifndef PERCEPTUALCOLORINTERNAL
65 return event->angleDelta().y() /
static_cast<qreal
>(8 * 15);
102QImage transparencyBackground(qreal devicePixelRatioF)
107 constexpr int lightnessDistance = 15;
108 constexpr int lightnessOne = 127 - lightnessDistance;
109 constexpr int lightnessTwo = 128 + lightnessDistance;
110 constexpr int squareSizeInLogicalPixel = 10;
111 const int squareSize = qRound(squareSizeInLogicalPixel * devicePixelRatioF);
114 temp.fill(
QColor(lightnessOne, lightnessOne, lightnessOne));
116 QColor foregroundColor(lightnessTwo, lightnessTwo, lightnessTwo);
117 painter.fillRect(0, 0, squareSize, squareSize, foregroundColor);
118 painter.fillRect(squareSize, squareSize, squareSize, squareSize, foregroundColor);
119 temp.setDevicePixelRatio(devicePixelRatioF);
143void drawQWidgetStyleSheetAware(
QWidget *widget)
177[[nodiscard]] QPair<QString, QString> getPrefixSuffix(
const QString &formatString)
180 const auto list = formatString
181 .
arg(QStringLiteral(
"%1"))
182 .
split(QStringLiteral(
"%1"));
204#ifdef PERCEPTUALCOLORINTERNAL
208 for (
auto const &name : std::as_const(names)) {
217 initializeLibraryResources();
219 ":/PerceptualColor/icons/lighttheme/%1.svg");
221 path = QStringLiteral(
222 ":/PerceptualColor/icons/darktheme/%1.svg");
259 const auto underlineStart = doUnderline ? QStringLiteral(
"<u>") :
QString();
260 const auto underlineStop = doUnderline ? QStringLiteral(
"</u>") :
QString();
262 bool underlineNextChar =
false;
263 for (
int i = 0; i < mnemonicText.
length(); ++i) {
264 if (mnemonicText[i] == QStringLiteral(
"&")) {
265 const auto nextChar =
266 (i + 1 < mnemonicText.
length())
267 ? mnemonicText[i + 1]
269 if (nextChar == QStringLiteral(
"&")) {
271 result.
append(QStringLiteral(
"&"));
275 underlineNextChar =
true;
278 if (underlineNextChar) {
280 result.
append(underlineStart);
281 result.
append(mnemonicText[i]);
282 result.
append(underlineStop);
283 underlineNextChar =
false;
285 result.
append(mnemonicText[i]);
328std::optional<ColorSchemeType> guessColorSchemeTypeFromWidget(
QWidget *widget)
330 if (widget ==
nullptr) {
341 QColorFloatType lightnessSum = 0;
342 for (
int y = 0; y < screenshot.
height(); ++y) {
343 for (
int x = 0; x < screenshot.
width(); ++x) {
347 const auto pixelCount = screenshot.
width() * screenshot.
height();
348 constexpr QColorFloatType threeshold = 0.5;
350 (lightnessSum /
static_cast<QColorFloatType
>(pixelCount)) < threeshold;
461 constexpr GenericColor red{41.22, 61.40, 17.92};
462 constexpr GenericColor orange{61.70, 29.38, 64.40};
463 constexpr GenericColor yellow{81.35, 07.28, 109.12};
464 constexpr GenericColor green{51.57, -63.28, 28.95};
465 constexpr GenericColor blue{51.57, -03.41, -48.08};
466 constexpr GenericColor purple{41.22, 33.08, -30.50};
467 constexpr GenericColor pink{61.70, 49.42, 18.23};
468 constexpr GenericColor brown{41.22, 17.04, 45.95};
469 constexpr std::array<GenericColor, 8> chromaticCielabColors
470 {{red, orange, yellow, green, blue, purple, pink, brown}};
473 using MySizeType = quint8;
475 constexpr MySizeType columnCount =
476 chromaticCielabColors.size() + 1;
477 constexpr auto rowCount = 5;
478 Swatches wcsSwatches{columnCount, rowCount};
481 constexpr double strongTint = 0.46;
482 constexpr double weakTint = 0.23;
483 constexpr double weakShade = 0.18;
484 constexpr double strongShade = 0.36;
485 std::array<GenericColor, rowCount> tintsAndShades;
486 for (MySizeType i = 0; i < chromaticCielabColors.size(); ++i) {
487 const auto oklch = AbsoluteColor::convert(
489 chromaticCielabColors.at(i),
492 .value_or(GenericColor());
493 tintsAndShades[0] = GenericColor
494 {oklch.first + (1 - oklch.first) * strongTint,
495 oklch.second * (1 - strongTint),
497 tintsAndShades[1] = GenericColor
498 {oklch.first + (1 - oklch.first) * weakTint,
499 oklch.second * (1 - weakTint),
501 tintsAndShades[2] = oklch;
502 tintsAndShades[3] = GenericColor
503 {oklch.first * (1 - weakShade),
504 oklch.second * (1 - weakShade),
506 tintsAndShades[4] = GenericColor
507 {oklch.first * (1 - strongShade),
508 oklch.second * (1 - strongShade),
510 for (MySizeType j = 0; j < rowCount; ++j) {
511 const auto variationCielchD50 = AbsoluteColor::convert(
513 tintsAndShades.at(j),
516 .value_or(GenericColor());
517 const auto variationRgb = colorSpace->fromCielchD50ToQRgbBound(
519 wcsSwatches.setValue(i,
527 for (
int j = 0; j < lightnesses.count(); ++j) {
528 const GenericColor myOklab{lightnesses.at(j), 0, 0};
529 const auto cielchD50 = AbsoluteColor::convert(
534 .value_or(GenericColor());
535 const auto rgb = colorSpace->fromCielchD50ToQRgbBound(cielchD50);
536 wcsSwatches.setValue(columnCount - 1, j, rgb);
QString path(const QString &relativePath)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
The namespace of this library.
Array2D< QColor > Swatches
Swatches organized in a grid.
ColorSchemeType
Represents the appearance of a theme.
Swatches wcsBasicColors(const QSharedPointer< PerceptualColor::RgbColorSpace > &colorSpace)
Swatch grid derived from the basic colors as by WCS (World color survey).
@ OklabD65
The Oklab color space, which by definition always and exclusively uses a D65 illuminant.
@ CielabD50
The Cielab color space using a D50 illuminant.
@ OklchD65
The Oklch color space, which by definition always and exclusively uses a D65 illuminant.
@ CielchD50
The Cielch color space using a D50 illuminant.
float lightnessF() const const
QIcon fromTheme(const QString &name)
bool isNull() const const
QRgb pixel(const QPoint &position) const const
bool isEmpty() const const
QKeySequence mnemonic(const QString &text)
const_reference at(qsizetype i) const const
qsizetype count() const const
QImage toImage() const const
bool isEmpty() const const
QString & append(QChar ch)
QString arg(Args &&... args) const const
qsizetype length() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const const=0
void initFrom(const QWidget *widget)