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

#include "QtResizableLineEdit.h"

#include <QDebug>

namespace Swift {

QtResizableLineEdit::QtResizableLineEdit(QWidget* parent) :
	QLineEdit(parent) {
	connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
	setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}

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 w = fontMetrics().boundingRect(text().isEmpty() ? placeholderText() : text()).width() + 10;
	return QSize(w, height());
}

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

}