Qt 4.8
qgtkpainter.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
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 ?
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 
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())
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");
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 
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)) {
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)) {
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)) {
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)) {
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)) {
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)) {
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  &gtkCliprect,
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)) {
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)) {
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  QPixmap cache;
590  QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) % pmKey;
591  if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
592  DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_shadow(style, pixmap, state, shadow, NULL,
593  gtkWidget, part, 0, 0, rect.width(), rect.height()));
594  if (m_usePixmapCache)
595  QPixmapCache::insert(pixmapName, cache);
596  }
597  m_painter->drawPixmap(rect.topLeft(), cache);
598 }
599 
600 void QGtkPainter::paintFlatBox(GtkWidget *gtkWidget, const gchar* part,
601  const QRect &rect, GtkStateType state,
602  GtkShadowType shadow, GtkStyle *style,
603  const QString &pmKey)
604 {
605  if (!rect.isValid())
606  return;
607  QPixmap cache;
608  QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) % pmKey;
609  if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
611  pixmap,
612  state,
613  shadow,
614  NULL,
615  gtkWidget,
616  part, 0, 0,
617  rect.width(),
618  rect.height()));
619  if (m_usePixmapCache)
620  QPixmapCache::insert(pixmapName, cache);
621  }
622  m_painter->drawPixmap(rect.topLeft(), cache);
623 }
624 
625 void QGtkPainter::paintExtention(GtkWidget *gtkWidget,
626  const gchar *part, const QRect &rect,
627  GtkStateType state, GtkShadowType shadow,
628  GtkPositionType gap_pos, GtkStyle *style)
629 {
630  if (!rect.isValid())
631  return;
632 
633  QPixmap cache;
634  QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget)
635  % HexString<uchar>(gap_pos);
636 
637  if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
638  DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_extension (style, pixmap, state, shadow,
639  NULL, gtkWidget,
640  (gchar*)part, 0, 0,
641  rect.width(),
642  rect.height(),
643  gap_pos));
644  if (m_usePixmapCache)
645  QPixmapCache::insert(pixmapName, cache);
646  }
647 
648  m_painter->drawPixmap(rect.topLeft(), cache);
649 }
650 
651 void QGtkPainter::paintOption(GtkWidget *gtkWidget, const QRect &radiorect,
652  GtkStateType state, GtkShadowType shadow,
653  GtkStyle *style, const QString &detail)
654 
655 {
656  QRect rect = m_cliprect.isValid() ? m_cliprect : radiorect;
657  if (!rect.isValid())
658  return;
659 
660  QPixmap cache;
661  QString pixmapName = uniqueName(detail, state, shadow, rect.size());
662  GdkRectangle gtkCliprect = {0, 0, rect.width(), rect.height()};
663  int xOffset = m_cliprect.isValid() ? radiorect.x() - m_cliprect.x() : 0;
664  int yOffset = m_cliprect.isValid() ? radiorect.y() - m_cliprect.y() : 0;
665  if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
667  state, shadow,
668  &gtkCliprect,
669  gtkWidget,
670  detail.toLatin1(),
671  xOffset, yOffset,
672  radiorect.width(),
673  radiorect.height()));
674 
675  if (m_usePixmapCache)
676  QPixmapCache::insert(pixmapName, cache);
677  }
678 
679  m_painter->drawPixmap(rect.topLeft(), cache);
680 }
681 
682 void QGtkPainter::paintCheckbox(GtkWidget *gtkWidget, const QRect &checkrect,
683  GtkStateType state, GtkShadowType shadow,
684  GtkStyle *style, const QString &detail)
685 
686 {
687  QRect rect = m_cliprect.isValid() ? m_cliprect : checkrect;
688  if (!rect.isValid())
689  return;
690 
691  QPixmap cache;
692  QString pixmapName = uniqueName(detail, state, shadow, rect.size());
693  GdkRectangle gtkCliprect = {0, 0, rect.width(), rect.height()};
694  int xOffset = m_cliprect.isValid() ? checkrect.x() - m_cliprect.x() : 0;
695  int yOffset = m_cliprect.isValid() ? checkrect.y() - m_cliprect.y() : 0;
696  if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) {
698  pixmap,
699  state,
700  shadow,
701  &gtkCliprect,
702  gtkWidget,
703  detail.toLatin1(),
704  xOffset, yOffset,
705  checkrect.width(),
706  checkrect.height()));
707  if (m_usePixmapCache)
708  QPixmapCache::insert(pixmapName, cache);
709  }
710 
711  m_painter->drawPixmap(rect.topLeft(), cache);
712 }
713 
715 
716 #endif
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
#define GTK_GREEN
Definition: qgtkpainter.cpp:72
static int pmKey(const QSize &size, QIcon::Mode mode, QIcon::State state)
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void paintOption(GtkWidget *gtkWidget, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkStyle *style, const QString &detail)
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QPointer< QWidget > widget
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
#define GTK_RED
Definition: qgtkpainter.cpp:71
void paintExpander(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkExpanderStyle expander_state, GtkStyle *style, const QString &pmKey=QString())
void paintFocus(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkStyle *style, const QString &pmKey=QString())
static Ptr_gtk_paint_check gtk_paint_check
Definition: qgtkstyle_p.h:410
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
void paintShadow(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkStyle *style, const QString &pmKey=QString())
void paintHandle(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkOrientation orientation, GtkStyle *style)
void paintFlatBox(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkStyle *style, const QString &=QString())
void paintArrow(GtkWidget *gtkWidget, const gchar *part, const QRect &arrowrect, GtkArrowType arrow_type, GtkStateType state, GtkShadowType shadow, gboolean fill, GtkStyle *style, const QString &pmKey=QString())
QPainter * m_painter
static QPixmap getIcon(const char *iconName, GtkIconSize size=GTK_ICON_SIZE_BUTTON)
void paintResizeGrip(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GdkWindowEdge edge, GtkStyle *style, const QString &pmKey=QString())
#define QT_RED
Definition: qgtkpainter.cpp:61
static Ptr_gdk_pixbuf_get_width gdk_pixbuf_get_width
Definition: qgtkstyle_p.h:461
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
static Ptr_gtk_paint_vline gtk_paint_vline
Definition: qgtkstyle_p.h:425
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
#define DRAW_TO_CACHE(draw_func)
static Ptr_gtk_paint_arrow gtk_paint_arrow
Definition: qgtkstyle_p.h:420
static Ptr_gtk_paint_option gtk_paint_option
Definition: qgtkstyle_p.h:414
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
GtkStateType gtkState(const QStyleOption *option)
static Ptr_gtk_paint_box gtk_paint_box
Definition: qgtkstyle_p.h:411
static Ptr_gtk_paint_handle gtk_paint_handle
Definition: qgtkstyle_p.h:421
void paintSlider(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkStyle *style, GtkOrientation orientation, const QString &pmKey=QString())
void paintBox(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkStyle *style, const QString &pmKey=QString())
void paintExtention(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkPositionType gap_pos, GtkStyle *style)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static QPixmap * find(const QString &key)
static Ptr_gtk_paint_extension gtk_paint_extension
Definition: qgtkstyle_p.h:415
static Ptr_gdk_pixbuf_get_height gdk_pixbuf_get_height
Definition: qgtkstyle_p.h:462
static QString uniqueName(const QString &key, GtkStateType state, GtkShadowType shadow, const QSize &size, GtkWidget *widget=0)
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the width.
Definition: qsize.h:126
static Ptr_gtk_paint_expander gtk_paint_expander
Definition: qgtkstyle_p.h:422
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static Ptr_gtk_icon_set_render_icon gtk_icon_set_render_icon
Definition: qgtkstyle_p.h:406
unsigned __int64 quint64
Definition: qglobal.h:943
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
#define QLS(x)
Definition: qgtkstyle_p.h:77
static Ptr_gtk_paint_focus gtk_paint_focus
Definition: qgtkstyle_p.h:419
void paintCheckbox(GtkWidget *gtkWidget, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkStyle *style, const QString &detail)
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
static Ptr_gdk_pixbuf_get_pixels gdk_pixbuf_get_pixels
Definition: qgtkstyle_p.h:460
static Ptr_gtk_paint_shadow gtk_paint_shadow
Definition: qgtkstyle_p.h:417
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
GtkStyle * getStyle(GtkWidget *gtkWidget)
QPixmap renderTheme(uchar *bdata, uchar *wdata, const QRect &)
Definition: qgtkpainter.cpp:79
static Ptr_gtk_paint_flat_box gtk_paint_flat_box
Definition: qgtkstyle_p.h:413
static Ptr_gtk_paint_box_gap gtk_paint_box_gap
Definition: qgtkstyle_p.h:412
static Ptr_gtk_paint_hline gtk_paint_hline
Definition: qgtkstyle_p.h:426
#define QT_GREEN
Definition: qgtkpainter.cpp:62
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
Definition: qpainter.cpp:7146
#define QT_BLUE
Definition: qgtkpainter.cpp:63
static Ptr_gtk_icon_factory_lookup_default gtk_icon_factory_lookup_default
Definition: qgtkstyle_p.h:403
static Ptr_gtk_paint_resize_grip gtk_paint_resize_grip
Definition: qgtkstyle_p.h:418
#define GTK_ALPHA
Definition: qgtkpainter.cpp:74
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
void paintHline(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkStyle *style, int x1, int x2, int y, const QString &pmKey=QString())
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QRect m_cliprect
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
static GtkStyle * gtkStyle(const QHashableLatin1Literal &path=QHashableLatin1Literal("GtkWindow"))
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
int height() const
Returns the height.
Definition: qsize.h:129
bool m_usePixmapCache
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QGtkPainter(QPainter *painter)
static Ptr_gdk_pixbuf_unref gdk_pixbuf_unref
Definition: qgtkstyle_p.h:467
quint16 index
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
GtkWidget * m_window
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static Ptr_gtk_paint_slider gtk_paint_slider
Definition: qgtkstyle_p.h:416
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
#define QT_ALPHA
Definition: qgtkpainter.cpp:64
#define GTK_BLUE
Definition: qgtkpainter.cpp:73
void paintVline(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkStyle *style, int y1, int y2, int x, const QString &pmKey=QString())
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
void paintBoxGap(GtkWidget *gtkWidget, const gchar *part, const QRect &rect, GtkStateType state, GtkShadowType shadow, GtkPositionType gap_side, gint x, gint width, GtkStyle *style)