diff --git a/src/ksqueezedtextlabel.h b/src/ksqueezedtextlabel.h --- a/src/ksqueezedtextlabel.h +++ b/src/ksqueezedtextlabel.h @@ -118,6 +118,15 @@ */ QString fullText() const; + /** + * @returns true if the text displayed is currently squeezed, + * i.e. the original text does not fit inside the space available + * and elide mode is set to a value other than Qt::ElideNone. + * + * @since 5.38 + */ + bool isSqueezed() const; + public Q_SLOTS: /** * Sets the text. diff --git a/src/ksqueezedtextlabel.cpp b/src/ksqueezedtextlabel.cpp --- a/src/ksqueezedtextlabel.cpp +++ b/src/ksqueezedtextlabel.cpp @@ -146,6 +146,11 @@ return d->fullText; } +bool KSqueezedTextLabel::isSqueezed() const +{ + return d->fullText != text(); +} + void KSqueezedTextLabel::contextMenuEvent(QContextMenuEvent *ev) { // We want to reimplement "Copy" to include the elided text. @@ -157,9 +162,7 @@ // For now I chose to show it when the text is squeezed; when it's not, the // standard popup menu can do the job (select all, copy). - const bool squeezed = text() != d->fullText; - const bool showCustomPopup = squeezed; - if (showCustomPopup) { + if (isSqueezed()) { QMenu menu(this); QAction *act = new QAction(tr("&Copy Full Text"), &menu);