GGroupBox.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <LibGUI/GGroupBox.h>
  2. #include <LibGUI/GPainter.h>
  3. #include <LibDraw/StylePainter.h>
  4. GGroupBox::GGroupBox(GWidget* parent)
  5. : GGroupBox({}, parent)
  6. {
  7. }
  8. GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
  9. : GWidget(parent)
  10. , m_title(title)
  11. {
  12. set_fill_with_background_color(true);
  13. set_background_color(Color::WarmGray);
  14. }
  15. GGroupBox::~GGroupBox()
  16. {
  17. }
  18. void GGroupBox::paint_event(GPaintEvent& event)
  19. {
  20. GPainter painter(*this);
  21. painter.add_clip_rect(event.rect());
  22. Rect frame_rect {
  23. 0, font().glyph_height() / 2,
  24. width(), height() - font().glyph_height() / 2
  25. };
  26. StylePainter::paint_frame(painter, frame_rect, FrameShape::Box, FrameShadow::Sunken, 2);
  27. Rect text_rect { 4, 0, font().width(m_title) + 6, font().glyph_height() };
  28. painter.fill_rect(text_rect, background_color());
  29. painter.draw_text(text_rect, m_title, TextAlignment::Center, foreground_color());
  30. }
  31. void GGroupBox::set_title(const StringView& title)
  32. {
  33. if (m_title == title)
  34. return;
  35. m_title = title;
  36. update();
  37. }