ImageViewer: Make arrow key shortcuts work

The user can now navigate to the previous and next image using the
left and right arrow keys respectively. These shortcuts were
previously not working.
This commit is contained in:
Tim Ledbetter 2023-01-28 21:18:33 +00:00 committed by Sam Atkins
parent 2a32f8ad42
commit b983dc8807
4 changed files with 51 additions and 4 deletions

View file

@ -7,6 +7,7 @@ serenity_component(
set(SOURCES
main.cpp
MainWidget.cpp
ViewWidget.cpp
)

View file

@ -0,0 +1,23 @@
/*
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "MainWidget.h"
namespace ImageViewer {
MainWidget::MainWidget()
{
set_fill_with_background_color(true);
set_layout<GUI::VerticalBoxLayout>();
layout()->set_spacing(2);
}
void MainWidget::keydown_event(GUI::KeyEvent& event)
{
event.ignore();
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Widget.h>
namespace ImageViewer {
class MainWidget final : public GUI::Widget {
C_OBJECT(MainWidget)
public:
virtual ~MainWidget() override = default;
private:
MainWidget();
virtual void keydown_event(GUI::KeyEvent& event) final;
};
}

View file

@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "MainWidget.h"
#include "ViewWidget.h"
#include <AK/URL.h>
#include <LibCore/ArgsParser.h>
@ -56,10 +57,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
window->set_title("Image Viewer");
auto root_widget = TRY(window->set_main_widget<GUI::Widget>());
root_widget->set_fill_with_background_color(true);
root_widget->set_layout<GUI::VerticalBoxLayout>();
root_widget->layout()->set_spacing(2);
auto root_widget = TRY(window->set_main_widget<MainWidget>());
auto toolbar_container = TRY(root_widget->try_add<GUI::ToolbarContainer>());
auto main_toolbar = TRY(toolbar_container->try_add<GUI::Toolbar>());