2019-01-20 04:49:48 +01:00
|
|
|
#include "GLabel.h"
|
2019-01-19 23:49:56 +01:00
|
|
|
#include <SharedGraphics/Painter.h>
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
GLabel::GLabel(GWidget* parent)
|
|
|
|
|
: GWidget(parent)
|
2018-10-10 16:49:36 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
GLabel::~GLabel()
|
2018-10-10 16:49:36 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
void GLabel::setText(String&& text)
|
2018-10-10 20:06:58 +02:00
|
|
|
{
|
|
|
|
|
if (text == m_text)
|
|
|
|
|
return;
|
2019-01-10 23:19:29 +01:00
|
|
|
m_text = move(text);
|
2018-10-10 20:06:58 +02:00
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
void GLabel::paintEvent(GPaintEvent&)
|
2018-10-10 16:49:36 +02:00
|
|
|
{
|
|
|
|
|
Painter painter(*this);
|
2019-01-13 06:25:30 +01:00
|
|
|
if (fillWithBackgroundColor())
|
|
|
|
|
painter.fill_rect({ 0, 0, width(), height() }, backgroundColor());
|
2018-12-21 02:10:45 +01:00
|
|
|
if (!text().is_empty())
|
2019-01-12 17:02:54 +01:00
|
|
|
painter.draw_text({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
|
2018-10-10 16:49:36 +02:00
|
|
|
}
|