diff options
author | gunnar <gunnar@trolltech.com> | 2009-10-09 17:39:17 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-10-13 11:17:17 (GMT) |
commit | c4bb0bd645e25bb68e9ac29f0dcc53566b148be9 (patch) | |
tree | b5f8cab2edbbc365d82371875d03db862f7a71f4 /src/gui/painting | |
parent | 33ed3d0bacddce214a43be60eb6481903e753a88 (diff) | |
download | Qt-c4bb0bd645e25bb68e9ac29f0dcc53566b148be9.zip Qt-c4bb0bd645e25bb68e9ac29f0dcc53566b148be9.tar.gz Qt-c4bb0bd645e25bb68e9ac29f0dcc53566b148be9.tar.bz2 |
Make QStrokerOps, QStroker and QDashStroker properly modular
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qstroker.cpp | 39 | ||||
-rw-r--r-- | src/gui/painting/qstroker_p.h | 7 |
2 files changed, 38 insertions, 8 deletions
diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp index 9063945..c57b3c1 100644 --- a/src/gui/painting/qstroker.cpp +++ b/src/gui/painting/qstroker.cpp @@ -969,13 +969,31 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt } +static inline void qdashstroker_moveTo(qfixed x, qfixed y, void *data) { + ((QStroker *) data)->moveTo(x, y); +} + +static inline void qdashstroker_lineTo(qfixed x, qfixed y, void *data) { + ((QStroker *) data)->lineTo(x, y); +} + +static inline void qdashstroker_cubicTo(qfixed, qfixed, qfixed, qfixed, qfixed, qfixed, void *) { + Q_ASSERT(0); +// ((QStroker *) data)->cubicTo(c1x, c1y, c2x, c2y, ex, ey); +} + + /******************************************************************************* * QDashStroker members */ QDashStroker::QDashStroker(QStroker *stroker) - : m_stroker(stroker), m_dashOffset(0) + : m_stroker(stroker), m_dashOffset(0), m_stroke_width(1), m_miter_limit(1) { - + if (m_stroker) { + setMoveToHook(qdashstroker_moveTo); + setLineToHook(qdashstroker_lineTo); + setCubicToHook(qdashstroker_cubicTo); + } } QVector<qfixed> QDashStroker::patternForStyle(Qt::PenStyle style) @@ -1012,10 +1030,16 @@ void QDashStroker::processCurrentSubpath() int dashCount = qMin(m_dashPattern.size(), 32); qfixed dashes[32]; + if (m_stroker) { + m_customData = m_stroker; + m_stroke_width = m_stroker->strokeWidth(); + m_miter_limit = m_stroker->miterLimit(); + } + qreal longestLength = 0; qreal sumLength = 0; for (int i=0; i<dashCount; ++i) { - dashes[i] = qMax(m_dashPattern.at(i), qreal(0)) * m_stroker->strokeWidth(); + dashes[i] = qMax(m_dashPattern.at(i), qreal(0)) * m_stroke_width; sumLength += dashes[i]; if (dashes[i] > longestLength) longestLength = dashes[i]; @@ -1031,7 +1055,7 @@ void QDashStroker::processCurrentSubpath() int idash = 0; // Index to current dash qreal pos = 0; // The position on the curve, 0 <= pos <= path.length qreal elen = 0; // element length - qreal doffset = m_dashOffset * m_stroker->strokeWidth(); + qreal doffset = m_dashOffset * m_stroke_width; // make sure doffset is in range [0..sumLength) doffset -= qFloor(doffset / sumLength) * sumLength; @@ -1056,7 +1080,7 @@ void QDashStroker::processCurrentSubpath() qfixed2d line_to_pos; // Pad to avoid clipping the borders of thick pens. - qfixed padding = qt_real_to_fixed(qMax(m_stroker->strokeWidth(), m_stroker->miterLimit()) * longestLength); + qfixed padding = qt_real_to_fixed(qMax(m_stroke_width, m_miter_limit) * longestLength); qfixed2d clip_tl = { qt_real_to_fixed(m_clip_rect.left()) - padding, qt_real_to_fixed(m_clip_rect.top()) - padding }; qfixed2d clip_br = { qt_real_to_fixed(m_clip_rect.right()) + padding , @@ -1108,7 +1132,7 @@ void QDashStroker::processCurrentSubpath() // continue the current dash, without starting a // new subpath. if (!has_offset || !hasMoveTo) { - m_stroker->moveTo(move_to_pos.x, move_to_pos.y); + emitMoveTo(move_to_pos.x, move_to_pos.y); hasMoveTo = true; } @@ -1120,7 +1144,7 @@ void QDashStroker::processCurrentSubpath() || (line_to_pos.x > clip_tl.x && line_to_pos.x < clip_br.x && line_to_pos.y > clip_tl.y && line_to_pos.y < clip_br.y)) { - m_stroker->lineTo(line_to_pos.x, line_to_pos.y); + emitLineTo(line_to_pos.x, line_to_pos.y); } } else { move_to_pos.x = qt_real_to_fixed(p2.x()); @@ -1134,6 +1158,7 @@ void QDashStroker::processCurrentSubpath() estart = estop; prev = e; } + } QT_END_NAMESPACE diff --git a/src/gui/painting/qstroker_p.h b/src/gui/painting/qstroker_p.h index d33eeb4..b78288c 100644 --- a/src/gui/painting/qstroker_p.h +++ b/src/gui/painting/qstroker_p.h @@ -171,7 +171,6 @@ protected: QRectF m_clip_rect; -private: void *m_customData; qStrokerMoveToHook m_moveTo; qStrokerLineToHook m_lineTo; @@ -258,12 +257,18 @@ public: virtual void begin(void *data); virtual void end(); + inline void setStrokeWidth(qreal width) { m_stroke_width = width; } + inline void setMiterLimit(qreal limit) { m_miter_limit = limit; } + protected: virtual void processCurrentSubpath(); QStroker *m_stroker; QVector<qfixed> m_dashPattern; qreal m_dashOffset; + + qreal m_stroke_width; + qreal m_miter_limit; }; |