summaryrefslogtreecommitdiffstats
blob: 733571ffa25927464bf0804b492b5db1ab43997c (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2010-2012 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <Swift/QtUI/QtSingleWindow.h>

#include <Swift/QtUI/QtSettingsProvider.h>
#include <Swiften/Base/foreach.h>

namespace Swift {

static const QString SINGLE_WINDOW_GEOMETRY = QString("SINGLE_WINDOW_GEOMETRY");
static const QString SINGLE_WINDOW_SPLITS = QString("SINGLE_WINDOW_SPLITS");

QtSingleWindow::QtSingleWindow(QtSettingsProvider* settings) : QSplitter() {
	settings_ = settings;
	QVariant geometryVariant = settings_->getQSettings()->value(SINGLE_WINDOW_GEOMETRY);
	if (geometryVariant.isValid()) {
		restoreGeometry(geometryVariant.toByteArray());
	}
	connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
	restoreSplitters();
}

QtSingleWindow::~QtSingleWindow() {

}

void QtSingleWindow::handleSplitterMoved(int, int) {
	QList<QVariant> variantValues;
	QList<int> intValues = sizes();
	foreach (int value, intValues) {
		variantValues.append(QVariant(value));
	}
	settings_->getQSettings()->setValue(SINGLE_WINDOW_SPLITS, QVariant(variantValues));
}

void QtSingleWindow::restoreSplitters() {
	QList<QVariant> variantValues = settings_->getQSettings()->value(SINGLE_WINDOW_SPLITS).toList();
	QList<int> intValues;
	foreach (QVariant value, variantValues) {
		intValues.append(value.toInt());
	}
	setSizes(intValues);
}

void QtSingleWindow::insertAtFront(QWidget* widget) {
	insertWidget(0, widget);
	restoreSplitters();
}

void QtSingleWindow::handleGeometryChanged() {
	settings_->getQSettings()->setValue(SINGLE_WINDOW_GEOMETRY, saveGeometry());

}

void QtSingleWindow::resizeEvent(QResizeEvent*) {
	handleGeometryChanged();
}

void QtSingleWindow::moveEvent(QMoveEvent*) {
	handleGeometryChanged();
}

}