7#include "absolutecolor.h"
8#include "genericcolor.h"
9#include "helperconversion.h"
10#include "initializelibraryresources.h"
11#include "rgbcolorspace.h"
17#include <qkeysequence.h>
23#include <qstringliteral.h>
25#include <qstyleoption.h>
28#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
31#include <qstringlist.h>
34#ifndef PERCEPTUALCOLORINTERNAL
62qreal standardWheelStepCount(QWheelEvent *event)
67 return event->angleDelta().y() /
static_cast<qreal
>(8 * 15);
104QImage transparencyBackground(qreal devicePixelRatioF)
109 constexpr int lightnessDistance = 15;
110 constexpr int lightnessOne = 127 - lightnessDistance;
111 constexpr int lightnessTwo = 128 + lightnessDistance;
112 constexpr int squareSizeInLogicalPixel = 10;
113 const int squareSize = qRound(squareSizeInLogicalPixel * devicePixelRatioF);
116 temp.fill(QColor(lightnessOne, lightnessOne, lightnessOne));
117 QPainter painter(&temp);
118 QColor foregroundColor(lightnessTwo, lightnessTwo, lightnessTwo);
119 painter.fillRect(0, 0, squareSize, squareSize, foregroundColor);
120 painter.fillRect(squareSize, squareSize, squareSize, squareSize, foregroundColor);
121 temp.setDevicePixelRatio(devicePixelRatioF);
145void drawQWidgetStyleSheetAware(QWidget *widget)
179[[nodiscard]] QPair<QString, QString> getPrefixSuffix(
const QString &formatString)
182 const auto list = formatString
183 .
arg(QStringLiteral(
"%1"))
184 .
split(QStringLiteral(
"%1"));
188 return QPair<QString, QString>(QString(), QString());
204QIcon qIconFromTheme(
const QStringList &names,
const QString &fallback,
ColorSchemeType type)
206#ifdef PERCEPTUALCOLORINTERNAL
210 for (
auto const &name : std::as_const(names)) {
219 initializeLibraryResources();
220 QString
path = QStringLiteral(
221 ":/PerceptualColor/icons/lighttheme/%1.svg");
223 path = QStringLiteral(
224 ":/PerceptualColor/icons/darktheme/%1.svg");
226 return QIcon(
path.
arg(fallback));
256QString fromMnemonicToRichText(
const QString &mnemonicText)
261 const auto underlineStart = doUnderline ? QStringLiteral(
"<u>") : QString();
262 const auto underlineStop = doUnderline ? QStringLiteral(
"</u>") : QString();
264 bool underlineNextChar =
false;
265 for (
int i = 0; i < mnemonicText.
length(); ++i) {
266 if (mnemonicText[i] == QStringLiteral(
"&")) {
267 const auto nextChar =
268 (i + 1 < mnemonicText.
length())
269 ? mnemonicText[i + 1]
271 if (nextChar == QStringLiteral(
"&")) {
273 result.
append(QStringLiteral(
"&"));
277 underlineNextChar =
true;
280 if (underlineNextChar) {
282 result.
append(underlineStart);
283 result.
append(mnemonicText[i]);
284 result.
append(underlineStop);
285 underlineNextChar =
false;
287 result.
append(mnemonicText[i]);
331 if (widget ==
nullptr) {
336 QScopedPointer<QLabel>
label{
new QLabel(widget)};
337 label->setText(QStringLiteral(
"abc"));
341 const QImage screenshot =
label->grab().toImage();
347 QColorFloatType lightnessSum = 0;
348 for (
int y = 0; y < screenshot.
height(); ++y) {
349 for (
int x = 0; x < screenshot.
width(); ++x) {
350 lightnessSum += QColor(screenshot.
pixel(x, y)).lightnessF();
353 const auto pixelCount = screenshot.
width() * screenshot.
height();
354 constexpr QColorFloatType threeshold = 0.5;
356 (lightnessSum /
static_cast<QColorFloatType
>(pixelCount)) < threeshold;
467 constexpr GenericColor red{41.22, 61.40, 17.92};
468 constexpr GenericColor orange{61.70, 29.38, 64.40};
469 constexpr GenericColor yellow{81.35, 07.28, 109.12};
470 constexpr GenericColor green{51.57, -63.28, 28.95};
471 constexpr GenericColor blue{51.57, -03.41, -48.08};
472 constexpr GenericColor purple{41.22, 33.08, -30.50};
473 constexpr GenericColor pink{61.70, 49.42, 18.23};
474 constexpr GenericColor brown{41.22, 17.04, 45.95};
475 constexpr std::array<GenericColor, 8> chromaticCielabColors
476 {{red, orange, yellow, green, blue, purple, pink, brown}};
479 using MySizeType = quint8;
481 constexpr MySizeType columnCount =
482 chromaticCielabColors.size() + 1;
483 constexpr auto rowCount = 5;
484 Swatches wcsSwatches{columnCount, rowCount};
487 constexpr double strongTint = 0.46;
488 constexpr double weakTint = 0.23;
489 constexpr double weakShade = 0.18;
490 constexpr double strongShade = 0.36;
491 std::array<GenericColor, rowCount> tintsAndShades;
492 for (MySizeType i = 0; i < chromaticCielabColors.size(); ++i) {
493 const auto oklch = AbsoluteColor::convert(
495 chromaticCielabColors.at(i),
498 .value_or(GenericColor());
499 tintsAndShades[0] = GenericColor
500 {oklch.first + (1 - oklch.first) * strongTint,
501 oklch.second * (1 - strongTint),
503 tintsAndShades[1] = GenericColor
504 {oklch.first + (1 - oklch.first) * weakTint,
505 oklch.second * (1 - weakTint),
507 tintsAndShades[2] = oklch;
508 tintsAndShades[3] = GenericColor
509 {oklch.first * (1 - weakShade),
510 oklch.second * (1 - weakShade),
512 tintsAndShades[4] = GenericColor
513 {oklch.first * (1 - strongShade),
514 oklch.second * (1 - strongShade),
516 for (MySizeType j = 0; j < rowCount; ++j) {
517 const auto variationCielchD50 = AbsoluteColor::convert(
519 tintsAndShades.at(j),
522 .value_or(GenericColor());
523 const auto variationRgb = colorSpace->fromCielchD50ToQRgbBound(
525 wcsSwatches.setValue(i,
533 for (
int j = 0; j < lightnesses.count(); ++j) {
534 const GenericColor myOklab{lightnesses.at(j), 0, 0};
535 const auto cielchD50 = AbsoluteColor::convert(
540 .value_or(GenericColor());
541 const auto rgb = colorSpace->fromCielchD50ToQRgbBound(cielchD50);
542 wcsSwatches.setValue(columnCount - 1, j, rgb);
584 const cmsUInt32Number intentCount =
585 cmsGetSupportedIntents(0,
nullptr,
nullptr);
586 cmsUInt32Number *codeArray =
new cmsUInt32Number[intentCount];
587 char **descriptionArray =
new char *[intentCount];
588 cmsGetSupportedIntents(intentCount, codeArray, descriptionArray);
589 for (cmsUInt32Number i = 0; i < intentCount; ++i) {
593 delete[] descriptionArray;
QString path(const QString &relativePath)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString label(StandardShortcut id)
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 absolute Oklab color space, which by definition always and exclusively uses a D65 illuminant.
@ CielabD50
The absolute Cielab color space using a D50 illuminant.
@ OklchD65
The absolute Oklch color space, which by definition always and exclusively uses a D65 illuminant.
@ CielchD50
The absolute Cielch color space using a D50 illuminant.
QMap< cmsUInt32Number, QString > lcmsIntentList()
The rendering intents supported by the LittleCMS library.
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
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
QString & append(QChar ch)
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
qsizetype length() const const
void resize(qsizetype newSize, QChar fillChar)
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)