Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion panels/dock/taskmanager/package/AppItemTitle.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects

import org.deepin.ds.dock.taskmanager 1.0
import org.deepin.dtk 1.0 as D
Expand All @@ -30,7 +31,20 @@ Item {
color: D.DTK.themeType === D.ApplicationHelper.DarkType ? "#FFFFFF" : "#000000"
font: root.TextCalculator.calculator.font
verticalAlignment: Text.AlignVCenter


layer.enabled: root.TextCalculator.isTruncated
layer.effect: OpacityMask {
maskSource: Rectangle {
id: maskRect
width: root.TextCalculator.ellipsisWidth
height: titleText.height
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop { position: 1; color: "#00FFFFFF" }
GradientStop { position: 0.6; color: "#FFFFFFFF" }
}
}
}
opacity: visible ? 1.0 : 0.0

Behavior on opacity {
Expand Down
18 changes: 16 additions & 2 deletions panels/dock/taskmanager/textcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ void TextCalculator::calculateOptimalTextWidth()
qreal newTotalWidth = 0.0;
int charCount = 7; // Maximum character count limit

// Iterate from 7 characters to 1 character, finding the optimal solution
for (; charCount >= 1; --charCount) {
// Iterate from 7 characters to 2 characters, finding the optimal solution
for (; charCount >= 2; --charCount) {
// 1. Calculate baseline width (based on character count)
qreal baselineWidth = calculateBaselineWidth(charCount);

Expand Down Expand Up @@ -401,7 +401,11 @@ void TextCalculatorAttached::updateElidedText()
if (!m_calculator) {
qCDebug(textCalculatorLog) << "No calculator available for elided text update";
m_elidedText.clear();
m_ellipsisWidth = 0.0;
m_isTruncated = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_ellipsisWidth 不为0是不是就是m_isTruncated

emit elidedTextChanged();
emit ellipsisWidthChanged();
emit isTruncatedChanged();
return;
}

Expand All @@ -411,7 +415,17 @@ void TextCalculatorAttached::updateElidedText()
QString newElidedText = fontMetrics.elidedText(m_text, Qt::ElideRight, maxWidth);
if (!isValidElidedText(newElidedText)) {
newElidedText = {};
} else {
m_isTruncated = (m_text != newElidedText);
emit isTruncatedChanged();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个加个判断来是否触发信号,

newElidedText.replace(QString::fromUtf8("…"), "");
}

if (m_isTruncated) {
m_ellipsisWidth = fontMetrics.horizontalAdvance(QString::fromUtf8("…"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_ellipsisWidth = maxWidth - 当前需要正常显示的字符的长度,
显示的字符 = 正常显示的字符 + 需要渐变的长度(例如省略号的长度),

emit ellipsisWidthChanged();
}

if (m_elidedText != newElidedText) {
m_elidedText = newElidedText;
emit elidedTextChanged();
Expand Down
16 changes: 16 additions & 0 deletions panels/dock/taskmanager/textcalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
QML_ELEMENT
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QString elidedText READ elidedText NOTIFY elidedTextChanged)
Q_PROPERTY(qreal ellipsisWidth READ ellipsisWidth NOTIFY ellipsisWidthChanged)
Q_PROPERTY(bool isTruncated READ isTruncated NOTIFY isTruncatedChanged)
Q_PROPERTY(TextCalculator *calculator READ calculator NOTIFY calculatorChanged)

public:
Expand All @@ -34,19 +36,33 @@

QString elidedText() const;

qreal ellipsisWidth() const
{
return m_ellipsisWidth;
}

bool isTruncated() const
{
return m_isTruncated;
}

void ensureInitialize();

Q_SIGNALS:
void textChanged();
void elidedTextChanged();
void ellipsisWidthChanged();
void isTruncatedChanged();
void calculatorChanged();

private Q_SLOTS:

Check warning on line 58 in panels/dock/taskmanager/textcalculator.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.
void updateElidedText();

private:
QString m_text;
QString m_elidedText;
qreal m_ellipsisWidth = 0.0;
bool m_isTruncated = false;
TextCalculator *m_calculator;
bool m_initialized = false;
};
Expand Down
Loading