GGroupBox.cpp 1009 B

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