javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/graphics/qt/graphicscontextimpl.h
changeset 21 2a9601315dfc
child 35 85266cc22c7f
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2008 Nokia Corporation.
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - initial implementation
       
    10  *******************************************************************************/
       
    11 #ifndef GRAPHICSCONTEXTQT_H_
       
    12 #define GRAPHICSCONTEXTQT_H_
       
    13 
       
    14 #include <QPaintDevice>
       
    15 #include <QMainWindow>
       
    16 #include <QPainter>
       
    17 #include <QPen>
       
    18 #include <QFont>
       
    19 #include "graphics.h"
       
    20 #include "surfaceimpl.h"
       
    21 #include "targetobserver.h"
       
    22 
       
    23 namespace Java { namespace GFX {
       
    24 
       
    25 class GraphicsContextImpl: public GraphicsContext
       
    26 {
       
    27 public:
       
    28     /**
       
    29      * Constructor
       
    30      */
       
    31     GraphicsContextImpl();
       
    32 
       
    33     /**
       
    34      * Destructor
       
    35      */
       
    36     ~GraphicsContextImpl();
       
    37 
       
    38     /**
       
    39      * From GraphicsContext
       
    40      * @see GraphicsContext
       
    41      */
       
    42      virtual WindowSurface* getWindowSurface();
       
    43 
       
    44     virtual void dispose();
       
    45     virtual void bindTarget(int aTarget, TTargetType aType, const int& aBufferFlushTargetHandle);
       
    46     virtual void render(Buffer* aBuffer);
       
    47     virtual void releaseTarget();
       
    48     virtual void cancelClipping();
       
    49     virtual void copyArea(Image* aImage, int aX, int aY);
       
    50     virtual void copyArea(int aSrcX, int aSrcY, int aWidth, int aHeight, int aDestX, int aDestY, bool aPaint);
       
    51     virtual void drawArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle);
       
    52     virtual void drawEllipse(int aX, int aY, int aWidth, int aHeight);
       
    53     virtual void drawFocus(int aX, int aY, int aWidth, int aHeight);
       
    54     virtual void drawImage(Image* aImage, int x, int y);
       
    55     virtual void drawImage(Image* aImage, int aManipulation, int aTx, int aTy, int aTw, int aTh, int aSx, int aSy, int aSw, int aSh);
       
    56     virtual void drawLine(int aX1, int aY1, int aX2, int aY2);
       
    57     virtual void drawPoint(int aX, int aY);
       
    58     virtual void drawPolygon(int aPointArray[], int aLength);
       
    59     virtual void drawPolyline(int aPointArray[], int aLength);
       
    60     virtual void drawRect(int aX, int aY, int aWidth, int aHeight);
       
    61     virtual void drawRGB(int aRgbData[], int aRgbDataLength, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, bool aProcessAlpha, int aManipulation);
       
    62     virtual void drawRGB(char aRgbData[], char aTransparencyMask[], int aRgbDataLength, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, int aManipulation, int aFormat);
       
    63     virtual void drawRGB(short aRgbData[], int aRgbDataLength, int aOffset, int aScanlength, int aX, int aY, int aWidth, int aHeight, bool aProcessAlpha, int aManipulation, int aFormat);
       
    64     virtual void drawRoundRect(int aX, int aY, int aWidth, int aHeight, int aArcWidth, int aArcHeight);
       
    65     virtual void drawString(
       
    66         const unsigned short* aText, int aX, int aY, int aWidth, int aHeight,
       
    67         int aLength, int aAlignments, int aFlags, bool aIsTransparent);
       
    68     virtual void fillArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle);
       
    69     virtual void fillEllipse(int aX, int aY, int aWidth, int aHeight);
       
    70     virtual void fillGradientRect(int aX, int aY, int aWidth, int aHeight, bool aVertical, bool aSwapColors);
       
    71     virtual void fillPolygon(int aPointArray[], int aLength);
       
    72     virtual void fillRect(int aX, int aY, int aWidth, int aHeight);
       
    73     virtual void fillRoundRect(int aX, int aY, int aWidth, int aHeight, int aArcWidth, int aArcHeight);
       
    74     virtual int  getBackgroundAlpha();
       
    75     virtual int  getBackgroundColor();
       
    76     virtual int  getBlendingMode();
       
    77     virtual int  getCharacterWidth(char aCh, bool aIsAdvanced);
       
    78     virtual void getClip(int aClipArray[]);
       
    79     virtual void getFontMetricsData(int aData[], const QFont& aFont);
       
    80     virtual void getFontMetricsData(int aData[]);
       
    81     virtual int  getForegroundAlpha();
       
    82     virtual int  getForegroundColor();
       
    83     virtual int  getStrokeWidth();
       
    84     virtual int  getStrokeStyle();
       
    85     virtual int  getTranslateX();
       
    86     virtual int  getTranslateY();
       
    87     virtual void getTextBoundingBox(
       
    88         int aBoundingBox[], const unsigned short* aText, int aTextLength, int aAlignments,
       
    89         int aFlags, int aRectX, int aRectY, int aRectWidth, int aRectHeight);
       
    90     virtual bool hasClipping();
       
    91     virtual void setBackgroundAlpha(int aAlpha);
       
    92     virtual void setBackgroundColor(int aArgb, bool aUpdateAlpha);
       
    93     virtual void setBlendingMode(TBlendingMode aMode);
       
    94     virtual void setClip(int aX, int aY, int aWidth, int aHeight, bool aIntersects);
       
    95     virtual void setFont(int aFontHandle);
       
    96     virtual void setForegroundAlpha(int aAlpha);
       
    97     virtual void setForegroundColor(int aArgb, bool aUpdateAlpha);
       
    98     virtual void setStrokeWidth(int aWidth);
       
    99     virtual void setStrokeStyle(TStrokeStyle aStyle);
       
   100     virtual void translate(int aX, int aY);
       
   101     virtual void scale(int aX, int aY);
       
   102     virtual void resetTransform();
       
   103     virtual void saveSettings();
       
   104     virtual void restoreSettings();
       
   105 
       
   106 private:
       
   107 
       
   108     /**
       
   109      * Checks if background color needs to be updated and updates it if necessary
       
   110      */
       
   111     void checkBgColor();
       
   112 
       
   113     /**
       
   114      * Checks if foreground color needs to be updated and updates it if necessary
       
   115      */
       
   116     void checkFgColor();
       
   117 
       
   118     /**
       
   119      * Converts given color to QColor
       
   120      *
       
   121      * @param aColor The color to be converted
       
   122      * @return QColor instance of given color
       
   123      */
       
   124     QColor convertArgbToQColor(unsigned int aColor);
       
   125 
       
   126     /**
       
   127      * Validates that given <code>aPrt</code> is with range defined by aStartPtr and aEndPtr
       
   128      *
       
   129      * @param aStartPrt pointer to start of memory area
       
   130      * @param aEndPrt pointer to end of memory area
       
   131      * @param aPrt the pointer to check
       
   132      * @return true if given ptr is with in bounds othewise false
       
   133      */
       
   134     bool isPtrWithinRange(const int* aStartPtr, const int* aEndPtr, const int* aPrt);
       
   135 
       
   136     /**
       
   137      * Returns trasformed image
       
   138      *
       
   139      * @param image image to perform transformation on
       
   140      * @param manuplation indicates what kind of transformation is needed
       
   141      */
       
   142 
       
   143     QImage doTransform(QImage image, int manipulation);
       
   144     /**
       
   145      * Performs clean for graphicsContext, i.e. deletes all allocations
       
   146      * and resets state.
       
   147      */
       
   148     void doCleanup();
       
   149 
       
   150     /**
       
   151      * Applies settings for painter needed when filling primitives
       
   152      * Settings:
       
   153      * Brush style -> Qt::SolidPattern
       
   154      * Brush color -> mBackground
       
   155      * Pen color -> mBackground
       
   156      */
       
   157     void setBrushForFill();
       
   158 
       
   159     /**
       
   160      * If SWT Control has a buffer then this synchronously flushes it.
       
   161      * @param aWidget The Widget which is the Control.handle
       
   162      * @param The area of the widget to draw. Reported to Qt as the invalid area when flushing.
       
   163      */
       
   164     void flushBufferToSwtWidget(QWidget* aWidget, const QRect& aPaintArea);
       
   165 
       
   166     /**
       
   167      * Gets the location of the widget in its window.
       
   168      */
       
   169     QPoint widgetOffsetInWindow(QWidget* aWidget);
       
   170 
       
   171     /**
       
   172      * Draws QImage to another (or the same) QImage handling also the case
       
   173      * where the source and target areas overlap. QPainter::drawImage doesn't
       
   174      * handle this. If called with different source and target images or
       
   175      * non-overlapping areas then simply calls QPainter::drawImage.
       
   176      */
       
   177     static void drawImageCheckOverlap(QPainter& aPainter,
       
   178             const QPaintDevice& aTargetDevice, const QRect& aTargetRect,
       
   179             const QImage& aSourceImage, const QRect& aSourceRect);
       
   180 
       
   181     /**
       
   182      * Draws QPixmap to another (or the same) QPixmap handling also the case
       
   183      * where the source and target areas overlap. QPainter::drawPixmap doesn't
       
   184      * handle this. If called with different source and target pixmaps or
       
   185      * non-overlapping areas then simply calls QPainter::drawPixmap.
       
   186      */
       
   187     static void drawPixmapCheckOverlap(QPainter& aPainter,
       
   188             const QPaintDevice& aTargetDevice, const QRect& aTargetRect,
       
   189             const QPixmap& aSourceImage, const QRect& aSourceRect);
       
   190 
       
   191 private:
       
   192     SurfaceImpl mSurface;
       
   193     QPainter* mPainter;
       
   194     QPen* mPen;
       
   195     QColor mBackground;
       
   196     QColor mForeground;
       
   197     bool mBgColorDirty;
       
   198     bool mFgColorDirty;
       
   199     TargetObserver mObserver;
       
   200 };
       
   201 
       
   202 } // namespace GFX
       
   203 } // namespace Java
       
   204 
       
   205 #endif /*GRAPHICSCONTEXTQT_H_*/