2019-04-10 06:52:15 +03:00
|
|
|
#include <LibGUI/GGroupBox.h>
|
|
|
|
#include <LibGUI/GPainter.h>
|
|
|
|
#include <SharedGraphics/StylePainter.h>
|
|
|
|
|
2019-05-08 15:32:46 +03:00
|
|
|
GGroupBox::GGroupBox(const String& title, GWidget* parent)
|
2019-04-10 06:52:15 +03:00
|
|
|
: GWidget(parent)
|
2019-05-08 15:32:46 +03:00
|
|
|
, m_title(title)
|
2019-04-10 06:52:15 +03:00
|
|
|
{
|
|
|
|
set_fill_with_background_color(true);
|
|
|
|
set_background_color(Color::LightGray);
|
|
|
|
}
|
|
|
|
|
|
|
|
GGroupBox::~GGroupBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GGroupBox::paint_event(GPaintEvent& event)
|
|
|
|
{
|
|
|
|
GPainter painter(*this);
|
|
|
|
painter.add_clip_rect(event.rect());
|
|
|
|
|
|
|
|
Rect frame_rect {
|
|
|
|
0, font().glyph_height() / 2,
|
|
|
|
width(), height() - font().glyph_height() / 2
|
|
|
|
};
|
2019-04-11 15:27:31 +03:00
|
|
|
StylePainter::paint_frame(painter, frame_rect, FrameShape::Box, FrameShadow::Sunken, 2);
|
2019-04-10 06:52:15 +03:00
|
|
|
|
2019-05-08 15:32:46 +03:00
|
|
|
Rect text_rect { 4, 0, font().width(m_title) + 6, font().glyph_height() };
|
2019-04-10 06:52:15 +03:00
|
|
|
painter.fill_rect(text_rect, background_color());
|
2019-05-08 15:32:46 +03:00
|
|
|
painter.draw_text(text_rect, m_title, TextAlignment::Center, foreground_color());
|
2019-04-10 06:52:15 +03:00
|
|
|
}
|
2019-04-19 02:40:25 +03:00
|
|
|
|
2019-05-08 15:32:46 +03:00
|
|
|
void GGroupBox::set_title(const String& title)
|
2019-04-19 02:40:25 +03:00
|
|
|
{
|
2019-05-08 15:32:46 +03:00
|
|
|
if (m_title == title)
|
2019-04-19 02:40:25 +03:00
|
|
|
return;
|
2019-05-08 15:32:46 +03:00
|
|
|
m_title = title;
|
2019-04-19 02:40:25 +03:00
|
|
|
update();
|
|
|
|
}
|