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