/* * This file is part of smolbote. It's copyrighted by the contributors recorded * in the version control history of the file, available from its original * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote * * SPDX-License-Identifier: GPL-3.0 */ #include "elidedlabel.h" #include <QPainter> #include <QTextLayout> ElidedLabel::ElidedLabel(QWidget *parent) : QLabel(parent) { setWordWrap(true); } void ElidedLabel::setText(const QString &text) { setToolTip(text); content = text; elideText(); } void ElidedLabel::elideText() { QFontMetrics font = this->fontMetrics(); QString elidedLine = font.elidedText(content, Qt::ElideRight, width()); QLabel::setText(elidedLine); } void ElidedLabel::resizeEvent(QResizeEvent *event) { QLabel::resizeEvent(event); elideText(); }