1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

Spreadsheet: Allow customising the cell foreground and background colors

This commit is contained in:
AnotherTest 2020-09-12 15:33:35 +04:30 committed by Andreas Kling
parent 8fa385f774
commit c2228b669d
2 changed files with 129 additions and 61 deletions

View file

@ -31,6 +31,7 @@
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/ColorInput.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
@ -137,6 +138,8 @@ void CellTypeDialog::setup_tabs(GUI::TabWidget& tabs, const Vector<Position>& po
m_type = &cell.type();
m_vertical_alignment = vertical_alignment_from(cell.type_metadata().alignment);
m_horizontal_alignment = horizontal_alignment_from(cell.type_metadata().alignment);
m_static_background_color = cell.type_metadata().static_background_color;
m_static_foreground_color = cell.type_metadata().static_foreground_color;
}
auto& type_tab = tabs.add_tab<GUI::Widget>("Type");
@ -214,7 +217,7 @@ void CellTypeDialog::setup_tabs(GUI::TabWidget& tabs, const Vector<Position>& po
auto& alignment_tab = tabs.add_tab<GUI::Widget>("Alignment");
alignment_tab.set_layout<GUI::VerticalBoxLayout>().set_margins({ 2, 2, 2, 2 });
{
// FIXME: Frame?
// Horizontal alignment
{
@ -285,6 +288,66 @@ void CellTypeDialog::setup_tabs(GUI::TabWidget& tabs, const Vector<Position>& po
}
};
}
}
auto& colors_tab = tabs.add_tab<GUI::Widget>("Color");
colors_tab.set_layout<GUI::VerticalBoxLayout>().set_margins({ 2, 2, 2, 2 });
{
// Static formatting
{
auto& static_formatting_container = colors_tab.add<GUI::Widget>();
static_formatting_container.set_layout<GUI::VerticalBoxLayout>();
static_formatting_container.layout()->set_margins({ 0, 0, 0, 0 });
static_formatting_container.set_preferred_size(0, 44);
static_formatting_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
// Foreground
{
// FIXME: Somehow allow unsetting these.
auto& foreground_container = static_formatting_container.add<GUI::Widget>();
foreground_container.set_layout<GUI::HorizontalBoxLayout>();
foreground_container.layout()->set_margins({ 0, 4, 0, 0 });
foreground_container.set_preferred_size(0, 22);
foreground_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
auto& foreground_label = foreground_container.add<GUI::Label>();
foreground_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
foreground_label.set_text("Static Foreground Color");
auto& foreground_selector = foreground_container.add<GUI::ColorInput>();
foreground_selector.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
foreground_selector.set_preferred_size(0, 22);
if (m_static_foreground_color.has_value())
foreground_selector.set_color(m_static_foreground_color.value());
foreground_selector.on_change = [&]() {
m_static_foreground_color = foreground_selector.color();
};
}
// Background
{
// FIXME: Somehow allow unsetting these.
auto& background_container = static_formatting_container.add<GUI::Widget>();
background_container.set_layout<GUI::HorizontalBoxLayout>();
background_container.layout()->set_margins({ 0, 4, 0, 0 });
background_container.set_preferred_size(0, 22);
background_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
auto& background_label = background_container.add<GUI::Label>();
background_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
background_label.set_text("Static Background Color");
auto& background_selector = background_container.add<GUI::ColorInput>();
background_selector.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
background_selector.set_preferred_size(0, 22);
if (m_static_background_color.has_value())
background_selector.set_color(m_static_background_color.value());
background_selector.on_change = [&]() {
m_static_background_color = background_selector.color();
};
}
}
}
}
CellTypeMetadata CellTypeDialog::metadata() const
@ -292,6 +355,8 @@ CellTypeMetadata CellTypeDialog::metadata() const
CellTypeMetadata metadata;
metadata.format = m_format;
metadata.length = m_length;
metadata.static_foreground_color = m_static_foreground_color;
metadata.static_background_color = m_static_background_color;
switch (m_vertical_alignment) {
case VerticalAlignment::Top:

View file

@ -171,6 +171,9 @@ void SpreadsheetView::TableCellPainter::paint(GUI::Painter& painter, const Gfx::
// Undo the horizontal padding done by the table view...
auto cell_rect = rect.inflated(m_table_view.horizontal_padding() * 2, 0);
if (auto bg = index.data(GUI::ModelRole::BackgroundColor); bg.is_color())
painter.fill_rect(cell_rect, bg.as_color());
if (m_table_view.selection().contains(index)) {
Color fill_color = palette.selection();
fill_color.set_alpha(80);