Show short previews in templates (support).

This commit is contained in:
John Preston 2018-10-07 12:33:10 +03:00
parent b322f986a8
commit 1b4f3a7529
2 changed files with 23 additions and 10 deletions

View File

@ -70,6 +70,14 @@ private:
}; };
int TextHeight(const Text &text, int available, int lines) {
Expects(text.style() != nullptr);
const auto st = text.style();
const auto line = st->lineHeight ? st->lineHeight : st->font->height;
return std::min(text.countHeight(available), lines * line);
};
Inner::Inner(QWidget *parent) : RpWidget(parent) { Inner::Inner(QWidget *parent) : RpWidget(parent) {
setMouseTracking(true); setMouseTracking(true);
} }
@ -120,9 +128,9 @@ int Inner::resizeRowGetHeight(Row &row, int newWidth) {
- st::autocompleteRowPadding.left() - st::autocompleteRowPadding.left()
- st::autocompleteRowPadding.right(); - st::autocompleteRowPadding.right();
return row.height = st::autocompleteRowPadding.top() return row.height = st::autocompleteRowPadding.top()
+ row.question.countHeight(available) + TextHeight(row.question, available, 1)
+ row.keys.countHeight(available) + TextHeight(row.keys, available, 1)
+ row.answer.countHeight(available) + TextHeight(row.answer, available, 2)
+ st::autocompleteRowPadding.bottom() + st::autocompleteRowPadding.bottom()
+ st::lineWidth; + st::lineWidth;
} }
@ -167,14 +175,15 @@ void Inner::paintEvent(QPaintEvent *e) {
const auto padding = st::autocompleteRowPadding; const auto padding = st::autocompleteRowPadding;
const auto available = width() - padding.left() - padding.right(); const auto available = width() - padding.left() - padding.right();
auto top = padding.top(); auto top = padding.top();
const auto drawText = [&](const Text &text) { const auto drawText = [&](const Text &text, int lines) {
text.drawLeft( text.drawLeftElided(
p, p,
padding.left(), padding.left(),
top, top,
available, available,
width()); width(),
top += text.countHeight(available); lines);
top += TextHeight(text, available, lines);
}; };
for (auto i = from; i != till; ++i) { for (auto i = from; i != till; ++i) {
const auto over = (i - begin(_rows) == _selected); const auto over = (i - begin(_rows) == _selected);
@ -182,11 +191,11 @@ void Inner::paintEvent(QPaintEvent *e) {
p.fillRect(0, 0, width(), i->height, st::windowBgOver); p.fillRect(0, 0, width(), i->height, st::windowBgOver);
} }
p.setPen(st::mentionNameFg); p.setPen(st::mentionNameFg);
drawText(i->question); drawText(i->question, 1);
p.setPen(over ? st::mentionFgOver : st::mentionFg); p.setPen(over ? st::mentionFgOver : st::mentionFg);
drawText(i->keys); drawText(i->keys, 1);
p.setPen(st::windowFg); p.setPen(st::windowFg);
drawText(i->answer); drawText(i->answer, 2);
p.translate(0, i->height); p.translate(0, i->height);
top = padding.top(); top = padding.top();

View File

@ -187,6 +187,10 @@ public:
return true; return true;
} }
const style::TextStyle *style() const {
return _st;
}
void clear(); void clear();
~Text(); ~Text();