MCPcopy Create free account
hub / github.com/IENT/YUView / paintEvent

Method paintEvent

YUViewLib/src/ui/ShowColorFrame.cpp:43–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void ShowColorWidget::paintEvent(QPaintEvent *event)
44{
45 QFrame::paintEvent(event);
46
47 QPainter painter(this);
48 auto fw = this->frameWidth();
49 auto r = this->rect();
50 auto drawRect = QRect(r.left() + fw, r.top() + fw, r.width() - fw * 2, r.height() - fw * 2);
51
52 // Get the min/max values from the color map
53 const auto minVal = this->colMapper.valueRange.min;
54 const auto maxVal = this->colMapper.valueRange.max;
55
56 if (this->renderRangeValues)
57 {
58 // How high is one digit when drawing it?
59 QFontMetrics metrics(this->font());
60 auto h = metrics.size(0, "0").height();
61
62 // Draw two small lines (at the left and at the right)
63 const int lineHeight = 3;
64 int y = drawRect.height() - h;
65 painter.drawLine(drawRect.left(), y, drawRect.left(), y - lineHeight);
66 painter.drawLine(drawRect.right(), y, drawRect.right(), y - lineHeight);
67
68 // Draw the text values left and right
69 painter.drawText(
70 drawRect.left(), y, drawRect.width(), h, Qt::AlignLeft, QString::number(minVal));
71 painter.drawText(
72 drawRect.left(), y, drawRect.width(), h, Qt::AlignRight, QString::number(maxVal));
73 // Draw the middle value
74 auto middleValue = (maxVal - minVal) / 2 + minVal;
75 if (middleValue != minVal && middleValue != maxVal)
76 {
77 // Where (x coordinate) to draw the middle value
78 auto xPos = drawRect.width() / 2;
79 auto drawWidth = drawRect.width();
80 if ((maxVal - minVal) % 2 == 1)
81 {
82 // The difference is uneven. The middle value is not in the exact middle of the interval.
83 auto step = drawRect.width() / (maxVal - minVal);
84 xPos = drawRect.left() + int(step * middleValue);
85 drawWidth = step * 2 * middleValue;
86 }
87 painter.drawLine(xPos, y, xPos, y - lineHeight);
88 painter.drawText(
89 drawRect.left(), y, drawWidth, h, Qt::AlignHCenter, QString::number(middleValue));
90 }
91
92 // Modify the draw rect, so that the actual range is drawn over the values
93 drawRect.setHeight(drawRect.height() - h - lineHeight);
94 }
95
96 if (this->renderRange)
97 {
98 // Split the rect into lines with width of 1 pixel
99 const auto y0 = drawRect.bottom();
100 const auto y1 = drawRect.top();

Callers

nothing calls this directly

Calls 3

getColorMethod · 0.80
grayMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected