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