1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include "arthurwidgets.h"
50 QT_FORWARD_DECLARE_CLASS(QPushButton)
51 QT_FORWARD_DECLARE_CLASS(QRadioButton)
53 #ifdef QT_OPENGL_SUPPORT
57 class CompositionWidget : public QWidget
62 CompositionWidget(QWidget *parent);
70 QRadioButton *rbClear;
71 QRadioButton *rbSource;
73 QRadioButton *rbSourceOver;
74 QRadioButton *rbDestOver;
75 QRadioButton *rbSourceIn;
76 QRadioButton *rbDestIn;
77 QRadioButton *rbSourceOut;
78 QRadioButton *rbDestOut;
79 QRadioButton *rbSourceAtop;
80 QRadioButton *rbDestAtop;
84 QRadioButton *rbMultiply;
85 QRadioButton *rbScreen;
86 QRadioButton *rbOverlay;
87 QRadioButton *rbDarken;
88 QRadioButton *rbLighten;
89 QRadioButton *rbColorDodge;
90 QRadioButton *rbColorBurn;
91 QRadioButton *rbHardLight;
92 QRadioButton *rbSoftLight;
93 QRadioButton *rbDifference;
94 QRadioButton *rbExclusion;
97 class CompositionRenderer : public ArthurFrame
101 enum ObjectType { NoObject, Circle, Rectangle, Image };
103 Q_PROPERTY(int circleColor READ circleColor WRITE setCircleColor)
104 Q_PROPERTY(int circleAlpha READ circleAlpha WRITE setCircleAlpha)
105 Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled)
108 CompositionRenderer(QWidget *parent);
110 void paint(QPainter *);
112 void setCirclePos(const QPointF &pos);
114 QSize sizeHint() const { return QSize(500, 400); }
116 bool animationEnabled() const { return m_animation_enabled; }
117 int circleColor() const { return m_circle_hue; }
118 int circleAlpha() const { return m_circle_alpha; }
121 void mousePressEvent(QMouseEvent *);
122 void mouseMoveEvent(QMouseEvent *);
123 void mouseReleaseEvent(QMouseEvent *);
124 void timerEvent(QTimerEvent *);
127 void setClearMode() { m_composition_mode = QPainter::CompositionMode_Clear; update(); }
128 void setSourceMode() { m_composition_mode = QPainter::CompositionMode_Source; update(); }
129 void setDestMode() { m_composition_mode = QPainter::CompositionMode_Destination; update(); }
130 void setSourceOverMode() { m_composition_mode = QPainter::CompositionMode_SourceOver; update(); }
131 void setDestOverMode() { m_composition_mode = QPainter::CompositionMode_DestinationOver; update(); }
132 void setSourceInMode() { m_composition_mode = QPainter::CompositionMode_SourceIn; update(); }
133 void setDestInMode() { m_composition_mode = QPainter::CompositionMode_DestinationIn; update(); }
134 void setSourceOutMode() { m_composition_mode = QPainter::CompositionMode_SourceOut; update(); }
135 void setDestOutMode() { m_composition_mode = QPainter::CompositionMode_DestinationOut; update(); }
136 void setSourceAtopMode() { m_composition_mode = QPainter::CompositionMode_SourceAtop; update(); }
137 void setDestAtopMode() { m_composition_mode = QPainter::CompositionMode_DestinationAtop; update(); }
138 void setXorMode() { m_composition_mode = QPainter::CompositionMode_Xor; update(); }
140 void setPlusMode() { m_composition_mode = QPainter::CompositionMode_Plus; update(); }
141 void setMultiplyMode() { m_composition_mode = QPainter::CompositionMode_Multiply; update(); }
142 void setScreenMode() { m_composition_mode = QPainter::CompositionMode_Screen; update(); }
143 void setOverlayMode() { m_composition_mode = QPainter::CompositionMode_Overlay; update(); }
144 void setDarkenMode() { m_composition_mode = QPainter::CompositionMode_Darken; update(); }
145 void setLightenMode() { m_composition_mode = QPainter::CompositionMode_Lighten; update(); }
146 void setColorDodgeMode() { m_composition_mode = QPainter::CompositionMode_ColorDodge; update(); }
147 void setColorBurnMode() { m_composition_mode = QPainter::CompositionMode_ColorBurn; update(); }
148 void setHardLightMode() { m_composition_mode = QPainter::CompositionMode_HardLight; update(); }
149 void setSoftLightMode() { m_composition_mode = QPainter::CompositionMode_SoftLight; update(); }
150 void setDifferenceMode() { m_composition_mode = QPainter::CompositionMode_Difference; update(); }
151 void setExclusionMode() { m_composition_mode = QPainter::CompositionMode_Exclusion; update(); }
153 void setCircleAlpha(int alpha) { m_circle_alpha = alpha; update(); }
154 void setCircleColor(int hue) { m_circle_hue = hue; update(); }
155 void setAnimationEnabled(bool enabled);
158 void updateCirclePos();
159 void drawBase(QPainter &p);
160 void drawSource(QPainter &p);
162 QPainter::CompositionMode m_composition_mode;
167 QPixmap m_base_buffer;
171 QImage m_base_buffer;
177 QPointF m_circle_pos;
180 ObjectType m_current_object;
181 bool m_animation_enabled;
182 int m_animationTimer;
184 #ifdef QT_OPENGL_SUPPORT
185 QGLPixelBuffer *m_pbuffer;
187 GLuint m_compositing_tex;
188 int m_pbuffer_size; // width==height==size of pbuffer
189 QSize m_previous_size;
193 #endif // COMPOSITION_H