! \internal Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to generate a gradient image. This gradient image will be used in the \ref draw method. */
| 20629 | generate a gradient image. This gradient image will be used in the \ref draw method. |
| 20630 | */ |
| 20631 | void QCPColorScaleAxisRectPrivate::updateGradientImage() |
| 20632 | { |
| 20633 | if (rect().isEmpty()) |
| 20634 | return; |
| 20635 | |
| 20636 | const QImage::Format format = QImage::Format_ARGB32_Premultiplied; |
| 20637 | int n = mParentColorScale->mGradient.levelCount(); |
| 20638 | int w, h; |
| 20639 | QVector<double> data(n); |
| 20640 | for (int i=0; i<n; ++i) |
| 20641 | data[i] = i; |
| 20642 | if (mParentColorScale->mType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) |
| 20643 | { |
| 20644 | w = n; |
| 20645 | h = rect().height(); |
| 20646 | mGradientImage = QImage(w, h, format); |
| 20647 | QVector<QRgb*> pixels; |
| 20648 | for (int y=0; y<h; ++y) |
| 20649 | pixels.append(reinterpret_cast<QRgb*>(mGradientImage.scanLine(y))); |
| 20650 | mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); |
| 20651 | for (int y=1; y<h; ++y) |
| 20652 | memcpy(pixels.at(y), pixels.first(), size_t(n)*sizeof(QRgb)); |
| 20653 | } else |
| 20654 | { |
| 20655 | w = rect().width(); |
| 20656 | h = n; |
| 20657 | mGradientImage = QImage(w, h, format); |
| 20658 | for (int y=0; y<h; ++y) |
| 20659 | { |
| 20660 | QRgb *pixels = reinterpret_cast<QRgb*>(mGradientImage.scanLine(y)); |
| 20661 | const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); |
| 20662 | for (int x=0; x<w; ++x) |
| 20663 | pixels[x] = lineColor; |
| 20664 | } |
| 20665 | } |
| 20666 | mGradientImageInvalidated = false; |
| 20667 | } |
| 20668 | |
| 20669 | /*! \internal |
| 20670 |