46 std::size_t
total()
const;
65 void exchange(std::size_t giver, std::size_t taker,
int amount);
66 bool grab_item(std::size_t taker,
int amount,
bool from_left =
true,
67 bool from_right =
true);
A widget that lets the user distribute a fixed number of items across multiple categories.
std::vector< int > m_values
Number of items in each category.
void mouseMoveEvent(QMouseEvent *event) override
Moves the current handle when dragging the mouse.
void paintEvent(QPaintEvent *event) override
Draws the widget.
void resizeEvent(QResizeEvent *event) override
Updates cached geometry information.
int m_closest_handle
Index of the handle being dragged with the mouse.
void set_range(std::size_t category, int min, int max)
Sets the minimum and maximum number of items a category can have.
virtual ~multi_slider()=default
void focus_some_category()
Makes sure the focused category is a visible one.
int left_margin
Empty space left of the icons.
std::vector< int > values() const
Retrieves the number of items in each category.
std::vector< category > m_categories
Category data.
double item_width
The logical width of one item.
struct freeciv::multi_slider::@154 m_geom
Cached geometry information.
void mouseDoubleClickEvent(QMouseEvent *event) override
Moves the closest handle when double-clicking.
bool move_focus(bool forward)
Moves focus to the next or previous visible category.
multi_slider(QWidget *parent=nullptr)
Constructor.
int handle_near(const QPoint &where)
Finds the index of the handle closest to the given position.
void set_values(const std::vector< int > &values)
Sets the contents of all item categories.
void mousePressEvent(QMouseEvent *event) override
Sets the current handle when pressing a mouse button.
bool event(QEvent *event) override
Overrides tab handling to also cycle through visible categories.
void leaveEvent(QEvent *event) override
Sopts highlighting the closest handle.
bool grab_item(std::size_t taker, int amount, bool from_left=true, bool from_right=true)
Grab an item from elsewhere and adds it to the taker category.
void mouseReleaseEvent(QMouseEvent *event) override
Unsets the current handle when releasing a mouse button.
void update_cached_geometry()
Updates cached geometry information.
std::size_t total() const
Returns the total number of items controlled by this widget.
void keyPressEvent(QKeyEvent *event) override
Handles arrow keys: left/right to change the focused category, up/down to add or remove items.
int icons_width
Width of the area covered with icons.
bool move_handle(int handle, const QPoint &where)
Tries to move a handle closer to a given position.
std::vector< handle > visible_handles() const
Returns the list of all visible handles.
int m_focused_category
Index of the category receiving keyboard input.
std::size_t add_category(const QPixmap &icon)
Adds a category.
void values_changed(const std::vector< int > &values) const
QSize minimumSizeHint() const override
Minimum size of the widget.
QSize sizeHint() const override
Preferred size of the widget.
void focusInEvent(QFocusEvent *event) override
Focuses the first or last category when focus is gained with the keyboard.
void exchange(std::size_t giver, std::size_t taker, int amount)
Exchange items between two categories.
bool allowed(int value) const
Checks if the category could take some value.