• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

GraphicsContextQt.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
00003  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
00004  * Copyright (C) 2006 George Staikos <staikos@kde.org>
00005  * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org>
00006  * Copyright (C) 2006 Allan Sandfeld Jensen <sandfeld@kde.org>
00007  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
00008  *
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00021  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00023  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00024  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00028  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #include "config.h"
00034 #include "wtf/Platform.h"
00035 
00036 #include "AffineTransform.h"
00037 #include "Path.h"
00038 //#include "Color.h"
00039 #include "GraphicsContext.h"
00040 //#include "ImageBuffer.h"
00041 //#include "Font.h"
00042 //#include "Pen.h"
00043 //#include "NotImplemented.h"
00044 
00045 #include <QStack>
00046 #include <QPainter>
00047 #include <QPolygonF>
00048 #include <QPainterPath>
00049 #include <QPaintDevice>
00050 #include <QPixmap>
00051 #include <QDebug>
00052 
00053 #ifndef M_PI
00054 #define M_PI 3.14159265358979323846
00055 #endif
00056 
00057 namespace WebCore {
00058 
00059 /*static inline QPainter::CompositionMode toQtCompositionMode(CompositeOperator op)
00060 {
00061     switch (op) {
00062         case CompositeClear:
00063             return QPainter::CompositionMode_Clear;
00064         case CompositeCopy:
00065             return QPainter::CompositionMode_Source;
00066         case CompositeSourceOver:
00067             return QPainter::CompositionMode_SourceOver;
00068         case CompositeSourceIn:
00069             return QPainter::CompositionMode_SourceIn;
00070         case CompositeSourceOut:
00071             return QPainter::CompositionMode_SourceOut;
00072         case CompositeSourceAtop:
00073             return QPainter::CompositionMode_SourceAtop;
00074         case CompositeDestinationOver:
00075             return QPainter::CompositionMode_DestinationOver;
00076         case CompositeDestinationIn:
00077             return QPainter::CompositionMode_DestinationIn;
00078         case CompositeDestinationOut:
00079             return QPainter::CompositionMode_DestinationOut;
00080         case CompositeDestinationAtop:
00081             return QPainter::CompositionMode_DestinationAtop;
00082         case CompositeXOR:
00083             return QPainter::CompositionMode_Xor;
00084         case CompositePlusDarker:
00085             return QPainter::CompositionMode_SourceOver;
00086         case CompositeHighlight:
00087             return QPainter::CompositionMode_SourceOver;
00088         case CompositePlusLighter:
00089             return QPainter::CompositionMode_SourceOver;
00090     }
00091 
00092     return QPainter::CompositionMode_SourceOver;
00093 }*/
00094 
00095 /*static inline Qt::PenCapStyle toQtLineCap(LineCap lc)
00096 {
00097     switch (lc) {
00098         case ButtCap:
00099             return Qt::FlatCap;
00100         case RoundCap:
00101             return Qt::RoundCap;
00102         case SquareCap:
00103             return Qt::SquareCap;
00104     }
00105 
00106     return Qt::FlatCap;
00107 }
00108 
00109 static inline Qt::PenJoinStyle toQtLineJoin(LineJoin lj)
00110 {
00111     switch (lj) {
00112         case MiterJoin:
00113             return Qt::SvgMiterJoin;
00114         case RoundJoin:
00115             return Qt::RoundJoin;
00116         case BevelJoin:
00117             return Qt::BevelJoin;
00118     }
00119 
00120     return Qt::MiterJoin;
00121 }
00122 
00123 static Qt::PenStyle toQPenStyle(StrokeStyle style)
00124 {
00125     switch (style) {
00126     case NoStroke:
00127         return Qt::NoPen;
00128         break;
00129     case SolidStroke:
00130         return Qt::SolidLine;
00131         break;
00132     case DottedStroke:
00133         return Qt::DotLine;
00134         break;
00135     case DashedStroke:
00136         return Qt::DashLine;
00137         break;
00138     }
00139     qWarning("couldn't recognize the pen style");
00140     return Qt::NoPen;
00141 }*/
00142 
00143 struct TransparencyLayer
00144 {
00145     TransparencyLayer(const QPainter* p, const QRect &rect)
00146         : pixmap(rect.width(), rect.height())
00147     {
00148         offset = rect.topLeft();
00149         pixmap.fill(Qt::transparent);
00150         painter.begin(&pixmap);
00151         painter.translate(-offset);
00152         painter.setPen(p->pen());
00153         painter.setBrush(p->brush());
00154         painter.setTransform(p->transform(), true);
00155         painter.setOpacity(p->opacity());
00156         painter.setFont(p->font());
00157         painter.setCompositionMode(p->compositionMode());
00158         painter.setClipPath(p->clipPath());
00159     }
00160 
00161     TransparencyLayer()
00162     {
00163     }
00164 
00165     QPixmap pixmap;
00166     QPoint offset;
00167     QPainter painter;
00168     qreal opacity;
00169 private:
00170     TransparencyLayer(const TransparencyLayer &) {}
00171     TransparencyLayer & operator=(const TransparencyLayer &) { return *this; }
00172 };
00173 
00174 struct TextShadow
00175 {
00176     TextShadow()
00177         : x(0)
00178         , y(0)
00179         , blur(0)
00180     {
00181     }
00182 
00183     bool isNull() { return !x && !y && !blur; }
00184 
00185     int x;
00186     int y;
00187     int blur;
00188 
00189     //Color color;
00190 };
00191 
00192 class GraphicsContextPlatformPrivate
00193 {
00194 public:
00195     GraphicsContextPlatformPrivate(QPainter* painter);
00196     ~GraphicsContextPlatformPrivate();
00197 
00198     inline QPainter* p()
00199     {
00200         if (layers.isEmpty()) {
00201             if (redirect)
00202                 return redirect;
00203 
00204             return painter;
00205         } else
00206             return &layers.top()->painter;
00207     }
00208 
00209     QPaintDevice* device;
00210 
00211     QStack<TransparencyLayer *> layers;
00212     QPainter* redirect;
00213 
00214     TextShadow shadow;
00215 
00216     // Only used by SVG for now.
00217     QPainterPath currentPath;
00218 
00219 private:
00220     QPainter* painter;
00221 };
00222 
00223 
00224 GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(QPainter* p)
00225 {
00226     painter = p;
00227     device = painter ? painter->device() : 0;
00228     redirect = 0;
00229 
00230     // FIXME: Maybe only enable in SVG mode?
00231     if (painter)
00232         painter->setRenderHint(QPainter::Antialiasing);
00233 }
00234 
00235 GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate()
00236 {
00237 }
00238 
00239 GraphicsContext::GraphicsContext(PlatformGraphicsContext* context)
00240     : m_common(createGraphicsContextPrivate())
00241     , m_data(new GraphicsContextPlatformPrivate(context))
00242 {
00243     setPaintingDisabled(!context);
00244     if (context) {
00245         // Make sure the context starts in sync with our state.
00246         /*setPlatformFillColor(fillColor());
00247         setPlatformStrokeColor(strokeColor());*/
00248     }
00249 }
00250 
00251 GraphicsContext::~GraphicsContext()
00252 {
00253     while(!m_data->layers.isEmpty())
00254         endTransparencyLayer();
00255 
00256     destroyGraphicsContextPrivate(m_common);
00257     delete m_data;
00258 }
00259 
00260 PlatformGraphicsContext* GraphicsContext::platformContext() const
00261 {
00262     return m_data->p();
00263 }
00264 
00265 AffineTransform GraphicsContext::getCTM() const
00266 {
00267     return platformContext()->combinedMatrix();
00268 }
00269 
00270 void GraphicsContext::savePlatformState()
00271 {
00272     m_data->p()->save();
00273 }
00274 
00275 void GraphicsContext::restorePlatformState()
00276 {
00277     m_data->p()->restore();
00278 }
00279 
00280 /* FIXME: DISABLED WHILE MERGING BACK FROM UNITY
00281 void GraphicsContext::drawTextShadow(const TextRun& run, const IntPoint& point, const FontStyle& style)
00282 {
00283     if (paintingDisabled())
00284         return;
00285 
00286     if (m_data->shadow.isNull())
00287         return;
00288 
00289     TextShadow* shadow = &m_data->shadow;
00290 
00291     if (shadow->blur <= 0) {
00292         Pen p = pen();
00293         setPen(shadow->color);
00294         font().drawText(this, run, style, IntPoint(point.x() + shadow->x, point.y() + shadow->y));
00295         setPen(p);
00296     } else {
00297         const int thickness = shadow->blur;
00298         // FIXME: OPTIMIZE: limit the area to only the actually painted area + 2*thickness
00299         const int w = m_data->p()->device()->width();
00300         const int h = m_data->p()->device()->height();
00301         const QRgb color = qRgb(255, 255, 255);
00302         const QRgb bgColor = qRgb(0, 0, 0);
00303         QImage image(QSize(w, h), QImage::Format_ARGB32);
00304         image.fill(bgColor);
00305         QPainter p;
00306 
00307         Pen curPen = pen();
00308         p.begin(&image);
00309         setPen(color);
00310         m_data->redirect = &p;
00311         font().drawText(this, run, style, IntPoint(point.x() + shadow->x, point.y() + shadow->y));
00312         m_data->redirect = 0;
00313         p.end();
00314         setPen(curPen);
00315 
00316         int md = thickness * thickness; // max-dist^2
00317 
00318         // blur map/precalculated shadow-decay
00319         float* bmap = (float*) alloca(sizeof(float) * (md + 1));
00320         for (int n = 0; n <= md; n++) {
00321             float f;
00322             f = n / (float) (md + 1);
00323             f = 1.0 - f * f;
00324             bmap[n] = f;
00325         }
00326 
00327         float factor = 0.0; // maximal potential opacity-sum
00328         for (int n = -thickness; n <= thickness; n++) {
00329             for (int m = -thickness; m <= thickness; m++) {
00330                 int d = n * n + m * m;
00331                 if (d <= md)
00332                     factor += bmap[d];
00333             }
00334         }
00335 
00336         // alpha map
00337         float* amap = (float*) alloca(sizeof(float) * (h * w));
00338         memset(amap, 0, h * w * (sizeof(float)));
00339 
00340         for (int j = thickness; j<h-thickness; j++) {
00341             for (int i = thickness; i<w-thickness; i++) {
00342                 QRgb col = image.pixel(i,j);
00343                 if (col == bgColor)
00344                     continue;
00345 
00346                 float g = qAlpha(col);
00347                 g = g / 255;
00348 
00349                 for (int n = -thickness; n <= thickness; n++) {
00350                     for (int m = -thickness; m <= thickness; m++) {
00351                         int d = n * n + m * m;
00352                         if (d > md)
00353                             continue;
00354 
00355                         float f = bmap[d];
00356                         amap[(i + m) + (j + n) * w] += (g * f);
00357                     }
00358                 }
00359             }
00360         }
00361 
00362         QImage res(QSize(w,h),QImage::Format_ARGB32);
00363         int r = shadow->color.red();
00364         int g = shadow->color.green();
00365         int b = shadow->color.blue();
00366         int a1 = shadow->color.alpha();
00367 
00368         // arbitratry factor adjustment to make shadows more solid.
00369         factor = 1.333 / factor;
00370 
00371         for (int j = 0; j < h; j++) {
00372             for (int i = 0; i < w; i++) {
00373                 int a = (int) (amap[i + j * w] * factor * a1);
00374                 if (a > 255)
00375                     a = 255;
00376 
00377                 res.setPixel(i,j, qRgba(r, g, b, a));
00378             }
00379         }
00380 
00381         m_data->p()->drawImage(0, 0, res, 0, 0, -1, -1, Qt::DiffuseAlphaDither | Qt::ColorOnly | Qt::PreferDither);
00382     }
00383 }
00384 */
00385 
00386 // Draws a filled rectangle with a stroked border.
00387 void GraphicsContext::drawRect(const IntRect& rect)
00388 {
00389     if (paintingDisabled())
00390         return;
00391 
00392     m_data->p()->drawRect(rect);
00393 }
00394 
00395 // FIXME: Now that this is refactored, it should be shared by all contexts.
00396 static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth,
00397                                         const StrokeStyle& penStyle)
00398 {
00399     // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
00400     // works out.  For example, with a border width of 3, KHTML will pass us (y1+y2)/2, e.g.,
00401     // (50+53)/2 = 103/2 = 51 when we want 51.5.  It is always true that an even width gave
00402     // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
00403     if (penStyle == DottedStroke || penStyle == DashedStroke) {
00404         if (p1.x() == p2.x()) {
00405             p1.setY(p1.y() + strokeWidth);
00406             p2.setY(p2.y() - strokeWidth);
00407         } else {
00408             p1.setX(p1.x() + strokeWidth);
00409             p2.setX(p2.x() - strokeWidth);
00410         }
00411     }
00412 
00413     if (((int) strokeWidth) % 2) {
00414         if (p1.x() == p2.x()) {
00415             // We're a vertical line.  Adjust our x.
00416             p1.setX(p1.x() + 0.5);
00417             p2.setX(p2.x() + 0.5);
00418         } else {
00419             // We're a horizontal line. Adjust our y.
00420             p1.setY(p1.y() + 0.5);
00421             p2.setY(p2.y() + 0.5);
00422         }
00423     }
00424 }
00425 
00426 // This is only used to draw borders.
00427 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
00428 {
00429     if (paintingDisabled())
00430         return;
00431 
00432     FloatPoint p1 = point1;
00433     FloatPoint p2 = point2;
00434 
00435     /*adjustLineToPixelBoundaries(p1, p2, strokeThickness(), strokeStyle());*/
00436     m_data->p()->drawLine(p1, p2);
00437 }
00438 
00439 // This method is only used to draw the little circles used in lists.
00440 void GraphicsContext::drawEllipse(const IntRect& rect)
00441 {
00442     if (paintingDisabled())
00443         return;
00444 
00445     m_data->p()->drawEllipse(rect);
00446 }
00447 
00448 void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan)
00449 {
00450     /*if (paintingDisabled() || strokeStyle() == NoStroke || strokeThickness() <= 0.0f || !strokeColor().alpha())
00451         return;*/
00452 
00453     m_data->p()->drawArc(rect, startAngle * 16, angleSpan * 16);
00454 }
00455 
00456 void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
00457 {
00458     if (paintingDisabled())
00459         return;
00460 
00461     if (npoints <= 1)
00462         return;
00463 
00464     QPolygonF polygon(npoints);
00465 
00466     for (size_t i = 0; i < npoints; i++)
00467         polygon[i] = points[i];
00468 
00469     QPainter *p = m_data->p();
00470     p->save();
00471     p->setRenderHint(QPainter::Antialiasing, shouldAntialias);
00472     p->drawConvexPolygon(polygon);
00473     p->restore();
00474 }
00475 
00476 /*void GraphicsContext::fillRect(const IntRect& rect, const Color& c)
00477 {
00478     if (paintingDisabled())
00479         return;
00480 
00481     m_data->p()->fillRect(rect, QColor(c));
00482 }
00483 
00484 void GraphicsContext::fillRect(const FloatRect& rect, const Color& c)
00485 {
00486     if (paintingDisabled())
00487         return;
00488 
00489     m_data->p()->fillRect(rect, QColor(c));
00490 }
00491 
00492 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color)
00493 {
00494     if (paintingDisabled() || !color.alpha())
00495         return;
00496 
00497     Path path = Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight);
00498     m_data->p()->fillPath(*path.platformPath(), QColor(color));
00499 }*/
00500 
00501 void GraphicsContext::beginPath()
00502 {
00503     m_data->currentPath = QPainterPath();
00504 }
00505 
00506 void GraphicsContext::addPath(const Path& path)
00507 {
00508     m_data->currentPath = *(path.platformPath());
00509 }
00510 
00511 void GraphicsContext::setFillRule(WindRule rule)
00512 {
00513     m_data->currentPath.setFillRule(rule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
00514 }
00515 
00516 PlatformPath* GraphicsContext::currentPath()
00517 {
00518     return &m_data->currentPath;
00519 }
00520 
00521 void GraphicsContext::clip(const FloatRect& rect)
00522 {
00523     if (paintingDisabled())
00524         return;
00525 
00526     QPainter *p = m_data->p();
00527     if (p->clipRegion().isEmpty())
00528         p->setClipRect(rect);
00529     else p->setClipRect(rect, Qt::IntersectClip);
00530 }
00531 
00537 void setFocusRingColorChangeFunction(void (*)()) { }
00538 /*Color focusRingColor() { return Color(0, 0, 0); }
00539 void GraphicsContext::drawFocusRing(const Color& color)
00540 {
00541     if (paintingDisabled())
00542         return;
00543 
00544     const Vector<IntRect>& rects = focusRingRects();
00545     unsigned rectCount = rects.size();
00546 
00547     if (rects.size() == 0)
00548         return;
00549 
00550     QPainter *p = m_data->p();
00551 
00552     const QPen oldPen = p->pen();
00553     const QBrush oldBrush = p->brush();
00554 
00555     QPen nPen = p->pen();
00556     nPen.setColor(color);
00557     p->setBrush(Qt::NoBrush);
00558     nPen.setStyle(Qt::DotLine);
00559     p->setPen(nPen);
00560 #if 0
00561     // FIXME How do we do a bounding outline with Qt?
00562     QPainterPath path;
00563     for (int i = 0; i < rectCount; ++i)
00564         path.addRect(QRectF(rects[i]));
00565     QPainterPathStroker stroker;
00566     QPainterPath newPath = stroker.createStroke(path);
00567     p->strokePath(newPath, nPen);
00568 #else
00569     for (int i = 0; i < rectCount; ++i)
00570         p->drawRect(QRectF(rects[i]));
00571 #endif
00572     p->setPen(oldPen);
00573     p->setBrush(oldBrush);
00574 }*/
00575 
00576 void GraphicsContext::drawLineForText(const IntPoint& origin, int width, bool printing)
00577 {
00578     if (paintingDisabled())
00579         return;
00580 
00581     IntPoint endPoint = origin + IntSize(width, 0);
00582     drawLine(origin, endPoint);
00583 }
00584 
00585 void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint&,
00586                                                          int width, bool grammar)
00587 {
00588     if (paintingDisabled())
00589         return;
00590 
00591     //notImplemented();
00592 }
00593 
00594 FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect)
00595 {
00596     QRectF rect(frect);
00597     rect = m_data->p()->deviceMatrix().mapRect(rect);
00598 
00599     QRect result = rect.toRect(); //round it
00600     return FloatRect(QRectF(result));
00601 }
00602 
00603 /*void GraphicsContext::setPlatformShadow(const IntSize& pos, int blur, const Color &color)
00604 {
00605     if (paintingDisabled())
00606         return;
00607 
00608     m_data->shadow.x = pos.width();
00609     m_data->shadow.y = pos.height();
00610     m_data->shadow.blur = blur;
00611     m_data->shadow.color = color;
00612 }*/
00613 
00614 void GraphicsContext::clearPlatformShadow()
00615 {
00616     if (paintingDisabled())
00617         return;
00618 
00619     m_data->shadow = TextShadow();
00620 }
00621 
00622 void GraphicsContext::beginTransparencyLayer(float opacity)
00623 {
00624     if (paintingDisabled())
00625         return;
00626 
00627     int x, y, w, h;
00628     x = y = 0;
00629     w = m_data->device->width();
00630     h = m_data->device->height();
00631 
00632     QPainter *p = m_data->p();
00633     QRectF clip = p->clipPath().boundingRect();
00634     bool ok;
00635     QTransform transform = p->transform().inverted(&ok);
00636     if (ok) {
00637         QRectF deviceClip = transform.mapRect(clip);
00638         x = int(qBound(qreal(0), deviceClip.x(), (qreal)w));
00639         y = int(qBound(qreal(0), deviceClip.y(), (qreal)h));
00640         w = int(qBound(qreal(0), deviceClip.width(), (qreal)w) + 2);
00641         h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2);
00642     }
00643     TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h));
00644 
00645     layer->opacity = opacity;
00646     m_data->layers.push(layer);
00647 }
00648 
00649 void GraphicsContext::endTransparencyLayer()
00650 {
00651     if (paintingDisabled())
00652         return;
00653 
00654     TransparencyLayer *layer = m_data->layers.pop();
00655     layer->painter.end();
00656 
00657     QPainter *p = m_data->p();
00658     p->save();
00659     p->resetTransform();
00660     p->setOpacity(layer->opacity);
00661     p->drawPixmap(layer->offset, layer->pixmap);
00662     p->restore();
00663 
00664     delete layer;
00665 }
00666 
00667 /*void GraphicsContext::clearRect(const FloatRect& rect)
00668 {
00669     if (paintingDisabled())
00670         return;
00671 
00672     QPainter *p = m_data->p();
00673     QPainter::CompositionMode currentCompositionMode = p->compositionMode();
00674     p->setCompositionMode(QPainter::CompositionMode_Source);
00675     p->eraseRect(rect);
00676     p->setCompositionMode(currentCompositionMode);
00677 }
00678 
00679 void GraphicsContext::strokeRect(const FloatRect& rect, float width)
00680 {
00681     if (paintingDisabled())
00682         return;
00683 
00684     QPainter *p = m_data->p();
00685     QPainterPath path;
00686     path.addRect(rect);
00687     QPen nPen = p->pen();
00688     nPen.setWidthF(width);
00689     p->strokePath(path, nPen);
00690 }
00691 
00692 void GraphicsContext::setLineCap(LineCap lc)
00693 {
00694     if (paintingDisabled())
00695         return;
00696 
00697     QPainter *p = m_data->p();
00698     QPen nPen = p->pen();
00699     nPen.setCapStyle(toQtLineCap(lc));
00700     p->setPen(nPen);
00701 }
00702 
00703 void GraphicsContext::setLineJoin(LineJoin lj)
00704 {
00705     if (paintingDisabled())
00706         return;
00707 
00708     QPainter *p = m_data->p();
00709     QPen nPen = p->pen();
00710     nPen.setJoinStyle(toQtLineJoin(lj));
00711     p->setPen(nPen);
00712 }*/
00713 
00714 void GraphicsContext::setMiterLimit(float limit)
00715 {
00716     if (paintingDisabled())
00717         return;
00718 
00719     QPainter *p = m_data->p();
00720     QPen nPen = p->pen();
00721     nPen.setMiterLimit(limit);
00722     p->setPen(nPen);
00723 }
00724 
00725 void GraphicsContext::setAlpha(float opacity)
00726 {
00727     if (paintingDisabled())
00728         return;
00729     QPainter *p = m_data->p();
00730     p->setOpacity(opacity);
00731 }
00732 
00733 /*void GraphicsContext::setCompositeOperation(CompositeOperator op)
00734 {
00735     if (paintingDisabled())
00736         return;
00737 
00738     m_data->p()->setCompositionMode(toQtCompositionMode(op));
00739 }*/
00740 
00741 void GraphicsContext::clip(const Path& path)
00742 {
00743     if (paintingDisabled())
00744         return;
00745 
00746     m_data->p()->setClipPath(*path.platformPath(), Qt::IntersectClip);
00747 }
00748 
00749 void GraphicsContext::clipOut(const Path& path)
00750 {
00751     if (paintingDisabled())
00752         return;
00753 
00754     QPainter *p = m_data->p();
00755     QRectF clipBounds = p->clipPath().boundingRect();
00756     QPainterPath clippedOut = *path.platformPath();
00757     QPainterPath newClip;
00758     newClip.setFillRule(Qt::OddEvenFill);
00759     newClip.addRect(clipBounds);
00760     newClip.addPath(clippedOut);
00761 
00762     p->setClipPath(newClip, Qt::IntersectClip);
00763 }
00764 
00765 void GraphicsContext::translate(float x, float y)
00766 {
00767     if (paintingDisabled())
00768         return;
00769 
00770     m_data->p()->translate(x, y);
00771 }
00772 
00773 IntPoint GraphicsContext::origin()
00774 {
00775     if (paintingDisabled())
00776         return IntPoint();
00777     const QTransform &transform = m_data->p()->transform();
00778     return IntPoint(qRound(transform.dx()), qRound(transform.dy()));
00779 }
00780 
00781 void GraphicsContext::rotate(float radians)
00782 {
00783     if (paintingDisabled())
00784         return;
00785 
00786     m_data->p()->rotate(radians);
00787 }
00788 
00789 void GraphicsContext::scale(const FloatSize& s)
00790 {
00791     if (paintingDisabled())
00792         return;
00793 
00794     m_data->p()->scale(s.width(), s.height());
00795 }
00796 
00797 void GraphicsContext::clipOut(const IntRect& rect)
00798 {
00799     if (paintingDisabled())
00800         return;
00801         
00802     QPainter *p = m_data->p();
00803     QRectF clipBounds = p->clipPath().boundingRect();
00804     QPainterPath newClip;
00805     newClip.setFillRule(Qt::OddEvenFill);
00806     newClip.addRect(clipBounds);
00807     newClip.addRect(QRect(rect));
00808 
00809     p->setClipPath(newClip, Qt::IntersectClip);
00810 }
00811 
00812 void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
00813 {
00814     if (paintingDisabled())
00815         return;
00816     
00817     QPainter *p = m_data->p();
00818     QRectF clipBounds = p->clipPath().boundingRect();
00819     QPainterPath newClip;
00820     newClip.setFillRule(Qt::OddEvenFill);
00821     newClip.addRect(clipBounds);
00822     newClip.addEllipse(QRect(rect));
00823 
00824     p->setClipPath(newClip, Qt::IntersectClip);
00825 }
00826 
00827 void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect,
00828                                               int thickness)
00829 {
00830     if (paintingDisabled())
00831         return;
00832 
00833     clip(rect);
00834     QPainterPath path;
00835 
00836     // Add outer ellipse
00837     path.addEllipse(QRectF(rect.x(), rect.y(), rect.width(), rect.height()));
00838 
00839     // Add inner ellipse.
00840     path.addEllipse(QRectF(rect.x() + thickness, rect.y() + thickness,
00841                            rect.width() - (thickness * 2), rect.height() - (thickness * 2)));
00842 
00843     path.setFillRule(Qt::OddEvenFill);
00844     m_data->p()->setClipPath(path, Qt::IntersectClip);
00845 }
00846 
00847 void GraphicsContext::concatCTM(const AffineTransform& transform)
00848 {
00849     if (paintingDisabled())
00850         return;
00851 
00852     m_data->p()->setMatrix(transform, true);
00853 }
00854 
00855 /*void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
00856 {
00857     //notImplemented();
00858 }
00859 
00860 void GraphicsContext::setPlatformFont(const Font& aFont)
00861 {
00862     if (paintingDisabled())
00863         return;
00864     m_data->p()->setFont(aFont.font());
00865 }
00866 
00867 void GraphicsContext::setPlatformStrokeColor(const Color& color)
00868 {
00869     if (paintingDisabled())
00870         return;
00871     QPainter *p = m_data->p();
00872     QPen newPen(p->pen());
00873     newPen.setColor(color);
00874     p->setPen(newPen);
00875 }
00876 
00877 void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& strokeStyle)
00878 {   
00879     if (paintingDisabled())
00880         return;
00881     QPainter *p = m_data->p();
00882     QPen newPen(p->pen());
00883     newPen.setStyle(toQPenStyle(strokeStyle));
00884     p->setPen(newPen);
00885 }*/
00886 
00887 void GraphicsContext::setPlatformStrokeThickness(float thickness)
00888 {
00889     if (paintingDisabled())
00890         return;
00891     QPainter *p = m_data->p();
00892     QPen newPen(p->pen());
00893     newPen.setWidthF(thickness);
00894     p->setPen(newPen);
00895 }
00896 
00897 /*void GraphicsContext::setPlatformFillColor(const Color& color)
00898 {
00899     if (paintingDisabled())
00900         return;
00901     m_data->p()->setBrush(QBrush(color));
00902 }*/
00903 
00904 void GraphicsContext::setUseAntialiasing(bool enable)
00905 {
00906     if (paintingDisabled())
00907         return;
00908     m_data->p()->setRenderHint(QPainter::Antialiasing, enable);
00909 }
00910 
00911 }
00912 
00913 // vim: ts=4 sw=4 et

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal