Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
flow_widget.h
Go to the documentation of this file.
1
7
8#ifndef FLOW_WIDGET_H
9#define FLOW_WIDGET_H
10
11#include <QLoggingCategory>
12#include <QWidget>
13#include <qlogging.h>
14#include <qnamespace.h>
15#include <qtmetamacros.h>
16
17class FlowLayout;
18class QHBoxLayout;
19class QKeyEvent;
20class QLayoutItem;
21class QScrollArea;
22
23inline Q_LOGGING_CATEGORY(FlowWidgetLog, "flow_widget", QtInfoMsg);
24inline Q_LOGGING_CATEGORY(FlowWidgetSizeLog, "flow_widget.size", QtInfoMsg);
25
26class FlowWidget : public QWidget
27{
28 Q_OBJECT
29
30public:
31 FlowWidget(QWidget *parent,
32 Qt::Orientation orientation,
33 Qt::ScrollBarPolicy horizontalPolicy,
34 Qt::ScrollBarPolicy verticalPolicy);
35
36 void addWidget(QWidget *widget_to_add);
37 void addNavigableWidget(QWidget *widget_to_add);
38 void insertWidgetAtIndex(QWidget *toInsert, int index);
39 void removeWidget(QWidget *widgetToRemove) const;
40 void clearLayout();
41
42 [[nodiscard]] int count() const;
43 [[nodiscard]] QLayoutItem *itemAt(int index) const;
44
45 QScrollArea *scrollArea;
46
47public slots:
49 void setSpacing(int hSpacing, int vSpacing);
50
51protected:
52 bool eventFilter(QObject *watched, QEvent *event) override;
53 void resizeEvent(QResizeEvent *event) override;
54 void keyPressEvent(QKeyEvent *event) override;
55
56private:
59 bool moveFocus(QKeyEvent *event);
60
61 Qt::Orientation flowDirection;
62 QHBoxLayout *mainLayout;
64 QWidget *container;
65};
66
67#endif // FLOW_WIDGET_H
Definition flow_layout.h:27
void setSpacing(int hSpacing, int vSpacing)
Definition flow_widget.cpp:172
bool eventFilter(QObject *watched, QEvent *event) override
Definition flow_widget.cpp:219
QScrollArea * scrollArea
Null when both scroll policies are AlwaysOff.
Definition flow_widget.h:45
int count() const
Definition flow_widget.cpp:270
QLayoutItem * itemAt(int index) const
Definition flow_widget.cpp:205
void clearLayout()
Removes all widgets from the flow layout and deletes them.
Definition flow_widget.cpp:136
void addNavigableWidget(QWidget *widget_to_add)
Adds a widget and routes its arrow keys to FlowWidget focus navigation.
Definition flow_widget.cpp:114
bool moveFocus(QKeyEvent *event)
Moves keyboard focus to an adjacent flow item for an arrow-key event.
Definition flow_widget.cpp:227
void removeWidget(QWidget *widgetToRemove) const
Definition flow_widget.cpp:126
FlowWidget(QWidget *parent, Qt::Orientation orientation, Qt::ScrollBarPolicy horizontalPolicy, Qt::ScrollBarPolicy verticalPolicy)
Constructs a FlowWidget.
Definition flow_widget.cpp:34
Qt::Orientation flowDirection
Definition flow_widget.h:61
void keyPressEvent(QKeyEvent *event) override
Definition flow_widget.cpp:210
QWidget * container
Definition flow_widget.h:64
void resizeEvent(QResizeEvent *event) override
Marks the flow layout as dirty so Qt recomputes item positions.
Definition flow_widget.cpp:162
void addWidget(QWidget *widget_to_add)
Adds a widget to the flow layout within the FlowWidget.
Definition flow_widget.cpp:98
QHBoxLayout * mainLayout
Definition flow_widget.h:62
void insertWidgetAtIndex(QWidget *toInsert, int index)
Definition flow_widget.cpp:120
void setMinimumSizeToMaxSizeHint()
Sets every child widget's minimum size to the largest sizeHint in the layout.
Definition flow_widget.cpp:184
FlowLayout * flowLayout
Definition flow_widget.h:63
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")