File indexing completed on 2024-05-12 15:56:39

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2008 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "KoColorBackground.h"
0008 #include "KoShapeSavingContext.h"
0009 #include <KoXmlNS.h>
0010 
0011 #include <QColor>
0012 #include <QPainter>
0013 
0014 class KoColorBackground::Private : public QSharedData
0015 {
0016 public:
0017     Private()
0018         : QSharedData()
0019         , color(Qt::black)
0020         , style(Qt::SolidPattern)
0021         {}
0022 
0023     QColor color;
0024     Qt::BrushStyle style;
0025 };
0026 
0027 KoColorBackground::KoColorBackground()
0028     : KoShapeBackground()
0029     , d(new Private)
0030 {
0031 }
0032 
0033 KoColorBackground::KoColorBackground(const QColor &color, Qt::BrushStyle style)
0034     : KoShapeBackground()
0035     , d(new Private)
0036 {
0037     if (style < Qt::SolidPattern || style >= Qt::LinearGradientPattern) {
0038         style = Qt::SolidPattern;
0039     }
0040 
0041     d->style = style;
0042     d->color = color;
0043 }
0044 
0045 KoColorBackground::~KoColorBackground()
0046 {
0047 }
0048 
0049 KoColorBackground::KoColorBackground(const KoColorBackground &rhs)
0050     : d(new Private(*rhs.d))
0051 {
0052 }
0053 
0054 KoColorBackground &KoColorBackground::operator=(const KoColorBackground &rhs)
0055 {
0056     d = rhs.d;
0057     return *this;
0058 }
0059 
0060 bool KoColorBackground::compareTo(const KoShapeBackground *other) const
0061 {
0062     const KoColorBackground *bg = dynamic_cast<const KoColorBackground*>(other);
0063     return bg && bg->color() == d->color;
0064 }
0065 
0066 QColor KoColorBackground::color() const
0067 {
0068     return d->color;
0069 }
0070 
0071 void KoColorBackground::setColor(const QColor &color)
0072 {
0073     d->color = color;
0074 }
0075 
0076 Qt::BrushStyle KoColorBackground::style() const
0077 {
0078     return d->style;
0079 }
0080 
0081 QBrush KoColorBackground::brush() const
0082 {
0083     return QBrush(d->color, d->style);
0084 }
0085 
0086 void KoColorBackground::paint(QPainter &painter, const QPainterPath &fillPath) const
0087 {
0088     painter.setBrush(brush());
0089     painter.drawPath(fillPath);
0090 }
0091