ColorUtils

Search for usage in LXR

#include <colorutils.h>

Inheritance diagram for ColorUtils:

Public Types

enum  Brightness { Dark , Light }
 
- Public Types inherited from QObject
typedef  QObjectList
 

Public Member Functions

 ColorUtils (QObject *parent=nullptr)
 
Q_INVOKABLE QColor adjustColor (const QColor &color, const QJSValue &adjustments)
 
Q_INVOKABLE QColor alphaBlend (const QColor &foreground, const QColor &background)
 
Q_INVOKABLE ColorUtils::Brightness brightnessForColor (const QColor &color)
 
Q_INVOKABLE qreal grayForColor (const QColor &color)
 
Q_INVOKABLE QColor linearInterpolation (const QColor &one, const QColor &two, double balance)
 
Q_INVOKABLE QColor scaleColor (const QColor &color, const QJSValue &adjustments)
 
Q_INVOKABLE QColor tintWithAlpha (const QColor &targetColor, const QColor &tintColor, double alpha)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
QBindable< QStringbindableObjectName ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo () const const
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isQuickItemType () const const
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_GADGET_EXPORT (EXPORT_MACRO)
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setObjectName (QAnyStringView name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool setProperty (const char *name, QVariant &&value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static Q_INVOKABLE qreal chroma (const QColor &color)
 
static ColorUtils::LabColor colorToLab (const QColor &color)
 
static ColorUtils::XYZColor colorToXYZ (const QColor &color)
 
static qreal luminance (const QColor &color)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

Utilities for processing items to obtain colors and information useful for UIs that need to adjust to variable elements.

Definition at line 20 of file colorutils.h.

Member Enumeration Documentation

◆ Brightness

Describes the contrast of an item.

Enumerator
Dark 

The item is dark and requires a light foreground color to achieve readable contrast.

Light 

The item is light and requires a dark foreground color to achieve readable contrast.

Definition at line 29 of file colorutils.h.

Constructor & Destructor Documentation

◆ ColorUtils()

ColorUtils::ColorUtils ( QObject * parent = nullptr)
explicit

Definition at line 16 of file colorutils.cpp.

Member Function Documentation

◆ adjustColor()

QColor ColorUtils::adjustColor ( const QColor & color,
const QJSValue & adjustments )

Increases or decreases the properties of color by fixed amounts.

Parameters
colorThe color to adjust.
adjustmentsThe adjustments to apply to the color.
{
red: null, // Range: -255 to 255
green: null, // Range: -255 to 255
blue: null, // Range: -255 to 255
hue: null, // Range: -360 to 360
saturation: null, // Range: -255 to 255
value: null // Range: -255 to 255
alpha: null, // Range: -255 to 255
}
Warning
It is an error to adjust both RGB and HSV properties.
Since
5.69
org.kde.kirigami 2.12

Definition at line 133 of file colorutils.cpp.

◆ alphaBlend()

QColor ColorUtils::alphaBlend ( const QColor & foreground,
const QColor & background )

Returns the result of overlaying the foreground color on the background color.

Parameters
foregroundThe color to overlay on the background.
backgroundThe color to overlay the foreground on.
import QtQuick
import org.kde.kirigami as Kirigami
Rectangle {
color: Kirigami.ColorUtils.alphaBlend(Qt.rgba(0, 0, 0, 0.5), Qt.rgba(1, 1, 1, 1))
}
Since
5.69
org.kde.kirigami 2.12

Definition at line 35 of file colorutils.cpp.

◆ brightnessForColor()

ColorUtils::Brightness ColorUtils::brightnessForColor ( const QColor & color)

Returns whether a color is bright or dark.

import QtQuick
import org.kde.kirigami as Kirigami
Kirigami.Heading {
text: {
if (Kirigami.ColorUtils.brightnessForColor("pink") == Kirigami.ColorUtils.Light) {
return "The color is light"
} else {
return "The color is dark"
}
}
}
Since
5.69
org.kde.kirigami 2.12

Definition at line 21 of file colorutils.cpp.

◆ chroma()

qreal ColorUtils::chroma ( const QColor & color)
static

Returns the CIELAB chroma of the given color.

CIELAB chroma may give a better quantification of how vibrant a color is compared to HSV saturation.

See also
https://en.wikipedia.org/wiki/Colorfulness
https://en.wikipedia.org/wiki/CIELAB_color_space

Definition at line 304 of file colorutils.cpp.

◆ colorToLab()

ColorUtils::LabColor ColorUtils::colorToLab ( const QColor & color)
static

Definition at line 274 of file colorutils.cpp.

◆ colorToXYZ()

ColorUtils::XYZColor ColorUtils::colorToXYZ ( const QColor & color)
static

Definition at line 247 of file colorutils.cpp.

◆ grayForColor()

qreal ColorUtils::grayForColor ( const QColor & color)

Same Algorithm as brightnessForColor but returns a 0 to 1 value for an estimate of the equivalent gray light value (luma).

0 as full black, 1 as full white and 0.5 equivalent to a 50% gray.

Since
5.81
org.kde.kirigami 2.16

Definition at line 30 of file colorutils.cpp.

◆ linearInterpolation()

QColor ColorUtils::linearInterpolation ( const QColor & one,
const QColor & two,
double balance )

Returns a linearly interpolated color between color one and color two.

Parameters
oneThe color to linearly interpolate from.
twoThe color to linearly interpolate to.
balanceThe balance between the two colors. 0.0 will return the first color, 1.0 will return the second color. Values beyond these bounds are valid, and will result in extrapolation.
import QtQuick
import org.kde.kirigami as Kirigami
Rectangle {
color: Kirigami.ColorUtils.linearInterpolation("black", "white", 0.5)
}
Since
5.69
org.kde.kirigami 2.12

Definition at line 61 of file colorutils.cpp.

◆ luminance()

qreal ColorUtils::luminance ( const QColor & color)
static

Definition at line 312 of file colorutils.cpp.

◆ scaleColor()

QColor ColorUtils::scaleColor ( const QColor & color,
const QJSValue & adjustments )

Smoothly scales colors.

Parameters
colorThe color to adjust.
adjustmentsThe adjustments to apply to the color. Each value must be between -100.0 and 100.0. This indicates how far the property should be scaled from its original to the maximum if positive or to the minimum if negative.
{
red: null
green: null
blue: null
saturation: null
value: null
alpha: null
}
Warning
It is an error to scale both RGB and HSV properties.
Since
5.69
org.kde.kirigami 2.12

Definition at line 179 of file colorutils.cpp.

◆ tintWithAlpha()

QColor ColorUtils::tintWithAlpha ( const QColor & targetColor,
const QColor & tintColor,
double alpha )

Tint a color using a separate alpha value.

This does the same as Qt.tint() except that rather than using the tint color's alpha value, it uses a separate value that gets multiplied with the tint color's alpha. This avoids needing to create a new color just to adjust an alpha value.

Parameters
targetColorThe color to tint.
tintColorThe color to tint with.
alphaThe amount of tinting to apply.
Returns
The tinted color.
See also
Qt.tint()

Definition at line 230 of file colorutils.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.