summaryrefslogtreecommitdiff
path: root/src/widgetinfomodel.h
blob: bc3cd674958a9e8d012a3ef9ee58a621b635297b (plain)
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
41
42
43
44
45
46
47
48
49
50
51
#ifndef WIDGETINFOMODEL_H
#define WIDGETINFOMODEL_H

#include <QtCore/QAbstractListModel>
#include <MDConfGroup>

#include "widgetinfo.h"

class WidgetInfoModel : public QAbstractListModel
{
	Q_OBJECT

public:
	explicit WidgetInfoModel(const QString &settingsPrefix, QObject *parent = 0);

	enum Roles {
		UrlRole = Qt::UserRole,
		InvertRole,
		PageRole,
		SizeRole,
		PositionRole
	};

	QHash<int, QByteArray> roleNames() const;
	int rowCount(const QModelIndex &parent) const;
	QVariant data(const QModelIndex &index, int role) const;

	QList<WidgetInfo> toList() const;

	Q_INVOKABLE bool widgetOverlaps(int page, WidgetInfo::WidgetPosition pos, WidgetInfo::WidgetSize size) const;

	Q_INVOKABLE int addWidget(const QUrl &url, int page, WidgetInfo::WidgetPosition pos, WidgetInfo::WidgetSize size);
	Q_INVOKABLE void removeWidget(int widgetId);

signals:

public slots:
	void reload();

private:
	int findEmptySlot();

private slots:
	void handleSettingChanged(const QString &key);

private:
	MDConfGroup *_settings;
	QVector<WidgetInfo> _widgets;
};

#endif // WIDGETINFOMODEL_H