| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#ifndef COMPOSITION_H |
| 5 |
#define COMPOSITION_H |
| 6 |
|
| 7 |
#include "arthurwidgets.h" |
| 8 |
|
| 9 |
#include <QBasicTimer> |
| 10 |
#include <QPainter> |
| 11 |
#include <QEvent> |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
|
| 15 |
QT_BEGIN_NAMESPACE |
| 16 |
class QPushButton; |
| 17 |
class QRadioButton; |
| 18 |
QT_END_NAMESPACE |
| 19 |
|
| 20 |
class CompositionWidget : public QWidget |
| 21 |
{ |
| 22 |
Q_OBJECT |
| 23 |
|
| 24 |
public: |
| 25 |
explicit CompositionWidget(QWidget *parent = nullptr); |
| 26 |
~CompositionWidget(); |
| 27 |
|
| 28 |
public slots: |
| 29 |
void nextMode(); |
| 30 |
|
| 31 |
private: |
| 32 |
bool m_cycle_enabled; |
| 33 |
|
| 34 |
QRadioButton *rbClear; |
| 35 |
QRadioButton *rbSource; |
| 36 |
QRadioButton *rbDest; |
| 37 |
QRadioButton *rbSourceOver; |
| 38 |
QRadioButton *rbDestOver; |
| 39 |
QRadioButton *rbSourceIn; |
| 40 |
QRadioButton *rbDestIn; |
| 41 |
QRadioButton *rbSourceOut; |
| 42 |
QRadioButton *rbDestOut; |
| 43 |
QRadioButton *rbSourceAtop; |
| 44 |
QRadioButton *rbDestAtop; |
| 45 |
QRadioButton *rbXor; |
| 46 |
|
| 47 |
QRadioButton *rbPlus; |
| 48 |
QRadioButton *rbMultiply; |
| 49 |
QRadioButton *rbScreen; |
| 50 |
QRadioButton *rbOverlay; |
| 51 |
QRadioButton *rbDarken; |
| 52 |
QRadioButton *rbLighten; |
| 53 |
QRadioButton *rbColorDodge; |
| 54 |
QRadioButton *rbColorBurn; |
| 55 |
QRadioButton *rbHardLight; |
| 56 |
QRadioButton *rbSoftLight; |
| 57 |
QRadioButton *rbDifference; |
| 58 |
QRadioButton *rbExclusion; |
| 59 |
}; |
| 60 |
|
| 61 |
class CompositionRenderer : public ArthurFrame |
| 62 |
{ |
| 63 |
Q_OBJECT |
| 64 |
|
| 65 |
enum ObjectType { NoObject, Circle, Rectangle, Image }; |
| 66 |
|
| 67 |
Q_PROPERTY(int circleColor READ circleColor WRITE setCircleColor) |
| 68 |
Q_PROPERTY(int circleAlpha READ circleAlpha WRITE setCircleAlpha) |
| 69 |
Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled) |
| 70 |
|
| 71 |
public: |
| 72 |
explicit CompositionRenderer(QWidget *parent = nullptr); |
| 73 |
~CompositionRenderer(); |
| 74 |
|
| 75 |
void paint(QPainter *) override; |
| 76 |
|
| 77 |
void setCirclePos(const QPointF &pos); |
| 78 |
|
| 79 |
QSize sizeHint() const override { return QSize(500, 400); } |
| 80 |
|
| 81 |
bool animationEnabled() const { return m_animation_enabled; } |
| 82 |
int circleColor() const { return m_circle_hue; } |
| 83 |
int circleAlpha() const { return m_circle_alpha; } |
| 84 |
|
| 85 |
protected: |
| 86 |
void mousePressEvent(QMouseEvent *) override; |
| 87 |
void mouseMoveEvent(QMouseEvent *) override; |
| 88 |
void mouseReleaseEvent(QMouseEvent *) override; |
| 89 |
void timerEvent(QTimerEvent *) override; |
| 90 |
|
| 91 |
public slots: |
| 92 |
void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); } |
| 93 |
void setSourceMode() { m_composition_mode = QPainter::CompositionMode_Source; update(); } |
| 94 |
void setDestMode() { m_composition_mode = QPainter::CompositionMode_Destination; update(); } |
| 95 |
void setSourceOverMode() { m_composition_mode = QPainter::CompositionMode_SourceOver; update(); } |
| 96 |
void setDestOverMode() { m_composition_mode = QPainter::CompositionMode_DestinationOver; update(); } |
| 97 |
void setSourceInMode() { m_composition_mode = QPainter::CompositionMode_SourceIn; update(); } |
| 98 |
void setDestInMode() { m_composition_mode = QPainter::CompositionMode_DestinationIn; update(); } |
| 99 |
void setSourceOutMode() { m_composition_mode = QPainter::CompositionMode_SourceOut; update(); } |
| 100 |
void setDestOutMode() { m_composition_mode = QPainter::CompositionMode_DestinationOut; update(); } |
| 101 |
void setSourceAtopMode() { m_composition_mode = QPainter::CompositionMode_SourceAtop; update(); } |
| 102 |
void setDestAtopMode() { m_composition_mode = QPainter::CompositionMode_DestinationAtop; update(); } |
| 103 |
void setXorMode() { m_composition_mode = QPainter::CompositionMode_Xor; update(); } |
| 104 |
|
| 105 |
void setPlusMode() { m_composition_mode = QPainter::CompositionMode_Plus; update(); } |
| 106 |
void setMultiplyMode() { m_composition_mode = QPainter::CompositionMode_Multiply; update(); } |
| 107 |
void setScreenMode() { m_composition_mode = QPainter::CompositionMode_Screen; update(); } |
| 108 |
void setOverlayMode() { m_composition_mode = QPainter::CompositionMode_Overlay; update(); } |
| 109 |
void setDarkenMode() { m_composition_mode = QPainter::CompositionMode_Darken; update(); } |
| 110 |
void setLightenMode() { m_composition_mode = QPainter::CompositionMode_Lighten; update(); } |
| 111 |
void setColorDodgeMode() { m_composition_mode = QPainter::CompositionMode_ColorDodge; update(); } |
| 112 |
void setColorBurnMode() { m_composition_mode = QPainter::CompositionMode_ColorBurn; update(); } |
| 113 |
void setHardLightMode() { m_composition_mode = QPainter::CompositionMode_HardLight; update(); } |
| 114 |
void setSoftLightMode() { m_composition_mode = QPainter::CompositionMode_SoftLight; update(); } |
| 115 |
void setDifferenceMode() { m_composition_mode = QPainter::CompositionMode_Difference; update(); } |
| 116 |
void setExclusionMode() { m_composition_mode = QPainter::CompositionMode_Exclusion; update(); } |
| 117 |
|
| 118 |
void setCircleAlpha(int alpha) { m_circle_alpha = alpha; update(); } |
| 119 |
void setCircleColor(int hue) { m_circle_hue = hue; update(); } |
| 120 |
void setAnimationEnabled(bool enabled); |
| 121 |
|
| 122 |
private: |
| 123 |
void updateCirclePos(); |
| 124 |
void drawBase(QPainter &p); |
| 125 |
void drawSource(QPainter &p); |
| 126 |
|
| 127 |
QPainter::CompositionMode m_composition_mode; |
| 128 |
|
| 129 |
QImage m_image; |
| 130 |
QImage m_buffer; |
| 131 |
QImage m_base_buffer; |
| 132 |
|
| 133 |
int m_circle_alpha; |
| 134 |
int m_circle_hue; |
| 135 |
|
| 136 |
QPointF m_circle_pos; |
| 137 |
QPointF m_offset; |
| 138 |
|
| 139 |
ObjectType m_current_object; |
| 140 |
bool m_animation_enabled; |
| 141 |
QBasicTimer m_animationTimer; |
| 142 |
}; |
| 143 |
|
| 144 |
#endif // COMPOSITION_H |