File: dynamicgridwidget.h

package info (click to toggle)
chiaki 2.2.0-1.2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,312 kB
  • sloc: ansic: 17,616; cpp: 7,901; xml: 2,691; sh: 395; python: 96; makefile: 6
file content (40 lines) | stat: -rw-r--r-- 911 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: LicenseRef-AGPL-3.0-only-OpenSSL

#ifndef CHIAKI_DYNAMICGRIDWIDGET_H
#define CHIAKI_DYNAMICGRIDWIDGET_H

#include <QWidget>

class QGridLayout;

class DynamicGridWidget : public QWidget
{
	Q_OBJECT

	private:
		QGridLayout *layout;
		QList<QWidget *> widgets;
		unsigned int item_width;
		unsigned int columns;

		void UpdateLayout();
		void UpdateLayoutIfNecessary();
		unsigned int CalculateColumns();

	protected:
		void resizeEvent(QResizeEvent *) override { UpdateLayoutIfNecessary(); }

	public:
		explicit DynamicGridWidget(unsigned int item_width, QWidget *parent = nullptr);

		void AddWidget(QWidget *widget);
		void AddWidgets(const QList<QWidget *> &widgets);

		void RemoveWidget(QWidget *widget);
		void ClearWidgets();

		void SetItemWidth(unsigned int item_width) { this->item_width = item_width; UpdateLayoutIfNecessary(); }

};

#endif //CHIAKI_DYNAMICGRIDWIDGET_H