2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-05-27 21:19:05 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/AbstractView.h>
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class ListView : public AbstractView {
|
|
|
|
C_OBJECT(ListView)
|
2019-05-27 21:19:05 +03:00
|
|
|
public:
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual ~ListView() override;
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2022-03-14 18:45:47 +03:00
|
|
|
int item_height() const { return font().preferred_line_height() + vertical_padding(); }
|
2022-09-21 15:06:43 +03:00
|
|
|
int item_count() const;
|
2019-05-27 21:19:05 +03:00
|
|
|
|
|
|
|
bool alternating_row_colors() const { return m_alternating_row_colors; }
|
|
|
|
void set_alternating_row_colors(bool b) { m_alternating_row_colors = b; }
|
|
|
|
|
2020-07-15 00:18:12 +03:00
|
|
|
bool hover_highlighting() const { return m_hover_highlighting; }
|
|
|
|
void set_hover_highlighting(bool b) { m_hover_highlighting = b; }
|
|
|
|
|
2019-05-27 21:19:05 +03:00
|
|
|
int horizontal_padding() const { return m_horizontal_padding; }
|
2022-03-14 18:45:47 +03:00
|
|
|
int vertical_padding() const { return m_vertical_padding; }
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual void scroll_into_view(ModelIndex const& index, bool scroll_horizontally, bool scroll_vertically) override;
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2022-12-06 23:27:44 +03:00
|
|
|
Gfx::IntPoint adjusted_position(Gfx::IntPoint) const;
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2022-12-06 23:27:44 +03:00
|
|
|
virtual ModelIndex index_at_event_position(Gfx::IntPoint) const override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual Gfx::IntRect content_rect(ModelIndex const&) const override;
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2019-08-05 19:32:04 +03:00
|
|
|
int model_column() const { return m_model_column; }
|
|
|
|
void set_model_column(int column) { m_model_column = column; }
|
|
|
|
|
2020-02-25 18:03:15 +03:00
|
|
|
virtual void select_all() override;
|
2020-05-12 16:10:31 +03:00
|
|
|
|
2020-07-15 00:18:12 +03:00
|
|
|
Function<void()> on_escape_pressed;
|
|
|
|
|
2020-09-02 22:15:26 +03:00
|
|
|
virtual void move_cursor(CursorMovement, SelectionUpdate) override;
|
|
|
|
void move_cursor_relative(int steps, SelectionUpdate);
|
|
|
|
|
2020-09-12 22:43:35 +03:00
|
|
|
protected:
|
2020-02-23 14:07:13 +03:00
|
|
|
ListView();
|
2020-09-12 22:43:35 +03:00
|
|
|
virtual void paint_list_item(Painter&, int row_index, int painted_item_index);
|
2020-02-23 14:07:13 +03:00
|
|
|
|
2020-09-12 22:43:35 +03:00
|
|
|
private:
|
2020-11-26 10:40:14 +03:00
|
|
|
virtual void model_did_update(unsigned flags) override;
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void paint_event(PaintEvent&) override;
|
|
|
|
virtual void keydown_event(KeyEvent&) override;
|
|
|
|
virtual void resize_event(ResizeEvent&) override;
|
2020-09-02 22:21:24 +03:00
|
|
|
virtual void mousemove_event(MouseEvent&) override;
|
2022-12-05 16:00:35 +03:00
|
|
|
virtual void layout_relevant_change_occurred() override;
|
2019-05-27 21:19:05 +03:00
|
|
|
|
2020-06-10 11:57:59 +03:00
|
|
|
Gfx::IntRect content_rect(int row) const;
|
2019-05-27 21:19:05 +03:00
|
|
|
void update_content_size();
|
|
|
|
|
|
|
|
int m_horizontal_padding { 2 };
|
2022-03-14 18:45:47 +03:00
|
|
|
int m_vertical_padding { 2 };
|
2019-05-27 21:19:05 +03:00
|
|
|
int m_model_column { 0 };
|
|
|
|
bool m_alternating_row_colors { true };
|
2020-07-15 00:18:12 +03:00
|
|
|
bool m_hover_highlighting { false };
|
2019-05-27 21:19:05 +03:00
|
|
|
};
|
2020-02-02 17:07:41 +03:00
|
|
|
|
|
|
|
}
|