5#include <private/qquickmultieffect_p_p.h>
6#include <private/qquickshadereffect_p.h>
7#include <private/qquickshadereffectsource_p.h>
162 setFlag(ItemHasContents);
216 return d->autoPaddingEnabled();
248 return d->paddingRect();
254 d->setPaddingRect(
rect);
269 return d->brightness();
290 return d->contrast();
311 return d->saturation();
332 return d->colorization();
354 return d->colorizationColor();
360 d->setColorizationColor(
color);
373 return d->blurEnabled();
453 return d->blurMultiplier();
472 return d->shadowEnabled();
493 return d->shadowOpacity();
518 return d->shadowBlur();
543 return d->shadowHorizontalOffset();
549 d->setShadowHorizontalOffset(
offset);
568 return d->shadowVerticalOffset();
574 d->setShadowVerticalOffset(
offset);
590 return d->shadowColor();
615 return d->shadowScale();
634 return d->maskEnabled();
654 return d->maskSource();
660 d->setMaskSource(
item);
678 return d->maskThresholdMin();
684 d->setMaskThresholdMin(threshold);
701 return d->maskSpreadAtMin();
707 d->setMaskSpreadAtMin(spread);
725 return d->maskThresholdMax();
731 d->setMaskThresholdMax(threshold);
748 return d->maskSpreadAtMax();
754 d->setMaskSpreadAtMax(spread);
769 return d->maskInverted();
775 d->setMaskInverted(inverted);
789 return d->itemRect();
801 return d->fragmentShader();
813 return d->vertexShader();
829 return d->hasProxySource();
846 d->handleGeometryChange(newGeometry, oldGeometry);
852 d->handleItemChange(change,
value);
893 if (
item == m_sourceItem)
898 m_shaderSource->
setInput(m_sourceItem);
907 return m_autoPaddingEnabled;
913 if (
enabled == m_autoPaddingEnabled)
916 m_autoPaddingEnabled =
enabled;
919 Q_EMIT q->autoPaddingEnabledChanged();
924 return m_paddingRect;
930 if (
rect == m_paddingRect)
932 m_paddingRect =
rect;
936 emit q->paddingRectChanged();
952 m_shaderEffect->
setProperty(
"brightness", m_brightness);
971 m_shaderEffect->
setProperty(
"contrast", m_contrast);
990 m_shaderEffect->
setProperty(
"saturation", m_saturation);
998 return m_colorization;
1011 Q_EMIT q->colorizationChanged();
1016 return m_colorizationColor;
1022 if (
color == m_colorizationColor)
1025 m_colorizationColor =
color;
1029 Q_EMIT q->colorizationColorChanged();
1034 return m_blurEnabled;
1049 Q_EMIT q->blurEnabledChanged();
1095 return m_blurMultiplier;
1111 Q_EMIT q->blurMultiplierChanged();
1116 return m_shadowEnabled;
1122 if (
enabled == m_shadowEnabled)
1131 Q_EMIT q->shadowEnabledChanged();
1136 return m_shadowOpacity;
1149 Q_EMIT q->shadowOpacityChanged();
1154 return m_shadowBlur;
1167 Q_EMIT q->shadowBlurChanged();
1172 return m_shadowHorizontalOffset;
1178 if (
offset == m_shadowHorizontalOffset)
1181 m_shadowHorizontalOffset =
offset;
1185 Q_EMIT q->shadowHorizontalOffsetChanged();
1190 return m_shadowVerticalOffset;
1196 if (
offset == m_shadowVerticalOffset)
1199 m_shadowVerticalOffset =
offset;
1203 Q_EMIT q->shadowVerticalOffsetChanged();
1208 return m_shadowColor;
1214 if (
color == m_shadowColor)
1217 m_shadowColor =
color;
1221 Q_EMIT q->shadowColorChanged();
1226 return m_shadowScale;
1238 m_shaderEffect->
setProperty(
"shadowScale", 1.0 / m_shadowScale);
1241 Q_EMIT q->shadowScaleChanged();
1246 return m_maskEnabled;
1259 Q_EMIT q->maskEnabledChanged();
1264 return m_maskSourceItem;
1270 if (
item == m_maskSourceItem)
1273 m_maskSourceItem =
item;
1274 if (m_shaderEffect) {
1275 auto maskSourceVariant = QVariant::fromValue<QQuickItem*>(m_maskSourceItem);
1276 m_shaderEffect->
setProperty(
"maskSrc", maskSourceVariant);
1280 Q_EMIT q->maskSourceChanged();
1285 return m_maskThresholdMin;
1291 if (threshold == m_maskThresholdMin)
1294 m_maskThresholdMin = threshold;
1298 Q_EMIT q->maskThresholdMinChanged();
1303 return m_maskSpreadAtMin;
1309 if (spread == m_maskSpreadAtMin)
1312 m_maskSpreadAtMin = spread;
1316 Q_EMIT q->maskSpreadAtMinChanged();
1321 return m_maskThresholdMax;
1327 if (threshold == m_maskThresholdMax)
1330 m_maskThresholdMax = threshold;
1334 Q_EMIT q->maskThresholdMaxChanged();
1339 return m_maskSpreadAtMax;
1345 if (spread == m_maskSpreadAtMax)
1348 m_maskSpreadAtMax = spread;
1352 Q_EMIT q->maskSpreadAtMaxChanged();
1357 return m_maskInverted;
1363 if (inverted == m_maskInverted)
1366 m_maskInverted = inverted;
1368 m_shaderEffect->
setProperty(
"maskInverted",
float(m_maskInverted));
1371 Q_EMIT q->maskInvertedChanged();
1376 if (!m_shaderEffect || !m_shaderSource)
1380 if (sourceRect.
width() > 0 && sourceRect.
height() > 0)
1388 return m_fragShader;
1393 return m_vertShader;
1398 return m_shaderSource && m_shaderSource->
isActive();
1408 if (!
q->isComponentComplete())
1412 if (
q->width() <= 0 ||
q->height() <= 0)
1421 m_shaderEffect->
setSize(
q->size());
1424 m_shaderSource->
setSize(
q->size());
1425 m_shaderSource->
setInput(m_sourceItem);
1436 auto sourceVariant = QVariant::fromValue<QQuickItem*>(m_shaderSource->
output());
1437 m_shaderEffect->
setProperty(
"src", sourceVariant);
1438 m_shaderEffect->
setProperty(
"brightness", m_brightness);
1439 m_shaderEffect->
setProperty(
"contrast", m_contrast);
1440 m_shaderEffect->
setProperty(
"saturation", m_saturation);
1441 m_shaderEffect->
setProperty(
"shadowScale", 1.0 / m_shadowScale);
1442 auto maskSourceVariant = QVariant::fromValue<QQuickItem*>(m_maskSourceItem);
1443 m_shaderEffect->
setProperty(
"maskSrc", maskSourceVariant);
1444 m_shaderEffect->
setProperty(
"maskInverted",
float(m_maskInverted));
1452 m_initialized =
true;
1457 if (!m_shaderEffect)
1462 const qreal c0 = 0.0001;
1463 const qreal c1 = 1.0 - c0;
1464 const qreal mt1 = m_maskThresholdMin + c0;
1465 const qreal ms1 = m_maskSpreadAtMin + 1.0;
1466 const qreal mt2 = c1 - m_maskThresholdMax;
1467 const qreal ms2 = m_maskSpreadAtMax + 1.0;
1469 mt1 * ms1 - (ms1 - c1),
1471 mt2 * ms2 - (ms2 - c1),
1473 m_shaderEffect->
setProperty(
"mask", maskThresholdSpread);
1478 if (!m_shaderEffect)
1483 (1.0 -
scale) * (0.5 + 0.5 * (m_paddingRect.
y() - m_paddingRect.
height()) / m_shaderEffect->
height()));
1489 if (!m_shaderEffect)
1493 m_shaderEffect->
setProperty(
"shadowOffset", shadowOffset);
1498 if (!m_shaderEffect)
1501 float alpha = std::clamp(
float(m_colorizationColor.
alphaF() * m_colorization), 0.0f, 1.0f);
1503 m_colorizationColor.
greenF(),
1504 m_colorizationColor.
blueF(),
1511 if (!m_shaderEffect)
1514 float alpha = std::clamp(
float(m_shadowColor.
alphaF() * m_shadowOpacity), 0.0f, 1.0f);
1517 m_shadowColor.
blueF(),
1525 return qSqrt(blurAmount *
float(m_blurMax) / 64.0f) * 1.2f - 0.2f;
1530 return std::max(0.0f, std::min(1.0f, 1.0f -
v * 2.0f));
1535 float bw1 =
blurWeight(std::fabs(blurLod - 0.1f));
1536 float bw2 =
blurWeight(std::fabs(blurLod - 0.3f));
1537 float bw3 =
blurWeight(std::fabs(blurLod - 0.5f));
1538 float bw4 =
blurWeight(std::fabs(blurLod - 0.7f));
1539 float bw5 =
blurWeight(std::fabs(blurLod - 0.9f));
1540 float bw6 =
blurWeight(std::fabs(blurLod - 1.1f));
1541 float bsum = bw1 + bw2 + bw3 + bw4 + bw5 + bw6;
1542 blurWeight1 =
QVector4D(bw1 / bsum, bw2 / bsum, bw3 / bsum, bw4 / bsum);
1543 blurWeight2 =
QVector2D(bw5 / bsum, bw6 / bsum);
1548 if (!m_shaderEffect)
1552 m_shaderEffect->
setProperty(
"blurWeight1", m_blurWeight1);
1553 m_shaderEffect->
setProperty(
"blurWeight2", m_blurWeight2);
1558 if (!m_shaderEffect)
1561 getBlurWeights(blurLod, m_shadowBlurWeight1, m_shadowBlurWeight2);
1562 m_shaderEffect->
setProperty(
"shadowBlurWeight1", m_shadowBlurWeight1);
1563 m_shaderEffect->
setProperty(
"shadowBlurWeight2", m_shadowBlurWeight2);
1568 if (m_blurEffects.isEmpty() || !m_shaderSource || !m_sourceItem)
1574 QSizeF firstItemSize(std::ceil(sourceSize.
width() / 16) * 8,
1575 std::ceil(sourceSize.
height() / 16) * 8);
1577 if (!
forceUpdate && m_firstBlurItemSize == firstItemSize)
1580 qCDebug(lcQuickEffect) <<
"Source size:" << sourceSize;
1581 m_firstBlurItemSize = firstItemSize;
1583 for (
int i = 0;
i < m_blurEffects.size();
i++) {
1584 auto *blurEffect = m_blurEffects[
i];
1585 QSizeF itemSize = (
i == 0) ? firstItemSize : m_blurEffects[
i - 1]->size() * 0.5;
1586 qCDebug(lcQuickEffect) <<
"Blur item" <<
i <<
":" << itemSize;
1587 blurEffect->setSize(itemSize);
1590 (1.0 + m_blurMultiplier) / itemSize.
height());
1591 blurEffect->setProperty(
"offset",
offset);
1598 if (!
q->isComponentComplete())
1602 if (m_shadowEnabled)
1608 if (m_blurEnabled && m_blurMax > 0)
1610 if (m_shadowEnabled)
1615 bool shaderChanged =
false;
1616 if (fShader != m_fragShader) {
1617 shaderChanged =
true;
1618 m_fragShader = fShader;
1621 Q_EMIT q->fragmentShaderChanged();
1623 if (vShader != m_vertShader) {
1624 shaderChanged =
true;
1625 m_vertShader = vShader;
1628 Q_EMIT q->vertexShaderChanged();
1630 if (shaderChanged) {
1631 qCDebug(lcQuickEffect) <<
this <<
"Shaders: " << m_fragShader << m_vertShader;
1639 if ((m_blurEnabled || m_shadowEnabled) && m_blurMax > 0) {
1642 else if (m_blurMax > 16)
1648 if (blurLevel != m_blurLevel || (blurLevel > 0 && m_blurEffects.isEmpty()) ||
forceUpdate) {
1653 if (blurLevel > m_blurLevel)
1656 m_blurLevel = blurLevel;
1662 if (!m_shaderEffect)
1666 int itemsAmount = blurLevel == 0 ? 0 : blurLevel + 2;
1668 if (m_blurEffects.size() < itemsAmount) {
1676 for (
int i = m_blurEffects.size();
i < itemsAmount;
i++) {
1677 auto blurEffect = qobject_cast<QQuickShaderEffect*>(blurComponent.
create());
1678 blurEffect->setParent(
q);
1679 blurEffect->setParentItem(
q);
1680 auto sourceVariant = QVariant::fromValue<QQuickItem*>(blurEffect);
1685 blurEffect->setProperty(
"source", sourceVariant);
1687 priv->layer()->setEnabled(
true);
1688 priv->layer()->setSmooth(
true);
1689 blurEffect->setVertexShader(blurVs);
1690 blurEffect->setFragmentShader(blurFs);
1691 m_blurEffects << blurEffect;
1697 for (
int i = 0;
i < m_blurEffects.size();
i++) {
1698 auto *blurEffect = m_blurEffects[
i];
1699 auto sourceItem = (
i >= itemsAmount) ?
1700 static_cast<QQuickItem *
>(dummyShaderSource) : (
i == 0) ?
1703 auto sourceVariant = QVariant::fromValue<QQuickItem*>(sourceItem);
1704 blurEffect->setProperty(
"source", sourceVariant);
1711 if (!m_shaderEffect || !m_shaderSource)
1714 const bool blurItemsNeeded = (m_blurEnabled || m_shadowEnabled) && (m_blurMax > 0);
1715 const int itemPadding = m_autoPaddingEnabled && blurItemsNeeded ? m_blurMax * (1.0 + m_blurMultiplier) : 0;
1718 if (m_paddingRect !=
QRectF() || itemPadding > 0) {
1719 QRectF effectRect(-m_paddingRect.
x() - itemPadding,
1720 -m_paddingRect.
y() - itemPadding,
1721 q->width() + m_paddingRect.
x() + m_paddingRect.
width() + (itemPadding * 2),
1722 q->height() + m_paddingRect.
y() + m_paddingRect.
height() + (itemPadding * 2));
1723 m_shaderEffect->
setX(effectRect.
x());
1724 m_shaderEffect->
setY(effectRect.
y());
1734 const qreal baseWidth = m_sourceItem && m_sourceItem->
width() > 0 ? m_sourceItem->
width() :
q->width();
1735 const qreal baseHeight = m_sourceItem && m_sourceItem->
height() > 0 ? m_sourceItem->
height() :
q->height();
1738 const qreal widthMultiplier =
q->width() > 0 ? baseWidth /
q->width() : 1.0;
1739 const qreal heightMultiplier =
q->height() > 0 ? baseHeight /
q->height() : 1.0;
1740 const qreal xPadding = itemPadding * widthMultiplier;
1741 const qreal yPadding = itemPadding * heightMultiplier;
1743 m_paddingRect.
y() * heightMultiplier,
1744 m_paddingRect.
width() * widthMultiplier,
1745 m_paddingRect.
height() * heightMultiplier);
1747 -
rect.y() - yPadding,
1748 baseWidth +
rect.x() +
rect.width() + xPadding * 2,
1749 baseHeight +
rect.y() +
rect.height() + yPadding * 2);
1752 m_shaderEffect->
setX(0);
1753 m_shaderEffect->
setY(0);
1754 m_shaderEffect->
setSize(
q->size());
1755 m_shaderSource->
setSize(
q->size());
1762 Q_EMIT q->paddingRectChanged();
1769 if (!m_shaderSource)
1772 auto sourceVariant = QVariant::fromValue<QQuickItem*>(m_shaderSource->
output());
1773 m_shaderEffect->
setProperty(
"src", sourceVariant);
1783 if (!m_shaderSource)
1786 m_shaderSource->
polish();
1791#include "moc_qquickmultieffect_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
float greenF() const noexcept
Returns the green color component of this color.
float redF() const noexcept
Returns the red color component of this color.
float alphaF() const noexcept
Returns the alpha color component of this color.
float blueF() const noexcept
Returns the blue color component of this color.
void setSourceRect(const QRectF &sourceRect)
void setInput(QQuickItem *input)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
The QQmlComponent class encapsulates a QML component definition.
virtual QObject * create(QQmlContext *context=nullptr)
Create an object instance from this component, within the specified context.
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setSize(const QSizeF &size)
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void setParentItem(QQuickItem *parent)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
qreal width
This property holds the width of this item.
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
qreal height
This property holds the height of this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
void polish()
Schedules a polish event for this item.
void setShadowOpacity(qreal shadowOpacity)
void setShadowColor(const QColor &color)
void setMaskSpreadAtMax(qreal spread)
bool maskInverted() const
void setColorizationColor(const QColor &color)
void setMaskThresholdMin(qreal threshold)
void updateEffectShaders()
void setColorization(qreal colorization)
void setShadowVerticalOffset(qreal offset)
void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
void setSource(QQuickItem *item)
qreal colorization() const
void setShadowBlur(qreal shadowBlur)
void setMaskSource(QQuickItem *item)
float blurWeight(float v)
QQuickItem * source() const
QString vertexShader() const
void updateShadowOffset()
~QQuickMultiEffectPrivate()
void setBlurMax(int blurMax)
QQuickMultiEffectPrivate()
void updateCenterOffset()
void setShadowScale(qreal shadowScale)
void updateProxyActiveCheck()
qreal maskSpreadAtMin() const
void setMaskThresholdMax(qreal threshold)
qreal shadowOpacity() const
QColor colorizationColor() const
qreal maskThresholdMax() const
void setShadowEnabled(bool enabled)
qreal shadowScale() const
void setMaskSpreadAtMin(qreal spread)
void updateMaskThresholdSpread()
void setBlurEnabled(bool enabled)
bool hasProxySource() const
QString fragmentShader() const
QQuickItem * maskSource() const
void setSaturation(qreal saturation)
qreal blurMultiplier() const
void proxyOutputChanged()
void updateBlurLevel(bool forceUpdate=false)
void setMaskInverted(bool inverted)
qreal shadowHorizontalOffset() const
void setBlurMultiplier(qreal blurMultiplier)
void setShadowHorizontalOffset(qreal offset)
float calculateLod(float blurAmount)
bool autoPaddingEnabled() const
void getBlurWeights(float blurLod, QVector4D &blurWeight1, QVector2D &blurWeight2)
QColor shadowColor() const
void setPaddingRect(const QRectF &rect)
qreal maskThresholdMin() const
void setContrast(qreal contrast)
void updateBlurItemSizes(bool forceUpdate=false)
qreal maskSpreadAtMax() const
void setBrightness(qreal brightness)
QRectF paddingRect() const
void updateColorizationColor()
void updateBlurItemsAmount(int blurLevel)
bool shadowEnabled() const
void handleGeometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void updateSourcePadding()
qreal shadowVerticalOffset() const
void updateShadowBlurWeights()
void setAutoPaddingEnabled(bool enabled)
void setMaskEnabled(bool enabled)
void setShadowHorizontalOffset(qreal offset)
qreal shadowHorizontalOffset
void setMaskEnabled(bool enabled)
void setBrightness(qreal brightness)
void setPaddingRect(const QRectF &rect)
void setShadowEnabled(bool enabled)
void setShadowOpacity(qreal shadowOpacity)
void setContrast(qreal contrast)
~QQuickMultiEffect() override
void setMaskSpreadAtMin(qreal spread)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void hasProxySourceChanged()
void setMaskThresholdMin(qreal threshold)
void setMaskInverted(bool inverted)
void setMaskThresholdMax(qreal threshold)
void setMaskSpreadAtMax(qreal spread)
void setSource(QQuickItem *item)
void setShadowBlur(qreal shadowBlur)
void setColorizationColor(const QColor &color)
qreal shadowVerticalOffset
void setShadowScale(qreal shadowScale)
void setAutoPaddingEnabled(bool enabled)
void setMaskSource(QQuickItem *item)
void setShadowColor(const QColor &color)
void setBlurMultiplier(qreal blurMultiplier)
void setBlurMax(int blurMax)
void setBlurEnabled(bool enabled)
void setSaturation(qreal saturation)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void setColorization(qreal colorization)
void setShadowVerticalOffset(qreal offset)
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
void setFragmentShader(const QUrl &fileUrl)
void setVertexShader(const QUrl &fileUrl)
\inmodule QtCore\reentrant
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray toUtf8() const &
The QVector2D class represents a vector or vertex in 2D space.
The QVector4D class represents a vector or vertex in 4D space.
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qfloat16 qSqrt(qfloat16 f)
static QPointF centerOffset(const QSizeF &screenSize, const QRectF &visibleArea)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLsizei const GLfloat * v
[13]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint GLintptr offset
GLdouble GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat alpha
GLenum GLenum GLenum GLenum GLenum scale
QQmlEngine * qmlEngine(const QObject *obj)
void forceUpdate(QQuickItem *item)
#define QStringLiteral(str)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent