2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-18 10:30:20 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the demonstration applications of the Qt Toolkit.
|
|
|
|
**
|
2016-01-18 10:30:20 +00:00
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-18 10:30:20 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** BSD License Usage
|
|
|
|
** Alternatively, you may use this file under the terms of the BSD license
|
|
|
|
** as follows:
|
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "composition.h"
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <qmath.h>
|
|
|
|
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
#include <QOpenGLWindow>
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
const int animationInterval = 15; // update every 16 ms = ~60FPS
|
|
|
|
|
|
|
|
CompositionWidget::CompositionWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
CompositionRenderer *view = new CompositionRenderer(this);
|
|
|
|
|
|
|
|
QGroupBox *mainGroup = new QGroupBox(parent);
|
|
|
|
mainGroup->setTitle(tr("Composition Modes"));
|
|
|
|
|
|
|
|
QGroupBox *modesGroup = new QGroupBox(mainGroup);
|
|
|
|
modesGroup->setTitle(tr("Mode"));
|
|
|
|
|
|
|
|
rbClear = new QRadioButton(tr("Clear"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbClear, &QAbstractButton::clicked, view, &CompositionRenderer::setClearMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbSource = new QRadioButton(tr("Source"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbSource, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDest = new QRadioButton(tr("Destination"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDest, &QAbstractButton::clicked, view, &CompositionRenderer::setDestMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbSourceOver = new QRadioButton(tr("Source Over"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbSourceOver, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceOverMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDestOver = new QRadioButton(tr("Destination Over"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDestOver, &QAbstractButton::clicked, view, &CompositionRenderer::setDestOverMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbSourceIn = new QRadioButton(tr("Source In"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbSourceIn, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceInMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDestIn = new QRadioButton(tr("Dest In"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDestIn, &QAbstractButton::clicked, view, &CompositionRenderer::setDestInMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbSourceOut = new QRadioButton(tr("Source Out"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbSourceOut, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceOutMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDestOut = new QRadioButton(tr("Dest Out"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDestOut, &QAbstractButton::clicked, view, &CompositionRenderer::setDestOutMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbSourceAtop = new QRadioButton(tr("Source Atop"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbSourceAtop, &QAbstractButton::clicked, view, &CompositionRenderer::setSourceAtopMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDestAtop = new QRadioButton(tr("Dest Atop"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDestAtop, &QAbstractButton::clicked, view, &CompositionRenderer::setDestAtopMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbXor = new QRadioButton(tr("Xor"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbXor, &QAbstractButton::clicked, view, &CompositionRenderer::setXorMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
rbPlus = new QRadioButton(tr("Plus"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbPlus, &QAbstractButton::clicked, view, &CompositionRenderer::setPlusMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbMultiply = new QRadioButton(tr("Multiply"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbMultiply, &QAbstractButton::clicked, view, &CompositionRenderer::setMultiplyMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbScreen = new QRadioButton(tr("Screen"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbScreen, &QAbstractButton::clicked, view, &CompositionRenderer::setScreenMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbOverlay = new QRadioButton(tr("Overlay"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbOverlay, &QAbstractButton::clicked, view, &CompositionRenderer::setOverlayMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDarken = new QRadioButton(tr("Darken"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDarken, &QAbstractButton::clicked, view, &CompositionRenderer::setDarkenMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbLighten = new QRadioButton(tr("Lighten"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbLighten, &QAbstractButton::clicked, view, &CompositionRenderer::setLightenMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbColorDodge = new QRadioButton(tr("Color Dodge"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbColorDodge, &QAbstractButton::clicked, view, &CompositionRenderer::setColorDodgeMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbColorBurn = new QRadioButton(tr("Color Burn"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbColorBurn, &QAbstractButton::clicked, view, &CompositionRenderer::setColorBurnMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbHardLight = new QRadioButton(tr("Hard Light"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbHardLight, &QAbstractButton::clicked, view, &CompositionRenderer::setHardLightMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbSoftLight = new QRadioButton(tr("Soft Light"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbSoftLight, &QAbstractButton::clicked, view, &CompositionRenderer::setSoftLightMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbDifference = new QRadioButton(tr("Difference"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbDifference, &QAbstractButton::clicked, view, &CompositionRenderer::setDifferenceMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
rbExclusion = new QRadioButton(tr("Exclusion"), modesGroup);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(rbExclusion, &QAbstractButton::clicked, view, &CompositionRenderer::setExclusionMode);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QGroupBox *circleColorGroup = new QGroupBox(mainGroup);
|
|
|
|
circleColorGroup->setTitle(tr("Circle color"));
|
|
|
|
QSlider *circleColorSlider = new QSlider(Qt::Horizontal, circleColorGroup);
|
|
|
|
circleColorSlider->setRange(0, 359);
|
|
|
|
circleColorSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(circleColorSlider, &QAbstractSlider::valueChanged, view, &CompositionRenderer::setCircleColor);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QGroupBox *circleAlphaGroup = new QGroupBox(mainGroup);
|
|
|
|
circleAlphaGroup->setTitle(tr("Circle alpha"));
|
|
|
|
QSlider *circleAlphaSlider = new QSlider(Qt::Horizontal, circleAlphaGroup);
|
|
|
|
circleAlphaSlider->setRange(0, 255);
|
|
|
|
circleAlphaSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(circleAlphaSlider, &QAbstractSlider::valueChanged, view, &CompositionRenderer::setCircleAlpha);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QPushButton *showSourceButton = new QPushButton(mainGroup);
|
|
|
|
showSourceButton->setText(tr("Show Source"));
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
2011-04-27 10:05:43 +00:00
|
|
|
QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
|
|
|
|
enableOpenGLButton->setText(tr("Use OpenGL"));
|
|
|
|
enableOpenGLButton->setCheckable(true);
|
|
|
|
enableOpenGLButton->setChecked(view->usesOpenGL());
|
|
|
|
#endif
|
|
|
|
QPushButton *whatsThisButton = new QPushButton(mainGroup);
|
|
|
|
whatsThisButton->setText(tr("What's This?"));
|
|
|
|
whatsThisButton->setCheckable(true);
|
|
|
|
|
|
|
|
QPushButton *animateButton = new QPushButton(mainGroup);
|
|
|
|
animateButton->setText(tr("Animated"));
|
|
|
|
animateButton->setCheckable(true);
|
|
|
|
animateButton->setChecked(true);
|
|
|
|
|
|
|
|
QHBoxLayout *viewLayout = new QHBoxLayout(this);
|
|
|
|
viewLayout->addWidget(view);
|
|
|
|
viewLayout->addWidget(mainGroup);
|
|
|
|
|
|
|
|
QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
|
|
|
|
mainGroupLayout->addWidget(circleColorGroup);
|
|
|
|
mainGroupLayout->addWidget(circleAlphaGroup);
|
|
|
|
mainGroupLayout->addWidget(modesGroup);
|
|
|
|
mainGroupLayout->addStretch();
|
|
|
|
mainGroupLayout->addWidget(animateButton);
|
|
|
|
mainGroupLayout->addWidget(whatsThisButton);
|
|
|
|
mainGroupLayout->addWidget(showSourceButton);
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
2011-04-27 10:05:43 +00:00
|
|
|
mainGroupLayout->addWidget(enableOpenGLButton);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QGridLayout *modesLayout = new QGridLayout(modesGroup);
|
2012-11-23 10:52:51 +00:00
|
|
|
modesLayout->addWidget(rbClear, 0, 0);
|
|
|
|
modesLayout->addWidget(rbSource, 1, 0);
|
|
|
|
modesLayout->addWidget(rbDest, 2, 0);
|
|
|
|
modesLayout->addWidget(rbSourceOver, 3, 0);
|
|
|
|
modesLayout->addWidget(rbDestOver, 4, 0);
|
|
|
|
modesLayout->addWidget(rbSourceIn, 5, 0);
|
|
|
|
modesLayout->addWidget(rbDestIn, 6, 0);
|
|
|
|
modesLayout->addWidget(rbSourceOut, 7, 0);
|
|
|
|
modesLayout->addWidget(rbDestOut, 8, 0);
|
|
|
|
modesLayout->addWidget(rbSourceAtop, 9, 0);
|
|
|
|
modesLayout->addWidget(rbDestAtop, 10, 0);
|
|
|
|
modesLayout->addWidget(rbXor, 11, 0);
|
|
|
|
|
|
|
|
modesLayout->addWidget(rbPlus, 0, 1);
|
|
|
|
modesLayout->addWidget(rbMultiply, 1, 1);
|
|
|
|
modesLayout->addWidget(rbScreen, 2, 1);
|
|
|
|
modesLayout->addWidget(rbOverlay, 3, 1);
|
|
|
|
modesLayout->addWidget(rbDarken, 4, 1);
|
|
|
|
modesLayout->addWidget(rbLighten, 5, 1);
|
|
|
|
modesLayout->addWidget(rbColorDodge, 6, 1);
|
|
|
|
modesLayout->addWidget(rbColorBurn, 7, 1);
|
|
|
|
modesLayout->addWidget(rbHardLight, 8, 1);
|
|
|
|
modesLayout->addWidget(rbSoftLight, 9, 1);
|
|
|
|
modesLayout->addWidget(rbDifference, 10, 1);
|
|
|
|
modesLayout->addWidget(rbExclusion, 11, 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *circleColorLayout = new QVBoxLayout(circleColorGroup);
|
|
|
|
circleColorLayout->addWidget(circleColorSlider);
|
|
|
|
|
|
|
|
QVBoxLayout *circleAlphaLayout = new QVBoxLayout(circleAlphaGroup);
|
|
|
|
circleAlphaLayout->addWidget(circleAlphaSlider);
|
|
|
|
|
|
|
|
view->loadDescription(":res/composition/composition.html");
|
|
|
|
view->loadSourceFile(":res/composition/composition.cpp");
|
|
|
|
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(whatsThisButton, &QAbstractButton::clicked, view, &ArthurFrame::setDescriptionEnabled);
|
|
|
|
connect(view, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked);
|
|
|
|
connect(showSourceButton, &QAbstractButton::clicked, view, &ArthurFrame::showSource);
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(enableOpenGLButton, &QAbstractButton::clicked, view, &ArthurFrame::enableOpenGL);
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2018-12-07 13:17:02 +00:00
|
|
|
connect(animateButton, &QAbstractButton::toggled, view, &CompositionRenderer::setAnimationEnabled);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
circleColorSlider->setValue(270);
|
|
|
|
circleAlphaSlider->setValue(200);
|
|
|
|
rbSourceOut->animateClick();
|
|
|
|
|
|
|
|
setWindowTitle(tr("Composition Modes"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CompositionWidget::nextMode()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (!m_animation_enabled)
|
|
|
|
return;
|
|
|
|
if (rbClear->isChecked()) rbSource->animateClick();
|
|
|
|
if (rbSource->isChecked()) rbDest->animateClick();
|
|
|
|
if (rbDest->isChecked()) rbSourceOver->animateClick();
|
|
|
|
if (rbSourceOver->isChecked()) rbDestOver->animateClick();
|
|
|
|
if (rbDestOver->isChecked()) rbSourceIn->animateClick();
|
|
|
|
if (rbSourceIn->isChecked()) rbDestIn->animateClick();
|
|
|
|
if (rbDestIn->isChecked()) rbSourceOut->animateClick();
|
|
|
|
if (rbSourceOut->isChecked()) rbDestOut->animateClick();
|
|
|
|
if (rbDestOut->isChecked()) rbSourceAtop->animateClick();
|
|
|
|
if (rbSourceAtop->isChecked()) rbDestAtop->animateClick();
|
|
|
|
if (rbDestAtop->isChecked()) rbXor->animateClick();
|
|
|
|
if (rbXor->isChecked()) rbClear->animateClick();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositionRenderer::CompositionRenderer(QWidget *parent)
|
|
|
|
: ArthurFrame(parent)
|
|
|
|
{
|
|
|
|
m_animation_enabled = true;
|
|
|
|
m_animationTimer = startTimer(animationInterval);
|
|
|
|
m_image = QImage(":res/composition/flower.jpg");
|
|
|
|
m_image.setAlphaChannel(QImage(":res/composition/flower_alpha.jpg"));
|
|
|
|
m_circle_alpha = 127;
|
|
|
|
m_circle_hue = 255;
|
|
|
|
m_current_object = NoObject;
|
|
|
|
m_composition_mode = QPainter::CompositionMode_SourceOut;
|
|
|
|
|
|
|
|
m_circle_pos = QPoint(200, 100);
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
2011-04-27 10:05:43 +00:00
|
|
|
m_pbuffer_size = 1024;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF rectangle_around(const QPointF &p, const QSizeF &size = QSize(250, 200))
|
|
|
|
{
|
|
|
|
QRectF rect(p, size);
|
|
|
|
rect.translate(-size.width()/2, -size.height()/2);
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::setAnimationEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
if (m_animation_enabled == enabled)
|
|
|
|
return;
|
|
|
|
m_animation_enabled = enabled;
|
|
|
|
if (enabled) {
|
|
|
|
Q_ASSERT(!m_animationTimer);
|
|
|
|
m_animationTimer = startTimer(animationInterval);
|
|
|
|
} else {
|
|
|
|
killTimer(m_animationTimer);
|
|
|
|
m_animationTimer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::updateCirclePos()
|
|
|
|
{
|
|
|
|
if (m_current_object != NoObject)
|
|
|
|
return;
|
|
|
|
QDateTime dt = QDateTime::currentDateTime();
|
2016-06-21 21:27:48 +00:00
|
|
|
qreal t = dt.toMSecsSinceEpoch() / 1000.0;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
qreal x = width() / qreal(2) + (qCos(t*8/11) + qSin(-t)) * width() / qreal(4);
|
|
|
|
qreal y = height() / qreal(2) + (qSin(t*6/7) + qCos(t * qreal(1.5))) * height() / qreal(4);
|
|
|
|
|
|
|
|
setCirclePos(QLineF(m_circle_pos, QPointF(x, y)).pointAt(0.02));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::drawBase(QPainter &p)
|
|
|
|
{
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
|
|
|
|
QLinearGradient rect_gradient(0, 0, 0, height());
|
|
|
|
rect_gradient.setColorAt(0, Qt::red);
|
|
|
|
rect_gradient.setColorAt(.17, Qt::yellow);
|
|
|
|
rect_gradient.setColorAt(.33, Qt::green);
|
|
|
|
rect_gradient.setColorAt(.50, Qt::cyan);
|
|
|
|
rect_gradient.setColorAt(.66, Qt::blue);
|
|
|
|
rect_gradient.setColorAt(.81, Qt::magenta);
|
|
|
|
rect_gradient.setColorAt(1, Qt::red);
|
|
|
|
p.setBrush(rect_gradient);
|
|
|
|
p.drawRect(width() / 2, 0, width() / 2, height());
|
|
|
|
|
|
|
|
QLinearGradient alpha_gradient(0, 0, width(), 0);
|
|
|
|
alpha_gradient.setColorAt(0, Qt::white);
|
|
|
|
alpha_gradient.setColorAt(0.2, Qt::white);
|
|
|
|
alpha_gradient.setColorAt(0.5, Qt::transparent);
|
|
|
|
alpha_gradient.setColorAt(0.8, Qt::white);
|
|
|
|
alpha_gradient.setColorAt(1, Qt::white);
|
|
|
|
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
p.setBrush(alpha_gradient);
|
|
|
|
p.drawRect(0, 0, width(), height());
|
|
|
|
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
p.drawImage(rect(), m_image);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::drawSource(QPainter &p)
|
|
|
|
{
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
|
|
|
p.setCompositionMode(m_composition_mode);
|
|
|
|
|
|
|
|
QRectF circle_rect = rectangle_around(m_circle_pos);
|
|
|
|
QColor color = QColor::fromHsvF(m_circle_hue / 360.0, 1, 1, m_circle_alpha / 255.0);
|
|
|
|
QLinearGradient circle_gradient(circle_rect.topLeft(), circle_rect.bottomRight());
|
Fix some deprecation warnings in examples
googlesuggest.cpp:163:36: warning: ‘void QTreeWidgetItem::setTextColor(int, const QColor&)’ is deprecated: Use QTreeWidgetItem::setForeground() instead [-Wdeprecated-declarations]
xbeltree.cpp:187:34: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
imageitem.cpp:114:21: warning: ‘void QGraphicsItem::setMatrix(const QMatrix&, bool)’ is deprecated: Use setTransform() instead [-Wdeprecated-declarations]
xbelreader.cpp:143:48: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
xbelgenerator.cpp:103:55: warning: ‘bool QTreeWidget::isItemExpanded(const QTreeWidgetItem*) const’ is deprecated: Use QTreeWidgetItem::isExpanded() instead [-Wdeprecated-declarations]
xbelwriter.cpp:90:55: warning: ‘bool QTreeWidget::isItemExpanded(const QTreeWidgetItem*) const’ is deprecated: Use QTreeWidgetItem::isExpanded() instead [-Wdeprecated-declarations]
xbelhandler.cpp:97:50: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
node.cpp:180:60: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
node.cpp:181:64: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
chip.cpp:82:81: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
chip.cpp:84:40: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
chip.cpp:108:93: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
roundrectitem.cpp:65:42: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
roundrectitem.cpp:97:51: warning: ‘void QPainter::drawRoundRect(const QRectF&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
roundrectitem.cpp:105:34: warning: ‘void QPainter::drawRoundRect(const QRectF&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
splashitem.cpp:82:57: warning: ‘void QPainter::drawRoundRect(int, int, int, int, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
robot.cpp:116:53: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
robot.cpp:176:49: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
robot.cpp:200:49: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
mandelbrotwidget.cpp:120:41: warning: ‘const QMatrix& QPainter::matrix() const’ is deprecated: Use transform() instead [-Wdeprecated-declarations]
composition.cpp:344:47: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
composition.cpp:346:46: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
colorswatch.cpp:89:34: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
mainwindow.cpp:81:62: warning: ‘void QTreeWidget::setItemSelected(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setSelected() instead [-Wdeprecated-declarations]
puzzlewidget.cpp:172:35: warning: ‘Qt::DropAction QDrag::start(Qt::DropActions)’ is deprecated: Use QDrag::exec() instead [-Wdeprecated-declarations]
spreadsheet.cpp:191:37: warning: ‘QColor QTableWidgetItem::backgroundColor() const’ is deprecated: Use QTableWidgetItem::background() instead [-Wdeprecated-declarations]
spreadsheet.cpp:198:32: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
spreadsheet.cpp:203:24: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
spreadsheet.cpp:238:47: warning: ‘QColor QTableWidgetItem::backgroundColor() const’ is deprecated: Use QTableWidgetItem::background() instead [-Wdeprecated-declarations]
spreadsheet.cpp:249:38: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:494:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:509:56: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:513:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:527:56: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:531:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:545:56: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:549:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:563:55: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:567:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:581:55: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:585:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:599:55: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
starrating.cpp:91:46: warning: ‘const QBrush& QPalette::foreground() const’ is deprecated: Use QPalette::windowText() instead [-Wdeprecated-declarations]
document.cpp:341:36: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
document.cpp:342:39: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
document.cpp:343:36: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:88:39: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:89:39: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:188:52: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:264:56: warning: ‘const QBrush& QPalette::foreground() const’ is deprecated: Use QPalette::windowText() instead [-Wdeprecated-declarations]
plugindialog.cpp:128:49: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
tetrixboard.cpp:361:74: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
tetrixboard.cpp:408:32: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
tetrixboard.cpp:412:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
mandelbrotwidget.cpp:120:41: warning: ‘const QMatrix& QPainter::matrix() const’ is deprecated: Use transform() instead [-Wdeprecated-declarations]
Change-Id: If0afabbc35ef25f127f211c11699011d4ae4ae65
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2019-02-06 09:52:23 +00:00
|
|
|
circle_gradient.setColorAt(0, color.lighter());
|
2011-04-27 10:05:43 +00:00
|
|
|
circle_gradient.setColorAt(0.5, color);
|
Fix some deprecation warnings in examples
googlesuggest.cpp:163:36: warning: ‘void QTreeWidgetItem::setTextColor(int, const QColor&)’ is deprecated: Use QTreeWidgetItem::setForeground() instead [-Wdeprecated-declarations]
xbeltree.cpp:187:34: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
imageitem.cpp:114:21: warning: ‘void QGraphicsItem::setMatrix(const QMatrix&, bool)’ is deprecated: Use setTransform() instead [-Wdeprecated-declarations]
xbelreader.cpp:143:48: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
xbelgenerator.cpp:103:55: warning: ‘bool QTreeWidget::isItemExpanded(const QTreeWidgetItem*) const’ is deprecated: Use QTreeWidgetItem::isExpanded() instead [-Wdeprecated-declarations]
xbelwriter.cpp:90:55: warning: ‘bool QTreeWidget::isItemExpanded(const QTreeWidgetItem*) const’ is deprecated: Use QTreeWidgetItem::isExpanded() instead [-Wdeprecated-declarations]
xbelhandler.cpp:97:50: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
node.cpp:180:60: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
node.cpp:181:64: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
chip.cpp:82:81: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
chip.cpp:84:40: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
chip.cpp:108:93: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
roundrectitem.cpp:65:42: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
roundrectitem.cpp:97:51: warning: ‘void QPainter::drawRoundRect(const QRectF&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
roundrectitem.cpp:105:34: warning: ‘void QPainter::drawRoundRect(const QRectF&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
splashitem.cpp:82:57: warning: ‘void QPainter::drawRoundRect(int, int, int, int, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
robot.cpp:116:53: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
robot.cpp:176:49: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
robot.cpp:200:49: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
mandelbrotwidget.cpp:120:41: warning: ‘const QMatrix& QPainter::matrix() const’ is deprecated: Use transform() instead [-Wdeprecated-declarations]
composition.cpp:344:47: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
composition.cpp:346:46: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
colorswatch.cpp:89:34: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
mainwindow.cpp:81:62: warning: ‘void QTreeWidget::setItemSelected(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setSelected() instead [-Wdeprecated-declarations]
puzzlewidget.cpp:172:35: warning: ‘Qt::DropAction QDrag::start(Qt::DropActions)’ is deprecated: Use QDrag::exec() instead [-Wdeprecated-declarations]
spreadsheet.cpp:191:37: warning: ‘QColor QTableWidgetItem::backgroundColor() const’ is deprecated: Use QTableWidgetItem::background() instead [-Wdeprecated-declarations]
spreadsheet.cpp:198:32: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
spreadsheet.cpp:203:24: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
spreadsheet.cpp:238:47: warning: ‘QColor QTableWidgetItem::backgroundColor() const’ is deprecated: Use QTableWidgetItem::background() instead [-Wdeprecated-declarations]
spreadsheet.cpp:249:38: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:494:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:509:56: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:513:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:527:56: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:531:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:545:56: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:549:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:563:55: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:567:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:581:55: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:585:58: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
spreadsheet.cpp:599:55: warning: ‘void QTableWidgetItem::setBackgroundColor(const QColor&)’ is deprecated: Use QTableWidgetItem::setBackground() instead [-Wdeprecated-declarations]
starrating.cpp:91:46: warning: ‘const QBrush& QPalette::foreground() const’ is deprecated: Use QPalette::windowText() instead [-Wdeprecated-declarations]
document.cpp:341:36: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
document.cpp:342:39: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
document.cpp:343:36: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:88:39: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:89:39: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:188:52: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
norwegianwoodstyle.cpp:264:56: warning: ‘const QBrush& QPalette::foreground() const’ is deprecated: Use QPalette::windowText() instead [-Wdeprecated-declarations]
plugindialog.cpp:128:49: warning: ‘void QTreeWidget::setItemExpanded(const QTreeWidgetItem*, bool)’ is deprecated: Use QTreeWidgetItem::setExpanded() instead [-Wdeprecated-declarations]
tetrixboard.cpp:361:74: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
tetrixboard.cpp:408:32: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
tetrixboard.cpp:412:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
mandelbrotwidget.cpp:120:41: warning: ‘const QMatrix& QPainter::matrix() const’ is deprecated: Use transform() instead [-Wdeprecated-declarations]
Change-Id: If0afabbc35ef25f127f211c11699011d4ae4ae65
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2019-02-06 09:52:23 +00:00
|
|
|
circle_gradient.setColorAt(1, color.darker());
|
2011-04-27 10:05:43 +00:00
|
|
|
p.setBrush(circle_gradient);
|
|
|
|
|
|
|
|
p.drawEllipse(circle_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::paint(QPainter *painter)
|
|
|
|
{
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
|
|
|
if (usesOpenGL() && glWindow()->isValid()) {
|
|
|
|
|
|
|
|
if (!m_blitter.isCreated())
|
|
|
|
m_blitter.create();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
int new_pbuf_size = m_pbuffer_size;
|
2018-11-01 14:05:29 +00:00
|
|
|
while (size().width() > new_pbuf_size || size().height() > new_pbuf_size)
|
2011-04-27 10:05:43 +00:00
|
|
|
new_pbuf_size *= 2;
|
|
|
|
|
2018-11-01 14:05:29 +00:00
|
|
|
while (size().width() < new_pbuf_size/2 && size().height() < new_pbuf_size/2)
|
2011-04-27 10:05:43 +00:00
|
|
|
new_pbuf_size /= 2;
|
|
|
|
|
2018-07-11 13:12:56 +00:00
|
|
|
if (!m_fbo || new_pbuf_size != m_pbuffer_size) {
|
|
|
|
m_fbo.reset(new QFboPaintDevice(QSize(new_pbuf_size, new_pbuf_size), false, false));
|
2011-04-27 10:05:43 +00:00
|
|
|
m_pbuffer_size = new_pbuf_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size() != m_previous_size) {
|
|
|
|
m_previous_size = size();
|
2018-07-11 13:12:56 +00:00
|
|
|
QPainter p(m_fbo.data());
|
2018-11-01 14:05:29 +00:00
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.fillRect(QRect(QPoint(0, 0), size()), Qt::transparent);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
2011-04-27 10:05:43 +00:00
|
|
|
drawBase(p);
|
|
|
|
p.end();
|
2018-07-11 13:12:56 +00:00
|
|
|
m_base_tex = m_fbo->takeTexture();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 13:12:56 +00:00
|
|
|
painter->beginNativePainting();
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2018-07-11 13:12:56 +00:00
|
|
|
QPainter p(m_fbo.data());
|
|
|
|
p.beginNativePainting();
|
|
|
|
m_blitter.bind();
|
|
|
|
const QRect targetRect(QPoint(0, 0), m_fbo->size());
|
|
|
|
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size()));
|
|
|
|
m_blitter.blit(m_base_tex, target, QOpenGLTextureBlitter::OriginBottomLeft);
|
|
|
|
m_blitter.release();
|
|
|
|
p.endNativePainting();
|
2011-04-27 10:05:43 +00:00
|
|
|
drawSource(p);
|
|
|
|
p.end();
|
2018-07-11 13:12:56 +00:00
|
|
|
m_compositing_tex = m_fbo->takeTexture();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2018-07-11 13:12:56 +00:00
|
|
|
painter->endNativePainting();
|
|
|
|
|
|
|
|
painter->beginNativePainting();
|
|
|
|
auto *funcs = QOpenGLContext::currentContext()->functions();
|
|
|
|
funcs->glEnable(GL_BLEND);
|
|
|
|
funcs->glBlendEquation(GL_FUNC_ADD);
|
|
|
|
funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
m_blitter.bind();
|
|
|
|
const QRect targetRect(QPoint(0, 0), m_fbo->size());
|
|
|
|
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), size()));
|
|
|
|
m_blitter.blit(m_compositing_tex, target, QOpenGLTextureBlitter::OriginBottomLeft);
|
|
|
|
m_blitter.release();
|
|
|
|
painter->endNativePainting();
|
2011-04-27 10:05:43 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// using a QImage
|
|
|
|
if (m_buffer.size() != size()) {
|
|
|
|
m_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
m_base_buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
|
|
|
|
m_base_buffer.fill(0);
|
|
|
|
|
|
|
|
QPainter p(&m_base_buffer);
|
|
|
|
|
|
|
|
drawBase(p);
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:05:13 +00:00
|
|
|
memcpy(m_buffer.bits(), m_base_buffer.bits(), m_buffer.sizeInBytes());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QPainter p(&m_buffer);
|
|
|
|
drawSource(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawImage(0, 0, m_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
setDescriptionEnabled(false);
|
|
|
|
|
|
|
|
QRectF circle = rectangle_around(m_circle_pos);
|
|
|
|
|
|
|
|
if (circle.contains(e->pos())) {
|
|
|
|
m_current_object = Circle;
|
|
|
|
m_offset = circle.center() - e->pos();
|
|
|
|
} else {
|
|
|
|
m_current_object = NoObject;
|
|
|
|
}
|
|
|
|
if (m_animation_enabled) {
|
|
|
|
killTimer(m_animationTimer);
|
|
|
|
m_animationTimer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::mouseMoveEvent(QMouseEvent *e)
|
|
|
|
{
|
2012-11-23 10:52:51 +00:00
|
|
|
if (m_current_object == Circle)
|
|
|
|
setCirclePos(e->pos() + m_offset);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::mouseReleaseEvent(QMouseEvent *)
|
|
|
|
{
|
|
|
|
m_current_object = NoObject;
|
|
|
|
|
|
|
|
if (m_animation_enabled) {
|
|
|
|
Q_ASSERT(!m_animationTimer);
|
|
|
|
m_animationTimer = startTimer(animationInterval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() == m_animationTimer)
|
|
|
|
updateCirclePos();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositionRenderer::setCirclePos(const QPointF &pos)
|
|
|
|
{
|
|
|
|
const QRect oldRect = rectangle_around(m_circle_pos).toAlignedRect();
|
|
|
|
m_circle_pos = pos;
|
|
|
|
const QRect newRect = rectangle_around(m_circle_pos).toAlignedRect();
|
2018-07-11 13:12:56 +00:00
|
|
|
#if QT_CONFIG(opengl)
|
2012-11-23 10:52:51 +00:00
|
|
|
if (usesOpenGL()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
update();
|
2012-11-23 10:52:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2012-11-23 10:52:51 +00:00
|
|
|
update(oldRect | newRect);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|