Support spoilers in FlatLabel.
This commit is contained in:
parent
e053e04607
commit
1b9b173964
1 changed files with 32 additions and 10 deletions
|
|
@ -262,6 +262,12 @@ void FlatLabel::init() {
|
||||||
void FlatLabel::textUpdated() {
|
void FlatLabel::textUpdated() {
|
||||||
refreshSize();
|
refreshSize();
|
||||||
setMouseTracking(_selectable || _text.hasLinks());
|
setMouseTracking(_selectable || _text.hasLinks());
|
||||||
|
if (_text.hasSpoilers()) {
|
||||||
|
_text.setSpoilerLinkFilter([weak = Ui::MakeWeak(this)](
|
||||||
|
const ClickContext &context) {
|
||||||
|
return (context.button == Qt::LeftButton) && weak;
|
||||||
|
});
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -942,16 +948,32 @@ void FlatLabel::paintEvent(QPaintEvent *e) {
|
||||||
? ((width() - _textWidth) / 2)
|
? ((width() - _textWidth) / 2)
|
||||||
: (width() - _st.margin.right() - _textWidth))
|
: (width() - _st.margin.right() - _textWidth))
|
||||||
: _st.margin.left();
|
: _st.margin.left();
|
||||||
auto selection = _selection.empty() ? (_contextMenu ? _savedSelection : _selection) : _selection;
|
const auto selection = !_selection.empty()
|
||||||
bool heightExceeded = _st.maxHeight && (_st.maxHeight < _fullTextHeight || textWidth < _text.maxWidth());
|
? _selection
|
||||||
bool renderElided = _breakEverywhere || heightExceeded;
|
: _contextMenu
|
||||||
if (renderElided) {
|
? _savedSelection
|
||||||
auto lineHeight = qMax(_st.style.lineHeight, _st.style.font->height);
|
: _selection;
|
||||||
auto lines = _st.maxHeight ? qMax(_st.maxHeight / lineHeight, 1) : ((height() / lineHeight) + 2);
|
const auto heightExceeded = _st.maxHeight
|
||||||
_text.drawElided(p, textLeft, _st.margin.top(), textWidth, lines, _st.align, e->rect().y(), e->rect().bottom(), 0, _breakEverywhere, selection);
|
&& (_st.maxHeight < _fullTextHeight || textWidth < _text.maxWidth());
|
||||||
} else {
|
const auto renderElided = _breakEverywhere || heightExceeded;
|
||||||
_text.draw(p, textLeft, _st.margin.top(), textWidth, _st.align, e->rect().y(), e->rect().bottom(), selection);
|
const auto lineHeight = qMax(_st.style.lineHeight, _st.style.font->height);
|
||||||
}
|
const auto lines = !renderElided
|
||||||
|
? 0
|
||||||
|
: _st.maxHeight
|
||||||
|
? qMax(_st.maxHeight / lineHeight, 1)
|
||||||
|
: ((height() / lineHeight) + 2);
|
||||||
|
_text.draw(p, {
|
||||||
|
.position = { textLeft, _st.margin.top() },
|
||||||
|
.availableWidth = textWidth,
|
||||||
|
.align = _st.align,
|
||||||
|
.clip = e->rect(),
|
||||||
|
.palette = &_st.palette,
|
||||||
|
.spoiler = Text::DefaultSpoilerCache(),
|
||||||
|
.now = crl::now(),
|
||||||
|
.selection = selection,
|
||||||
|
.elisionLines = lines,
|
||||||
|
.elisionBreakEverywhere = renderElided && _breakEverywhere,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DividerLabel::DividerLabel(
|
DividerLabel::DividerLabel(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue