mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Spreadsheet: Add toolbar actions to change the cell style
This commit is contained in:
parent
a0598aaef7
commit
5f76ab9836
Notes:
sideshowbarker
2024-07-17 06:37:18 +09:00
Author: https://github.com/marcosantos98 Commit: https://github.com/SerenityOS/serenity/commit/5f76ab9836 Pull-request: https://github.com/SerenityOS/serenity/pull/15304 Reviewed-by: https://github.com/alimpfard
3 changed files with 44 additions and 0 deletions
|
@ -22,6 +22,11 @@ struct ConditionalFormat : public Format {
|
|||
String condition;
|
||||
};
|
||||
|
||||
enum class FormatType {
|
||||
Background = 0,
|
||||
Foreground = 1
|
||||
};
|
||||
|
||||
class ConditionView : public GUI::Widget {
|
||||
C_OBJECT(ConditionView)
|
||||
public:
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/ColorPicker.h>
|
||||
#include <LibGUI/EmojiInputDialog.h>
|
||||
#include <LibGUI/InputBox.h>
|
||||
#include <LibGUI/Label.h>
|
||||
|
@ -250,6 +251,21 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
|
|||
m_undo_action->set_enabled(false);
|
||||
m_redo_action->set_enabled(false);
|
||||
|
||||
m_change_background_color_action = GUI::Action::create(
|
||||
"&Change Background Color", { Mod_Ctrl, Key_B }, Gfx::Bitmap::try_load_from_file("/res/icons/pixelpaint/bucket.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
change_cell_static_color_format(Spreadsheet::FormatType::Background);
|
||||
},
|
||||
window());
|
||||
|
||||
m_change_foreground_color_action = GUI::Action::create(
|
||||
"&Change Foreground Color", { Mod_Ctrl, Key_T }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/text-color.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
change_cell_static_color_format(Spreadsheet::FormatType::Foreground);
|
||||
},
|
||||
window());
|
||||
|
||||
m_change_background_color_action->set_enabled(false);
|
||||
m_change_foreground_color_action->set_enabled(false);
|
||||
|
||||
m_functions_help_action = GUI::Action::create(
|
||||
"&Functions Help", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-help.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
if (auto* worksheet_ptr = current_worksheet_if_available()) {
|
||||
|
@ -274,6 +290,9 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
|
|||
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_change_background_color_action);
|
||||
toolbar.add_action(*m_change_foreground_color_action);
|
||||
|
||||
m_cut_action->set_enabled(false);
|
||||
m_copy_action->set_enabled(false);
|
||||
|
@ -334,6 +353,8 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
|||
m_insert_emoji_action->set_enabled(true);
|
||||
m_current_cell_label->set_enabled(true);
|
||||
m_cell_value_editor->set_enabled(true);
|
||||
m_change_background_color_action->set_enabled(true);
|
||||
m_change_foreground_color_action->set_enabled(true);
|
||||
|
||||
if (selection.size() == 1) {
|
||||
auto& position = selection.first();
|
||||
|
@ -455,6 +476,21 @@ void SpreadsheetWidget::redo()
|
|||
update();
|
||||
}
|
||||
|
||||
void SpreadsheetWidget::change_cell_static_color_format(Spreadsheet::FormatType format_type)
|
||||
{
|
||||
VERIFY(current_worksheet_if_available());
|
||||
|
||||
auto dialog = GUI::ColorPicker::construct(Color::White, window(), "Select Color");
|
||||
if (dialog->exec() == GUI::Dialog::ExecResult::OK) {
|
||||
for (auto& position : current_worksheet_if_available()->selected_cells()) {
|
||||
if (format_type == Spreadsheet::FormatType::Background)
|
||||
current_worksheet_if_available()->at(position)->type_metadata().static_format.background_color = dialog->color();
|
||||
else
|
||||
current_worksheet_if_available()->at(position)->type_metadata().static_format.foreground_color = dialog->color();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpreadsheetWidget::save(Core::File& file)
|
||||
{
|
||||
auto result = m_workbook->write_to_file(file);
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
|
||||
void undo();
|
||||
void redo();
|
||||
void change_cell_static_color_format(Spreadsheet::FormatType);
|
||||
auto& undo_stack() { return m_undo_stack; }
|
||||
|
||||
private:
|
||||
|
@ -92,6 +93,8 @@ private:
|
|||
RefPtr<GUI::Action> m_insert_emoji_action;
|
||||
RefPtr<GUI::Action> m_undo_action;
|
||||
RefPtr<GUI::Action> m_redo_action;
|
||||
RefPtr<GUI::Action> m_change_background_color_action;
|
||||
RefPtr<GUI::Action> m_change_foreground_color_action;
|
||||
|
||||
RefPtr<GUI::Action> m_functions_help_action;
|
||||
RefPtr<GUI::Action> m_about_action;
|
||||
|
|
Loading…
Reference in a new issue