/* * Copyright (c) 2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include struct Annotation { size_t start_offset { 0 }; size_t end_offset { 0 }; Gfx::Color background_color { Color::from_argb(0xfffce94f) }; String comments {}; bool operator==(Annotation const& other) const = default; }; class AnnotationsModel final : public GUI::Model { public: enum Column { Start, End, Comments, }; enum class CustomRole { StartOffset = to_underlying(GUI::ModelRole::Custom) + 1, EndOffset, Comments, }; virtual int row_count(GUI::ModelIndex const& index = GUI::ModelIndex()) const override { if (!index.is_valid()) return m_annotations.size(); return 0; } virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return 3; } virtual ErrorOr column_name(int column) const override { switch (column) { case Column::Start: return "Start"_string; case Column::End: return "End"_string; case Column::Comments: return "Comments"_string; } VERIFY_NOT_REACHED(); } virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role = GUI::ModelRole::Display) const override; void add_annotation(Annotation); void delete_annotation(Annotation const&); Optional closest_annotation_at(size_t position); Optional get_annotation(GUI::ModelIndex const& index); ErrorOr save_to_file(Core::File&) const; ErrorOr load_from_file(Core::File&); private: Vector m_annotations; };