Diffstat (limited to 'noncore/decorations/flat/flat.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/decorations/flat/flat.cpp | 360 |
1 files changed, 360 insertions, 0 deletions
diff --git a/noncore/decorations/flat/flat.cpp b/noncore/decorations/flat/flat.cpp new file mode 100644 index 0000000..b6a81a3 --- a/dev/null +++ b/noncore/decorations/flat/flat.cpp | |||
@@ -0,0 +1,360 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of the Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "flat.h" | ||
22 | #include <qpainter.h> | ||
23 | #include <qapplication.h> | ||
24 | |||
25 | |||
26 | /* XPM */ | ||
27 | static const char * ok_xpm[] = { | ||
28 | "32 32 3 1", | ||
29 | " c None", | ||
30 | ".c #000000", | ||
31 | "+c #FFFFFF", | ||
32 | " ", | ||
33 | " ", | ||
34 | " ++++++++ ", | ||
35 | " ++++++++++++ ", | ||
36 | " +++++ +++++ ", | ||
37 | " +++ +++ ", | ||
38 | " +++ +++ ", | ||
39 | " +++ +++ ", | ||
40 | " +++ +++ ", | ||
41 | " ++ ++ ", | ||
42 | " ++ +++++ ++ ++ ++ ", | ||
43 | " ++ ++++++++ ++ +++ ++ ", | ||
44 | " +++ +++ +++ ++ +++ +++ ", | ||
45 | " ++ +++ ++ ++ +++ ++ ", | ||
46 | " ++ ++ ++ ++ ++ ++ ", | ||
47 | " ++ ++ ++ +++++ ++ ", | ||
48 | " ++ ++ ++ ++++ ++ ", | ||
49 | " ++ ++ ++ ++ ++ ++ ", | ||
50 | " ++ +++ ++ ++ +++ ++ ", | ||
51 | " +++ +++ +++ ++ +++ +++ ", | ||
52 | " ++ ++++++++ ++ ++ ++ ", | ||
53 | " ++ +++++ ++ ++ ++ ", | ||
54 | " ++ ++ ", | ||
55 | " +++ +++ ", | ||
56 | " +++ +++ ", | ||
57 | " +++ +++ ", | ||
58 | " +++ +++ ", | ||
59 | " +++++ +++++ ", | ||
60 | " ++++++++++++ ", | ||
61 | " ++++++++ ", | ||
62 | " ", | ||
63 | " "}; | ||
64 | |||
65 | |||
66 | /* XPM */ | ||
67 | static const char * close_xpm[] = { | ||
68 | "32 32 3 1", | ||
69 | " c None", | ||
70 | ".c #000000", | ||
71 | "+c #FFFFFF", | ||
72 | " ", | ||
73 | " ", | ||
74 | " ++++++++ ", | ||
75 | " ++++++++++++ ", | ||
76 | " +++++ +++++ ", | ||
77 | " +++ +++ ", | ||
78 | " +++ +++ ", | ||
79 | " +++ +++ ", | ||
80 | " +++ +++ ", | ||
81 | " ++ ++ ++ ++ ", | ||
82 | " ++ +++ +++ ++ ", | ||
83 | " ++ +++ +++ ++ ", | ||
84 | " +++ +++ +++ +++ ", | ||
85 | " ++ +++ +++ ++ ", | ||
86 | " ++ ++++++ ++ ", | ||
87 | " ++ ++++ ++ ", | ||
88 | " ++ ++++ ++ ", | ||
89 | " ++ ++++++ ++ ", | ||
90 | " ++ +++ +++ ++ ", | ||
91 | " +++ +++ +++ +++ ", | ||
92 | " ++ +++ +++ ++ ", | ||
93 | " ++ +++ +++ ++ ", | ||
94 | " ++ ++ ++ ++ ", | ||
95 | " +++ +++ ", | ||
96 | " +++ +++ ", | ||
97 | " +++ +++ ", | ||
98 | " +++ +++ ", | ||
99 | " +++++ +++++ ", | ||
100 | " ++++++++++++ ", | ||
101 | " ++++++++ ", | ||
102 | " ", | ||
103 | " "}; | ||
104 | |||
105 | |||
106 | /* XPM */ | ||
107 | static const char * help_xpm[] = { | ||
108 | "32 32 3 1", | ||
109 | " c None", | ||
110 | ".c #000000", | ||
111 | "+c #FFFFFF", | ||
112 | " ", | ||
113 | " ", | ||
114 | " ++++++++ ", | ||
115 | " ++++++++++++ ", | ||
116 | " +++++ +++++ ", | ||
117 | " +++ +++ ", | ||
118 | " +++ +++ ", | ||
119 | " +++ +++ ", | ||
120 | " +++ +++++ +++ ", | ||
121 | " ++ ++++++++ ++ ", | ||
122 | " ++ ++++ ++++ ++ ", | ||
123 | " ++ +++ +++ ++ ", | ||
124 | " +++ +++ +++ +++ ", | ||
125 | " ++ ++++ ++ ", | ||
126 | " ++ +++++ ++ ", | ||
127 | " ++ +++++ ++ ", | ||
128 | " ++ ++++ ++ ", | ||
129 | " ++ ++++ ++ ", | ||
130 | " ++ +++ ++ ", | ||
131 | " +++ +++ +++ ", | ||
132 | " ++ ++ ", | ||
133 | " ++ ++ ", | ||
134 | " ++ +++ ++ ", | ||
135 | " +++ +++ +++ ", | ||
136 | " +++ +++ ", | ||
137 | " +++ +++ ", | ||
138 | " +++ +++ ", | ||
139 | " +++++ +++++ ", | ||
140 | " ++++++++++++ ", | ||
141 | " ++++++++ ", | ||
142 | " ", | ||
143 | " "}; | ||
144 | |||
145 | |||
146 | /* XPM */ | ||
147 | static const char * maximize_xpm[] = { | ||
148 | "32 32 3 1", | ||
149 | " c None", | ||
150 | ".c #000000", | ||
151 | "+c #FFFFFF", | ||
152 | " ", | ||
153 | " ", | ||
154 | " ++++++++ ", | ||
155 | " ++++++++++++ ", | ||
156 | " +++++ +++++ ", | ||
157 | " +++ +++ ", | ||
158 | " +++ +++ ", | ||
159 | " +++ +++ ", | ||
160 | " +++ ++++++++++++++ +++ ", | ||
161 | " ++ ++++++++++++++ ++ ", | ||
162 | " ++ ++++++++++++++ ++ ", | ||
163 | " ++ +++ +++ ++ ", | ||
164 | " +++ +++ +++ +++ ", | ||
165 | " ++ +++ +++ ++ ", | ||
166 | " ++ +++ +++ ++ ", | ||
167 | " ++ +++ +++ ++ ", | ||
168 | " ++ +++ +++ ++ ", | ||
169 | " ++ +++ +++ ++ ", | ||
170 | " ++ +++ +++ ++ ", | ||
171 | " +++ +++ +++ +++ ", | ||
172 | " ++ +++ +++ ++ ", | ||
173 | " ++ ++++++++++++++ ++ ", | ||
174 | " ++ ++++++++++++++ ++ ", | ||
175 | " +++ ++++++++++++++ +++ ", | ||
176 | " +++ +++ ", | ||
177 | " +++ +++ ", | ||
178 | " +++ +++ ", | ||
179 | " +++++ +++++ ", | ||
180 | " ++++++++++++ ", | ||
181 | " ++++++++ ", | ||
182 | " ", | ||
183 | " "}; | ||
184 | |||
185 | static QImage scaleButton( const QImage &img, int height ) | ||
186 | { | ||
187 | if ( img.height() != height ) { | ||
188 | return img.smoothScale( img.width()*height/img.height(), height ); | ||
189 | } else { | ||
190 | return img; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | static void colorize( QImage &img, const QColor &c, bool rev ) | ||
195 | { | ||
196 | for ( int i = 0; i < img.numColors(); i++ ) { | ||
197 | bool sc = (img.color(i) & 0xff000000); | ||
198 | if ( rev ) sc = !sc; | ||
199 | img.setColor(i, sc ? c.rgb() : 0x00000000 ); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | FlatDecoration::FlatDecoration() : ref(0), buttonCache(16) | ||
204 | { | ||
205 | buttonCache.setAutoDelete(TRUE); | ||
206 | } | ||
207 | |||
208 | FlatDecoration::~FlatDecoration() | ||
209 | { | ||
210 | } | ||
211 | |||
212 | int FlatDecoration::metric( Metric m, const WindowData *wd ) const | ||
213 | { | ||
214 | switch ( m ) { | ||
215 | case TopBorder: | ||
216 | return 1; | ||
217 | break; | ||
218 | case LeftBorder: | ||
219 | case RightBorder: | ||
220 | return 2; | ||
221 | case BottomBorder: | ||
222 | return 4; | ||
223 | case TitleHeight: | ||
224 | if ( QApplication::desktop()->height() > 320 ) | ||
225 | return 20; | ||
226 | else | ||
227 | return 18; | ||
228 | case OKWidth: | ||
229 | case CloseWidth: | ||
230 | case HelpWidth: | ||
231 | case MaximizeWidth: | ||
232 | return metric(TitleHeight,wd); | ||
233 | break; | ||
234 | default: | ||
235 | return WindowDecorationInterface::metric( m, wd ); | ||
236 | break; | ||
237 | } | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | void FlatDecoration::drawArea( Area a, QPainter *p, const WindowData *wd ) const | ||
243 | { | ||
244 | int th = metric( TitleHeight, wd ); | ||
245 | QRect r = wd->rect; | ||
246 | |||
247 | switch ( a ) { | ||
248 | case Border: | ||
249 | { | ||
250 | const QColorGroup &cg = wd->palette.active(); | ||
251 | if ( wd->flags & WindowData::Active ) { | ||
252 | p->setBrush( cg.color(QColorGroup::Highlight) ); | ||
253 | } else { | ||
254 | p->setBrush( cg.color(QColorGroup::Background) ); | ||
255 | } | ||
256 | p->setPen( cg.foreground() ); | ||
257 | int lb = metric(LeftBorder,wd); | ||
258 | int rb = metric(RightBorder,wd); | ||
259 | int tb = metric(TopBorder,wd); | ||
260 | int bb = metric(BottomBorder,wd); | ||
261 | p->drawRect( r.x()-lb, r.y()-tb-th, r.width()+lb+rb, | ||
262 | r.height()+th+tb+bb ); | ||
263 | } | ||
264 | break; | ||
265 | case Title: | ||
266 | if ( r.height() < 2 ) { | ||
267 | WindowDecorationInterface::drawArea( a, p, wd ); | ||
268 | } else { | ||
269 | const QColorGroup &cg = wd->palette.active(); | ||
270 | QColor c; | ||
271 | if ( wd->flags & WindowData::Active ) | ||
272 | c = cg.color(QColorGroup::Highlight); | ||
273 | else | ||
274 | c = cg.color(QColorGroup::Background); | ||
275 | p->fillRect( QRect(r.x(),r.y()-th,r.width(),th), c ); | ||
276 | } | ||
277 | break; | ||
278 | case TitleText: | ||
279 | p->drawText( r.left()+3+metric(HelpWidth,wd), r.top()-th, | ||
280 | r.width()-metric(HelpWidth,wd)-metric(CloseWidth,wd), th, | ||
281 | Qt::AlignVCenter, wd->caption ); | ||
282 | break; | ||
283 | default: | ||
284 | FlatDecoration::drawArea( a, p, wd ); | ||
285 | break; | ||
286 | } | ||
287 | } | ||
288 | |||
289 | void FlatDecoration::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int w, int h, QWSButton::State state ) const | ||
290 | { | ||
291 | QColor c; | ||
292 | const QColorGroup &cg = wd->palette.active(); | ||
293 | if ( wd->flags & WindowDecorationInterface::WindowData::Active ) | ||
294 | c = cg.color(QColorGroup::HighlightedText); | ||
295 | else | ||
296 | c = cg.color(QColorGroup::Foreground); | ||
297 | bool r = (state & QWSButton::MouseOver) && (state & QWSButton::Clicked); | ||
298 | int th = metric(TitleHeight, wd); | ||
299 | |||
300 | QString key( "%1-%2-%3-%4" ); | ||
301 | key = key.arg(b).arg(th).arg(c.name()).arg(r ? "1" : "0"); | ||
302 | QImage *img = buttonCache.find( key ); | ||
303 | if ( !img ) { | ||
304 | QImage tmp; | ||
305 | switch ( b ) { | ||
306 | case OK: | ||
307 | tmp = QImage( ok_xpm ); | ||
308 | break; | ||
309 | case Close: | ||
310 | tmp = QImage( close_xpm ); | ||
311 | break; | ||
312 | case Help: | ||
313 | tmp = QImage( help_xpm ); | ||
314 | break; | ||
315 | case Maximize: | ||
316 | tmp = QImage( maximize_xpm ); | ||
317 | break; | ||
318 | } | ||
319 | colorize( tmp, c, r ); | ||
320 | img = new QImage( scaleButton(tmp,th) ); | ||
321 | FlatDecoration *that = (FlatDecoration *)this; | ||
322 | that->buttonCache.insert( key, img, 1 ); | ||
323 | } | ||
324 | |||
325 | p->drawImage( x, y, *img ); | ||
326 | } | ||
327 | |||
328 | QRegion FlatDecoration::mask( const WindowData *wd ) const | ||
329 | { | ||
330 | return WindowDecorationInterface::mask( wd ); | ||
331 | } | ||
332 | |||
333 | QString FlatDecoration::name() const | ||
334 | { | ||
335 | return qApp->translate( "Decoration", "Flat" ); | ||
336 | } | ||
337 | |||
338 | QPixmap FlatDecoration::icon() const | ||
339 | { | ||
340 | return QPixmap(); | ||
341 | } | ||
342 | |||
343 | QRESULT FlatDecoration::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) | ||
344 | { | ||
345 | *iface = 0; | ||
346 | if ( uuid == IID_QUnknown ) | ||
347 | *iface = this; | ||
348 | else if ( uuid == IID_WindowDecoration ) | ||
349 | *iface = this; | ||
350 | |||
351 | if ( *iface ) | ||
352 | (*iface)->addRef(); | ||
353 | return QS_OK; | ||
354 | } | ||
355 | |||
356 | Q_EXPORT_INTERFACE() | ||
357 | { | ||
358 | Q_CREATE_INSTANCE( FlatDecoration ) | ||
359 | } | ||
360 | |||