GGroupBox.cpp 877 B

12345678910111213141516171819202122232425262728293031
  1. #include <LibGUI/GGroupBox.h>
  2. #include <LibGUI/GPainter.h>
  3. #include <SharedGraphics/StylePainter.h>
  4. GGroupBox::GGroupBox(const String& name, GWidget* parent)
  5. : GWidget(parent)
  6. , m_name(name)
  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::Panel, FrameShadow::Sunken, 1);
  23. Rect text_rect { 4, 0, font().width(m_name) + 6, font().glyph_height() };
  24. painter.fill_rect(text_rect, background_color());
  25. painter.draw_text(text_rect, m_name, TextAlignment::Center, foreground_color());
  26. }