PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
/*
* Copyright ( c ) 2018 - 2021 , Andreas Kling < kling @ serenityos . org >
2022-01-04 23:42:26 -03:00
* Copyright ( c ) 2021 - 2022 , Mustafa Quraish < mustafa @ serenityos . org >
2021-12-31 20:52:32 -03:00
* Copyright ( c ) 2021 - 2022 , Tobias Christiansen < tobyase @ serenityos . org >
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# include "MainWidget.h"
# include "CreateNewImageDialog.h"
# include "CreateNewLayerDialog.h"
# include "EditGuideDialog.h"
2021-12-31 18:17:24 -03:00
# include "FilterGallery.h"
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
# include "FilterParams.h"
2022-04-24 05:46:59 -03:00
# include "LevelsDialog.h"
2022-03-08 09:00:04 -03:00
# include "ResizeImageDialog.h"
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
# include <Applications/PixelPaint/PixelPaintWindowGML.h>
2021-09-12 00:40:59 -03:00
# include <LibConfig/Client.h>
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
# include <LibCore/File.h>
# include <LibCore/MimeData.h>
# include <LibFileSystemAccessClient/Client.h>
# include <LibGUI/Application.h>
# include <LibGUI/Clipboard.h>
# include <LibGUI/Icon.h>
2021-11-21 20:49:10 -03:00
# include <LibGUI/ItemListModel.h>
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
# include <LibGUI/Menubar.h>
# include <LibGUI/MessageBox.h>
# include <LibGUI/Toolbar.h>
2021-09-17 14:28:22 -03:00
# include <LibGUI/Window.h>
2022-01-14 15:51:33 -03:00
# include <LibGfx/Rect.h>
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
namespace PixelPaint {
2022-02-09 15:48:56 -03:00
IconBag g_icon_bag ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
MainWidget : : MainWidget ( )
: Widget ( )
{
load_from_gml ( pixel_paint_window_gml ) ;
m_toolbox = find_descendant_of_type_named < PixelPaint : : ToolboxWidget > ( " toolbox " ) ;
m_statusbar = * find_descendant_of_type_named < GUI : : Statusbar > ( " statusbar " ) ;
m_tab_widget = find_descendant_of_type_named < GUI : : TabWidget > ( " tab_widget " ) ;
m_palette_widget = * find_descendant_of_type_named < PixelPaint : : PaletteWidget > ( " palette_widget " ) ;
2022-04-18 10:24:49 -03:00
m_histogram_widget = * find_descendant_of_type_named < PixelPaint : : HistogramWidget > ( " histogram_widget " ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget = * find_descendant_of_type_named < PixelPaint : : VectorscopeWidget > ( " vectorscope_widget " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget = * find_descendant_of_type_named < PixelPaint : : LayerListWidget > ( " layer_list_widget " ) ;
m_layer_list_widget - > on_layer_select = [ & ] ( auto * layer ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_active_layer ( layer ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ;
m_layer_properties_widget = * find_descendant_of_type_named < PixelPaint : : LayerPropertiesWidget > ( " layer_properties_widget " ) ;
m_tool_properties_widget = * find_descendant_of_type_named < PixelPaint : : ToolPropertiesWidget > ( " tool_properties_widget " ) ;
m_toolbox - > on_tool_selection = [ & ] ( auto * tool ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_active_tool ( tool ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_tool_properties_widget - > set_active_tool ( tool ) ;
} ;
2021-09-25 16:59:05 -03:00
m_tab_widget - > on_middle_click = [ & ] ( auto & widget ) {
m_tab_widget - > on_tab_close_click ( widget ) ;
} ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_tab_widget - > on_tab_close_click = [ & ] ( auto & widget ) {
2022-01-07 19:49:18 -03:00
auto & image_editor = verify_cast < PixelPaint : : ImageEditor > ( widget ) ;
if ( image_editor . request_close ( ) ) {
2021-09-17 14:28:22 -03:00
m_tab_widget - > deferred_invoke ( [ & ] {
m_tab_widget - > remove_tab ( image_editor ) ;
2022-01-07 19:52:35 -03:00
if ( m_tab_widget - > children ( ) . size ( ) = = 0 ) {
2022-04-18 10:24:49 -03:00
m_histogram_widget - > set_image ( nullptr ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > set_image ( nullptr ) ;
2021-09-17 14:28:22 -03:00
m_layer_list_widget - > set_image ( nullptr ) ;
m_layer_properties_widget - > set_layer ( nullptr ) ;
2022-01-09 07:59:32 -03:00
m_palette_widget - > set_image_editor ( nullptr ) ;
2022-01-08 20:58:33 -03:00
m_tool_properties_widget - > set_enabled ( false ) ;
set_actions_enabled ( false ) ;
2021-09-17 14:28:22 -03:00
}
} ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
} ;
m_tab_widget - > on_change = [ & ] ( auto & widget ) {
auto & image_editor = verify_cast < PixelPaint : : ImageEditor > ( widget ) ;
2022-01-09 07:59:32 -03:00
m_palette_widget - > set_image_editor ( & image_editor ) ;
2022-04-18 10:24:49 -03:00
m_histogram_widget - > set_image ( & image_editor . image ( ) ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > set_image ( & image_editor . image ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > set_image ( & image_editor . image ( ) ) ;
m_layer_properties_widget - > set_layer ( image_editor . active_layer ( ) ) ;
2022-03-23 16:25:54 -03:00
window ( ) - > set_modified ( image_editor . is_modified ( ) ) ;
image_editor . on_modified_change = [ this ] ( bool modified ) {
window ( ) - > set_modified ( modified ) ;
2022-04-18 10:24:49 -03:00
m_histogram_widget - > image_changed ( ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > image_changed ( ) ;
2022-03-23 16:25:54 -03:00
} ;
2021-09-12 22:36:44 -03:00
if ( auto * active_tool = m_toolbox - > active_tool ( ) )
image_editor . set_active_tool ( active_tool ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_show_guides_action - > set_checked ( image_editor . guide_visibility ( ) ) ;
2021-09-05 07:22:27 -03:00
m_show_rulers_action - > set_checked ( image_editor . ruler_visibility ( ) ) ;
2022-01-08 06:44:19 -03:00
image_editor . on_scale_change ( image_editor . scale ( ) ) ;
2022-08-21 15:33:03 -03:00
image_editor . undo_stack ( ) . on_state_change = [ this ] {
image_editor_did_update_undo_stack ( ) ;
} ;
// Ensure that our undo/redo actions are in sync with the current editor.
image_editor_did_update_undo_stack ( ) ;
} ;
}
void MainWidget : : image_editor_did_update_undo_stack ( )
{
auto * image_editor = current_image_editor ( ) ;
if ( ! image_editor ) {
m_undo_action - > set_enabled ( false ) ;
m_redo_action - > set_enabled ( false ) ;
return ;
}
auto make_action_text = [ ] ( auto prefix , auto suffix ) {
StringBuilder builder ;
builder . append ( prefix ) ;
if ( suffix . has_value ( ) ) {
builder . append ( ' ' ) ;
builder . append ( suffix . value ( ) ) ;
}
return builder . to_string ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ;
2022-08-21 15:33:03 -03:00
auto & undo_stack = image_editor - > undo_stack ( ) ;
m_undo_action - > set_enabled ( undo_stack . can_undo ( ) ) ;
m_redo_action - > set_enabled ( undo_stack . can_redo ( ) ) ;
m_undo_action - > set_text ( make_action_text ( " &Undo " sv , undo_stack . undo_action_text ( ) ) ) ;
m_redo_action - > set_text ( make_action_text ( " &Redo " sv , undo_stack . redo_action_text ( ) ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
2021-11-21 20:49:10 -03:00
// Note: Update these together! v
2022-04-01 14:58:27 -03:00
static Vector < String > const s_suggested_zoom_levels { " 25% " , " 50% " , " 100% " , " 200% " , " 300% " , " 400% " , " 800% " , " 1600% " , " Fit to width " , " Fit to height " , " Fit entire image " } ;
2021-11-21 20:49:10 -03:00
static constexpr int s_zoom_level_fit_width = 8 ;
static constexpr int s_zoom_level_fit_height = 9 ;
static constexpr int s_zoom_level_fit_image = 10 ;
// Note: Update these together! ^
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
void MainWidget : : initialize_menubar ( GUI : : Window & window )
{
auto & file_menu = window . add_menu ( " &File " ) ;
m_new_image_action = GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" &New Image... " , { Mod_Ctrl , Key_N } , g_icon_bag . filetype_pixelpaint , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto dialog = PixelPaint : : CreateNewImageDialog : : construct ( & window ) ;
2022-05-13 09:10:27 -03:00
if ( dialog - > exec ( ) = = GUI : : Dialog : : ExecResult : : OK ) {
2021-11-07 07:22:35 -03:00
auto image = PixelPaint : : Image : : try_create_with_size ( dialog - > image_size ( ) ) . release_value_but_fixme_should_propagate_errors ( ) ;
auto bg_layer = PixelPaint : : Layer : : try_create_with_size ( * image , image - > size ( ) , " Background " ) . release_value_but_fixme_should_propagate_errors ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
image - > add_layer ( * bg_layer ) ;
2022-03-07 17:24:05 -03:00
bg_layer - > content_bitmap ( ) . fill ( Color : : White ) ;
2022-01-04 23:42:26 -03:00
auto & editor = create_new_editor ( * image ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto image_title = dialog - > image_name ( ) . trim_whitespace ( ) ;
2022-01-04 23:42:26 -03:00
editor . set_title ( image_title . is_empty ( ) ? " Untitled " : image_title ) ;
2022-01-04 23:49:52 -03:00
editor . undo_stack ( ) . set_current_unmodified ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-04-18 10:24:49 -03:00
m_histogram_widget - > set_image ( image ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > set_image ( image ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > set_image ( image ) ;
m_layer_list_widget - > set_selected_layer ( bg_layer ) ;
}
} ) ;
2021-11-26 17:04:12 -03:00
m_new_image_from_clipboard_action = GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" &New Image from Clipboard " , { Mod_Ctrl | Mod_Shift , Key_V } , g_icon_bag . new_clipboard , [ & ] ( auto & ) {
2021-11-26 17:09:22 -03:00
create_image_from_clipboard ( ) ;
2021-11-26 17:04:12 -03:00
} ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_open_image_action = GUI : : CommonActions : : make_open_action ( [ & ] ( auto & ) {
2022-01-16 06:30:06 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_open_file ( & window ) ;
if ( response . is_error ( ) )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2022-01-16 06:30:06 -03:00
open_image ( response . value ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
m_save_image_as_action = GUI : : CommonActions : : make_save_as_action ( [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > save_project_as ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
2022-01-04 13:48:49 -03:00
m_save_image_action = GUI : : CommonActions : : make_save_action ( [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > save_project ( ) ;
2022-01-04 13:48:49 -03:00
} ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
file_menu . add_action ( * m_new_image_action ) ;
2021-11-26 17:04:12 -03:00
file_menu . add_action ( * m_new_image_from_clipboard_action ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
file_menu . add_action ( * m_open_image_action ) ;
2022-01-04 13:48:49 -03:00
file_menu . add_action ( * m_save_image_action ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
file_menu . add_action ( * m_save_image_as_action ) ;
2022-01-08 20:58:33 -03:00
m_export_submenu = file_menu . add_submenu ( " &Export " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-01-08 20:58:33 -03:00
m_export_submenu - > add_action (
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
GUI : : Action : : create (
" As &BMP " , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
2022-07-16 04:42:26 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_save_file ( & window , editor - > title ( ) , " bmp " ) ;
2022-01-16 06:30:06 -03:00
if ( response . is_error ( ) )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2022-07-11 14:32:29 -03:00
auto preserve_alpha_channel = GUI : : MessageBox : : show ( & window , " Do you wish to preserve transparency? " sv , " Preserve transparency? " sv , GUI : : MessageBox : : Type : : Question , GUI : : MessageBox : : InputType : : YesNo ) ;
2022-05-13 09:10:27 -03:00
auto result = editor - > image ( ) . export_bmp_to_file ( response . value ( ) , preserve_alpha_channel = = GUI : : MessageBox : : ExecResult : : Yes ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( result . is_error ( ) )
GUI : : MessageBox : : show_error ( & window , String : : formatted ( " Export to BMP failed: {} " , result . error ( ) ) ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_export_submenu - > add_action (
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
GUI : : Action : : create (
" As &PNG " , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
2022-01-16 06:30:06 -03:00
// TODO: fix bmp on line below?
2022-07-16 04:42:26 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_save_file ( & window , editor - > title ( ) , " png " ) ;
2022-01-16 06:30:06 -03:00
if ( response . is_error ( ) )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2022-07-11 14:32:29 -03:00
auto preserve_alpha_channel = GUI : : MessageBox : : show ( & window , " Do you wish to preserve transparency? " sv , " Preserve transparency? " sv , GUI : : MessageBox : : Type : : Question , GUI : : MessageBox : : InputType : : YesNo ) ;
2022-05-13 09:10:27 -03:00
auto result = editor - > image ( ) . export_png_to_file ( response . value ( ) , preserve_alpha_channel = = GUI : : MessageBox : : ExecResult : : Yes ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( result . is_error ( ) )
GUI : : MessageBox : : show_error ( & window , String : : formatted ( " Export to PNG failed: {} " , result . error ( ) ) ) ;
} ) ) ;
2022-04-07 09:23:54 -03:00
m_export_submenu - > add_action (
GUI : : Action : : create (
" As &QOI " , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
2022-07-16 04:42:26 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_save_file ( & window , editor - > title ( ) , " qoi " ) ;
2022-04-07 09:23:54 -03:00
if ( response . is_error ( ) )
return ;
auto result = editor - > image ( ) . export_qoi_to_file ( response . value ( ) ) ;
if ( result . is_error ( ) )
GUI : : MessageBox : : show_error ( & window , String : : formatted ( " Export to QOI failed: {} " , result . error ( ) ) ) ;
} ) ) ;
2022-02-09 15:48:56 -03:00
m_export_submenu - > set_icon ( g_icon_bag . file_export ) ;
2022-01-11 01:00:09 -03:00
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
file_menu . add_separator ( ) ;
2022-01-08 20:58:33 -03:00
2022-02-12 21:08:48 -03:00
m_close_image_action = GUI : : Action : : create ( " &Close Image " , { Mod_Ctrl , Key_W } , g_icon_bag . close_image , [ & ] ( auto & ) {
2022-01-08 20:58:33 -03:00
auto * active_widget = m_tab_widget - > active_widget ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( active_widget ) ;
2022-01-08 20:58:33 -03:00
m_tab_widget - > on_tab_close_click ( * active_widget ) ;
} ) ;
file_menu . add_action ( * m_close_image_action ) ;
2021-09-17 14:28:22 -03:00
file_menu . add_action ( GUI : : CommonActions : : make_quit_action ( [ this ] ( auto & ) {
if ( request_close ( ) )
GUI : : Application : : the ( ) - > quit ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu = window . add_menu ( " &Edit " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-03-18 19:36:17 -03:00
m_cut_action = GUI : : CommonActions : : make_cut_action ( [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
if ( ! editor - > active_layer ( ) ) {
dbgln ( " Cannot cut with no active layer selected " ) ;
return ;
}
2022-08-25 15:50:15 -03:00
auto bitmap = editor - > active_layer ( ) - > try_copy_bitmap ( editor - > image ( ) . selection ( ) ) ;
2022-03-18 19:36:17 -03:00
if ( ! bitmap ) {
dbgln ( " try_copy_bitmap() from Layer failed " ) ;
return ;
}
GUI : : Clipboard : : the ( ) . set_bitmap ( * bitmap ) ;
2022-08-25 15:50:15 -03:00
editor - > active_layer ( ) - > erase_selection ( editor - > image ( ) . selection ( ) ) ;
2022-03-18 19:36:17 -03:00
} ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_copy_action = GUI : : CommonActions : : make_copy_action ( [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( ! editor - > active_layer ( ) ) {
dbgln ( " Cannot copy with no active layer selected " ) ;
return ;
}
2022-08-25 15:50:15 -03:00
auto bitmap = editor - > active_layer ( ) - > try_copy_bitmap ( editor - > image ( ) . selection ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( ! bitmap ) {
dbgln ( " try_copy_bitmap() from Layer failed " ) ;
return ;
}
GUI : : Clipboard : : the ( ) . set_bitmap ( * bitmap ) ;
} ) ;
m_copy_merged_action = GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Copy &Merged " , { Mod_Ctrl | Mod_Shift , Key_C } , g_icon_bag . edit_copy , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
2022-08-25 15:50:15 -03:00
auto bitmap = editor - > image ( ) . try_copy_bitmap ( editor - > image ( ) . selection ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( ! bitmap ) {
dbgln ( " try_copy_bitmap() from Image failed " ) ;
return ;
}
GUI : : Clipboard : : the ( ) . set_bitmap ( * bitmap ) ;
} ) ;
m_paste_action = GUI : : CommonActions : : make_paste_action ( [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
2021-11-26 17:09:22 -03:00
if ( ! editor ) {
create_image_from_clipboard ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2021-11-26 17:09:22 -03:00
}
2021-11-20 11:22:01 -03:00
auto bitmap = GUI : : Clipboard : : the ( ) . fetch_data_and_type ( ) . as_bitmap ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( ! bitmap )
return ;
2021-11-07 07:22:35 -03:00
auto layer = PixelPaint : : Layer : : try_create_with_bitmap ( editor - > image ( ) , * bitmap , " Pasted layer " ) . release_value_but_fixme_should_propagate_errors ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . add_layer ( * layer ) ;
editor - > set_active_layer ( layer ) ;
2022-08-25 15:50:15 -03:00
editor - > image ( ) . selection ( ) . clear ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
GUI : : Clipboard : : the ( ) . on_change = [ & ] ( auto & mime_type ) {
m_paste_action - > set_enabled ( mime_type = = " image/x-serenityos " ) ;
} ;
2021-11-20 11:22:01 -03:00
m_paste_action - > set_enabled ( GUI : : Clipboard : : the ( ) . fetch_mime_type ( ) = = " image/x-serenityos " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_undo_action = GUI : : CommonActions : : make_undo_action ( [ & ] ( auto & ) {
if ( auto * editor = current_image_editor ( ) )
editor - > undo ( ) ;
} ) ;
m_redo_action = GUI : : CommonActions : : make_redo_action ( [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > redo ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
2022-03-18 19:35:32 -03:00
m_edit_menu - > add_action ( * m_undo_action ) ;
m_edit_menu - > add_action ( * m_redo_action ) ;
m_edit_menu - > add_separator ( ) ;
2022-03-18 19:36:17 -03:00
m_edit_menu - > add_action ( * m_cut_action ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_action ( * m_copy_action ) ;
m_edit_menu - > add_action ( * m_copy_merged_action ) ;
m_edit_menu - > add_action ( * m_paste_action ) ;
m_edit_menu - > add_separator ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_action ( GUI : : CommonActions : : make_select_all_action ( [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( ! editor - > active_layer ( ) )
return ;
2022-08-25 15:50:15 -03:00
editor - > image ( ) . selection ( ) . merge ( editor - > active_layer ( ) - > relative_rect ( ) , PixelPaint : : Selection : : MergeMode : : Set ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Clear &Selection " , g_icon_bag . clear_selection , [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
2022-08-25 15:50:15 -03:00
editor - > image ( ) . selection ( ) . clear ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_separator ( ) ;
m_edit_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" S&wap Colors " , { Mod_None , Key_X } , g_icon_bag . swap_colors , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto old_primary_color = editor - > primary_color ( ) ;
editor - > set_primary_color ( editor - > secondary_color ( ) ) ;
editor - > set_secondary_color ( old_primary_color ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" &Default Colors " , { Mod_None , Key_D } , g_icon_bag . default_colors , [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_primary_color ( Color : : Black ) ;
editor - > set_secondary_color ( Color : : White ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_action ( GUI : : Action : : create (
2022-02-12 21:08:48 -03:00
" &Load Color Palette " , g_icon_bag . load_color_palette , [ & ] ( auto & ) {
2022-01-16 06:30:06 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_open_file ( & window , " Load Color Palette " ) ;
if ( response . is_error ( ) )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2022-01-16 06:30:06 -03:00
auto result = PixelPaint : : PaletteWidget : : load_palette_file ( * response . value ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( result . is_error ( ) ) {
GUI : : MessageBox : : show_error ( & window , String : : formatted ( " Loading color palette failed: {} " , result . error ( ) ) ) ;
return ;
}
m_palette_widget - > display_color_list ( result . value ( ) ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_edit_menu - > add_action ( GUI : : Action : : create (
2022-02-12 21:08:48 -03:00
" Sa&ve Color Palette " , g_icon_bag . save_color_palette , [ & ] ( auto & ) {
2022-01-16 06:30:06 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_save_file ( & window , " untitled " , " palette " ) ;
if ( response . is_error ( ) )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2022-01-16 06:30:06 -03:00
auto result = PixelPaint : : PaletteWidget : : save_palette_file ( m_palette_widget - > colors ( ) , * response . value ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( result . is_error ( ) )
GUI : : MessageBox : : show_error ( & window , String : : formatted ( " Writing color palette failed: {} " , result . error ( ) ) ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_view_menu = window . add_menu ( " &View " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_zoom_in_action = GUI : : CommonActions : : make_zoom_in_action (
[ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > scale_by ( 0.1f ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
m_zoom_out_action = GUI : : CommonActions : : make_zoom_out_action (
[ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > scale_by ( - 0.1f ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
m_reset_zoom_action = GUI : : CommonActions : : make_reset_zoom_action (
[ & ] ( auto & ) {
2022-01-08 06:44:19 -03:00
if ( auto * editor = current_image_editor ( ) )
editor - > reset_view ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
m_add_guide_action = GUI : : Action : : create (
2022-02-12 21:08:48 -03:00
" &Add Guide " , g_icon_bag . add_guide , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto dialog = PixelPaint : : EditGuideDialog : : construct ( & window ) ;
2022-05-13 09:10:27 -03:00
if ( dialog - > exec ( ) ! = GUI : : Dialog : : ExecResult : : OK )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto offset = dialog - > offset_as_pixel ( * editor ) ;
if ( ! offset . has_value ( ) )
return ;
editor - > add_guide ( PixelPaint : : Guide : : construct ( dialog - > orientation ( ) , offset . value ( ) ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
// Save this so other methods can use it
m_show_guides_action = GUI : : Action : : create_checkable (
2021-09-12 22:50:46 -03:00
" Show &Guides " , [ & ] ( auto & action ) {
2022-07-11 14:32:29 -03:00
Config : : write_bool ( " PixelPaint " sv , " Guides " sv , " Show " sv , action . is_checked ( ) ) ;
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_guide_visibility ( action . is_checked ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ;
2022-07-11 14:32:29 -03:00
m_show_guides_action - > set_checked ( Config : : read_bool ( " PixelPaint " sv , " Guides " sv , " Show " sv , true ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-01-08 20:58:33 -03:00
m_view_menu - > add_action ( * m_zoom_in_action ) ;
m_view_menu - > add_action ( * m_zoom_out_action ) ;
m_view_menu - > add_action ( * m_reset_zoom_action ) ;
m_view_menu - > add_action ( GUI : : Action : : create (
2022-08-23 20:26:06 -03:00
" Fit Image To &View " , g_icon_bag . fit_image_to_view , [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > fit_image_to_view ( ) ;
2021-09-07 15:14:18 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_view_menu - > add_separator ( ) ;
m_view_menu - > add_action ( * m_add_guide_action ) ;
m_view_menu - > add_action ( * m_show_guides_action ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-01-08 20:58:33 -03:00
m_view_menu - > add_action ( GUI : : Action : : create (
2022-02-12 21:08:48 -03:00
" &Clear Guides " , g_icon_bag . clear_guides , [ & ] ( auto & ) {
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > clear_guides ( ) ;
2021-09-10 12:41:28 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_view_menu - > add_separator ( ) ;
2021-09-11 00:12:25 -03:00
auto show_pixel_grid_action = GUI : : Action : : create_checkable (
2021-09-12 22:50:46 -03:00
" Show &Pixel Grid " , [ & ] ( auto & action ) {
2022-07-11 14:32:29 -03:00
Config : : write_bool ( " PixelPaint " sv , " PixelGrid " sv , " Show " sv , action . is_checked ( ) ) ;
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_pixel_grid_visibility ( action . is_checked ( ) ) ;
2021-09-11 00:12:25 -03:00
} ) ;
2022-07-11 14:32:29 -03:00
show_pixel_grid_action - > set_checked ( Config : : read_bool ( " PixelPaint " sv , " PixelGrid " sv , " Show " sv , true ) ) ;
2022-01-08 20:58:33 -03:00
m_view_menu - > add_action ( * show_pixel_grid_action ) ;
2021-09-10 12:41:28 -03:00
2021-09-05 07:22:27 -03:00
m_show_rulers_action = GUI : : Action : : create_checkable (
2021-09-12 22:50:46 -03:00
" Show R&ulers " , { Mod_Ctrl , Key_R } , [ & ] ( auto & action ) {
2022-07-11 14:32:29 -03:00
Config : : write_bool ( " PixelPaint " sv , " Rulers " sv , " Show " sv , action . is_checked ( ) ) ;
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_ruler_visibility ( action . is_checked ( ) ) ;
2021-09-05 07:22:27 -03:00
} ) ;
2022-07-11 14:32:29 -03:00
m_show_rulers_action - > set_checked ( Config : : read_bool ( " PixelPaint " sv , " Rulers " sv , " Show " sv , true ) ) ;
2022-01-08 20:58:33 -03:00
m_view_menu - > add_action ( * m_show_rulers_action ) ;
2021-09-05 07:22:27 -03:00
2021-11-19 13:26:49 -03:00
m_show_active_layer_boundary_action = GUI : : Action : : create_checkable (
" Show Active Layer &Boundary " , [ & ] ( auto & action ) {
2022-07-11 14:32:29 -03:00
Config : : write_bool ( " PixelPaint " sv , " ImageEditor " sv , " ShowActiveLayerBoundary " sv , action . is_checked ( ) ) ;
2022-01-08 21:15:10 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
editor - > set_show_active_layer_boundary ( action . is_checked ( ) ) ;
2021-11-19 13:26:49 -03:00
} ) ;
2022-07-11 14:32:29 -03:00
m_show_active_layer_boundary_action - > set_checked ( Config : : read_bool ( " PixelPaint " sv , " ImageEditor " sv , " ShowActiveLayerBoundary " sv , true ) ) ;
2022-01-08 20:58:33 -03:00
m_view_menu - > add_action ( * m_show_active_layer_boundary_action ) ;
2021-11-19 13:26:49 -03:00
2022-01-08 20:58:33 -03:00
m_tool_menu = window . add_menu ( " &Tool " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_toolbox - > for_each_tool ( [ & ] ( auto & tool ) {
if ( tool . action ( ) )
2022-01-08 20:58:33 -03:00
m_tool_menu - > add_action ( * tool . action ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return IterationDecision : : Continue ;
} ) ;
2022-01-08 20:58:33 -03:00
m_image_menu = window . add_menu ( " &Image " ) ;
m_image_menu - > add_action ( GUI : : Action : : create (
2022-08-22 14:29:27 -03:00
" Flip Image &Vertically " , g_icon_bag . edit_flip_vertical , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . flip ( Gfx : : Orientation : : Vertical ) ;
2022-08-22 14:08:00 -03:00
editor - > did_complete_action ( " Flip Image Vertically " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_image_menu - > add_action ( GUI : : Action : : create (
2022-08-22 14:29:27 -03:00
" Flip Image &Horizontally " , g_icon_bag . edit_flip_horizontal , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . flip ( Gfx : : Orientation : : Horizontal ) ;
2022-08-22 14:08:00 -03:00
editor - > did_complete_action ( " Flip Image Horizontally " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_image_menu - > add_separator ( ) ;
2022-01-03 07:19:05 -03:00
2022-08-22 14:29:27 -03:00
m_image_menu - > add_action ( GUI : : Action : : create ( " Rotate Image &Counterclockwise " , { Mod_Ctrl | Mod_Shift , Key_LessThan } , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/edit-rotate-ccw.png " sv ) . release_value_but_fixme_should_propagate_errors ( ) ,
2022-01-03 07:19:05 -03:00
[ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . rotate ( Gfx : : RotationDirection : : CounterClockwise ) ;
2022-08-22 14:08:00 -03:00
editor - > did_complete_action ( " Rotate Image Counterclockwise " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-03 07:19:05 -03:00
2022-08-22 14:29:27 -03:00
m_image_menu - > add_action ( GUI : : Action : : create ( " Rotate Image Clock&wise " , { Mod_Ctrl | Mod_Shift , Key_GreaterThan } , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/edit-rotate-cw.png " sv ) . release_value_but_fixme_should_propagate_errors ( ) ,
2022-01-03 07:19:05 -03:00
[ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . rotate ( Gfx : : RotationDirection : : Clockwise ) ;
2022-08-22 14:08:00 -03:00
editor - > did_complete_action ( " Rotate Image Clockwise " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_image_menu - > add_separator ( ) ;
2022-03-08 09:00:04 -03:00
m_image_menu - > add_action ( GUI : : Action : : create (
" &Resize Image... " , { Mod_Ctrl | Mod_Shift , Key_R } , g_icon_bag . resize_image , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto dialog = PixelPaint : : ResizeImageDialog : : construct ( editor - > image ( ) . size ( ) , & window ) ;
2022-08-22 14:08:00 -03:00
if ( dialog - > exec ( ) = = GUI : : Dialog : : ExecResult : : OK ) {
2022-03-08 09:00:04 -03:00
editor - > image ( ) . resize ( dialog - > desired_size ( ) , dialog - > scaling_mode ( ) ) ;
2022-08-22 14:08:00 -03:00
editor - > did_complete_action ( " Resize Image " sv ) ;
}
2022-03-08 09:00:04 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_image_menu - > add_action ( GUI : : Action : : create (
2022-08-22 14:29:27 -03:00
" &Crop Image to Selection " , g_icon_bag . crop , [ & ] ( auto & ) {
2021-09-02 22:09:04 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
2021-09-02 22:09:04 -03:00
// FIXME: disable this action if there is no selection
2022-08-25 15:50:15 -03:00
if ( editor - > image ( ) . selection ( ) . is_empty ( ) )
2021-09-02 22:09:04 -03:00
return ;
2022-08-25 15:50:15 -03:00
auto crop_rect = editor - > image ( ) . rect ( ) . intersected ( editor - > image ( ) . selection ( ) . bounding_rect ( ) ) ;
2021-09-02 22:09:04 -03:00
editor - > image ( ) . crop ( crop_rect ) ;
2022-08-25 15:50:15 -03:00
editor - > image ( ) . selection ( ) . clear ( ) ;
2022-08-22 14:29:27 -03:00
editor - > did_complete_action ( " Crop Image to Selection " sv ) ;
2021-09-02 22:09:04 -03:00
} ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-08-23 16:33:52 -03:00
m_image_menu - > add_action ( GUI : : Action : : create (
" &Crop Image to Content " , g_icon_bag . crop , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto content_bounding_rect = editor - > image ( ) . nonempty_content_bounding_rect ( ) ;
if ( ! content_bounding_rect . has_value ( ) )
return ;
editor - > image ( ) . crop ( content_bounding_rect . value ( ) ) ;
editor - > did_complete_action ( " Crop Image to Content " sv ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu = window . add_menu ( " &Layer " ) ;
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" New &Layer... " , { Mod_Ctrl | Mod_Shift , Key_N } , g_icon_bag . new_layer , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto dialog = PixelPaint : : CreateNewLayerDialog : : construct ( editor - > image ( ) . size ( ) , & window ) ;
2022-05-13 09:10:27 -03:00
if ( dialog - > exec ( ) = = GUI : : Dialog : : ExecResult : : OK ) {
2021-11-07 07:22:35 -03:00
auto layer_or_error = PixelPaint : : Layer : : try_create_with_size ( editor - > image ( ) , dialog - > layer_size ( ) , dialog - > layer_name ( ) ) ;
if ( layer_or_error . is_error ( ) ) {
GUI : : MessageBox : : show_error ( & window , String : : formatted ( " Unable to create layer with size {} " , dialog - > size ( ) ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
}
2021-11-07 07:22:35 -03:00
editor - > image ( ) . add_layer ( layer_or_error . release_value ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > layers_did_change ( ) ;
2022-08-21 17:41:06 -03:00
editor - > did_complete_action ( " New Layer " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > select_top_layer ( ) ;
}
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_separator ( ) ;
2022-03-07 18:09:07 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-08-23 20:26:06 -03:00
" Add M&ask " , { Mod_Ctrl | Mod_Shift , Key_M } , g_icon_bag . add_mask , [ & ] ( auto & ) {
2022-03-07 18:09:07 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
active_layer - > create_mask ( ) ;
editor - > update ( ) ;
m_layer_list_widget - > repaint ( ) ;
} ) ) ;
m_layer_menu - > add_separator ( ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Select &Previous Layer " , { 0 , Key_PageUp } , g_icon_bag . previous_layer , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > cycle_through_selection ( 1 ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Select &Next Layer " , { 0 , Key_PageDown } , g_icon_bag . next_layer , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > cycle_through_selection ( - 1 ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Select &Top Layer " , { 0 , Key_Home } , g_icon_bag . top_layer , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > select_top_layer ( ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Select B&ottom Layer " , { 0 , Key_End } , g_icon_bag . bottom_layer , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > select_bottom_layer ( ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_separator ( ) ;
m_layer_menu - > add_action ( GUI : : CommonActions : : make_move_to_front_action (
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
[ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
editor - > image ( ) . move_layer_to_front ( * active_layer ) ;
editor - > layers_did_change ( ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : CommonActions : : make_move_to_back_action (
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
[ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
editor - > image ( ) . move_layer_to_back ( * active_layer ) ;
editor - > layers_did_change ( ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_separator ( ) ;
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Move Active Layer &Up " , { Mod_Ctrl , Key_PageUp } , g_icon_bag . active_layer_up , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
editor - > image ( ) . move_layer_up ( * active_layer ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" Move Active Layer &Down " , { Mod_Ctrl , Key_PageDown } , g_icon_bag . active_layer_down , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
editor - > image ( ) . move_layer_down ( * active_layer ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_separator ( ) ;
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-09 15:48:56 -03:00
" &Remove Active Layer " , { Mod_Ctrl , Key_D } , g_icon_bag . delete_layer , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
auto active_layer_index = editor - > image ( ) . index_of ( * active_layer ) ;
editor - > image ( ) . remove_layer ( * active_layer ) ;
if ( editor - > image ( ) . layer_count ( ) ) {
auto & next_active_layer = editor - > image ( ) . layer ( active_layer_index > 0 ? active_layer_index - 1 : 0 ) ;
editor - > set_active_layer ( & next_active_layer ) ;
} else {
2021-11-07 07:22:35 -03:00
auto layer = PixelPaint : : Layer : : try_create_with_size ( editor - > image ( ) , editor - > image ( ) . size ( ) , " Background " ) . release_value_but_fixme_should_propagate_errors ( ) ;
editor - > image ( ) . add_layer ( move ( layer ) ) ;
2021-09-24 16:27:09 -03:00
editor - > layers_did_change ( ) ;
m_layer_list_widget - > select_top_layer ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
} ) ) ;
m_layer_list_widget - > on_context_menu_request = [ & ] ( auto & event ) {
2022-01-08 20:58:33 -03:00
m_layer_menu - > popup ( event . screen_position ( ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_separator ( ) ;
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-08-23 20:26:06 -03:00
" Fl&atten Image " , { Mod_Ctrl , Key_F } , g_icon_bag . flatten_image , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . flatten_all_layers ( ) ;
2022-08-21 15:33:03 -03:00
editor - > did_complete_action ( " Flatten Image " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-12 21:08:48 -03:00
" &Merge Visible " , { Mod_Ctrl , Key_M } , g_icon_bag . merge_visible , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor - > image ( ) . merge_visible_layers ( ) ;
2022-08-21 15:33:03 -03:00
editor - > did_complete_action ( " Merge Visible " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-02-15 01:49:20 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-15 01:51:05 -03:00
" Merge &Active Layer Up " , g_icon_bag . merge_active_layer_up , [ & ] ( auto & ) {
2022-02-15 01:49:20 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
editor - > image ( ) . merge_active_layer_up ( * active_layer ) ;
2022-08-21 15:33:03 -03:00
editor - > did_complete_action ( " Merge Active Layer Up " sv ) ;
2022-02-15 01:49:20 -03:00
} ) ) ;
2022-01-08 20:58:33 -03:00
m_layer_menu - > add_action ( GUI : : Action : : create (
2022-02-15 01:51:05 -03:00
" M&erge Active Layer Down " , { Mod_Ctrl , Key_E } , g_icon_bag . merge_active_layer_down , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
editor - > image ( ) . merge_active_layer_down ( * active_layer ) ;
2022-08-21 15:33:03 -03:00
editor - > did_complete_action ( " Merge Active Layer Down " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ) ) ;
2022-08-22 14:25:54 -03:00
m_layer_menu - > add_separator ( ) ;
m_layer_menu - > add_action ( GUI : : Action : : create (
" Flip Layer &Vertically " , g_icon_bag . edit_flip_vertical , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
active_layer - > flip ( Gfx : : Orientation : : Vertical ) ;
editor - > did_complete_action ( " Flip Layer Vertically " sv ) ;
} ) ) ;
m_layer_menu - > add_action ( GUI : : Action : : create (
" Flip Layer &Horizontally " , g_icon_bag . edit_flip_horizontal , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
active_layer - > flip ( Gfx : : Orientation : : Horizontal ) ;
editor - > did_complete_action ( " Flip Layer Horizontally " sv ) ;
} ) ) ;
m_layer_menu - > add_separator ( ) ;
m_layer_menu - > add_action ( GUI : : Action : : create ( " Rotate Layer &Counterclockwise " , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/edit-rotate-ccw.png " sv ) . release_value_but_fixme_should_propagate_errors ( ) ,
[ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
active_layer - > rotate ( Gfx : : RotationDirection : : CounterClockwise ) ;
editor - > did_complete_action ( " Rotate Layer Counterclockwise " sv ) ;
} ) ) ;
m_layer_menu - > add_action ( GUI : : Action : : create ( " Rotate Layer Clock&wise " , Gfx : : Bitmap : : try_load_from_file ( " /res/icons/16x16/edit-rotate-cw.png " sv ) . release_value_but_fixme_should_propagate_errors ( ) ,
[ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto active_layer = editor - > active_layer ( ) ;
if ( ! active_layer )
return ;
active_layer - > rotate ( Gfx : : RotationDirection : : Clockwise ) ;
editor - > did_complete_action ( " Rotate Layer Clockwise " sv ) ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_filter_menu = window . add_menu ( " &Filter " ) ;
2021-12-31 18:17:24 -03:00
2022-02-09 15:48:56 -03:00
m_filter_menu - > add_action ( GUI : : Action : : create ( " Filter &Gallery " , g_icon_bag . filter , [ & ] ( auto & ) {
2021-12-31 20:42:28 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
2021-12-31 20:42:28 -03:00
auto dialog = PixelPaint : : FilterGallery : : construct ( & window , editor ) ;
2022-05-13 09:10:27 -03:00
if ( dialog - > exec ( ) ! = GUI : : Dialog : : ExecResult : : OK )
2021-12-31 18:17:24 -03:00
return ;
} ) ) ;
2022-01-08 20:58:33 -03:00
m_filter_menu - > add_separator ( ) ;
2022-08-23 20:26:06 -03:00
m_filter_menu - > add_action ( GUI : : Action : : create ( " Generic 5x5 &Convolution " , g_icon_bag . generic_5x5_convolution , [ & ] ( auto & ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( auto * layer = editor - > active_layer ( ) ) {
Gfx : : GenericConvolutionFilter < 5 > filter ;
if ( auto parameters = PixelPaint : : FilterParameters < Gfx : : GenericConvolutionFilter < 5 > > : : get ( & window ) ) {
2022-03-07 17:24:05 -03:00
filter . apply ( layer - > content_bitmap ( ) , layer - > rect ( ) , layer - > content_bitmap ( ) , layer - > rect ( ) , * parameters ) ;
2021-09-12 22:09:07 -03:00
layer - > did_modify_bitmap ( layer - > rect ( ) ) ;
2022-08-21 15:33:03 -03:00
editor - > did_complete_action ( " Generic 5x5 Convolution " sv ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
}
} ) ) ;
auto & help_menu = window . add_menu ( " &Help " ) ;
2022-07-11 14:32:29 -03:00
help_menu . add_action ( GUI : : CommonActions : : make_about_action ( " Pixel Paint " , GUI : : Icon : : default_icon ( " app-pixel-paint " sv ) , & window ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2022-04-24 05:46:59 -03:00
m_levels_dialog_action = GUI : : Action : : create (
" Change &Levels... " , { Mod_Ctrl , Key_L } , g_icon_bag . levels , [ & ] ( auto & ) {
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
auto dialog = PixelPaint : : LevelsDialog : : construct ( & window , editor ) ;
if ( dialog - > exec ( ) ! = GUI : : Dialog : : ExecResult : : OK )
dialog - > revert_possible_changes ( ) ;
} ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
auto & toolbar = * find_descendant_of_type_named < GUI : : Toolbar > ( " toolbar " ) ;
toolbar . add_action ( * m_new_image_action ) ;
toolbar . add_action ( * m_open_image_action ) ;
2022-01-05 00:12:24 -03:00
toolbar . add_action ( * m_save_image_action ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
toolbar . add_separator ( ) ;
2022-03-18 19:36:17 -03:00
toolbar . add_action ( * m_cut_action ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
toolbar . add_action ( * m_copy_action ) ;
toolbar . add_action ( * m_paste_action ) ;
toolbar . add_action ( * m_undo_action ) ;
toolbar . add_action ( * m_redo_action ) ;
toolbar . add_separator ( ) ;
toolbar . add_action ( * m_zoom_in_action ) ;
toolbar . add_action ( * m_zoom_out_action ) ;
toolbar . add_action ( * m_reset_zoom_action ) ;
2022-04-24 05:46:59 -03:00
2021-11-21 20:49:10 -03:00
m_zoom_combobox = toolbar . add < GUI : : ComboBox > ( ) ;
m_zoom_combobox - > set_max_width ( 75 ) ;
m_zoom_combobox - > set_model ( * GUI : : ItemListModel < String > : : create ( s_suggested_zoom_levels ) ) ;
m_zoom_combobox - > on_change = [ this ] ( String const & value , GUI : : ModelIndex const & index ) {
auto * editor = current_image_editor ( ) ;
2022-01-08 21:15:10 -03:00
VERIFY ( editor ) ;
2021-11-21 20:49:10 -03:00
if ( index . is_valid ( ) ) {
switch ( index . row ( ) ) {
case s_zoom_level_fit_width :
editor - > fit_image_to_view ( ImageEditor : : FitType : : Width ) ;
return ;
case s_zoom_level_fit_height :
editor - > fit_image_to_view ( ImageEditor : : FitType : : Height ) ;
return ;
case s_zoom_level_fit_image :
2022-01-21 04:53:49 -03:00
editor - > fit_image_to_view ( ImageEditor : : FitType : : Both ) ;
2021-11-21 20:49:10 -03:00
return ;
}
}
auto zoom_level_optional = value . view ( ) . trim ( " % " sv , TrimMode : : Right ) . to_int ( ) ;
if ( ! zoom_level_optional . has_value ( ) ) {
// Indicate that a parse-error occurred by resetting the text to the current state.
2022-01-08 06:44:19 -03:00
editor - > on_scale_change ( editor - > scale ( ) ) ;
2021-11-21 20:49:10 -03:00
return ;
}
2022-01-08 06:44:19 -03:00
editor - > set_scale ( zoom_level_optional . value ( ) * 1.0f / 100 ) ;
2021-11-21 20:49:10 -03:00
// If the selected zoom level got clamped, or a "fit to …" level was selected,
// there is a chance that the new scale is identical to the old scale.
// In these cases, we need to manually reset the text:
2022-01-08 06:44:19 -03:00
editor - > on_scale_change ( editor - > scale ( ) ) ;
2021-11-21 20:49:10 -03:00
} ;
m_zoom_combobox - > on_return_pressed = [ this ] ( ) {
m_zoom_combobox - > on_change ( m_zoom_combobox - > text ( ) , GUI : : ModelIndex ( ) ) ;
} ;
2022-04-24 05:46:59 -03:00
toolbar . add_separator ( ) ;
toolbar . add_action ( * m_levels_dialog_action ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
2022-01-08 20:58:33 -03:00
void MainWidget : : set_actions_enabled ( bool enabled )
{
m_save_image_action - > set_enabled ( enabled ) ;
m_save_image_as_action - > set_enabled ( enabled ) ;
m_close_image_action - > set_enabled ( enabled ) ;
m_export_submenu - > set_children_actions_enabled ( enabled ) ;
m_edit_menu - > set_children_actions_enabled ( enabled ) ;
m_paste_action - > set_enabled ( true ) ;
m_view_menu - > set_children_actions_enabled ( enabled ) ;
m_layer_menu - > set_children_actions_enabled ( enabled ) ;
m_image_menu - > set_children_actions_enabled ( enabled ) ;
m_tool_menu - > set_children_actions_enabled ( enabled ) ;
m_filter_menu - > set_children_actions_enabled ( enabled ) ;
m_zoom_combobox - > set_enabled ( enabled ) ;
}
2022-01-16 06:30:06 -03:00
void MainWidget : : open_image ( Core : : File & file )
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
{
2022-01-16 06:30:06 -03:00
auto try_load = m_loader . try_load_from_file ( file ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( try_load . is_error ( ) ) {
2022-01-16 06:30:06 -03:00
GUI : : MessageBox : : show_error ( window ( ) , String : : formatted ( " Unable to open file: {}, {} " , file . filename ( ) , try_load . error ( ) ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return ;
}
auto & image = * m_loader . release_image ( ) ;
2022-01-04 23:42:26 -03:00
auto & editor = create_new_editor ( image ) ;
2022-02-03 07:22:35 -03:00
editor . set_loaded_from_image ( m_loader . is_raw_image ( ) ) ;
2022-01-16 06:30:06 -03:00
editor . set_path ( file . filename ( ) ) ;
2022-01-04 22:24:14 -03:00
editor . undo_stack ( ) . set_current_unmodified ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > set_image ( & image ) ;
}
void MainWidget : : create_default_image ( )
{
2021-11-21 11:31:52 -03:00
auto image = Image : : try_create_with_size ( { 510 , 356 } ) . release_value_but_fixme_should_propagate_errors ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
2021-11-07 07:22:35 -03:00
auto bg_layer = Layer : : try_create_with_size ( * image , image - > size ( ) , " Background " ) . release_value_but_fixme_should_propagate_errors ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
image - > add_layer ( * bg_layer ) ;
2022-08-23 16:09:30 -03:00
bg_layer - > content_bitmap ( ) . fill ( Color : : Transparent ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_layer_list_widget - > set_image ( image ) ;
auto & editor = create_new_editor ( * image ) ;
2022-05-02 01:21:16 -03:00
editor . set_title ( " Untitled " ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
editor . set_active_layer ( bg_layer ) ;
2022-01-04 23:49:52 -03:00
editor . undo_stack ( ) . set_current_unmodified ( ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
2021-11-26 17:09:22 -03:00
void MainWidget : : create_image_from_clipboard ( )
{
auto bitmap = GUI : : Clipboard : : the ( ) . fetch_data_and_type ( ) . as_bitmap ( ) ;
if ( ! bitmap ) {
2022-07-11 14:32:29 -03:00
GUI : : MessageBox : : show ( window ( ) , " There is no image in a clipboard to paste. " sv , " PixelPaint " sv , GUI : : MessageBox : : Type : : Warning ) ;
2021-11-26 17:09:22 -03:00
return ;
}
auto image = PixelPaint : : Image : : try_create_with_size ( bitmap - > size ( ) ) . release_value_but_fixme_should_propagate_errors ( ) ;
auto layer = PixelPaint : : Layer : : try_create_with_bitmap ( image , * bitmap , " Pasted layer " ) . release_value_but_fixme_should_propagate_errors ( ) ;
image - > add_layer ( * layer ) ;
2022-01-04 23:42:26 -03:00
auto & editor = create_new_editor ( * image ) ;
editor . set_title ( " Untitled " ) ;
2021-11-26 17:09:22 -03:00
m_layer_list_widget - > set_image ( image ) ;
m_layer_list_widget - > set_selected_layer ( layer ) ;
}
2022-01-04 23:35:55 -03:00
bool MainWidget : : request_close ( )
{
while ( ! m_tab_widget - > children ( ) . is_empty ( ) ) {
2022-01-07 19:49:18 -03:00
auto * editor = current_image_editor ( ) ;
VERIFY ( editor ) ;
if ( ! editor - > request_close ( ) )
2022-01-04 23:35:55 -03:00
return false ;
m_tab_widget - > remove_tab ( * m_tab_widget - > active_widget ( ) ) ;
}
return true ;
}
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
ImageEditor * MainWidget : : current_image_editor ( )
{
if ( ! m_tab_widget - > active_widget ( ) )
return nullptr ;
return verify_cast < PixelPaint : : ImageEditor > ( m_tab_widget - > active_widget ( ) ) ;
}
ImageEditor & MainWidget : : create_new_editor ( NonnullRefPtr < Image > image )
{
auto & image_editor = m_tab_widget - > add_tab < PixelPaint : : ImageEditor > ( " Untitled " , image ) ;
image_editor . on_active_layer_change = [ & ] ( auto * layer ) {
if ( current_image_editor ( ) ! = & image_editor )
return ;
m_layer_list_widget - > set_selected_layer ( layer ) ;
m_layer_properties_widget - > set_layer ( layer ) ;
} ;
2022-01-04 23:42:26 -03:00
image_editor . on_title_change = [ & ] ( auto const & title ) {
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
m_tab_widget - > set_tab_title ( image_editor , title ) ;
} ;
image_editor . on_image_mouse_position_change = [ & ] ( auto const & mouse_position ) {
auto const & image_size = current_image_editor ( ) - > image ( ) . size ( ) ;
auto image_rectangle = Gfx : : IntRect { 0 , 0 , image_size . width ( ) , image_size . height ( ) } ;
if ( image_rectangle . contains ( mouse_position ) ) {
m_statusbar - > set_override_text ( mouse_position . to_string ( ) ) ;
2022-04-18 10:24:49 -03:00
m_histogram_widget - > set_color_at_mouseposition ( current_image_editor ( ) - > image ( ) . color_at ( mouse_position ) ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > set_color_at_mouseposition ( current_image_editor ( ) - > image ( ) . color_at ( mouse_position ) ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} else {
m_statusbar - > set_override_text ( { } ) ;
2022-04-18 10:24:49 -03:00
m_histogram_widget - > set_color_at_mouseposition ( Color : : Transparent ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > set_color_at_mouseposition ( Color : : Transparent ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}
} ;
image_editor . on_leave = [ & ] ( ) {
m_statusbar - > set_override_text ( { } ) ;
2022-04-18 10:24:49 -03:00
m_histogram_widget - > set_color_at_mouseposition ( Color : : Transparent ) ;
2022-08-17 07:18:16 -03:00
m_vectorscope_widget - > set_color_at_mouseposition ( Color : : Transparent ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
} ;
image_editor . on_set_guide_visibility = [ & ] ( bool show_guides ) {
m_show_guides_action - > set_checked ( show_guides ) ;
} ;
2021-09-05 07:22:27 -03:00
image_editor . on_set_ruler_visibility = [ & ] ( bool show_rulers ) {
m_show_rulers_action - > set_checked ( show_rulers ) ;
} ;
2022-01-08 06:44:19 -03:00
image_editor . on_scale_change = [ this ] ( float scale ) {
2021-11-21 20:49:10 -03:00
m_zoom_combobox - > set_text ( String : : formatted ( " {}% " , roundf ( scale * 100 ) ) ) ;
} ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
if ( image - > layer_count ( ) )
image_editor . set_active_layer ( & image - > layer ( 0 ) ) ;
if ( ! m_loader . is_raw_image ( ) ) {
m_loader . json_metadata ( ) . for_each ( [ & ] ( JsonValue const & value ) {
if ( ! value . is_object ( ) )
return ;
auto & json_object = value . as_object ( ) ;
auto orientation_value = json_object . get ( " orientation " sv ) ;
if ( ! orientation_value . is_string ( ) )
return ;
auto offset_value = json_object . get ( " offset " sv ) ;
if ( ! offset_value . is_number ( ) )
return ;
auto orientation_string = orientation_value . as_string ( ) ;
PixelPaint : : Guide : : Orientation orientation ;
if ( orientation_string = = " horizontal " sv )
orientation = PixelPaint : : Guide : : Orientation : : Horizontal ;
else if ( orientation_string = = " vertical " sv )
orientation = PixelPaint : : Guide : : Orientation : : Vertical ;
else
return ;
image_editor . add_guide ( PixelPaint : : Guide : : construct ( orientation , offset_value . to_number < float > ( ) ) ) ;
} ) ;
}
m_tab_widget - > set_active_widget ( & image_editor ) ;
image_editor . set_focus ( true ) ;
2021-09-11 15:36:24 -03:00
image_editor . fit_image_to_view ( ) ;
2022-01-08 20:58:33 -03:00
m_tool_properties_widget - > set_enabled ( true ) ;
set_actions_enabled ( true ) ;
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
return image_editor ;
}
2021-09-06 01:24:12 -03:00
void MainWidget : : drop_event ( GUI : : DropEvent & event )
{
if ( ! event . mime_data ( ) . has_urls ( ) )
return ;
event . accept ( ) ;
if ( event . mime_data ( ) . urls ( ) . is_empty ( ) )
return ;
for ( auto & url : event . mime_data ( ) . urls ( ) ) {
if ( url . protocol ( ) ! = " file " )
continue ;
2022-01-16 06:30:06 -03:00
auto response = FileSystemAccessClient : : Client : : the ( ) . try_request_file ( window ( ) , url . path ( ) , Core : : OpenMode : : ReadOnly ) ;
if ( response . is_error ( ) )
return ;
open_image ( response . value ( ) ) ;
2021-09-06 01:24:12 -03:00
}
}
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole
bunch of lambdas,, and actions etc just being stored in the main
function. This is probably an artifact from back when it was first
created.
Most other applications now have a "MainWidget" class of some sort
which handles setting up all the UI/menubars, etc. More importantly,,
it also lets us handle application-wide events which we were
previously not able to do directly, since the main widget was just
a default GUI::Widget.
This patch moves all the core functionality of the PixelPaint
application into PixelPaint::MainWidget, which is then instantiated
by the main function. There is likely some more refactoring that
would help, but this commit is big enough as it is doing mostly
a direct port.
2021-09-06 01:11:46 -03:00
}