summaryrefslogtreecommitdiffstats
blob: f60f9a8ab89dbd37cd2ca74afc12622e6d0b3103 (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
/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2014 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */


#include "QtResizableLineEdit.h"

namespace Swift {

QtResizableLineEdit::QtResizableLineEdit(QWidget* parent) :
	QLineEdit(parent), editable(false) {
	connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
	setMinimumWidth(30);
}

QtResizableLineEdit::~QtResizableLineEdit() {
}

bool QtResizableLineEdit::isEditable() const {
	return editable;
}
void QtResizableLineEdit::setEditable(const bool editable) {
	this->editable = editable;
	if (editable) {
		setReadOnly(false);
	} else {
		setReadOnly(true);
	}
}


QSize QtResizableLineEdit::sizeHint() const {
	int horizontalMargin = 10;
	int verticalMargin = 6;
	QSize textDimensions;
#if QT_VERSION >= 0x040700
	textDimensions = fontMetrics().boundingRect(text().isEmpty() ? placeholderText() : text()).size();
#else
	textDimensions = fontMetrics().boundingRect(text().isEmpty() ? QString("   ") : text()).size();
#endif
	textDimensions.setWidth(textDimensions.width() + horizontalMargin);
	textDimensions.setHeight(textDimensions.height() + verticalMargin);
	return textDimensions;
}

void QtResizableLineEdit::textChanged(QString) {
	updateGeometry();
}

}