| 105 | } |
| 106 | |
| 107 | void ScrollText::resizeEvent(QResizeEvent*) |
| 108 | { |
| 109 | // When the widget is resized, we need to update the alpha channel. |
| 110 | |
| 111 | alphaChannel = QImage(size(), QImage::Format_ARGB32_Premultiplied); |
| 112 | buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); |
| 113 | |
| 114 | // Create Alpha Channel: |
| 115 | if (width() > 64) |
| 116 | { |
| 117 | // create first scanline |
| 118 | QRgb *scanline1 = (QRgb*) alphaChannel.scanLine(0); |
| 119 | |
| 120 | for (int x = 1; x < 16; ++x) |
| 121 | { |
| 122 | scanline1[x - 1] = scanline1[width() - x] = qRgba(0, 0, 0, x << 4); |
| 123 | } |
| 124 | |
| 125 | for (int x = 15; x < width() - 15; ++x) |
| 126 | { |
| 127 | scanline1[x] = qRgb(0, 0, 0); |
| 128 | } |
| 129 | |
| 130 | // copy scanline to the other ones |
| 131 | for (int y = 1; y < height(); ++y) |
| 132 | { |
| 133 | memcpy(alphaChannel.scanLine(y), (uchar*) scanline1, width() * 4); |
| 134 | } |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | alphaChannel.fill(qRgb(0, 0, 0)); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | // Update scrolling state |
| 143 | bool newScrollEnabled = (singleTextWidth > width() - leftMargin); |
| 144 | |
| 145 | if (newScrollEnabled != scrollEnabled) |
| 146 | { |
| 147 | updateText(); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void ScrollText::timer_timeout() |
| 152 | { |