|
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 drawWindowSurface(WindowSurface* aSurface, int aX, int aY, int aWidth, int aHeight); |
|
69 virtual void fillArc(int aX, int aY, int aWidth, int aHeight, int aStartAngle, int aArcAngle); |
|
70 virtual void fillEllipse(int aX, int aY, int aWidth, int aHeight); |
|
71 virtual void fillGradientRect(int aX, int aY, int aWidth, int aHeight, bool aVertical, bool aSwapColors); |
|
72 virtual void fillPolygon(int aPointArray[], int aLength); |
|
73 virtual void fillRect(int aX, int aY, int aWidth, int aHeight); |
|
74 virtual void fillRoundRect(int aX, int aY, int aWidth, int aHeight, int aArcWidth, int aArcHeight); |
|
75 virtual int getBackgroundAlpha(); |
|
76 virtual int getBackgroundColor(); |
|
77 virtual int getBlendingMode(); |
|
78 virtual int getCharacterWidth(char aCh, bool aIsAdvanced); |
|
79 virtual void getClip(int aClipArray[]); |
|
80 virtual void getFontMetricsData(int aData[], const QFont& aFont); |
|
81 virtual void getFontMetricsData(int aData[]); |
|
82 virtual int getForegroundAlpha(); |
|
83 virtual int getForegroundColor(); |
|
84 virtual int getStrokeWidth(); |
|
85 virtual int getStrokeStyle(); |
|
86 virtual int getTranslateX(); |
|
87 virtual int getTranslateY(); |
|
88 virtual void getTextBoundingBox( |
|
89 int aBoundingBox[], const unsigned short* aText, int aTextLength, int aAlignments, |
|
90 int aFlags, int aRectX, int aRectY, int aRectWidth, int aRectHeight); |
|
91 virtual bool hasClipping(); |
|
92 virtual void setBackgroundAlpha(int aAlpha); |
|
93 virtual void setBackgroundColor(int aArgb, bool aUpdateAlpha); |
|
94 virtual void setBlendingMode(TBlendingMode aMode); |
|
95 virtual void setClip(int aX, int aY, int aWidth, int aHeight, bool aIntersects); |
|
96 virtual void setFont(int aFontHandle); |
|
97 virtual void setForegroundAlpha(int aAlpha); |
|
98 virtual void setForegroundColor(int aArgb, bool aUpdateAlpha); |
|
99 virtual void setStrokeWidth(int aWidth); |
|
100 virtual void setStrokeStyle(TStrokeStyle aStyle); |
|
101 virtual void translate(int aX, int aY); |
|
102 virtual void scale(int aX, int aY); |
|
103 virtual void resetTransform(); |
|
104 virtual void saveSettings(); |
|
105 virtual void restoreSettings(); |
|
106 |
|
107 private: |
|
108 |
|
109 /** |
|
110 * Checks if background color needs to be updated and updates it if necessary |
|
111 */ |
|
112 void checkBgColor(); |
|
113 |
|
114 /** |
|
115 * Checks if foreground color needs to be updated and updates it if necessary |
|
116 */ |
|
117 void checkFgColor(); |
|
118 |
|
119 /** |
|
120 * Converts given color to QColor |
|
121 * |
|
122 * @param aColor The color to be converted |
|
123 * @return QColor instance of given color |
|
124 */ |
|
125 QColor convertArgbToQColor(unsigned int aColor); |
|
126 |
|
127 /** |
|
128 * Validates that given <code>aPrt</code> is with range defined by aStartPtr and aEndPtr |
|
129 * |
|
130 * @param aStartPrt pointer to start of memory area |
|
131 * @param aEndPrt pointer to end of memory area |
|
132 * @param aPrt the pointer to check |
|
133 * @return true if given ptr is with in bounds othewise false |
|
134 */ |
|
135 bool isPtrWithinRange(const int* aStartPtr, const int* aEndPtr, const int* aPrt); |
|
136 |
|
137 /** |
|
138 * Returns trasformed image |
|
139 * |
|
140 * @param image image to perform transformation on |
|
141 * @param manuplation indicates what kind of transformation is needed |
|
142 */ |
|
143 |
|
144 QImage doTransform(QImage image, int manipulation); |
|
145 /** |
|
146 * Performs clean for graphicsContext, i.e. deletes all allocations |
|
147 * and resets state. |
|
148 */ |
|
149 void doCleanup(); |
|
150 |
|
151 /** |
|
152 * Applies settings for painter needed when filling primitives |
|
153 * Settings: |
|
154 * Brush style -> Qt::SolidPattern |
|
155 * Brush color -> mBackground |
|
156 * Pen color -> mBackground |
|
157 */ |
|
158 void setBrushForFill(); |
|
159 |
|
160 /** |
|
161 * If SWT Control has a buffer then this synchronously flushes it. |
|
162 * @param aWidget The Widget which is the Control.handle |
|
163 * @param The area of the widget to draw. Reported to Qt as the invalid area when flushing. |
|
164 */ |
|
165 void flushBufferToSwtWidget(QWidget* aWidget, const QRect& aPaintArea); |
|
166 |
|
167 /** |
|
168 * Gets the location of the widget in its window. |
|
169 */ |
|
170 QPoint widgetOffsetInWindow(QWidget* aWidget); |
|
171 |
|
172 /** |
|
173 * Draws QImage to another (or the same) QImage handling also the case |
|
174 * where the source and target areas overlap. QPainter::drawImage doesn't |
|
175 * handle this. If called with different source and target images or |
|
176 * non-overlapping areas then simply calls QPainter::drawImage. |
|
177 */ |
|
178 static void drawImageCheckOverlap(QPainter& aPainter, |
|
179 const QPaintDevice& aTargetDevice, const QRect& aTargetRect, |
|
180 const QImage& aSourceImage, const QRect& aSourceRect); |
|
181 |
|
182 /** |
|
183 * Draws QPixmap to another (or the same) QPixmap handling also the case |
|
184 * where the source and target areas overlap. QPainter::drawPixmap doesn't |
|
185 * handle this. If called with different source and target pixmaps or |
|
186 * non-overlapping areas then simply calls QPainter::drawPixmap. |
|
187 */ |
|
188 static void drawPixmapCheckOverlap(QPainter& aPainter, |
|
189 const QPaintDevice& aTargetDevice, const QRect& aTargetRect, |
|
190 const QPixmap& aSourceImage, const QRect& aSourceRect); |
|
191 |
|
192 private: |
|
193 SurfaceImpl mSurface; |
|
194 QPainter* mPainter; |
|
195 QPen* mPen; |
|
196 QColor mBackground; |
|
197 QColor mForeground; |
|
198 bool mBgColorDirty; |
|
199 bool mFgColorDirty; |
|
200 TargetObserver mObserver; |
|
201 }; |
|
202 |
|
203 } // namespace GFX |
|
204 } // namespace Java |
|
205 |
|
206 #endif /*GRAPHICSCONTEXTQT_H_*/ |