| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Lesser General Public License Usage | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 20 | ** packaging of this file.  Please review the following information to | 
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 23 | ** | 
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
| 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #include "qgtkpainter_p.h" | 
|---|
| 43 |  | 
|---|
| 44 | #include <QtCore/qglobal.h> | 
|---|
| 45 | #if !defined(QT_NO_STYLE_GTK) | 
|---|
| 46 |  | 
|---|
| 47 | // This class is primarily a wrapper around the gtk painter functions | 
|---|
| 48 | // and takes care of converting all such calls into cached Qt pixmaps. | 
|---|
| 49 |  | 
|---|
| 50 | #include <QtGui/QWidget> | 
|---|
| 51 | #include <QtGui/QStyleOption> | 
|---|
| 52 | #include <QtGui/QPixmapCache> | 
|---|
| 53 |  | 
|---|
| 54 | QT_BEGIN_NAMESPACE | 
|---|
| 55 |  | 
|---|
| 56 | #undef GTK_OBJECT_FLAGS | 
|---|
| 57 | #define GTK_OBJECT_FLAGS(obj)(((GtkObject*)(obj))->flags) | 
|---|
| 58 |  | 
|---|
| 59 | #if Q_BYTE_ORDER == Q_BIG_ENDIAN | 
|---|
| 60 | #   define QT_RED 3 | 
|---|
| 61 | #   define QT_GREEN 2 | 
|---|
| 62 | #   define QT_BLUE 1 | 
|---|
| 63 | #   define QT_ALPHA 0 | 
|---|
| 64 | #else | 
|---|
| 65 | #   define QT_RED 0 | 
|---|
| 66 | #   define QT_GREEN 1 | 
|---|
| 67 | #   define QT_BLUE 2 | 
|---|
| 68 | #   define QT_ALPHA 3 | 
|---|
| 69 | #endif | 
|---|
| 70 | #   define GTK_RED 2 | 
|---|
| 71 | #   define GTK_GREEN 1 | 
|---|
| 72 | #   define GTK_BLUE 0 | 
|---|
| 73 | #   define GTK_ALPHA 3 | 
|---|
| 74 |  | 
|---|
| 75 | // To recover alpha we apply the gtk painting function two times to | 
|---|
| 76 | // white, and black window backgrounds. This can be used to | 
|---|
| 77 | // recover the premultiplied alpha channel | 
|---|
| 78 | QPixmap QGtkPainter::renderTheme(uchar *bdata, uchar *wdata, const QRect &rect) | 
|---|
| 79 | { | 
|---|
| 80 | const int bytecount = rect.width() * rect.height() * 4; | 
|---|
| 81 | for (int index = 0; index < bytecount ; index += 4) { | 
|---|
| 82 | uchar val = bdata[index + GTK_BLUE]; | 
|---|
| 83 | if (m_alpha) { | 
|---|
| 84 | int alphaval = qMax(bdata[index + GTK_BLUE] - wdata[index + GTK_BLUE], | 
|---|
| 85 | bdata[index + GTK_GREEN] - wdata[index + GTK_GREEN]); | 
|---|
| 86 | alphaval = qMax(alphaval, bdata[index + GTK_RED] - wdata[index + GTK_RED]) + 255; | 
|---|
| 87 | bdata[index + QT_ALPHA] = alphaval; | 
|---|
| 88 | } | 
|---|
| 89 | bdata[index + QT_RED] = bdata[index + GTK_RED]; | 
|---|
| 90 | bdata[index + QT_GREEN] = bdata[index + GTK_GREEN]; | 
|---|
| 91 | bdata[index + QT_BLUE] = val; | 
|---|
| 92 | } | 
|---|
| 93 | QImage converted((const uchar*)bdata, rect.width(), rect.height(), m_alpha ? | 
|---|
| 94 | QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); | 
|---|
| 95 |  | 
|---|
| 96 | if (m_hflipped || m_vflipped) { | 
|---|
| 97 | return QPixmap::fromImage(converted.mirrored(m_hflipped, m_vflipped)); | 
|---|
| 98 | } else { | 
|---|
| 99 | // on raster graphicssystem we need to do a copy here, because | 
|---|
| 100 | // we intend to deallocate the qimage bits shortly after... | 
|---|
| 101 | return QPixmap::fromImage(converted.copy()); | 
|---|
| 102 | } | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | // This macro is responsible for painting any GtkStyle painting function onto a QPixmap | 
|---|
| 106 | #define DRAW_TO_CACHE(draw_func)                                                                   \ | 
|---|
| 107 | if (rect.width() > QWIDGETSIZE_MAX || rect.height() > QWIDGETSIZE_MAX)                         \ | 
|---|
| 108 | return;                                                                                    \ | 
|---|
| 109 | QRect pixmapRect(0, 0, rect.width(), rect.height());                                           \ | 
|---|
| 110 | {                                                                                              \ | 
|---|
| 111 | GdkPixmap *pixmap = QGtkStylePrivate::gdk_pixmap_new((GdkDrawable*)(m_window->window),                    \ | 
|---|
| 112 | rect.width(), rect.height(), -1);                      \ | 
|---|
| 113 | if (!pixmap)                                                                               \ | 
|---|
| 114 | return;                                                                                \ | 
|---|
| 115 | style = QGtkStylePrivate::gtk_style_attach (style, m_window->window);                                  \ | 
|---|
| 116 | QGtkStylePrivate::gdk_draw_rectangle(pixmap, m_alpha ? style->black_gc : *style->bg_gc, true,                \ | 
|---|
| 117 | 0, 0, rect.width(), rect.height());                                     \ | 
|---|
| 118 | draw_func;                                                                                 \ | 
|---|
| 119 | GdkPixbuf *imgb = QGtkStylePrivate::gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, rect.width(), rect.height());\ | 
|---|
| 120 | if (!imgb)                                                                                 \ | 
|---|
| 121 | return;                                                                                \ | 
|---|
| 122 | imgb = QGtkStylePrivate::gdk_pixbuf_get_from_drawable(imgb, pixmap, NULL, 0, 0, 0, 0,                  \ | 
|---|
| 123 | rect.width(), rect.height());                          \ | 
|---|
| 124 | uchar* bdata = (uchar*)QGtkStylePrivate::gdk_pixbuf_get_pixels(imgb);                                  \ | 
|---|
| 125 | if (m_alpha) {                                                                             \ | 
|---|
| 126 | QGtkStylePrivate::gdk_draw_rectangle(pixmap, style->white_gc, true, 0, 0, rect.width(), rect.height());  \ | 
|---|
| 127 | draw_func;                                                                             \ | 
|---|
| 128 | GdkPixbuf *imgw = QGtkStylePrivate::gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, rect.              \ | 
|---|
| 129 | width(), rect.height());                              \ | 
|---|
| 130 | if (!imgw)                                                                             \ | 
|---|
| 131 | return;                                                                            \ | 
|---|
| 132 | imgw = QGtkStylePrivate::gdk_pixbuf_get_from_drawable(imgw, pixmap, NULL, 0, 0, 0, 0,              \ | 
|---|
| 133 | rect.width(), rect.height());                      \ | 
|---|
| 134 | uchar* wdata = (uchar*)QGtkStylePrivate::gdk_pixbuf_get_pixels(imgw);                                    \ | 
|---|
| 135 | cache = renderTheme(bdata, wdata, rect);                                               \ | 
|---|
| 136 | QGtkStylePrivate::gdk_pixbuf_unref(imgw);                                                          \ | 
|---|
| 137 | } else {                                                                                   \ | 
|---|
| 138 | cache = renderTheme(bdata, 0, rect);                                                   \ | 
|---|
| 139 | }                                                                                          \ | 
|---|
| 140 | QGtkStylePrivate::gdk_drawable_unref(pixmap);                                                          \ | 
|---|
| 141 | QGtkStylePrivate::gdk_pixbuf_unref(imgb);                                                              \ | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | QGtkPainter::QGtkPainter(QPainter *_painter) | 
|---|
| 145 | : m_window(QGtkStylePrivate::gtkWidget(QLatin1String("GtkWindow"))) | 
|---|
| 146 | , m_painter(_painter) | 
|---|
| 147 | , m_alpha(true) | 
|---|
| 148 | , m_hflipped(false) | 
|---|
| 149 | , m_vflipped(false) | 
|---|
| 150 | , m_usePixmapCache(true) | 
|---|
| 151 | {} | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|
| 154 | static QString uniqueName(const QString &key, GtkStateType state, GtkShadowType shadow, | 
|---|
| 155 | const QSize &size, GtkWidget *widget = 0) | 
|---|
| 156 | { | 
|---|
| 157 | // Note the widget arg should ideally use the widget path, though would compromise performance | 
|---|
| 158 | QString tmp = QString(QLS("%0-%1-%2-%3x%4-%5")).arg(key).arg(uint(state)).arg(shadow) | 
|---|
| 159 | .arg(size.width()).arg(size.height()).arg(quintptr(widget)); | 
|---|
| 160 | return tmp; | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 |  | 
|---|
| 164 | GtkStateType QGtkPainter::gtkState(const QStyleOption *option) | 
|---|
| 165 |  | 
|---|
| 166 | { | 
|---|
| 167 | GtkStateType state = GTK_STATE_NORMAL; | 
|---|
| 168 | if (!(option->state & QStyle::State_Enabled)) | 
|---|
| 169 | state = GTK_STATE_INSENSITIVE; | 
|---|
| 170 | else if (option->state & QStyle::State_MouseOver) | 
|---|
| 171 | state = GTK_STATE_PRELIGHT; | 
|---|
| 172 |  | 
|---|
| 173 | return state; | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 |  | 
|---|
| 177 | GtkStyle* QGtkPainter::getStyle(GtkWidget *gtkWidget) | 
|---|
| 178 |  | 
|---|
| 179 | { | 
|---|
| 180 | Q_ASSERT(gtkWidget); | 
|---|
| 181 | GtkStyle* style = gtkWidget->style; | 
|---|
| 182 | Q_ASSERT(style); | 
|---|
| 183 | return style; | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | QPixmap QGtkPainter::getIcon(const char* iconName, GtkIconSize size) | 
|---|
| 187 | { | 
|---|
| 188 | GtkStyle *style = QGtkStylePrivate::gtkStyle(); | 
|---|
| 189 | GtkIconSet* iconSet  = QGtkStylePrivate::gtk_icon_factory_lookup_default (iconName); | 
|---|
| 190 | GdkPixbuf* icon = QGtkStylePrivate::gtk_icon_set_render_icon(iconSet, | 
|---|
| 191 | style, | 
|---|
| 192 | GTK_TEXT_DIR_LTR, | 
|---|
| 193 | GTK_STATE_NORMAL, | 
|---|
| 194 | size, | 
|---|
| 195 | NULL, | 
|---|
| 196 | "button"); | 
|---|
| 197 | uchar* data = (uchar*)QGtkStylePrivate::gdk_pixbuf_get_pixels(icon); | 
|---|
| 198 | int width = QGtkStylePrivate::gdk_pixbuf_get_width(icon); | 
|---|
| 199 | int height = QGtkStylePrivate::gdk_pixbuf_get_height(icon); | 
|---|
| 200 | QImage converted(width, height, QImage::Format_ARGB32); | 
|---|
| 201 | uchar* tdata = (uchar*)converted.bits(); | 
|---|
| 202 |  | 
|---|
| 203 | for ( int index = 0 ; index < height * width*4 ; index +=4 ) { | 
|---|
| 204 | //int index = y * rowstride + x; | 
|---|
| 205 | tdata[index + QT_RED] = data[index + GTK_RED]; | 
|---|
| 206 | tdata[index + QT_GREEN] = data[index + GTK_GREEN]; | 
|---|
| 207 | tdata[index + QT_BLUE] = data[index + GTK_BLUE]; | 
|---|
| 208 | tdata[index + QT_ALPHA] = data[index + GTK_ALPHA]; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | QGtkStylePrivate::gdk_pixbuf_unref(icon); | 
|---|
| 212 |  | 
|---|
| 213 | // should we free iconset? | 
|---|
| 214 | return QPixmap::fromImage(converted); | 
|---|
| 215 |  | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 | // Note currently painted without alpha for performance reasons | 
|---|
| 219 | void QGtkPainter::paintBoxGap(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 220 | const QRect &paintRect, GtkStateType state, | 
|---|
| 221 | GtkShadowType shadow, GtkPositionType gap_side, | 
|---|
| 222 | gint x, gint width, | 
|---|
| 223 | GtkStyle *style) | 
|---|
| 224 | { | 
|---|
| 225 | if (!paintRect.isValid()) | 
|---|
| 226 | return; | 
|---|
| 227 |  | 
|---|
| 228 | QPixmap cache; | 
|---|
| 229 | QRect rect = paintRect; | 
|---|
| 230 |  | 
|---|
| 231 | // To avoid exhausting cache on large tabframes we cheat a bit by | 
|---|
| 232 | // tiling the center part. | 
|---|
| 233 |  | 
|---|
| 234 | const int maxHeight = 256; | 
|---|
| 235 | const int border = 16; | 
|---|
| 236 | if (rect.height() > maxHeight && (gap_side == GTK_POS_TOP || gap_side == GTK_POS_BOTTOM)) | 
|---|
| 237 | rect.setHeight(2 * border + 1); | 
|---|
| 238 |  | 
|---|
| 239 | QString gapExtras = QString(QLS("s %0 w %1 g %2")).arg(gap_side).arg(width).arg(x); | 
|---|
| 240 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + gapExtras; | 
|---|
| 241 |  | 
|---|
| 242 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 243 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_box_gap (style, | 
|---|
| 244 | pixmap, | 
|---|
| 245 | state, | 
|---|
| 246 | shadow, | 
|---|
| 247 | NULL, | 
|---|
| 248 | gtkWidget, | 
|---|
| 249 | (gchar*)part, | 
|---|
| 250 | 0, 0, | 
|---|
| 251 | rect.width(), | 
|---|
| 252 | rect.height(), | 
|---|
| 253 | gap_side, | 
|---|
| 254 | x, | 
|---|
| 255 | width)); | 
|---|
| 256 | if (m_usePixmapCache) | 
|---|
| 257 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 258 | } | 
|---|
| 259 | if (rect.size() != paintRect.size()) { | 
|---|
| 260 | // We assume we can stretch the middle tab part | 
|---|
| 261 | // Note: the side effect of this is that pinstripe patterns will get fuzzy | 
|---|
| 262 | const QSize size = cache.size(); | 
|---|
| 263 | // top part | 
|---|
| 264 | m_painter->drawPixmap(QRect(paintRect.left(), paintRect.top(), | 
|---|
| 265 | paintRect.width(), border), cache, | 
|---|
| 266 | QRect(0, 0, size.width(), border)); | 
|---|
| 267 |  | 
|---|
| 268 | // tiled center part | 
|---|
| 269 | QPixmap tilePart(cache.width(), 1); | 
|---|
| 270 | QPainter scanLinePainter(&tilePart); | 
|---|
| 271 | scanLinePainter.drawPixmap(QRect(0, 0, tilePart.width(), tilePart.height()), cache, QRect(0, border, size.width(), 1)); | 
|---|
| 272 | scanLinePainter.end(); | 
|---|
| 273 | m_painter->drawTiledPixmap(QRect(paintRect.left(), paintRect.top() + border, | 
|---|
| 274 | paintRect.width(), paintRect.height() - 2*border), tilePart); | 
|---|
| 275 |  | 
|---|
| 276 | // bottom part | 
|---|
| 277 | m_painter->drawPixmap(QRect(paintRect.left(), paintRect.top() + paintRect.height() - border, | 
|---|
| 278 | paintRect.width(), border), cache, | 
|---|
| 279 | QRect(0, size.height() - border, size.width(), border)); | 
|---|
| 280 | } else | 
|---|
| 281 | m_painter->drawPixmap(paintRect.topLeft(), cache); | 
|---|
| 282 | } | 
|---|
| 283 |  | 
|---|
| 284 | void QGtkPainter::paintBox(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 285 | const QRect &paintRect, GtkStateType state, | 
|---|
| 286 | GtkShadowType shadow, GtkStyle *style, | 
|---|
| 287 | const QString &pmKey) | 
|---|
| 288 | { | 
|---|
| 289 | if (!paintRect.isValid()) | 
|---|
| 290 | return; | 
|---|
| 291 |  | 
|---|
| 292 | QPixmap cache; | 
|---|
| 293 | QRect rect = paintRect; | 
|---|
| 294 |  | 
|---|
| 295 | // To avoid exhausting cache on large tabframes we cheat a bit by | 
|---|
| 296 | // tiling the center part. | 
|---|
| 297 |  | 
|---|
| 298 | const int maxHeight = 256; | 
|---|
| 299 | const int maxArea = 256*512; | 
|---|
| 300 | const int border = 32; | 
|---|
| 301 | if (rect.height() > maxHeight && (rect.width()*rect.height() > maxArea)) | 
|---|
| 302 | rect.setHeight(2 * border + 1); | 
|---|
| 303 |  | 
|---|
| 304 | QString pixmapName = uniqueName(QLS(part), state, shadow, | 
|---|
| 305 | rect.size(), gtkWidget) + pmKey; | 
|---|
| 306 |  | 
|---|
| 307 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 308 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_box (style, | 
|---|
| 309 | pixmap, | 
|---|
| 310 | state, | 
|---|
| 311 | shadow, | 
|---|
| 312 | NULL, | 
|---|
| 313 | gtkWidget, | 
|---|
| 314 | part, | 
|---|
| 315 | 0, 0, | 
|---|
| 316 | rect.width(), | 
|---|
| 317 | rect.height())); | 
|---|
| 318 | if (m_usePixmapCache) | 
|---|
| 319 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 320 | } | 
|---|
| 321 | if (rect.size() != paintRect.size()) { | 
|---|
| 322 | // We assume we can stretch the middle tab part | 
|---|
| 323 | // Note: the side effect of this is that pinstripe patterns will get fuzzy | 
|---|
| 324 | const QSize size = cache.size(); | 
|---|
| 325 | // top part | 
|---|
| 326 | m_painter->drawPixmap(QRect(paintRect.left(), paintRect.top(), | 
|---|
| 327 | paintRect.width(), border), cache, | 
|---|
| 328 | QRect(0, 0, size.width(), border)); | 
|---|
| 329 |  | 
|---|
| 330 | // tiled center part | 
|---|
| 331 | QPixmap tilePart(cache.width(), 1); | 
|---|
| 332 | QPainter scanLinePainter(&tilePart); | 
|---|
| 333 | scanLinePainter.drawPixmap(QRect(0, 0, tilePart.width(), tilePart.height()), cache, QRect(0, border, size.width(), 1)); | 
|---|
| 334 | scanLinePainter.end(); | 
|---|
| 335 | m_painter->drawTiledPixmap(QRect(paintRect.left(), paintRect.top() + border, | 
|---|
| 336 | paintRect.width(), paintRect.height() - 2*border), tilePart); | 
|---|
| 337 |  | 
|---|
| 338 | // bottom part | 
|---|
| 339 | m_painter->drawPixmap(QRect(paintRect.left(), paintRect.top() + paintRect.height() - border, | 
|---|
| 340 | paintRect.width(), border), cache, | 
|---|
| 341 | QRect(0, size.height() - border, size.width(), border)); | 
|---|
| 342 | } else | 
|---|
| 343 | m_painter->drawPixmap(paintRect.topLeft(), cache); | 
|---|
| 344 | } | 
|---|
| 345 |  | 
|---|
| 346 | void QGtkPainter::paintHline(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 347 | const QRect &rect, GtkStateType state, | 
|---|
| 348 | GtkStyle *style, int x1, int x2, int y, | 
|---|
| 349 | const QString &pmKey) | 
|---|
| 350 | { | 
|---|
| 351 | if (!rect.isValid()) | 
|---|
| 352 | return; | 
|---|
| 353 |  | 
|---|
| 354 | QPixmap cache; | 
|---|
| 355 | QString hLineExtras = QString(QLS("%0 %1 %2")).arg(x1).arg(x2).arg(y); | 
|---|
| 356 | QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) | 
|---|
| 357 | + hLineExtras + pmKey; | 
|---|
| 358 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 359 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_hline (style, | 
|---|
| 360 | pixmap, | 
|---|
| 361 | state, | 
|---|
| 362 | NULL, | 
|---|
| 363 | gtkWidget, | 
|---|
| 364 | part, | 
|---|
| 365 | x1, x2, y)); | 
|---|
| 366 | if (m_usePixmapCache) | 
|---|
| 367 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 368 | } | 
|---|
| 369 |  | 
|---|
| 370 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 371 | } | 
|---|
| 372 |  | 
|---|
| 373 | void QGtkPainter::paintVline(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 374 | const QRect &rect, GtkStateType state, | 
|---|
| 375 | GtkStyle *style, int y1, int y2, int x, | 
|---|
| 376 | const QString &pmKey) | 
|---|
| 377 | { | 
|---|
| 378 | if (!rect.isValid()) | 
|---|
| 379 | return; | 
|---|
| 380 |  | 
|---|
| 381 | QPixmap cache; | 
|---|
| 382 | QString vLineExtras = QString(QLS("%0 %1 %2")).arg(y1).arg(y2).arg(x); | 
|---|
| 383 | QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), | 
|---|
| 384 | gtkWidget) + vLineExtras +pmKey; | 
|---|
| 385 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 386 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_vline (style, | 
|---|
| 387 | pixmap, | 
|---|
| 388 | state, | 
|---|
| 389 | NULL, | 
|---|
| 390 | gtkWidget, | 
|---|
| 391 | part, | 
|---|
| 392 | y1, y2, | 
|---|
| 393 | x)); | 
|---|
| 394 | if (m_usePixmapCache) | 
|---|
| 395 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 396 | } | 
|---|
| 397 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 398 | } | 
|---|
| 399 |  | 
|---|
| 400 |  | 
|---|
| 401 | void QGtkPainter::paintExpander(GtkWidget *gtkWidget, | 
|---|
| 402 | const gchar* part, const QRect &rect, | 
|---|
| 403 | GtkStateType state, GtkExpanderStyle expander_state, | 
|---|
| 404 | GtkStyle *style, const QString &pmKey) | 
|---|
| 405 | { | 
|---|
| 406 | if (!rect.isValid()) | 
|---|
| 407 | return; | 
|---|
| 408 |  | 
|---|
| 409 | QPixmap cache; | 
|---|
| 410 | QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), | 
|---|
| 411 | gtkWidget) + QString::number(expander_state) + pmKey; | 
|---|
| 412 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 413 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_expander (style, pixmap, | 
|---|
| 414 | state, NULL, | 
|---|
| 415 | gtkWidget, part, | 
|---|
| 416 | rect.width()/2, | 
|---|
| 417 | rect.height()/2, | 
|---|
| 418 | expander_state)); | 
|---|
| 419 | if (m_usePixmapCache) | 
|---|
| 420 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 421 | } | 
|---|
| 422 |  | 
|---|
| 423 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 424 | } | 
|---|
| 425 |  | 
|---|
| 426 | void QGtkPainter::paintFocus(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 427 | const QRect &rect, GtkStateType state, | 
|---|
| 428 | GtkStyle *style, const QString &pmKey) | 
|---|
| 429 | { | 
|---|
| 430 | if (!rect.isValid()) | 
|---|
| 431 | return; | 
|---|
| 432 |  | 
|---|
| 433 | QPixmap cache; | 
|---|
| 434 | QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + pmKey; | 
|---|
| 435 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 436 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_focus (style, pixmap, state, NULL, | 
|---|
| 437 | gtkWidget, | 
|---|
| 438 | part, | 
|---|
| 439 | 0, 0, | 
|---|
| 440 | rect.width(), | 
|---|
| 441 | rect.height())); | 
|---|
| 442 | if (m_usePixmapCache) | 
|---|
| 443 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 444 | } | 
|---|
| 445 |  | 
|---|
| 446 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 447 | } | 
|---|
| 448 |  | 
|---|
| 449 |  | 
|---|
| 450 | void QGtkPainter::paintResizeGrip(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 451 | const QRect &rect, GtkStateType state, | 
|---|
| 452 | GtkShadowType shadow, GdkWindowEdge edge, | 
|---|
| 453 | GtkStyle *style, const QString &pmKey) | 
|---|
| 454 | { | 
|---|
| 455 | if (!rect.isValid()) | 
|---|
| 456 | return; | 
|---|
| 457 |  | 
|---|
| 458 | QPixmap cache; | 
|---|
| 459 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + pmKey; | 
|---|
| 460 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 461 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_resize_grip (style, pixmap, state, | 
|---|
| 462 | NULL, gtkWidget, | 
|---|
| 463 | part, edge, 0, 0, | 
|---|
| 464 | rect.width(), | 
|---|
| 465 | rect.height())); | 
|---|
| 466 | if (m_usePixmapCache) | 
|---|
| 467 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 468 | } | 
|---|
| 469 |  | 
|---|
| 470 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 471 | } | 
|---|
| 472 |  | 
|---|
| 473 |  | 
|---|
| 474 | void QGtkPainter::paintArrow(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 475 | const QRect &arrowrect, GtkArrowType arrow_type, | 
|---|
| 476 | GtkStateType state, GtkShadowType shadow, | 
|---|
| 477 | gboolean fill, GtkStyle *style, const QString &pmKey) | 
|---|
| 478 | { | 
|---|
| 479 | QRect rect = m_cliprect.isValid() ? m_cliprect : arrowrect; | 
|---|
| 480 | if (!rect.isValid()) | 
|---|
| 481 | return; | 
|---|
| 482 |  | 
|---|
| 483 | QPixmap cache; | 
|---|
| 484 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + | 
|---|
| 485 | QString::number((int)arrow_type) + pmKey; | 
|---|
| 486 |  | 
|---|
| 487 | GdkRectangle gtkCliprect = {0, 0, rect.width(), rect.height()}; | 
|---|
| 488 | int xOffset = m_cliprect.isValid() ? arrowrect.x() - m_cliprect.x() : 0; | 
|---|
| 489 | int yOffset = m_cliprect.isValid() ? arrowrect.y() - m_cliprect.y() : 0; | 
|---|
| 490 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 491 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_arrow (style, pixmap, state, shadow, | 
|---|
| 492 | >kCliprect, | 
|---|
| 493 | gtkWidget, | 
|---|
| 494 | part, | 
|---|
| 495 | arrow_type, fill, | 
|---|
| 496 | xOffset, yOffset, | 
|---|
| 497 | arrowrect.width(), | 
|---|
| 498 | arrowrect.height())) | 
|---|
| 499 | if (m_usePixmapCache) | 
|---|
| 500 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 501 | } | 
|---|
| 502 |  | 
|---|
| 503 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 504 | } | 
|---|
| 505 |  | 
|---|
| 506 |  | 
|---|
| 507 | void QGtkPainter::paintHandle(GtkWidget *gtkWidget, const gchar* part, const QRect &rect, | 
|---|
| 508 | GtkStateType state, GtkShadowType shadow, | 
|---|
| 509 | GtkOrientation orientation, GtkStyle *style) | 
|---|
| 510 | { | 
|---|
| 511 | if (!rect.isValid()) | 
|---|
| 512 | return; | 
|---|
| 513 |  | 
|---|
| 514 | QPixmap cache; | 
|---|
| 515 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) | 
|---|
| 516 | + QString::number(orientation); | 
|---|
| 517 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 518 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_handle (style, | 
|---|
| 519 | pixmap, | 
|---|
| 520 | state, | 
|---|
| 521 | shadow, | 
|---|
| 522 | NULL, | 
|---|
| 523 | gtkWidget, | 
|---|
| 524 | part, 0, 0, | 
|---|
| 525 | rect.width(), | 
|---|
| 526 | rect.height(), | 
|---|
| 527 | orientation)); | 
|---|
| 528 | if (m_usePixmapCache) | 
|---|
| 529 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 530 | } | 
|---|
| 531 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 532 | } | 
|---|
| 533 |  | 
|---|
| 534 |  | 
|---|
| 535 | void QGtkPainter::paintSlider(GtkWidget *gtkWidget, const gchar* part, const QRect &rect, | 
|---|
| 536 | GtkStateType state, GtkShadowType shadow, | 
|---|
| 537 | GtkStyle *style, GtkOrientation orientation, | 
|---|
| 538 | const QString &pmKey) | 
|---|
| 539 | { | 
|---|
| 540 | if (!rect.isValid()) | 
|---|
| 541 | return; | 
|---|
| 542 |  | 
|---|
| 543 | QPixmap cache; | 
|---|
| 544 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + pmKey; | 
|---|
| 545 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 546 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_slider (style, | 
|---|
| 547 | pixmap, | 
|---|
| 548 | state, | 
|---|
| 549 | shadow, | 
|---|
| 550 | NULL, | 
|---|
| 551 | gtkWidget, | 
|---|
| 552 | part, | 
|---|
| 553 | 0, 0, | 
|---|
| 554 | rect.width(), | 
|---|
| 555 | rect.height(), | 
|---|
| 556 | orientation)); | 
|---|
| 557 | if (m_usePixmapCache) | 
|---|
| 558 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 559 | } | 
|---|
| 560 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 561 | } | 
|---|
| 562 |  | 
|---|
| 563 |  | 
|---|
| 564 | void QGtkPainter::paintShadow(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 565 | const QRect &rect, GtkStateType state, | 
|---|
| 566 | GtkShadowType shadow, GtkStyle *style, | 
|---|
| 567 | const QString &pmKey) | 
|---|
| 568 |  | 
|---|
| 569 | { | 
|---|
| 570 | if (!rect.isValid()) | 
|---|
| 571 | return; | 
|---|
| 572 |  | 
|---|
| 573 | QRect r = rect; | 
|---|
| 574 | QPixmap cache; | 
|---|
| 575 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + pmKey; | 
|---|
| 576 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 577 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_shadow(style, pixmap, state, shadow, NULL, | 
|---|
| 578 | gtkWidget, part, 0, 0, rect.width(), rect.height())); | 
|---|
| 579 | if (m_usePixmapCache) | 
|---|
| 580 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 581 | } | 
|---|
| 582 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 583 | } | 
|---|
| 584 |  | 
|---|
| 585 | void QGtkPainter::paintFlatBox(GtkWidget *gtkWidget, const gchar* part, | 
|---|
| 586 | const QRect &rect, GtkStateType state, | 
|---|
| 587 | GtkShadowType shadow, GtkStyle *style, | 
|---|
| 588 | const QString &pmKey) | 
|---|
| 589 | { | 
|---|
| 590 | if (!rect.isValid()) | 
|---|
| 591 | return; | 
|---|
| 592 | QRect r = rect; | 
|---|
| 593 | QPixmap cache; | 
|---|
| 594 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + pmKey; | 
|---|
| 595 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 596 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_flat_box (style, | 
|---|
| 597 | pixmap, | 
|---|
| 598 | state, | 
|---|
| 599 | shadow, | 
|---|
| 600 | NULL, | 
|---|
| 601 | gtkWidget, | 
|---|
| 602 | part, 0, 0, | 
|---|
| 603 | rect.width(), | 
|---|
| 604 | rect.height())); | 
|---|
| 605 | if (m_usePixmapCache) | 
|---|
| 606 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 607 | } | 
|---|
| 608 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 609 | } | 
|---|
| 610 |  | 
|---|
| 611 | void QGtkPainter::paintExtention(GtkWidget *gtkWidget, | 
|---|
| 612 | const gchar *part, const QRect &rect, | 
|---|
| 613 | GtkStateType state, GtkShadowType shadow, | 
|---|
| 614 | GtkPositionType gap_pos, GtkStyle *style) | 
|---|
| 615 | { | 
|---|
| 616 | if (!rect.isValid()) | 
|---|
| 617 | return; | 
|---|
| 618 |  | 
|---|
| 619 | QRect r = rect; | 
|---|
| 620 | QPixmap cache; | 
|---|
| 621 | QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget); | 
|---|
| 622 | pixmapName += QString::number(gap_pos); | 
|---|
| 623 |  | 
|---|
| 624 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 625 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_extension (style, pixmap, state, shadow, | 
|---|
| 626 | NULL, gtkWidget, | 
|---|
| 627 | (gchar*)part, 0, 0, | 
|---|
| 628 | rect.width(), | 
|---|
| 629 | rect.height(), | 
|---|
| 630 | gap_pos)); | 
|---|
| 631 | if (m_usePixmapCache) | 
|---|
| 632 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 636 | } | 
|---|
| 637 |  | 
|---|
| 638 | void QGtkPainter::paintOption(GtkWidget *gtkWidget, const QRect &radiorect, | 
|---|
| 639 | GtkStateType state, GtkShadowType shadow, | 
|---|
| 640 | GtkStyle *style, const QString &detail) | 
|---|
| 641 |  | 
|---|
| 642 | { | 
|---|
| 643 | QRect rect = m_cliprect.isValid() ? m_cliprect : radiorect; | 
|---|
| 644 | if (!rect.isValid()) | 
|---|
| 645 | return; | 
|---|
| 646 |  | 
|---|
| 647 | QRect r = rect; | 
|---|
| 648 | QPixmap cache; | 
|---|
| 649 | QString pixmapName = uniqueName(detail, state, shadow, rect.size()); | 
|---|
| 650 | GdkRectangle gtkCliprect = {0, 0, rect.width(), rect.height()}; | 
|---|
| 651 | int xOffset = m_cliprect.isValid() ? radiorect.x() - m_cliprect.x() : 0; | 
|---|
| 652 | int yOffset = m_cliprect.isValid() ? radiorect.y() - m_cliprect.y() : 0; | 
|---|
| 653 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 654 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_option(style, pixmap, | 
|---|
| 655 | state, shadow, | 
|---|
| 656 | >kCliprect, | 
|---|
| 657 | gtkWidget, | 
|---|
| 658 | detail.toLatin1(), | 
|---|
| 659 | xOffset, yOffset, | 
|---|
| 660 | radiorect.width(), | 
|---|
| 661 | radiorect.height())); | 
|---|
| 662 |  | 
|---|
| 663 | if (m_usePixmapCache) | 
|---|
| 664 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 665 | } | 
|---|
| 666 |  | 
|---|
| 667 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 668 | } | 
|---|
| 669 |  | 
|---|
| 670 | void QGtkPainter::paintCheckbox(GtkWidget *gtkWidget, const QRect &checkrect, | 
|---|
| 671 | GtkStateType state, GtkShadowType shadow, | 
|---|
| 672 | GtkStyle *style, const QString &detail) | 
|---|
| 673 |  | 
|---|
| 674 | { | 
|---|
| 675 | QRect rect = m_cliprect.isValid() ? m_cliprect : checkrect; | 
|---|
| 676 | if (!rect.isValid()) | 
|---|
| 677 | return; | 
|---|
| 678 |  | 
|---|
| 679 | QRect r = rect; | 
|---|
| 680 | QPixmap cache; | 
|---|
| 681 | QString pixmapName = uniqueName(detail, state, shadow, rect.size()); | 
|---|
| 682 | GdkRectangle gtkCliprect = {0, 0, rect.width(), rect.height()}; | 
|---|
| 683 | int xOffset = m_cliprect.isValid() ? checkrect.x() - m_cliprect.x() : 0; | 
|---|
| 684 | int yOffset = m_cliprect.isValid() ? checkrect.y() - m_cliprect.y() : 0; | 
|---|
| 685 | if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { | 
|---|
| 686 | DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_check (style, | 
|---|
| 687 | pixmap, | 
|---|
| 688 | state, | 
|---|
| 689 | shadow, | 
|---|
| 690 | >kCliprect, | 
|---|
| 691 | gtkWidget, | 
|---|
| 692 | detail.toLatin1(), | 
|---|
| 693 | xOffset, yOffset, | 
|---|
| 694 | checkrect.width(), | 
|---|
| 695 | checkrect.height())); | 
|---|
| 696 | if (m_usePixmapCache) | 
|---|
| 697 | QPixmapCache::insert(pixmapName, cache); | 
|---|
| 698 | } | 
|---|
| 699 |  | 
|---|
| 700 | m_painter->drawPixmap(rect.topLeft(), cache); | 
|---|
| 701 | } | 
|---|
| 702 |  | 
|---|
| 703 | QT_END_NAMESPACE | 
|---|
| 704 |  | 
|---|
| 705 | #endif //!defined(QT_NO_STYLE_GTK) | 
|---|