Label.cpp 700 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "Label.h"
  2. #include "Painter.h"
  3. #include <cstdio>
  4. Label::Label(Widget* parent)
  5. : Widget(parent)
  6. {
  7. }
  8. Label::~Label()
  9. {
  10. }
  11. void Label::setText(String&& text)
  12. {
  13. if (text == m_text)
  14. return;
  15. m_text = std::move(text);
  16. update();
  17. }
  18. void Label::paintEvent(PaintEvent&)
  19. {
  20. Painter painter(*this);
  21. painter.fillRect({ 0, 0, width(), height() }, backgroundColor());
  22. if (!text().is_empty())
  23. painter.drawText({ 4, 4, width(), height() }, text(), Painter::TextAlignment::TopLeft, foregroundColor());
  24. }
  25. void Label::mouseMoveEvent(MouseEvent& event)
  26. {
  27. printf("Label::mouseMoveEvent: x=%d, y=%d\n", event.x(), event.y());
  28. Widget::mouseMoveEvent(event);
  29. }