1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

LibGUI: Put all classes in the GUI namespace and remove the leading G

This took me a moment. Welcome to the new world of GUI::Widget! :^)
This commit is contained in:
Andreas Kling 2020-02-02 15:07:41 +01:00
parent 2d39da5405
commit c5bd9d4ed1
337 changed files with 5400 additions and 4816 deletions

View file

@ -29,8 +29,8 @@
#include <LibGUI/GPainter.h>
#include <LibM/math.h>
SampleWidget::SampleWidget(GWidget* parent)
: GFrame(parent)
SampleWidget::SampleWidget(GUI::Widget* parent)
: GUI::Frame(parent)
{
set_frame_shape(FrameShape::Container);
set_frame_shadow(FrameShadow::Sunken);
@ -41,10 +41,10 @@ SampleWidget::~SampleWidget()
{
}
void SampleWidget::paint_event(GPaintEvent& event)
void SampleWidget::paint_event(GUI::PaintEvent& event)
{
GFrame::paint_event(event);
GPainter painter(*this);
GUI::Frame::paint_event(event);
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.fill_rect(frame_inner_rect(), Color::Black);

View file

@ -30,15 +30,15 @@
class ABuffer;
class SampleWidget final : public GFrame {
class SampleWidget final : public GUI::Frame {
C_OBJECT(SampleWidget)
public:
virtual ~SampleWidget() override;
void set_buffer(ABuffer*);
private:
explicit SampleWidget(GWidget* parent);
virtual void paint_event(GPaintEvent&) override;
explicit SampleWidget(GUI::Widget* parent);
virtual void paint_event(GUI::PaintEvent&) override;
RefPtr<ABuffer> m_buffer;
};

View file

@ -32,37 +32,37 @@
#include <LibGUI/GMessageBox.h>
#include <LibM/math.h>
SoundPlayerWidget::SoundPlayerWidget(GWindow& window, NonnullRefPtr<AClientConnection> connection)
SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, NonnullRefPtr<AClientConnection> connection)
: m_window(window)
, m_connection(connection)
, m_manager(connection)
{
set_fill_with_background_color(true);
set_layout(make<GVBoxLayout>());
set_layout(make<GUI::VBoxLayout>());
layout()->set_margins({ 2, 2, 2, 2 });
auto status_widget = GWidget::construct(this);
auto status_widget = GUI::Widget::construct(this);
status_widget->set_fill_with_background_color(true);
status_widget->set_layout(make<GHBoxLayout>());
status_widget->set_layout(make<GUI::HBoxLayout>());
m_elapsed = GLabel::construct(status_widget);
m_elapsed = GUI::Label::construct(status_widget);
m_elapsed->set_frame_shape(FrameShape::Container);
m_elapsed->set_frame_shadow(FrameShadow::Sunken);
m_elapsed->set_frame_thickness(2);
m_elapsed->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
m_elapsed->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_elapsed->set_preferred_size(80, 0);
auto sample_widget_container = GWidget::construct(status_widget.ptr());
sample_widget_container->set_layout(make<GHBoxLayout>());
sample_widget_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
auto sample_widget_container = GUI::Widget::construct(status_widget.ptr());
sample_widget_container->set_layout(make<GUI::HBoxLayout>());
sample_widget_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
m_sample_widget = SampleWidget::construct(sample_widget_container);
m_remaining = GLabel::construct(status_widget);
m_remaining = GUI::Label::construct(status_widget);
m_remaining->set_frame_shape(FrameShape::Container);
m_remaining->set_frame_shadow(FrameShadow::Sunken);
m_remaining->set_frame_thickness(2);
m_remaining->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
m_remaining->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_remaining->set_preferred_size(80, 0);
m_slider = Slider::construct(Orientation::Horizontal, this);
@ -70,32 +70,32 @@ SoundPlayerWidget::SoundPlayerWidget(GWindow& window, NonnullRefPtr<AClientConne
m_slider->set_enabled(false);
m_slider->on_knob_released = [&](int value) { m_manager.seek(denormalize_rate(value)); };
auto control_widget = GWidget::construct(this);
auto control_widget = GUI::Widget::construct(this);
control_widget->set_fill_with_background_color(true);
control_widget->set_layout(make<GHBoxLayout>());
control_widget->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
control_widget->set_layout(make<GUI::HBoxLayout>());
control_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
control_widget->set_preferred_size(0, 30);
control_widget->layout()->set_margins({ 10, 2, 10, 2 });
control_widget->layout()->set_spacing(10);
m_play = GButton::construct(control_widget);
m_play = GUI::Button::construct(control_widget);
m_play->set_icon(*m_pause_icon);
m_play->set_enabled(false);
m_play->on_click = [this](GButton& button) {
m_play->on_click = [this](GUI::Button& button) {
button.set_icon(m_manager.toggle_pause() ? *m_play_icon : *m_pause_icon);
};
m_stop = GButton::construct(control_widget);
m_stop = GUI::Button::construct(control_widget);
m_stop->set_enabled(false);
m_stop->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/stop.png"));
m_stop->on_click = [&](GButton&) { m_manager.stop(); };
m_stop->on_click = [&](GUI::Button&) { m_manager.stop(); };
m_status = GLabel::construct(this);
m_status = GUI::Label::construct(this);
m_status->set_frame_shape(FrameShape::Box);
m_status->set_frame_shadow(FrameShadow::Raised);
m_status->set_frame_thickness(4);
m_status->set_text_alignment(TextAlignment::CenterLeft);
m_status->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_status->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_status->set_preferred_size(0, 18);
m_status->set_text("No file open!");
@ -120,18 +120,18 @@ void SoundPlayerWidget::hide_scope(bool hide)
void SoundPlayerWidget::open_file(String path)
{
if (!path.ends_with(".wav")) {
GMessageBox::show("Selected file is not a \".wav\" file!", "Filetype error", GMessageBox::Type::Error);
GUI::MessageBox::show("Selected file is not a \".wav\" file!", "Filetype error", GUI::MessageBox::Type::Error);
return;
}
OwnPtr<AWavLoader> loader = make<AWavLoader>(path);
if (loader->has_error()) {
GMessageBox::show(
GUI::MessageBox::show(
String::format(
"Failed to load WAV file: %s (%s)",
path.characters(),
loader->error_string()),
"Filetype error", GMessageBox::Type::Error);
"Filetype error", GUI::MessageBox::Type::Error);
return;
}

View file

@ -34,7 +34,7 @@
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
class SoundPlayerWidget final : public GWidget {
class SoundPlayerWidget final : public GUI::Widget {
C_OBJECT(SoundPlayerWidget)
public:
virtual ~SoundPlayerWidget() override;
@ -43,14 +43,14 @@ public:
PlaybackManager& manager() { return m_manager; }
private:
explicit SoundPlayerWidget(GWindow&, NonnullRefPtr<AClientConnection>);
explicit SoundPlayerWidget(GUI::Window&, NonnullRefPtr<AClientConnection>);
void update_position(const int position);
void update_ui();
int normalize_rate(int) const;
int denormalize_rate(int) const;
class Slider final : public GSlider {
class Slider final : public GUI::Slider {
C_OBJECT(Slider)
public:
virtual ~Slider() override;
@ -58,35 +58,35 @@ private:
void set_value(int value)
{
if (!knob_dragging())
GSlider::set_value(value);
GUI::Slider::set_value(value);
}
protected:
Slider(Orientation orientation, GWidget* parent)
: GSlider(orientation, parent)
Slider(Orientation orientation, GUI::Widget* parent)
: GUI::Slider(orientation, parent)
{
}
virtual void mouseup_event(GMouseEvent& event) override
virtual void mouseup_event(GUI::MouseEvent& event) override
{
if (on_knob_released && is_enabled())
on_knob_released(value());
GSlider::mouseup_event(event);
GUI::Slider::mouseup_event(event);
}
};
GWindow& m_window;
GUI::Window& m_window;
NonnullRefPtr<AClientConnection> m_connection;
PlaybackManager m_manager;
float m_sample_ratio;
RefPtr<GLabel> m_status;
RefPtr<GLabel> m_elapsed;
RefPtr<GLabel> m_remaining;
RefPtr<GUI::Label> m_status;
RefPtr<GUI::Label> m_elapsed;
RefPtr<GUI::Label> m_remaining;
RefPtr<Slider> m_slider;
RefPtr<SampleWidget> m_sample_widget;
RefPtr<GraphicsBitmap> m_play_icon { GraphicsBitmap::load_from_file("/res/icons/16x16/play.png") };
RefPtr<GraphicsBitmap> m_pause_icon { GraphicsBitmap::load_from_file("/res/icons/16x16/pause.png") };
RefPtr<GButton> m_play;
RefPtr<GButton> m_stop;
RefPtr<GUI::Button> m_play;
RefPtr<GUI::Button> m_stop;
};

View file

@ -43,7 +43,7 @@ int main(int argc, char** argv)
return 1;
}
GApplication app(argc, argv);
GUI::Application app(argc, argv);
if (pledge("stdio shared_buffer accept rpath unix", nullptr) < 0) {
perror("pledge");
@ -58,14 +58,14 @@ int main(int argc, char** argv)
return 1;
}
auto window = GWindow::construct();
auto window = GUI::Window::construct();
window->set_title("SoundPlayer");
window->set_resizable(false);
window->set_rect(300, 300, 350, 140);
window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/app-sound-player.png"));
auto menubar = make<GMenuBar>();
auto app_menu = GMenu::construct("SoundPlayer");
auto menubar = make<GUI::MenuBar>();
auto app_menu = GUI::Menu::construct("SoundPlayer");
auto player = SoundPlayerWidget::construct(window, audio_client);
if (argc > 1) {
@ -74,27 +74,27 @@ int main(int argc, char** argv)
player->manager().play();
}
auto hide_scope = GAction::create("Hide scope", { Mod_Ctrl, Key_H }, [&](GAction& action) {
auto hide_scope = GUI::Action::create("Hide scope", { Mod_Ctrl, Key_H }, [&](GUI::Action& action) {
action.set_checked(!action.is_checked());
player->hide_scope(action.is_checked());
});
hide_scope->set_checkable(true);
app_menu->add_action(GCommonActions::make_open_action([&](auto&) {
Optional<String> path = GFilePicker::get_open_filepath("Open wav file...");
app_menu->add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<String> path = GUI::FilePicker::get_open_filepath("Open wav file...");
if (path.has_value()) {
player->open_file(path.value());
}
}));
app_menu->add_action(move(hide_scope));
app_menu->add_separator();
app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
app_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) {
app.quit();
}));
auto help_menu = GMenu::construct("Help");
help_menu->add_action(GAction::create("About", [](auto&) {
GAboutDialog::show("SoundPlayer", GraphicsBitmap::load_from_file("/res/icons/32x32/app-sound-player.png"));
auto help_menu = GUI::Menu::construct("Help");
help_menu->add_action(GUI::Action::create("About", [](auto&) {
GUI::AboutDialog::show("SoundPlayer", GraphicsBitmap::load_from_file("/res/icons/32x32/app-sound-player.png"));
}));
menubar->add_menu(move(app_menu));