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)
196[[nodiscard]] QPair<QString, QString> getPrefixSuffix(
const QString &formatString)
199 const auto list = formatString
200 .
arg(QStringLiteral(
"%1"))
201 .
split(QStringLiteral(
"%1"));
205 return QPair<QString, QString>(QString(), QString());
230QIcon qIconFromTheme(
const QStringList &names,
const QString &fallback,
ColorSchemeType type)
232#ifdef PERCEPTUALCOLORINTERNAL
236 for (
auto const &name : std::as_const(names)) {
245 initializeLibraryResources();
246 QString
path = QStringLiteral(
247 ":/PerceptualColor/icons/lighttheme/%1.svg");
249 path = QStringLiteral(
250 ":/PerceptualColor/icons/darktheme/%1.svg");
252 return QIcon(
path.
arg(fallback));
282QString fromMnemonicToRichText(
const QString &mnemonicText)
287 const auto underlineStart = doUnderline ? QStringLiteral(
"<u>") : QString();
288 const auto underlineStop = doUnderline ? QStringLiteral(
"</u>") : QString();
290 bool underlineNextChar =
false;
291 for (
int i = 0; i < mnemonicText.
length(); ++i) {
292 if (mnemonicText[i] == QStringLiteral(
"&")) {
293 const auto nextChar =
294 (i + 1 < mnemonicText.
length())
295 ? mnemonicText[i + 1]
297 if (nextChar == QStringLiteral(
"&")) {
299 result.
append(QStringLiteral(
"&"));
303 underlineNextChar =
true;
306 if (underlineNextChar) {
308 result.
append(underlineStart);
309 result.
append(mnemonicText[i]);
310 result.
append(underlineStop);
311 underlineNextChar =
false;
313 result.
append(mnemonicText[i]);
357 if (widget ==
nullptr) {
362 QScopedPointer<QLabel>
label{
new QLabel(widget)};
363 label->setText(QStringLiteral(
"abc"));
367 const QImage screenshot =
label->grab().toImage();
373 QColorFloatType lightnessSum = 0;
374 for (
int y = 0; y < screenshot.
height(); ++y) {
375 for (
int x = 0; x < screenshot.
width(); ++x) {
376 lightnessSum += QColor(screenshot.
pixel(x, y)).lightnessF();
379 const auto pixelCount = screenshot.
width() * screenshot.
height();
380 constexpr QColorFloatType threeshold = 0.5;
382 (lightnessSum /
static_cast<QColorFloatType
>(pixelCount)) < threeshold;
493 constexpr GenericColor red{41.22, 61.40, 17.92};
494 constexpr GenericColor orange{61.70, 29.38, 64.40};
495 constexpr GenericColor yellow{81.35, 07.28, 109.12};
496 constexpr GenericColor green{51.57, -63.28, 28.95};
497 constexpr GenericColor blue{51.57, -03.41, -48.08};
498 constexpr GenericColor purple{41.22, 33.08, -30.50};
499 constexpr GenericColor pink{61.70, 49.42, 18.23};
500 constexpr GenericColor brown{41.22, 17.04, 45.95};
501 constexpr std::array<GenericColor, 8> chromaticCielabColors
502 {{red, orange, yellow, green, blue, purple, pink, brown}};
505 using MySizeType = quint8;
507 constexpr MySizeType columnCount =
508 chromaticCielabColors.size() + 1;
509 constexpr auto rowCount = 5;
510 Swatches wcsSwatches{columnCount, rowCount};
513 constexpr double strongTint = 0.46;
514 constexpr double weakTint = 0.23;
515 constexpr double weakShade = 0.18;
516 constexpr double strongShade = 0.36;
517 std::array<GenericColor, rowCount> tintsAndShades;
518 for (MySizeType i = 0; i < chromaticCielabColors.size(); ++i) {
519 const auto oklch = AbsoluteColor::convert(
521 chromaticCielabColors.at(i),
524 .value_or(GenericColor());
525 tintsAndShades[0] = GenericColor
526 {oklch.first + (1 - oklch.first) * strongTint,
527 oklch.second * (1 - strongTint),
529 tintsAndShades[1] = GenericColor
530 {oklch.first + (1 - oklch.first) * weakTint,
531 oklch.second * (1 - weakTint),
533 tintsAndShades[2] = oklch;
534 tintsAndShades[3] = GenericColor
535 {oklch.first * (1 - weakShade),
536 oklch.second * (1 - weakShade),
538 tintsAndShades[4] = GenericColor
539 {oklch.first * (1 - strongShade),
540 oklch.second * (1 - strongShade),
542 for (MySizeType j = 0; j < rowCount; ++j) {
543 const auto variationCielchD50 = AbsoluteColor::convert(
545 tintsAndShades.at(j),
548 .value_or(GenericColor());
549 const auto variationRgb = colorSpace->fromCielchD50ToQRgbBound(
551 wcsSwatches.setValue(i,
559 for (
int j = 0; j < lightnesses.count(); ++j) {
560 const GenericColor myOklab{lightnesses.at(j), 0, 0};
561 const auto cielchD50 = AbsoluteColor::convert(
566 .value_or(GenericColor());
567 const auto rgb = colorSpace->fromCielchD50ToQRgbBound(cielchD50);
568 wcsSwatches.setValue(columnCount - 1, j, rgb);
610 const cmsUInt32Number intentCount =
611 cmsGetSupportedIntents(0,
nullptr,
nullptr);
612 cmsUInt32Number *codeArray =
new cmsUInt32Number[intentCount];
613 char **descriptionArray =
new char *[intentCount];
614 cmsGetSupportedIntents(intentCount, codeArray, descriptionArray);
615 for (cmsUInt32Number i = 0; i < intentCount; ++i) {
619 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)