2019-03-19 00:01:02 +01:00
|
|
|
#include <LibGUI/GMessageBox.h>
|
|
|
|
#include <LibGUI/GBoxLayout.h>
|
|
|
|
#include <LibGUI/GLabel.h>
|
|
|
|
#include <LibGUI/GButton.h>
|
|
|
|
|
2019-04-10 17:01:54 +02:00
|
|
|
GMessageBox::GMessageBox(const String& text, const String& title, CObject* parent)
|
2019-03-19 00:01:02 +01:00
|
|
|
: GDialog(parent)
|
|
|
|
, m_text(text)
|
|
|
|
{
|
|
|
|
set_title(title);
|
|
|
|
build();
|
|
|
|
}
|
|
|
|
|
|
|
|
GMessageBox::~GMessageBox()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GMessageBox::build()
|
|
|
|
{
|
|
|
|
auto* widget = new GWidget;
|
|
|
|
set_main_widget(widget);
|
|
|
|
|
|
|
|
int text_width = widget->font().width(m_text);
|
|
|
|
|
|
|
|
set_rect(x(), y(), text_width + 80, 80);
|
|
|
|
|
|
|
|
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
|
|
|
widget->set_fill_with_background_color(true);
|
|
|
|
|
|
|
|
widget->layout()->set_margins({ 0, 15, 0, 15 });
|
|
|
|
widget->layout()->set_spacing(15);
|
|
|
|
|
|
|
|
auto* label = new GLabel(m_text, widget);
|
|
|
|
label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
|
|
|
label->set_preferred_size({ text_width, 16 });
|
|
|
|
|
|
|
|
auto* button = new GButton(widget);
|
|
|
|
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
2019-03-27 20:47:48 +01:00
|
|
|
button->set_preferred_size({ 100, 20 });
|
2019-03-19 00:01:02 +01:00
|
|
|
button->set_caption("OK");
|
|
|
|
button->on_click = [this] (auto&) {
|
2019-03-20 22:31:21 +01:00
|
|
|
dbgprintf("GMessageBox: OK button clicked\n");
|
2019-03-19 00:01:02 +01:00
|
|
|
done(0);
|
|
|
|
};
|
|
|
|
}
|