aboutsummaryrefslogtreecommitdiff
path: root/src/scrolltext.h
blob: 83b65aa15f5acb4b8c3f6e9052163734d6a96d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once

#include <QDebug>
#include <QPainter>
#include <QStaticText>
#include <QTimer>
#include <QWidget>

class ScrollText : public QWidget
{
  Q_OBJECT

  Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
  Q_PROPERTY(QString separator READ separator WRITE setSeparator NOTIFY separatorChanged)

public:
  explicit ScrollText(QWidget *parent = nullptr);

  QString text() const;
  QString separator() const;

signals:
  void textChanged(QString newText);
  void separatorChanged(QString newSeparator);

public Q_SLOTS:
  void setText(QString text);

  void setSeparator(QString separator);

protected:
  virtual void paintEvent(QPaintEvent *);
  virtual void resizeEvent(QResizeEvent *);

private:
  QString m_text;
  QString _separator;
  QStaticText staticText;
  int singleTextWidth;
  QSize wholeTextSize;
  int leftMargin;
  bool scrollEnabled;
  int scrollPos;
  QImage alphaChannel;
  QImage buffer;
  QTimer timer;

  void updateText();

private Q_SLOTS:
  virtual void timer_timeout();
};