libs/flake
KoLineBorder.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
00021
00022 #include "KoLineBorder.h"
00023 #include "KoViewConverter.h"
00024 #include "KoShape.h"
00025 #include "KoShapeSavingContext.h"
00026
00027 #include <QPainterPath>
00028
00029 #include <KoGenStyle.h>
00030 #include <KoGenStyles.h>
00031 #include <KoOdfGraphicStyles.h>
00032
00033 #include <math.h>
00034
00035 class KoLineBorder::Private
00036 {
00037 public:
00038 QColor color;
00039 QPen pen;
00040 QBrush brush;
00041 };
00042
00043 KoLineBorder::KoLineBorder()
00044 : d(new Private())
00045 {
00046 d->color = QColor(Qt::black);
00047
00048
00049 d->pen.setWidthF(1.0);
00050 }
00051
00052 KoLineBorder::KoLineBorder(const KoLineBorder & other)
00053 : KoShapeBorderModel(), d(new Private())
00054 {
00055 d->color = other.d->color;
00056 d->pen = other.d->pen;
00057 d->brush = other.d->brush;
00058 }
00059
00060 KoLineBorder::KoLineBorder(qreal lineWidth, const QColor &color)
00061 : d(new Private())
00062 {
00063 d->pen.setWidthF(qMax(qreal(0.0), lineWidth));
00064 d->pen.setJoinStyle(Qt::MiterJoin);
00065 d->color = color;
00066 }
00067
00068 KoLineBorder::~KoLineBorder()
00069 {
00070 delete d;
00071 }
00072
00073 KoLineBorder& KoLineBorder::operator = (const KoLineBorder & rhs)
00074 {
00075 if (this == &rhs)
00076 return *this;
00077
00078 d->pen = rhs.d->pen;
00079 d->color = rhs.d->color;
00080 d->brush = rhs.d->brush;
00081
00082 return *this;
00083 }
00084
00085 void KoLineBorder::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
00086 {
00087 QPen pen = d->pen;
00088 if (d->brush.gradient())
00089 pen.setBrush(d->brush);
00090 else
00091 pen.setColor(d->color);
00092 KoOdfGraphicStyles::saveOdfStrokeStyle(style, context.mainStyles(), pen);
00093 }
00094
00095 void KoLineBorder::borderInsets(const KoShape *shape, KoInsets &insets)
00096 {
00097 Q_UNUSED(shape);
00098 qreal lineWidth = d->pen.widthF();
00099 if (lineWidth < 0)
00100 lineWidth = 1;
00101 lineWidth *= 0.5;
00102
00103
00104
00105 if( capStyle() == Qt::SquareCap )
00106 lineWidth *= M_SQRT2;
00107
00108 insets.top = lineWidth;
00109 insets.bottom = lineWidth;
00110 insets.left = lineWidth;
00111 insets.right = lineWidth;
00112 }
00113
00114 bool KoLineBorder::hasTransparency()
00115 {
00116 return d->color.alpha() > 0;
00117 }
00118
00119 void KoLineBorder::paintBorder(KoShape *shape, QPainter &painter, const KoViewConverter &converter)
00120 {
00121 KoShape::applyConversion(painter, converter);
00122
00123 QPen pen = d->pen;
00124
00125 if (d->brush.gradient())
00126 pen.setBrush(d->brush);
00127 else
00128 pen.setColor(d->color);
00129
00130 if(!pen.isCosmetic())
00131 painter.strokePath(shape->outline(), pen);
00132 }
00133
00134 void KoLineBorder::paintBorder(KoShape *shape, QPainter &painter, const KoViewConverter &converter, const QColor & color )
00135 {
00136 KoShape::applyConversion(painter, converter);
00137
00138 QPen pen = d->pen;
00139 pen.setColor(color);
00140
00141 if(!pen.isCosmetic()) {
00142 painter.strokePath(shape->outline(), pen);
00143 }
00144 }
00145
00146 void KoLineBorder::setCapStyle(Qt::PenCapStyle style)
00147 {
00148 d->pen.setCapStyle(style);
00149 }
00150
00151 Qt::PenCapStyle KoLineBorder::capStyle() const
00152 {
00153 return d->pen.capStyle();
00154 }
00155
00156 void KoLineBorder::setJoinStyle(Qt::PenJoinStyle style)
00157 {
00158 d->pen.setJoinStyle(style);
00159 }
00160
00161 Qt::PenJoinStyle KoLineBorder::joinStyle() const
00162 {
00163 return d->pen.joinStyle();
00164 }
00165
00166 void KoLineBorder::setLineWidth(qreal lineWidth)
00167 {
00168 d->pen.setWidthF(qMax(qreal(0.0), lineWidth));
00169 }
00170
00171 qreal KoLineBorder::lineWidth() const
00172 {
00173 return d->pen.widthF();
00174 }
00175
00176 void KoLineBorder::setMiterLimit(qreal miterLimit)
00177 {
00178 d->pen.setMiterLimit(miterLimit);
00179 }
00180
00181 qreal KoLineBorder::miterLimit() const
00182 {
00183 return d->pen.miterLimit();
00184 }
00185
00186 const QColor & KoLineBorder::color() const
00187 {
00188 return d->color;
00189 }
00190
00191 void KoLineBorder::setColor(const QColor & color)
00192 {
00193 d->color = color;
00194 }
00195
00196 void KoLineBorder::setLineStyle(Qt::PenStyle style, const QVector<qreal> &dashes)
00197 {
00198 if (style < Qt::CustomDashLine)
00199 d->pen.setStyle(style);
00200 else
00201 d->pen.setDashPattern(dashes);
00202 }
00203
00204 Qt::PenStyle KoLineBorder::lineStyle() const
00205 {
00206 return d->pen.style();
00207 }
00208
00209 QVector<qreal> KoLineBorder::lineDashes() const
00210 {
00211 return d->pen.dashPattern();
00212 }
00213
00214 void KoLineBorder::setDashOffset(qreal dashOffset)
00215 {
00216 d->pen.setDashOffset(dashOffset);
00217 }
00218
00219 qreal KoLineBorder::dashOffset() const
00220 {
00221 return d->pen.dashOffset();
00222 }
00223
00224 void KoLineBorder::setLineBrush(const QBrush & brush)
00225 {
00226 d->brush = brush;
00227 }
00228
00229 QBrush KoLineBorder::lineBrush() const
00230 {
00231 return d->brush;
00232 }
|