summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp')
-rw-r--r--Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
new file mode 100644
index 0000000..efe04dc
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtResizableLineEdit.h"
+
+namespace Swift {
+
+QtResizableLineEdit::QtResizableLineEdit(QWidget* parent) :
+ QLineEdit(parent) {
+ connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
+ int marginHeight = 6;
+ setMaximumHeight(fontMetrics().height() + marginHeight);
+}
+
+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;
+#if QT_VERSION >= 0x040700
+ int w = fontMetrics().boundingRect(text().isEmpty() ? placeholderText() : text()).width() + horizontalMargin;
+#else
+ int w = fontMetrics().boundingRect(text().isEmpty() ? QString(" ") : text()).width() + horizontalMargin;
+#endif
+ return QSize(w, height());
+}
+
+void QtResizableLineEdit::textChanged(QString) {
+ updateGeometry();
+}
+
+}