Vuo  2.1.2
VuoInputEditorIcon.hh
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <QtGui/QIcon>
13 
14 #include "VuoInputEditor.hh"
15 
20 {
21 public:
25  static QPixmap * renderPixmap(void (^render)(QPainter &p), int width=16, int height=16)
26  {
27  if (!render)
28  return NULL;
29 
30  qreal devicePixelRatio = qApp->primaryScreen()->devicePixelRatio();
31  QPixmap *px = new QPixmap(width*devicePixelRatio, height*devicePixelRatio);
32  px->setDevicePixelRatio(devicePixelRatio);
33  px->fill(Qt::transparent);
34 
35  QPainter p(px);
36  p.setRenderHint(QPainter::Antialiasing);
37  render(p);
38 
39  return px;
40  }
41 
45  static QIcon * renderIcon(void (^render)(QPainter &p), int width=16, int height=16)
46  {
47  QPixmap *px = renderPixmap(render, width, height);
48 
49  // https://b33p.net/kosada/node/12462
50  px->setDevicePixelRatio(1);
51 
52  QIcon *icon = new QIcon(*px);
53  delete px;
54 
55  return icon;
56  }
57 
61  static QPixmap *renderErrorPixmap(bool isDark)
62  {
63  const int size = 12;
64  return renderPixmap(^(QPainter &p){
65  p.setPen(QPen(QColor(isDark ? "#a82c2c" : "#dc3e39"), 0));
66  p.setBrush(QColor(isDark ? "#cc433f" : "#ff554e"));
67  QRectF r(0.5, 0.5, size-1, size-1);
68  p.drawEllipse(r);
69  p.setPen(QColor(255,255,255, isDark ? 192 : 255));
70  p.setBrush(Qt::NoBrush);
71  p.setFont(QFont(VuoInputEditor::getDefaultFont().family(), 11, QFont::Bold));
72  p.drawText(r, Qt::AlignCenter, "!");
73  },
74  size, size);
75  }
76 };