Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <mail@ckamm.de>2017-07-11 16:50:56 +0300
committerckamm <mail@ckamm.de>2017-07-12 10:04:27 +0300
commite13b618a6574f3a47c12b12af6586dfc4e3efb69 (patch)
tree6e527966e625831e4ef7f4b5b84bff0803098de4 /src/gui/elidedlabel.cpp
parentcd1b89475c65807a52fff22f9c3a3cbb6d44b998 (diff)
Add ElidedLabel
A label that adjusts its text based on Qt::TextElideMode.
Diffstat (limited to 'src/gui/elidedlabel.cpp')
-rw-r--r--src/gui/elidedlabel.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/gui/elidedlabel.cpp b/src/gui/elidedlabel.cpp
new file mode 100644
index 000000000..a5ce9bb22
--- /dev/null
+++ b/src/gui/elidedlabel.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) by Christian Kamm <mail@ckamm.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "elidedlabel.h"
+
+#include <QResizeEvent>
+
+namespace OCC {
+
+ElidedLabel::ElidedLabel(const QString &text, QWidget *parent)
+ : QLabel(text, parent)
+ , _text(text)
+ , _elideMode(Qt::ElideNone)
+{
+}
+
+void ElidedLabel::setText(const QString &text)
+{
+ _text = text;
+ QLabel::setText(text);
+ update();
+}
+
+void ElidedLabel::setElideMode(Qt::TextElideMode elideMode)
+{
+ _elideMode = elideMode;
+ update();
+}
+
+void ElidedLabel::resizeEvent(QResizeEvent *event)
+{
+ QLabel::resizeEvent(event);
+
+ QFontMetrics fm = fontMetrics();
+ QString elided = fm.elidedText(_text, _elideMode, event->size().width());
+ QLabel::setText(elided);
+}
+}