diff options
| author | TrickyLeifa <date.epoch@gmail.com> | 2024-05-15 00:00:17 +0200 |
|---|---|---|
| committer | TrickyLeifa <date.epoch@gmail.com> | 2024-05-15 00:04:16 +0200 |
| commit | c9f52b7223685d2e7fca925594171f94dd8c6e3b (patch) | |
| tree | 740bb32a40da98a4d52836432f59a16b31333900 /src/scrolltext.cpp | |
| parent | 951766666621fa77e257e6b5616fe4ab1eb2a52f (diff) | |
Ported to CMake, ...
* Ported the project to CMake
* Android and Mac support dropped for the time
being.
* Tests, BASS and Discord-RPC are now options
* Restructured and reformated the project.
* Merged `include` and `src`
* Renamed `resource` to `data`
* Renamed various files
* External libraries headers are no longer included in `src`
* Replaced header guards with #pragma once
* Multiple refactors (keywords, headers)
* Added Qt6 compatibility
* Removed various unused functions and headers
* Reworked AOPacket
* When content is passed to AOPacket, it should be ensured that the content is already decoded.
* Encoding/decoding are now static methods.
* Fixed various memory leaks
* Removed animation code for AOImage
* AOImage is always using static images
* Simplified ChatLogPiece
Diffstat (limited to 'src/scrolltext.cpp')
| -rw-r--r-- | src/scrolltext.cpp | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/src/scrolltext.cpp b/src/scrolltext.cpp index b526a8ab..25090a7a 100644 --- a/src/scrolltext.cpp +++ b/src/scrolltext.cpp @@ -1,6 +1,8 @@ #include "scrolltext.h" -ScrollText::ScrollText(QWidget *parent) : QWidget(parent), scrollPos(0) +ScrollText::ScrollText(QWidget *parent) + : QWidget(parent) + , scrollPos(0) { staticText.setTextFormat(Qt::PlainText); @@ -13,7 +15,10 @@ ScrollText::ScrollText(QWidget *parent) : QWidget(parent), scrollPos(0) timer.setInterval(50); } -QString ScrollText::text() const { return _text; } +QString ScrollText::text() const +{ + return _text; +} void ScrollText::setText(QString text) { @@ -22,7 +27,10 @@ void ScrollText::setText(QString text) update(); } -QString ScrollText::separator() const { return _separator; } +QString ScrollText::separator() const +{ + return _separator; +} void ScrollText::setSeparator(QString separator) { @@ -42,39 +50,40 @@ void ScrollText::updateText() scrollEnabled = (singleTextWidth > width() - leftMargin * 2); - if (scrollEnabled) { + if (scrollEnabled) + { scrollPos = -64; staticText.setText(_text + _separator); timer.start(); } else + { staticText.setText(_text); + } staticText.prepare(QTransform(), font()); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) - wholeTextSize = QSize(fontMetrics().horizontalAdvance(staticText.text()), - fontMetrics().height()); + wholeTextSize = QSize(fontMetrics().horizontalAdvance(staticText.text()), fontMetrics().height()); #else - wholeTextSize = QSize(fontMetrics().boundingRect(staticText.text()).width(), - fontMetrics().height()); + wholeTextSize = QSize(fontMetrics().boundingRect(staticText.text()).width(), fontMetrics().height()); #endif - } void ScrollText::paintEvent(QPaintEvent *) { QPainter p(this); - if (scrollEnabled) { + if (scrollEnabled) + { buffer.fill(qRgba(0, 0, 0, 0)); QPainter pb(&buffer); pb.setPen(p.pen()); pb.setFont(p.font()); int x = qMin(-scrollPos, 0) + leftMargin; - while (x < width()) { - pb.drawStaticText(QPointF(x, (height() - wholeTextSize.height()) / 2), - staticText); + while (x < width()) + { + pb.drawStaticText(QPointF(x, (height() - wholeTextSize.height()) / 2), staticText); x += wholeTextSize.width(); } @@ -86,16 +95,17 @@ void ScrollText::paintEvent(QPaintEvent *) // initial situation: don't apply alpha channel in the left half of the // image at all; apply it more and more until scrollPos gets positive if (scrollPos < 0) + { pb.setOpacity(static_cast<qreal>((qMax(-8, scrollPos) + 8) / 8.0)); + } pb.drawImage(0, 0, alphaChannel); // pb.end(); p.drawImage(0, 0, buffer); } - else { - p.drawStaticText( - QPointF(leftMargin, (height() - wholeTextSize.height()) / 2), - staticText); + else + { + p.drawStaticText(QPointF(leftMargin, (height() - wholeTextSize.height()) / 2), staticText); } } @@ -107,25 +117,35 @@ void ScrollText::resizeEvent(QResizeEvent *) buffer = QImage(size(), QImage::Format_ARGB32_Premultiplied); // Create Alpha Channel: - if (width() > 64) { + if (width() > 64) + { // create first scanline QRgb *scanline1 = reinterpret_cast<QRgb *>(alphaChannel.scanLine(0)); for (int x = 1; x < 16; ++x) + { scanline1[x - 1] = scanline1[width() - x] = qRgba(0, 0, 0, x << 4); + } for (int x = 15; x < width() - 15; ++x) + { scanline1[x] = qRgb(0, 0, 0); + } // copy scanline to the other ones for (int y = 1; y < height(); ++y) - memcpy(alphaChannel.scanLine(y), scanline1, - static_cast<uint>(width() * 4)); + { + memcpy(alphaChannel.scanLine(y), scanline1, static_cast<uint>(width() * 4)); + } } else + { alphaChannel.fill(qRgb(0, 0, 0)); + } // Update scrolling state bool newScrollEnabled = (singleTextWidth > width() - leftMargin); if (newScrollEnabled != scrollEnabled) + { updateText(); + } } void ScrollText::timer_timeout() |
