Serenity Operating System
at master 62 lines 1.9 kB view raw
1/* 2 * Copyright (c) 2021-2022, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include "Tree.h" 10#include <AK/DeprecatedString.h> 11#include <LibGUI/Frame.h> 12#include <LibGfx/Rect.h> 13 14namespace SpaceAnalyzer { 15 16class TreeMapWidget final : public GUI::Frame { 17 C_OBJECT(TreeMapWidget) 18 19public: 20 virtual ~TreeMapWidget() override = default; 21 Function<void()> on_path_change; 22 Function<void(GUI::ContextMenuEvent&)> on_context_menu_request; 23 size_t path_size() const; 24 TreeNode const* path_node(size_t n) const; 25 size_t viewpoint() const; 26 void set_viewpoint(size_t); 27 ErrorOr<void> analyze(GUI::Statusbar&); 28 29private: 30 TreeMapWidget() = default; 31 virtual void paint_event(GUI::PaintEvent&) override; 32 virtual void mousemove_event(GUI::MouseEvent&) override; 33 virtual void mousedown_event(GUI::MouseEvent&) override; 34 virtual void doubleclick_event(GUI::MouseEvent&) override; 35 virtual void mousewheel_event(GUI::MouseEvent&) override; 36 virtual void context_menu_event(GUI::ContextMenuEvent&) override; 37 virtual void keydown_event(GUI::KeyEvent&) override; 38 39 bool rect_can_contain_label(Gfx::IntRect const& rect) const; 40 41 enum class HasLabel { 42 Yes, 43 No 44 }; 45 enum class IsRemainder { 46 Yes, 47 No 48 }; 49 50 template<typename Function> 51 void lay_out_children(TreeNode const&, Gfx::IntRect const&, int depth, Function); 52 void paint_cell_frame(GUI::Painter&, TreeNode const&, Gfx::IntRect const&, Gfx::IntRect const&, int depth, HasLabel has_label) const; 53 Vector<DeprecatedString> path_to_position(Gfx::IntPoint); 54 void recalculate_path_for_new_tree(); 55 56 OwnPtr<Tree> m_tree; 57 Vector<DeprecatedString> m_path_segments; 58 size_t m_viewpoint { 0 }; // Current position within m_path_segments. 59 void const* m_selected_node_cache; 60}; 61 62}