diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2011-09-17 03:03:23 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2011-09-17 03:03:23 +0200 |
commit | 3a755f46d9cf6e3650d40a960d0d0db8c1ad9fa1 (patch) | |
tree | f330f63caec08b6626c808b5ae70c64cab0246a6 /libsowatch/metawatchpaintengine.cpp | |
parent | 0dca79a8c15b76ca53617c0ed3396ab6435f0152 (diff) | |
download | sowatch-3a755f46d9cf6e3650d40a960d0d0db8c1ad9fa1.tar.gz sowatch-3a755f46d9cf6e3650d40a960d0d0db8c1ad9fa1.zip |
preparing for library package
Diffstat (limited to 'libsowatch/metawatchpaintengine.cpp')
-rw-r--r-- | libsowatch/metawatchpaintengine.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/libsowatch/metawatchpaintengine.cpp b/libsowatch/metawatchpaintengine.cpp new file mode 100644 index 0000000..71ad452 --- /dev/null +++ b/libsowatch/metawatchpaintengine.cpp @@ -0,0 +1,82 @@ +#include "metawatch.h" +#include "metawatchpaintengine.h" + +using namespace sowatch; + +MetaWatchPaintEngine::MetaWatchPaintEngine(MetaWatch* watch, QImage* image) : + WatchPaintEngine(watch, image), _watch(watch), + _imageRect(image->rect()) +{ +} + +void MetaWatchPaintEngine::drawRects(const QRectF *rects, int rectCount) +{ + int i; + for (i = 0; i < rectCount; i++) { + const QRectF& r = rects[i]; + if (_hasBrush && fillsEntireImage(r.toRect()) && (_isBrushBlack | _isBrushWhite)) { + _watch->clear(_isBrushWhite); + _damaged = QRegion(); + continue; + } + if (_hasBrush) { + damageRect(r); + } + if (_hasPen) { + damagePenStroke(QLineF(r.left(), r.top(), r.right(), r.top())); + damagePenStroke(QLineF(r.right(), r.top(), r.right(), r.bottom())); + damagePenStroke(QLineF(r.left(), r.bottom(), r.right(), r.bottom())); + damagePenStroke(QLineF(r.left(), r.top(), r.left(), r.bottom())); + } + } + _painter.drawRects(rects, rectCount); +} + +void MetaWatchPaintEngine::drawRects(const QRect *rects, int rectCount) +{ + int i; + for (i = 0; i < rectCount; i++) { + const QRect& r = rects[i]; + if (_hasBrush && fillsEntireImage(r) && (_isBrushBlack | _isBrushWhite)) { + _watch->clear(_isBrushWhite); + _damaged = QRegion(); + continue; + } + if (_hasBrush) { + damageRect(r); + } + if (_hasPen) { + damagePenStroke(QLine(r.left(), r.top(), r.right(), r.top())); + damagePenStroke(QLine(r.right(), r.top(), r.right(), r.bottom())); + damagePenStroke(QLine(r.left(), r.bottom(), r.right(), r.bottom())); + damagePenStroke(QLine(r.left(), r.top(), r.left(), r.bottom())); + } + } + + _painter.drawRects(rects, rectCount); +} + +void MetaWatchPaintEngine::updateState(const QPaintEngineState &state) +{ + WatchPaintEngine::updateState(state); + if (state.state() & QPaintEngine::DirtyBrush) { + QBrush brush = state.brush(); + _isBrushBlack = false; + _isBrushWhite = false; + if (brush.style() == Qt::SolidPattern) { + const QColor color = brush.color(); + if (color == Qt::black) { + _isBrushBlack = true; + } else if (color == Qt::white) { + _isBrushWhite = true; + } + } + } +} + +bool MetaWatchPaintEngine::fillsEntireImage(const QRect& rect) +{ + return rect == _imageRect && + (!_clipEnabled || + (_clipRegion.numRects() == 1 && _clipRegion.rects().at(0) == _imageRect)); +} |