Warning, file /office/calligra/libs/flake/KoColorBackground.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KoColorBackground.h"
0021 #include "KoColorBackground_p.h"
0022 #include "KoShapeSavingContext.h"
0023 #include <KoOdfGraphicStyles.h>
0024 #include <KoOdfLoadingContext.h>
0025 #include <KoXmlNS.h>
0026 #include <KoStyleStack.h>
0027 
0028 #include <QColor>
0029 #include <QPainter>
0030 
0031 KoColorBackground::KoColorBackground()
0032 : KoShapeBackground(*(new KoColorBackgroundPrivate()))
0033 {
0034 }
0035 
0036 KoColorBackground::KoColorBackground(KoShapeBackgroundPrivate &dd)
0037 : KoShapeBackground(dd)
0038 {
0039 }
0040 
0041 KoColorBackground::KoColorBackground(const QColor &color, Qt::BrushStyle style)
0042 : KoShapeBackground(*(new KoColorBackgroundPrivate()))
0043 {
0044     Q_D(KoColorBackground);
0045     if (style < Qt::SolidPattern || style >= Qt::LinearGradientPattern)
0046         style = Qt::SolidPattern;
0047     d->style = style;
0048     d->color = color;
0049 }
0050 
0051 KoColorBackground::~KoColorBackground()
0052 {
0053 }
0054 
0055 QColor KoColorBackground::color() const
0056 {
0057     Q_D(const KoColorBackground);
0058     return d->color;
0059 }
0060 
0061 void KoColorBackground::setColor(const QColor &color)
0062 {
0063     Q_D(KoColorBackground);
0064     d->color = color;
0065 }
0066 
0067 Qt::BrushStyle KoColorBackground::style() const
0068 {
0069     Q_D(const KoColorBackground);
0070     return d->style;
0071 }
0072 
0073 void KoColorBackground::paint(QPainter &painter, const KoViewConverter &/*converter*/, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
0074 {
0075     Q_D(const KoColorBackground);
0076     painter.setBrush(QBrush(d->color, d->style));
0077     painter.drawPath(fillPath);
0078 }
0079 
0080 void KoColorBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
0081 {
0082     Q_D(KoColorBackground);
0083     KoOdfGraphicStyles::saveOdfFillStyle(style, context.mainStyles(), QBrush(d->color, d->style));
0084 }
0085 
0086 bool KoColorBackground::loadStyle(KoOdfLoadingContext & context, const QSizeF &)
0087 {
0088     Q_D(KoColorBackground);
0089     KoStyleStack &styleStack = context.styleStack();
0090     if (! styleStack.hasProperty(KoXmlNS::draw, "fill"))
0091         return false;
0092 
0093     QString fillStyle = styleStack.property(KoXmlNS::draw, "fill");
0094     if (fillStyle == "solid" || fillStyle == "hatch") {
0095         QBrush brush = KoOdfGraphicStyles::loadOdfFillStyle(styleStack, fillStyle, context.stylesReader());
0096         d->color = brush.color();
0097         d->style = brush.style();
0098         return true;
0099     }
0100 
0101     return false;
0102 }