diff options
| author | Weinan Li <[email protected]> | 2025-09-10 15:19:36 +0800 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2025-09-12 08:29:47 +0000 |
| commit | 112f375ec175e5aedfb58a3a3bf76535cc959575 (patch) | |
| tree | a41e5e89de804bd3b72e71cb4d96e1aa33d9ae5d /src/panels/information/informationpanelcontent.cpp | |
| parent | 26f06895b92bf72b310c6b6a48c1b45a126711c8 (diff) | |
informationpanel: use QTextEdit for filename display to avoid newlines in copied text
QLabel does not support line wrapping at arbitrary positions. The original code achieved word wrap by manually adding newline characters to the text, which resulted in these newlines being included when the filename was selected and copied.
This patch replaces QLabel with QTextEdit for filename display, leveraging QTextEdit's built-in word wrap functionality that handles line breaks purely for display without modifying the underlying text. This ensures copied filenames remain free of unintended newlines.
BUG: 493279
Diffstat (limited to 'src/panels/information/informationpanelcontent.cpp')
| -rw-r--r-- | src/panels/information/informationpanelcontent.cpp | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 134c5e056..db7117e5a 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -81,14 +81,22 @@ InformationPanelContent::InformationPanelContent(QWidget *parent) connect(m_mediaWidget, &MediaWidget::hasVideoChanged, this, &InformationPanelContent::slotHasVideoChanged); // name - m_nameLabel = new QLabel(parent); + m_nameLabel = new QTextEdit(parent); QFont font = m_nameLabel->font(); font.setBold(true); m_nameLabel->setFont(font); - m_nameLabel->setTextFormat(Qt::PlainText); m_nameLabel->setAlignment(Qt::AlignHCenter); m_nameLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); m_nameLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + m_nameLabel->setFrameShape(QFrame::NoFrame); + m_nameLabel->setStyleSheet("background-color: transparent; padding: 0px;"); + m_nameLabel->setContentsMargins(0, 0, 0, 0); + m_nameLabel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_nameLabel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + QTextDocument *doc = m_nameLabel->document(); + QTextOption option = doc->defaultTextOption(); + option.setWrapMode(QTextOption::WrapAnywhere); + doc->setDefaultTextOption(option); const bool previewsShown = InformationPanelSettings::previewsShown(); m_preview->setVisible(previewsShown); @@ -459,28 +467,9 @@ void InformationPanelContent::setNameLabelText(const QString &text) const QString processedText = Qt::mightBeRichText(text) ? text : KStringHandler::preProcessWrap(text); - QTextLayout textLayout(processedText); - textLayout.setFont(m_nameLabel->font()); - textLayout.setTextOption(textOption); - - QString wrappedText; - wrappedText.reserve(processedText.length()); - - // wrap the text to fit into the width of m_nameLabel - textLayout.beginLayout(); - QTextLine line = textLayout.createLine(); - while (line.isValid()) { - line.setLineWidth(m_nameLabel->width()); - wrappedText += QStringView(processedText).mid(line.textStart(), line.textLength()); - - line = textLayout.createLine(); - if (line.isValid()) { - wrappedText += QChar::LineSeparator; - } - } - textLayout.endLayout(); - - m_nameLabel->setText(wrappedText); + m_nameLabel->setText(processedText); + m_nameLabel->setFixedHeight(m_nameLabel->document()->size().height()); + m_nameLabel->setAlignment(Qt::AlignHCenter); } void InformationPanelContent::adjustWidgetSizes(int width) |
