2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Support url authorizations.

This commit is contained in:
John Preston
2019-05-22 16:29:02 +02:00
parent 8660f976a9
commit c92a798e1b
12 changed files with 473 additions and 144 deletions

View File

@@ -20,6 +20,13 @@ TextParseOptions _checkboxOptions = {
Qt::LayoutDirectionAuto, // dir
};
TextParseOptions _checkboxRichOptions = {
TextParseMultiline | TextParseRichText, // flags
0, // maxw
0, // maxh
Qt::LayoutDirectionAuto, // dir
};
} // namespace
AbstractCheckView::AbstractCheckView(int duration, bool checked, Fn<void()> updateCallback)
@@ -401,7 +408,7 @@ Checkbox::Checkbox(
: RippleButton(parent, st.ripple)
, _st(st)
, _check(std::move(check))
, _text(_st.style, text, _checkboxOptions) {
, _text(_st.style, text, _checkboxOptions, (_st.width > 0) ? _st.width : QFIXED_MAX) {
_check->setUpdateCallback([=] { updateCheck(); });
resizeToText();
setCursor(style::cur_pointer);
@@ -423,8 +430,8 @@ QRect Checkbox::checkRect() const {
}, size);
}
void Checkbox::setText(const QString &text) {
_text.setText(_st.style, text, _checkboxOptions);
void Checkbox::setText(const QString &text, bool rich) {
_text.setText(_st.style, text, rich ? _checkboxRichOptions : _checkboxOptions);
resizeToText();
update();
}
@@ -436,6 +443,11 @@ void Checkbox::setCheckAlignment(style::align alignment) {
}
}
void Checkbox::setAllowMultiline(bool allow) {
_allowMultiline = allow;
update();
}
bool Checkbox::checked() const {
return _check->checked();
}
@@ -519,19 +531,37 @@ void Checkbox::paintEvent(QPaintEvent *e) {
+ _st.textPosition.x();
auto textTop = _st.margin.top() + _st.textPosition.y();
if (_checkAlignment & Qt::AlignLeft) {
_text.drawLeftElided(
p,
textSkip,
textTop,
availableTextWidth,
width());
if (_allowMultiline) {
_text.drawLeft(
p,
textSkip,
textTop,
availableTextWidth,
width());
} else {
_text.drawLeftElided(
p,
textSkip,
textTop,
availableTextWidth,
width());
}
} else if (_checkAlignment & Qt::AlignRight) {
_text.drawRightElided(
p,
textSkip,
textTop,
availableTextWidth,
width());
if (_allowMultiline) {
_text.drawRight(
p,
textSkip,
textTop,
availableTextWidth,
width());
} else {
_text.drawRightElided(
p,
textSkip,
textTop,
availableTextWidth,
width());
}
} else {
_text.drawLeft(
p,
@@ -582,13 +612,18 @@ void Checkbox::handlePress() {
int Checkbox::resizeGetHeight(int newWidth) {
const auto result = _check->getSize().height();
if (!(_checkAlignment & Qt::AlignHCenter)) {
const auto centered = ((_checkAlignment & Qt::AlignHCenter) != 0);
if (!centered && !_allowMultiline) {
return result;
}
const auto textBottom = _st.margin.top()
+ _st.textPosition.y()
+ _text.countHeight(
newWidth - _st.margin.left() - _st.margin.right());
const auto leftSkip = _st.checkPosition.x()
+ checkRect().width()
+ _st.textPosition.x();
const auto availableTextWidth = centered
? (newWidth - _st.margin.left() - _st.margin.right())
: qMax(width() - leftSkip, 1);
const auto textBottom = _st.textPosition.y()
+ _text.countHeight(availableTextWidth);
return std::max(result, textBottom);
}

View File

@@ -150,8 +150,9 @@ public:
const style::Checkbox &st,
std::unique_ptr<AbstractCheckView> check);
void setText(const QString &text);
void setText(const QString &text, bool rich = false);
void setCheckAlignment(style::align alignment);
void setAllowMultiline(bool allow);
bool checked() const;
rpl::producer<bool> checkedChanges() const;
@@ -198,6 +199,7 @@ private:
Text _text;
style::align _checkAlignment = style::al_left;
bool _allowMultiline = false;
};