mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
Screenshot: Add graphical frontend to shot
Co-authored-by: cubiclove <7754483+cubiclove@users.noreply.github.com>
This commit is contained in:
4
Base/res/apps/Screenshot.af
Normal file
4
Base/res/apps/Screenshot.af
Normal file
@@ -0,0 +1,4 @@
|
||||
[App]
|
||||
Name=&Screenshot
|
||||
Executable=/bin/Screenshot
|
||||
Category=&Utilities
|
||||
@@ -1,4 +1,4 @@
|
||||
[App]
|
||||
Name=&Space Analyzer
|
||||
Name=Space Ana&lyzer
|
||||
Executable=/bin/SpaceAnalyzer
|
||||
Category=&Utilities
|
||||
|
||||
BIN
Base/res/icons/16x16/app-screenshot.png
Normal file
BIN
Base/res/icons/16x16/app-screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 297 B |
BIN
Base/res/icons/32x32/app-screenshot.png
Normal file
BIN
Base/res/icons/32x32/app-screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 414 B |
@@ -35,6 +35,7 @@ add_subdirectory(Piano)
|
||||
add_subdirectory(PixelPaint)
|
||||
add_subdirectory(Presenter)
|
||||
add_subdirectory(Run)
|
||||
add_subdirectory(Screenshot)
|
||||
add_subdirectory(Settings)
|
||||
add_subdirectory(SoundPlayer)
|
||||
add_subdirectory(SpaceAnalyzer)
|
||||
|
||||
16
Userland/Applications/Screenshot/CMakeLists.txt
Normal file
16
Userland/Applications/Screenshot/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
serenity_component(
|
||||
Screenshot
|
||||
RECOMMENDED
|
||||
TARGETS Screenshot
|
||||
)
|
||||
|
||||
compile_gml(Screenshot.gml ScreenshotGML.cpp)
|
||||
|
||||
set(SOURCES
|
||||
ScreenshotGML.cpp
|
||||
MainWindow.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
serenity_app(Screenshot ICON app-screenshot)
|
||||
target_link_libraries(Screenshot PRIVATE LibCore LibConfig LibGfx LibGUI LibMain)
|
||||
22
Userland/Applications/Screenshot/MainWidget.h
Normal file
22
Userland/Applications/Screenshot/MainWidget.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2024, circl <circl.lastname@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace Screenshot {
|
||||
|
||||
class MainWidget : public GUI::Widget {
|
||||
C_OBJECT(MainWidget)
|
||||
public:
|
||||
MainWidget() = default;
|
||||
static ErrorOr<NonnullRefPtr<MainWidget>> try_create();
|
||||
|
||||
virtual ~MainWidget() override = default;
|
||||
};
|
||||
|
||||
}
|
||||
81
Userland/Applications/Screenshot/MainWindow.cpp
Normal file
81
Userland/Applications/Screenshot/MainWindow.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2024, circl <circl.lastname@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "MainWidget.h"
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibGUI/FilePicker.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
|
||||
namespace Screenshot {
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
auto app_icon = GUI::Icon::default_icon("app-screenshot"sv);
|
||||
|
||||
set_title("Screenshot");
|
||||
set_icon(app_icon.bitmap_for_size(16));
|
||||
resize(300, 150);
|
||||
set_resizable(false);
|
||||
set_minimizable(false);
|
||||
|
||||
auto main_widget = MUST(MainWidget::try_create());
|
||||
set_main_widget(main_widget);
|
||||
|
||||
m_ok_button = *main_widget->find_descendant_of_type_named<GUI::DialogButton>("ok_button");
|
||||
m_ok_button->set_default(true);
|
||||
m_ok_button->on_click = [this](auto) {
|
||||
take_screenshot();
|
||||
};
|
||||
|
||||
m_cancel_button = *main_widget->find_descendant_of_type_named<GUI::DialogButton>("cancel_button");
|
||||
m_cancel_button->on_click = [this](auto) {
|
||||
close();
|
||||
};
|
||||
|
||||
m_browse = *main_widget->find_descendant_of_type_named<GUI::Button>("browse");
|
||||
m_browse->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_browse->on_click = [this](auto) {
|
||||
auto filepath = GUI::FilePicker::get_open_filepath(this, "Save screenshot to...", m_destination->text(), true);
|
||||
|
||||
if (filepath.has_value()) {
|
||||
Config::write_string("Screenshot"sv, "General"sv, "SavePath"sv, filepath.value());
|
||||
m_destination->set_text(filepath.value());
|
||||
m_destination->repaint();
|
||||
}
|
||||
};
|
||||
|
||||
m_selected_area = *main_widget->find_descendant_of_type_named<GUI::RadioButton>("selected_area");
|
||||
|
||||
m_edit_in_pixel_paint = *main_widget->find_descendant_of_type_named<GUI::CheckBox>("edit_in_pixel_paint");
|
||||
m_edit_in_pixel_paint->on_checked = [this](bool is_checked) {
|
||||
m_browse->set_enabled(!is_checked);
|
||||
m_destination->set_enabled(!is_checked);
|
||||
};
|
||||
|
||||
m_destination = *main_widget->find_descendant_of_type_named<GUI::TextBox>("destination");
|
||||
m_destination->set_text(Config::read_string("Screenshot"sv, "General"sv, "SavePath"sv, Core::StandardPaths::pictures_directory()));
|
||||
}
|
||||
|
||||
void MainWindow::take_screenshot()
|
||||
{
|
||||
close();
|
||||
|
||||
Vector<StringView> arguments;
|
||||
|
||||
if (m_selected_area->is_checked())
|
||||
arguments.append("-r"sv);
|
||||
|
||||
if (m_edit_in_pixel_paint->is_checked())
|
||||
arguments.append("-e"sv);
|
||||
|
||||
// FIXME: Place common screenshot code into library and use that
|
||||
MUST(Core::Process::spawn("/bin/shot"sv, arguments, m_destination->text(), Core::Process::KeepAsChild::No));
|
||||
}
|
||||
|
||||
}
|
||||
35
Userland/Applications/Screenshot/MainWindow.h
Normal file
35
Userland/Applications/Screenshot/MainWindow.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024, circl <circl.lastname@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/RadioButton.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/Window.h>
|
||||
|
||||
namespace Screenshot {
|
||||
|
||||
class MainWindow final : public GUI::Window {
|
||||
C_OBJECT(MainWindow)
|
||||
public:
|
||||
virtual ~MainWindow() override = default;
|
||||
|
||||
private:
|
||||
MainWindow();
|
||||
|
||||
void take_screenshot();
|
||||
|
||||
RefPtr<GUI::Button> m_ok_button;
|
||||
RefPtr<GUI::Button> m_cancel_button;
|
||||
RefPtr<GUI::Button> m_browse;
|
||||
RefPtr<GUI::RadioButton> m_selected_area;
|
||||
RefPtr<GUI::CheckBox> m_edit_in_pixel_paint;
|
||||
RefPtr<GUI::TextBox> m_destination;
|
||||
};
|
||||
|
||||
}
|
||||
80
Userland/Applications/Screenshot/Screenshot.gml
Normal file
80
Userland/Applications/Screenshot/Screenshot.gml
Normal file
@@ -0,0 +1,80 @@
|
||||
@Screenshot::MainWidget {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::HorizontalBoxLayout {
|
||||
margins: [6, 4, 4, 4]
|
||||
spacing: 6
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
max_width: 32
|
||||
layout: @GUI::VerticalBoxLayout {}
|
||||
|
||||
@GUI::ImageWidget {
|
||||
bitmap: "/res/icons/32x32/app-screenshot.png"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::VerticalBoxLayout {}
|
||||
|
||||
@GUI::GroupBox {
|
||||
title: "Take screenshot of:"
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
spacing: 0
|
||||
}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "whole_desktop"
|
||||
text: "Whole desktop"
|
||||
checked: true
|
||||
}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "selected_area"
|
||||
text: "Selected area"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [0, 0, 0, 8]
|
||||
}
|
||||
|
||||
@GUI::CheckBox {
|
||||
name: "edit_in_pixel_paint"
|
||||
text: "Edit in Pixel Paint"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::HorizontalBoxLayout {}
|
||||
|
||||
@GUI::TextBox {
|
||||
name: "destination"
|
||||
mode: "DisplayOnly"
|
||||
}
|
||||
|
||||
@GUI::Button {
|
||||
name: "browse"
|
||||
max_width: 22
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::HorizontalBoxLayout {}
|
||||
|
||||
@GUI::Layout::Spacer {}
|
||||
|
||||
@GUI::DialogButton {
|
||||
name: "ok_button"
|
||||
text: "OK"
|
||||
}
|
||||
|
||||
@GUI::DialogButton {
|
||||
name: "cancel_button"
|
||||
text: "Cancel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Userland/Applications/Screenshot/main.cpp
Normal file
25
Userland/Applications/Screenshot/main.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2024, circl <circl.lastname@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::pledge("stdio recvfd sendfd thread cpath rpath wpath unix proc exec"));
|
||||
|
||||
auto app = TRY(GUI::Application::create(arguments));
|
||||
app->set_config_domain("Screenshot"_string);
|
||||
|
||||
auto window = TRY(Screenshot::MainWindow::try_create());
|
||||
|
||||
window->show();
|
||||
|
||||
return app->exec();
|
||||
}
|
||||
Reference in New Issue
Block a user