-
Notifications
You must be signed in to change notification settings - Fork 1
/
Painter.h
51 lines (46 loc) · 2.68 KB
/
Painter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef PAINTER_H
#define PAINTER_H
namespace Painter
{
inline void drawStretched(QPainter &painter, const QPixmap &source, const QRect &dstRect)
{
QSize corner((source.width() - 1) / 2, (source.height() - 1) / 2);
// Top left corner
painter.drawPixmap(dstRect.x(), dstRect.y(), corner.width(), corner.height(),
source,
0, 0, corner.width(), corner.height());
// Left edge
painter.drawPixmap(dstRect.x(), dstRect.y()+corner.height(), corner.width(), dstRect.height()-corner.height()*2,
source,
0, corner.height(), corner.width(), 1);
// Bottom left corner
painter.drawPixmap(dstRect.x(), dstRect.y()+dstRect.height()-corner.height(), corner.width(), corner.height(),
source,
0, source.height()-corner.height(), corner.width(), corner.height());
// Top edge
painter.drawPixmap(dstRect.x()+corner.width(), dstRect.y(), dstRect.width()-corner.width()*2, corner.height(),
source,
corner.width(), 0, 1, corner.height());
// Center
painter.drawPixmap(dstRect.x()+corner.width(), dstRect.y()+corner.height(), dstRect.width()-corner.width()*2, dstRect.height()-corner.height()*2,
source,
corner.width(), corner.height(), 1, 1);
// Bottom edge
painter.drawPixmap(dstRect.x()+corner.width(), dstRect.y()+dstRect.height()-corner.height(), dstRect.width()-corner.width()*2, corner.height(),
source,
corner.width(), source.height()-corner.height(), 1, corner.height());
// Top right corner
painter.drawPixmap(dstRect.x()+dstRect.width()-corner.width(), dstRect.y(), corner.width(), corner.height(),
source,
source.width()-corner.width(), 0, corner.width(), corner.height());
// Right edge
painter.drawPixmap(dstRect.x()+dstRect.width()-corner.width(), dstRect.y()+corner.height(), corner.width(), dstRect.height()-corner.height()*2,
source,
source.width()-corner.width(), corner.height(), corner.width(), 1);
// Bottom right corner
painter.drawPixmap(dstRect.x()+dstRect.width()-corner.width(), dstRect.y()+dstRect.height()-corner.height(), corner.width(), corner.height(),
source,
source.width()-corner.width(), source.height()-corner.height(), corner.width(), corner.height());
}
}
#endif // PAINTER_H