Changeset View
Changeset View
Standalone View
Standalone View
tools/rectangular/kpToolRoundedRectangle.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | 49 | | |||
50 | //--------------------------------------------------------------------- | 50 | //--------------------------------------------------------------------- | ||
51 | 51 | | |||
52 | void kpToolRoundedRectangle::drawRoundedRect(kpImage *image, | 52 | void kpToolRoundedRectangle::drawRoundedRect(kpImage *image, | ||
53 | int x, int y, int width, int height, | 53 | int x, int y, int width, int height, | ||
54 | const kpColor &fcolor, int penWidth, | 54 | const kpColor &fcolor, int penWidth, | ||
55 | const kpColor &bcolor) | 55 | const kpColor &bcolor) | ||
56 | { | 56 | { | ||
57 | if ( (width == 0) || (height == 0) ) | 57 | if ( (width == 0) || (height == 0) ) { | ||
58 | return; | 58 | return; | ||
59 | } | ||||
59 | 60 | | |||
60 | QPainter painter(image); | 61 | QPainter painter(image); | ||
61 | painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased); | 62 | painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased); | ||
62 | 63 | | |||
63 | if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) | 64 | if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) { | ||
64 | penWidth = qMin(width, height) / 2; | 65 | penWidth = qMin(width, height) / 2; | ||
66 | } | ||||
65 | 67 | | |||
66 | painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); | 68 | painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); | ||
67 | 69 | | |||
68 | if ( bcolor.isValid() ) | 70 | if ( bcolor.isValid() ) { | ||
69 | painter.setBrush(QBrush(bcolor.toQColor())); | 71 | painter.setBrush(QBrush(bcolor.toQColor())); | ||
70 | else | 72 | } | ||
73 | else { | ||||
71 | painter.setBrush(Qt::NoBrush); | 74 | painter.setBrush(Qt::NoBrush); | ||
75 | } | ||||
72 | 76 | | |||
73 | int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0; | 77 | int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0; | ||
74 | 78 | | |||
75 | int radius = qMin(width, height) / 4; | 79 | int radius = qMin(width, height) / 4; | ||
76 | 80 | | |||
77 | painter.drawRoundedRect( | 81 | painter.drawRoundedRect( | ||
78 | x + penWidth / 2 + offset, | 82 | x + penWidth / 2 + offset, | ||
79 | y + penWidth / 2 + offset, | 83 | y + penWidth / 2 + offset, | ||
80 | qMax(1, width - penWidth - offset), | 84 | qMax(1, width - penWidth - offset), | ||
81 | qMax(1, height - penWidth - offset), | 85 | qMax(1, height - penWidth - offset), | ||
82 | radius, radius); | 86 | radius, radius); | ||
83 | } | 87 | } | ||
84 | 88 | | |||
85 | //--------------------------------------------------------------------- | 89 | //--------------------------------------------------------------------- |