aboutsummaryrefslogtreecommitdiff
path: root/src/scrolltext.cpp
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2020-05-22 01:18:24 +0300
committerCrystalwarrior <varsash@gmail.com>2020-05-22 01:18:24 +0300
commitc8e12558cdd3fd0769b81679ad09edf1f29b780f (patch)
tree7dae2225e574c3ee55d6b82a1d2f399db4ace5c0 /src/scrolltext.cpp
parentdfac0652c8eb9bd48ceea7ae755e9c2f7e5cb1a2 (diff)
Clang-ify the code with this styling using Visual Studio Code:
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Stroustrup, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All } (this is the Visual Studio preset with only "BreakBeforeBraces" changed from Allman to Stroustrup)
Diffstat (limited to 'src/scrolltext.cpp')
-rw-r--r--src/scrolltext.cpp43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/scrolltext.cpp b/src/scrolltext.cpp
index 6cf075d2..543f0f62 100644
--- a/src/scrolltext.cpp
+++ b/src/scrolltext.cpp
@@ -1,12 +1,10 @@
#include "scrolltext.h"
-
-ScrollText::ScrollText(QWidget *parent) :
- QWidget(parent), scrollPos(0)
+ScrollText::ScrollText(QWidget *parent) : QWidget(parent), scrollPos(0)
{
staticText.setTextFormat(Qt::PlainText);
-// setFixedHeight(fontMetrics().height()*2); //The theme sets this
+ // setFixedHeight(fontMetrics().height()*2); //The theme sets this
leftMargin = height() / 3;
setSeparator(" --- ");
@@ -44,10 +42,9 @@ void ScrollText::updateText()
timer.stop();
singleTextWidth = fontMetrics().horizontalAdvance(_text);
- scrollEnabled = (singleTextWidth > width() - leftMargin*2);
+ scrollEnabled = (singleTextWidth > width() - leftMargin * 2);
- if(scrollEnabled)
- {
+ if (scrollEnabled) {
scrollPos = -64;
staticText.setText(_text + _separator);
timer.start();
@@ -59,20 +56,18 @@ void ScrollText::updateText()
wholeTextSize = QSize(fontMetrics().horizontalAdvance(staticText.text()), fontMetrics().height());
}
-void ScrollText::paintEvent(QPaintEvent*)
+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())
- {
+ while (x < width()) {
pb.drawStaticText(QPointF(x, (height() - wholeTextSize.height()) / 2), staticText);
x += wholeTextSize.width();
}
@@ -83,20 +78,19 @@ void ScrollText::paintEvent(QPaintEvent*)
pb.drawImage(0, 0, alphaChannel);
pb.setClipRect(0, 0, 15, height());
//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)
+ 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
- {
+ else {
p.drawStaticText(QPointF(leftMargin, (height() - wholeTextSize.height()) / 2), staticText);
}
}
-void ScrollText::resizeEvent(QResizeEvent*)
+void ScrollText::resizeEvent(QResizeEvent *)
{
//When the widget is resized, we need to update the alpha channel.
@@ -104,31 +98,28 @@ 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)
+ 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)
+ 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)
+ for (int y = 1; y < height(); ++y)
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)
+ if (newScrollEnabled != scrollEnabled)
updateText();
}
void ScrollText::timer_timeout()
{
- scrollPos = (scrollPos + 2)
- % wholeTextSize.width();
+ scrollPos = (scrollPos + 2) % wholeTextSize.width();
update();
}