| 29 | } |
| 30 | |
| 31 | void QmitkColorTransferFunctionCanvas::paintEvent(QPaintEvent *) |
| 32 | { |
| 33 | QPainter painter(this); |
| 34 | |
| 35 | // Render gray background |
| 36 | QRect contentsRect = this->contentsRect(); |
| 37 | painter.setPen(Qt::gray); |
| 38 | painter.drawRect(0, 0, contentsRect.width() + 1, contentsRect.height() + 1); |
| 39 | |
| 40 | if (!this->isEnabled()) |
| 41 | return; |
| 42 | |
| 43 | if (m_ColorTransferFunction) |
| 44 | { |
| 45 | for (int x = contentsRect.x(); x < contentsRect.x() + contentsRect.width(); x++) |
| 46 | { |
| 47 | double xVal = m_Min + ((float)x) / contentsRect.width() * (m_Max - m_Min); |
| 48 | QColor col((int)(m_ColorTransferFunction->GetRedValue(xVal) * 255), |
| 49 | (int)(m_ColorTransferFunction->GetGreenValue(xVal) * 255), |
| 50 | (int)(m_ColorTransferFunction->GetBlueValue(xVal) * 255)); |
| 51 | painter.setPen(col); |
| 52 | painter.drawLine(x, 1, x, contentsRect.height()); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // paint title |
| 57 | if (m_Title.size() > 0) |
| 58 | { |
| 59 | painter.setPen(Qt::black); |
| 60 | painter.drawText(QPoint(11, 21), m_Title); |
| 61 | painter.setPen(Qt::white); |
| 62 | painter.drawText(QPoint(10, 20), m_Title); |
| 63 | } |
| 64 | |
| 65 | // paint min and max |
| 66 | QString qs_min = QString::number(m_Min); |
| 67 | QString qs_max = QString::number(m_Max); |
| 68 | |
| 69 | QRect qr_min = painter.fontMetrics().boundingRect(qs_min); |
| 70 | QRect qr_max = painter.fontMetrics().boundingRect(qs_max); |
| 71 | |
| 72 | int y, x; |
| 73 | |
| 74 | y = this->contentsRect().height() - qr_min.height() + 5; |
| 75 | x = 10; |
| 76 | |
| 77 | painter.setPen(Qt::black); |
| 78 | painter.drawText(QPoint(x + 1, y + 1), qs_min); |
| 79 | painter.setPen(Qt::white); |
| 80 | painter.drawText(QPoint(x, y), qs_min); |
| 81 | |
| 82 | y = this->contentsRect().height() - qr_max.height() + 5; |
| 83 | x = this->contentsRect().width() - qr_max.width() - 6; |
| 84 | |
| 85 | painter.setPen(Qt::black); |
| 86 | painter.drawText(QPoint(x, y + 1), qs_max); |
| 87 | painter.setPen(Qt::white); |
| 88 | painter.drawText(QPoint(x, y), qs_max); |
nothing calls this directly
no test coverage detected