summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtElidingLabel.cpp')
-rw-r--r--Swift/QtUI/QtElidingLabel.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Swift/QtUI/QtElidingLabel.cpp b/Swift/QtUI/QtElidingLabel.cpp
new file mode 100644
index 0000000..80da607
--- /dev/null
+++ b/Swift/QtUI/QtElidingLabel.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swift/QtUI/QtElidingLabel.h"
+
+namespace Swift {
+QtElidingLabel::QtElidingLabel(QWidget* parent, Qt::WindowFlags f) : QLabel(parent, f) {
+ setSizes();
+}
+
+QtElidingLabel::QtElidingLabel(const QString& text, QWidget* parent, Qt::WindowFlags f) : QLabel(text, parent, f) {
+ setSizes();
+}
+
+QtElidingLabel::~QtElidingLabel() {
+
+}
+
+void QtElidingLabel::setSizes() {
+ setMinimumSize(1, minimumHeight());
+}
+
+void QtElidingLabel::paintEvent(QPaintEvent* event) {
+ //QPainter painter(this);
+ QString fullText(text());
+ if (fontMetrics().width(fullText) > contentsRect().width()) {
+ //QString elidedText(fontMetrics().elidedText(fullText));
+ setText(fontMetrics().elidedText(fullText, Qt::ElideRight, rect().width(), Qt::TextShowMnemonic));
+ }
+ QLabel::paintEvent(event);
+ setText(fullText);
+}
+
+}