libs/flake
KoColorBackground.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KoColorBackground.h"
00021 #include "KoShapeSavingContext.h"
00022 #include <KoOdfGraphicStyles.h>
00023 #include <KoOdfLoadingContext.h>
00024 #include <KoXmlNS.h>
00025
00026 #include <QtGui/QColor>
00027 #include <QtGui/QPainter>
00028
00029 class KoColorBackground::Private
00030 {
00031 public:
00032 Private() {
00033 color = Qt::black;
00034 style = Qt::SolidPattern;
00035 };
00036 Qt::BrushStyle style;
00037 QColor color;
00038 };
00039
00040 KoColorBackground::KoColorBackground()
00041 : d(new Private())
00042 {
00043 }
00044
00045 KoColorBackground::KoColorBackground(const QColor &color, Qt::BrushStyle style)
00046 : d(new Private())
00047 {
00048 if (style < Qt::SolidPattern || style >= Qt::LinearGradientPattern)
00049 style = Qt::SolidPattern;
00050 d->style = style;
00051 d->color = color;
00052 }
00053
00054 KoColorBackground::~KoColorBackground()
00055 {
00056 delete d;
00057 }
00058
00059 QColor KoColorBackground::color() const
00060 {
00061 return d->color;
00062 }
00063
00064 void KoColorBackground::setColor( const QColor &color )
00065 {
00066 d->color = color;
00067 }
00068
00069 Qt::BrushStyle KoColorBackground::style() const
00070 {
00071 return d->style;
00072 }
00073
00074 void KoColorBackground::paint(QPainter &painter, const QPainterPath &fillPath) const
00075 {
00076 painter.setBrush(QBrush(d->color, d->style));
00077 painter.drawPath(fillPath);
00078 }
00079
00080 void KoColorBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
00081 {
00082 KoOdfGraphicStyles::saveOdfFillStyle(style, context.mainStyles(), QBrush(d->color, d->style));
00083 }
00084
00085 bool KoColorBackground::loadStyle(KoOdfLoadingContext & context, const QSizeF &)
00086 {
00087 KoStyleStack &styleStack = context.styleStack();
00088 if (! styleStack.hasProperty(KoXmlNS::draw, "fill"))
00089 return false;
00090
00091 QString fillStyle = styleStack.property(KoXmlNS::draw, "fill");
00092 if (fillStyle == "solid" || fillStyle == "hatch") {
00093 QBrush brush = KoOdfGraphicStyles::loadOdfFillStyle(styleStack, fillStyle, context.stylesReader());
00094 d->color = brush.color();
00095 d->style = brush.style();
00096 return true;
00097 }
00098
00099 return false;
00100 }
|