summaryrefslogtreecommitdiff
path: root/src/widgetview.cpp
blob: e5bf21e80ce8d71ea37f0be4e808546593dd6d42 (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
#include <QtQml/QQmlContext>
#include <sailfishapp.h>

#include "widgetview.h"

#define NUM_WIDGETS 16

WidgetView::WidgetView(const QString &settingsPrefix, QQuickView *view, QObject *parent)
	: QObject(parent),
	  _settings(new MDConfGroup(this)),
	  _view(view)
{
	_settings->setPath(settingsPrefix);

	if (!_view) {
		_view = new QQuickView;
	}

	for (int w = 0; w < NUM_WIDGETS; w++) {
		WidgetInfo *info = new WidgetInfo(this);

		_widgets.append(info);
		_widgetObjects.append(static_cast<QObject*>(info));
	}

	reload();

	_view->setResizeMode(QQuickView::SizeViewToRootObject);
	_view->setSource(SailfishApp::pathTo("qml/widgetview.qml"));
	_view->rootContext()->setContextProperty("widgets", QVariant::fromValue(_widgetObjects));
}

QList<WidgetInfo*> WidgetView::widgets()
{
	return _widgets;
}

void WidgetView::reload()
{
	for (int w = 0; w < _widgets.size(); w++) {
		WidgetInfo *widget = _widgets[w];
		QString base = QString("widget%1/").arg(w);

		widget->setInvert(_settings->value(base + "invert").toBool());
		widget->setPage(_settings->value(base + "page").toInt());
		widget->setSize(static_cast<WidgetInfo::WidgetSize>(_settings->value(base + "size").toInt()));
		widget->setPosition(static_cast<WidgetInfo::WidgetPosition>(_settings->value(base + "position").toInt()));
		widget->setUrl(_settings->value(base + "url").toUrl());
	}
}