aboutsummaryrefslogtreecommitdiff
path: root/src/aotextboxwidgets.cpp
blob: a6999bebf92598744340346d5b5226176f986827 (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
53
54
55
56
57
58
59
60
61
#include "aotextboxwidgets.h"

AOChatboxLabel::AOChatboxLabel(QWidget *parent)
    : QLabel(parent)
{}

void AOChatboxLabel::setOutlineColor(QColor color)
{
  m_outline_color = color;
}

void AOChatboxLabel::setOutlineWidth(int width)
{
  m_outline_width = width;
}

void AOChatboxLabel::setIsOutlined(bool outlined)
{
  m_outline = outlined;
}

void AOChatboxLabel::setTextColor(QColor color)
{
  m_text_color = color;
}

void AOChatboxLabel::paintEvent(QPaintEvent *event)
{
  if (m_outline)
  {
    QBrush brush;
    QPen pen;
    QPointF baseline(m_outline_width, fontMetrics().height());

    // Set up brush (base text)
    brush.setColor(m_text_color);
    brush.setStyle(Qt::SolidPattern);

    // Set up outline
    pen.setColor(m_outline_color);
    pen.setWidthF(m_outline_width);

    QPainterPath path;
    path.addText(baseline, font(), text());

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    // draw outline
    painter.setPen(pen);
    painter.drawPath(path);
    // remove outline pen, then draw text on top
    painter.setPen(Qt::NoPen);
    painter.setBrush(brush);
    painter.drawPath(path);
  }
  else
  {
    // Use the default renderer
    QLabel::paintEvent(event);
  }
}