1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtGui>
#include "renderarea.h"
RenderArea::RenderArea(QBrush *brush, QWidget *parent)
: QWidget(parent)
{
currentBrush = brush;
}
QSize RenderArea::minimumSizeHint() const
{
return QSize(120, 60);
}
void RenderArea::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setRenderHint(QPainter::Antialiasing);
if(currentBrush->style() == Qt::LinearGradientPattern) {
currentBrush = new QBrush(QLinearGradient(0, 0, width(), 60));
} else if(currentBrush->style() == Qt::RadialGradientPattern) {
QRadialGradient radial(width() / 2, 30, width() / 2, width() / 2, 30);
radial.setColorAt(0, Qt::white);
radial.setColorAt(1, Qt::black);
currentBrush = new QBrush(radial);
} else if(currentBrush->style() == Qt::ConicalGradientPattern) {
currentBrush = new QBrush(QConicalGradient(width() / 2, 30, 90));
}
painter.setBrush(*currentBrush);
QPainterPath path;
path.addRect(0, 0, parentWidget()->width(), 60);
painter.drawPath(path);
}
|