update about dialog
[presencevnc] / test / painting.cpp
1 #include <QtGui>
2 #include <iostream>
3
4 //use this rectangle in source image
5 const int src_xoff = 15;
6 const int src_yoff = 23;
7 const int src_width = 600;
8 const int src_height = 500;
9 const QRect src_rect(src_xoff, src_yoff, src_width, src_height);
10
11
12 class Widget : public QWidget {
13 public:
14         Widget():
15                 QWidget(0)
16         {
17                 msecs = paints = mode = 0;
18                 img = QImage("stripes.png");
19
20                 QTimer *timer = new QTimer(this);
21                 connect(timer, SIGNAL(timeout()),
22                         this, SLOT(repaint()));
23                 timer->start(150);
24
25         }
26 protected:
27         virtual void paintEvent(QPaintEvent*);
28 private:
29         QImage img;
30         int msecs, paints, mode;
31 };
32
33 void Widget::paintEvent(QPaintEvent*)
34 {
35         QPainter painter(this);
36         //painter.setRenderHint(QPainter::SmoothPixmapTransform);
37
38         QTime t;
39         t.start();
40
41         switch(mode) {
42 //scaled (fit to window)
43         case 0: //this is how small updates in 0.6 are done
44                 painter.drawImage(rect(),
45                         img.copy(src_rect)
46                         .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
47                 break;
48         case 1: //fast transformation
49                 painter.drawImage(rect(),
50                         img.copy(src_rect)
51                         .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
52                 break;
53         case 2: //tell drawImage() that no further scaling is required
54         //why different from 1?
55                 painter.drawImage(rect().topLeft(),
56                         img.copy(src_rect)
57                         .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
58                 break;
59         case 3: //avoid scaled()
60                 painter.drawImage(rect(),
61                         img.copy(src_rect));
62                 break;
63         case 4: //avoid copy() and scaled()
64                 painter.drawImage(rect(), img, src_rect);
65                 break;
66
67 // not scaled - repeat preceeding tests with dimensions that just happen to require no transformation
68 // these are all comparable
69         case 5: //this is how small updates in 0.6 are done
70                 painter.drawImage(rect(),
71                         img.copy(rect())
72                         .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
73                 break;
74         case 6: //fast transformation
75                 painter.drawImage(rect(),
76                         img.copy(rect())
77                         .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation));
78                 break;
79         case 7: //tell drawImage() that no further scaling is required
80                 painter.drawImage(rect().topLeft(),
81                         img.copy(rect())
82                         .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
83                 break;
84         case 8: //avoid scaled()
85                 painter.drawImage(rect(),
86                         img.copy(rect()));
87                 break;
88         case 9: //avoid copy() and scaled()
89                 painter.drawImage(rect(), img, rect());
90                 break;
91 //and a few extra
92         case 10:
93                 painter.drawImage(rect().topLeft(), img, rect());
94                 break;
95         case 11:
96                 painter.drawImage(rect().topLeft(), img);
97                 break;
98         case 12:
99                 painter.drawImage(rect().topLeft(),
100                         img.copy(rect()));
101                 break;
102         case 13: //5 with KeepAspectRatio
103                 painter.drawImage(rect(),
104                         img.copy(rect())
105                         .scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
106                 break;
107         }
108
109         msecs += t.elapsed();
110         paints++;
111
112         const int paints_per_mode = 20;
113         const int num_modes = 14;
114
115         if(paints > paints_per_mode) {
116                 std::cout << mode << ":\t" << double(msecs)/paints << " msecs per paint\n";
117                 msecs = paints = 0;
118                 mode++;
119                 if(mode >= num_modes)
120                         close();
121         }
122
123 }
124
125 int main(int argc, char* argv[])
126 {
127         QApplication app(argc, argv);
128
129         Widget w;
130         w.show();
131         
132         return app.exec();
133 }