1 module examplewidgets.tabpainter;
2 
3 import qt.config;
4 import qt.core.string;
5 import qt.core.timer;
6 import qt.gui.brush;
7 import qt.gui.color;
8 import qt.gui.event;
9 import qt.gui.image;
10 import qt.gui.painter;
11 import qt.gui.picture;
12 import qt.gui.pixmap;
13 import qt.gui.statictext;
14 import qt.helpers;
15 import qt.widgets.widget;
16 
17 class TabPainter : QWidget
18 {
19     mixin(Q_OBJECT_D);
20 public:
21     /+ explicit +/this(QWidget parent = null)
22     {
23         super(parent);
24 
25         timer = new QTimer(this);
26         connect(timer.signal!"timeout", this.slot!"update");
27         timer.setInterval(100);
28         timer.start();
29 
30         staticText = QStaticText(globalInitVar!QString);
31         staticText.setText(QString("drawStaticText"));
32     }
33 
34 protected:
35     override extern(C++) void paintEvent(QPaintEvent e)
36     {
37         auto p = QPainter(this);
38         drawImage(&p, QString("QPainter(QWidget)"));
39 
40         QImage image = createImage();
41         QPixmap pixmap = createPixmap();
42         QPicture picture = createPicture();
43 
44         p.drawImage(0, 100, image);
45         p.drawPixmap(0, 200, pixmap);
46         p.drawPicture(0, 300, picture);
47     }
48 
49 private:
50     QTimer timer;
51     QStaticText staticText;
52 
53     final void drawImage(QPainter* p, const(QString) title)
54     {
55         import qt.core.datetime;
56         import qt.core.namespace;
57         import qt.core.rect;
58         import qt.gui.textoption;
59 
60         p.drawText(15, 20, title);
61         QBrush brush = QBrush(/+ Qt:: +/qt.core.namespace.GlobalColor.blue);
62         p.setBrush(brush);
63         p.drawRect(15, 30, 100, 30);
64         auto tmp = QRectF(15, 30, 100, 30); auto tmp__1 = QTextOption(/+ Qt:: +/qt.core.namespace.Alignment.AlignCenter); auto tmpx1 = QString("drawRect"); p.drawText(tmp, tmpx1, tmp__1);
65 
66         brush = QBrush(/+ Qt:: +/qt.core.namespace.GlobalColor.green);
67         p.setBrush(brush);
68         p.drawEllipse(140, 30, 100, 30);
69         auto tmp__2 = QRectF(140, 30, 100, 30); auto tmp__3 = QTextOption(/+ Qt:: +/qt.core.namespace.Alignment.AlignCenter); auto tmpx2 = QString("drawEllipse"); p.drawText(tmp__2, tmpx2, tmp__3);
70 
71         p.drawStaticText(270, 30, staticText);
72 
73         auto tmpx3 = "currentDateTime: " ~ QDateTime.currentDateTime().toString(/+ Qt:: +/qt.core.namespace.DateFormat.ISODate); p.drawText(15, 90, tmpx3);
74     }
75     final QImage createImage()
76     {
77         import qt.core.namespace;
78 
79         auto image = QImage(400, 100, QImage.Format.Format_RGBA8888);
80         QColor tmp = QColor(/+ Qt:: +/qt.core.namespace.GlobalColor.white);
81         image.fill(tmp);
82         auto p = QPainter(image.paintDevice);
83         drawImage(&p, QString("QPainter(QImage)"));
84         return image;
85     }
86     final QPixmap createPixmap()
87     {
88         import qt.core.namespace;
89 
90         auto image = QPixmap(400, 100);
91         QColor tmp = QColor(/+ Qt:: +/qt.core.namespace.GlobalColor.gray);
92         image.fill(tmp);
93         auto p = QPainter(image.paintDevice);
94         drawImage(&p, QString("QPainter(QPixmap)"));
95         return image;
96     }
97     final QPicture createPicture()
98     {
99         QPicture image = QPicture(-1);
100         auto p = QPainter(image.paintDevice);
101         drawImage(&p, QString("QPainter(QPicture)"));
102         return image;
103     }
104 }
105