mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-22 19:34:27 +00:00
Return FlatLabel.margins in getMargins().
This commit is contained in:
parent
e1ba9f8ff8
commit
703b944839
@ -162,6 +162,10 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
|
||||
_variables.groupStickersSectionHidden = std::move(groupStickersSectionHidden);
|
||||
_variables.thirdSectionInfoEnabled = thirdSectionInfoEnabled;
|
||||
_variables.smallDialogsList = smallDialogsList;
|
||||
|
||||
if (_variables.thirdSectionInfoEnabled) {
|
||||
_variables.tabbedSelectorSectionEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AuthSessionData::setTabbedSelectorSectionEnabled(bool enabled) {
|
||||
|
@ -582,13 +582,13 @@ editPrivacyTitle: FlatLabel(defaultFlatLabel) {
|
||||
width: 320px;
|
||||
textFg: boxTitleFg;
|
||||
maxHeight: 56px;
|
||||
margin: margins(0px, 20px, 0px, 13px);
|
||||
style: TextStyle(defaultTextStyle) {
|
||||
font: boxTitleFont;
|
||||
linkFont: boxTitleFont;
|
||||
linkFontOver: boxTitleFont;
|
||||
}
|
||||
}
|
||||
editPrivacyTitlePadding: margins(23px, 20px, 21px, 13px);
|
||||
editPrivacyLabel: FlatLabel(defaultFlatLabel) {
|
||||
width: 320px;
|
||||
textFg: membersAboutLimitFg;
|
||||
@ -674,11 +674,11 @@ mutePhotoButton: PeerAvatarButton {
|
||||
muteChatTitle: FlatLabel(boxLabel) {
|
||||
width: 235px;
|
||||
maxHeight: 20px; // block word wrap
|
||||
margin: margins(50px, 0px, 0px, 0px); // left offset for place peer avatar
|
||||
style: TextStyle(boxTextStyle) {
|
||||
font: font(boxFontSize semibold);
|
||||
}
|
||||
}
|
||||
muteChatTitleLeft: 50px;
|
||||
|
||||
groupStickersRemove: contactsSearchCancel;
|
||||
groupStickersRemovePosition: point(6px, 6px);
|
||||
|
@ -119,7 +119,7 @@ int EditPrivacyBox::resizeGetHeight(int newWidth) {
|
||||
layoutRow(_contacts, st::editPrivacyOptionMargin);
|
||||
layoutRow(_nobody, st::editPrivacyOptionMargin);
|
||||
layoutRow(_warning, st::editPrivacyWarningPadding);
|
||||
layoutRow(_exceptionsTitle, st::editPrivacyPadding);
|
||||
layoutRow(_exceptionsTitle, st::editPrivacyTitlePadding);
|
||||
auto linksTop = top;
|
||||
layoutRow(_alwaysLink, st::editPrivacyPadding);
|
||||
layoutRow(_neverLink, st::editPrivacyPadding);
|
||||
@ -167,7 +167,7 @@ int EditPrivacyBox::countDefaultHeight(int newWidth) {
|
||||
height += optionHeight(Option::Contacts);
|
||||
height += optionHeight(Option::Nobody);
|
||||
height += labelHeight(_controller->warning(), st::editPrivacyLabel, st::editPrivacyWarningPadding);
|
||||
height += labelHeight(lang(lng_edit_privacy_exceptions), st::editPrivacyTitle, st::editPrivacyPadding);
|
||||
height += labelHeight(lang(lng_edit_privacy_exceptions), st::editPrivacyTitle, st::editPrivacyTitlePadding);
|
||||
height += linkHeight();
|
||||
height += linkHeight();
|
||||
height += labelHeight(_controller->exceptionsDescription(), st::editPrivacyLabel, st::editPrivacyPadding);
|
||||
|
@ -29,8 +29,9 @@ void MuteSettingsBox::prepare() {
|
||||
|
||||
object_ptr<Ui::FlatLabel> title(this, st::muteChatTitle);
|
||||
title->setText(App::peerName(_peer, true));
|
||||
title->moveToLeft(st::boxPadding.left(),
|
||||
y + icon->height() / 2 - title->height() / 2);
|
||||
title->moveToLeft(
|
||||
st::boxPadding.left() + st::muteChatTitleLeft,
|
||||
y + (icon->height() / 2) - (title->height() / 2));
|
||||
// the icon is always higher than this chat title
|
||||
y += icon->height() + st::boxMediumSkip;
|
||||
|
||||
|
@ -197,7 +197,8 @@ callRatingComment: InputField(defaultInputField) {
|
||||
}
|
||||
callRatingCommentTop: 8px;
|
||||
|
||||
callDebugPadding: margins(24px, 0px, 24px, 0px);
|
||||
callDebugLabel: FlatLabel(defaultFlatLabel) {
|
||||
margin: margins(24px, 0px, 24px, 0px);
|
||||
margin: callDebugPadding;
|
||||
}
|
||||
callPanelDuration: 150;
|
||||
|
@ -23,6 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "styles/style_calls.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "calls/calls_call.h"
|
||||
#include "calls/calls_instance.h"
|
||||
@ -59,7 +60,11 @@ void DebugInfoBox::prepare() {
|
||||
setTitle([] { return QString("Call Debug"); });
|
||||
|
||||
addButton(langFactory(lng_close), [this] { closeBox(); });
|
||||
_text = setInnerWidget(object_ptr<Ui::FlatLabel>(this, st::callDebugLabel));
|
||||
_text = setInnerWidget(
|
||||
object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||
this,
|
||||
object_ptr<Ui::FlatLabel>(this, st::callDebugLabel),
|
||||
st::callDebugPadding))->entity();
|
||||
_text->setSelectable(true);
|
||||
updateText();
|
||||
_updateTextTimer.setCallback([this] { updateText(); });
|
||||
|
@ -138,8 +138,15 @@ infoIconNotifications: icon {{ "info_notifications", infoIconFg }};
|
||||
infoIconActions: icon {{ "info_actions", infoIconFg }};
|
||||
|
||||
infoLabel: FlatLabel(defaultFlatLabel) {
|
||||
textFg: windowSubTextFg;
|
||||
}
|
||||
infoLabeled: FlatLabel(defaultFlatLabel) {
|
||||
width: 180px;
|
||||
margin: margins(5px, 5px, 5px, 5px);
|
||||
}
|
||||
infoLabeledOneLine: FlatLabel(infoLabeled) {
|
||||
width: 0px; // No need to set minWidth in one-line text.
|
||||
maxHeight: 20px;
|
||||
}
|
||||
|
||||
infoProfileButton: InfoProfileButton {
|
||||
|
@ -167,19 +167,34 @@ object_ptr<Ui::RpWidget> InnerWidget::setupInfoLines(
|
||||
auto infoPartsShown = std::vector<rpl::producer<bool>>();
|
||||
auto addInfoLine = [&](
|
||||
LangKey label,
|
||||
rpl::producer<TextWithEntities> &&text) {
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
bool selectByDoubleClick = false,
|
||||
const style::FlatLabel &textSt = st::infoLabeled) {
|
||||
auto line = result->add(object_ptr<LabeledLine>(
|
||||
result,
|
||||
Lang::Viewer(label) | WithEmptyEntities(),
|
||||
std::move(text)));
|
||||
std::move(text),
|
||||
textSt,
|
||||
st::infoProfileLabeledPadding,
|
||||
selectByDoubleClick));
|
||||
infoPartsShown.push_back(line->shownValue());
|
||||
return line;
|
||||
};
|
||||
auto addInfoOneLine = [&](
|
||||
LangKey label,
|
||||
rpl::producer<TextWithEntities> &&text) {
|
||||
addInfoLine(
|
||||
label,
|
||||
std::move(text),
|
||||
true,
|
||||
st::infoLabeledOneLine);
|
||||
};
|
||||
if (auto user = _peer->asUser()) {
|
||||
addInfoLine(lng_info_mobile_label, PhoneViewer(user));
|
||||
addInfoOneLine(lng_info_mobile_label, PhoneViewer(user));
|
||||
addInfoLine(lng_info_bio_label, BioViewer(user));
|
||||
addInfoLine(lng_info_username_label, UsernameViewer(user));
|
||||
addInfoOneLine(lng_info_username_label, UsernameViewer(user));
|
||||
} else {
|
||||
addInfoLine(lng_info_link_label, LinkViewer(_peer));
|
||||
addInfoOneLine(lng_info_link_label, LinkViewer(_peer));
|
||||
addInfoLine(lng_info_about_label, AboutViewer(_peer));
|
||||
}
|
||||
auto separator = result->add(object_ptr<Ui::SlideWrap<>>(
|
||||
|
@ -257,8 +257,9 @@ LabeledLine::LabeledLine(
|
||||
parent,
|
||||
std::move(label),
|
||||
std::move(text),
|
||||
st::infoLabeled,
|
||||
st::infoProfileLabeledPadding) {
|
||||
st::infoLabeledOneLine,
|
||||
st::infoProfileLabeledPadding,
|
||||
true) {
|
||||
}
|
||||
|
||||
LabeledLine::LabeledLine(
|
||||
@ -266,7 +267,8 @@ LabeledLine::LabeledLine(
|
||||
rpl::producer<TextWithEntities> &&label,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
const style::FlatLabel &textSt,
|
||||
const style::margins &padding)
|
||||
const style::margins &padding,
|
||||
bool doubleClickSelects)
|
||||
: SlideWrap<Ui::VerticalLayout>(
|
||||
parent,
|
||||
object_ptr<Ui::VerticalLayout>(parent),
|
||||
@ -285,10 +287,12 @@ LabeledLine::LabeledLine(
|
||||
| rpl::after_next([this](const TextWithEntities &value) {
|
||||
showAnimated();
|
||||
});
|
||||
layout->add(object_ptr<Ui::FlatLabel>(
|
||||
auto labeled = layout->add(object_ptr<Ui::FlatLabel>(
|
||||
this,
|
||||
std::move(nonEmptyText),
|
||||
textSt));
|
||||
labeled->setSelectable(true);
|
||||
labeled->setDoubleClickSelectsParagraph(doubleClickSelects);
|
||||
layout->add(object_ptr<Ui::FlatLabel>(
|
||||
this,
|
||||
std::move(label),
|
||||
|
@ -134,7 +134,8 @@ public:
|
||||
rpl::producer<TextWithEntities> &&label,
|
||||
rpl::producer<TextWithEntities> &&text,
|
||||
const style::FlatLabel &textSt,
|
||||
const style::margins &padding);
|
||||
const style::margins &padding,
|
||||
bool doubleClickSelects);
|
||||
|
||||
};
|
||||
|
||||
|
@ -153,24 +153,23 @@ void CoverWidget::refreshButtonsGeometry(int newWidth) {
|
||||
void CoverWidget::refreshNameGeometry(int newWidth) {
|
||||
auto margins = getMargins();
|
||||
auto infoLeft = _userpicButton->x() + _userpicButton->width();
|
||||
auto nameLeft = infoLeft + st::settingsNameLeft - st::settingsNameLabel.margin.left();
|
||||
auto nameTop = _userpicButton->y() + st::settingsNameTop - st::settingsNameLabel.margin.top();
|
||||
auto nameLeft = infoLeft + st::settingsNameLeft;
|
||||
auto nameTop = _userpicButton->y() + st::settingsNameTop;
|
||||
auto nameWidth = newWidth - infoLeft - st::settingsNameLeft;
|
||||
auto editNameInlineVisible = !_editNameVisible;
|
||||
if (editNameInlineVisible) {
|
||||
nameWidth -= _editNameInline->width();
|
||||
}
|
||||
int marginsAdd = st::settingsNameLabel.margin.left() + st::settingsNameLabel.margin.right();
|
||||
|
||||
_name->resizeToWidth(qMin(nameWidth - marginsAdd, _name->naturalWidth()) + marginsAdd);
|
||||
_name->resizeToNaturalWidth(nameWidth);
|
||||
_name->moveToLeft(
|
||||
margins.left() + nameLeft,
|
||||
margins.top() + nameTop,
|
||||
newWidth);
|
||||
|
||||
_editNameInline->moveToLeft(
|
||||
margins.left() + nameLeft + _name->width(),
|
||||
margins.top() + nameTop,
|
||||
margins.left() + nameLeft + _name->widthNoMargins(),
|
||||
margins.top() + nameTop + st::settingsNameLabel.margin.top(),
|
||||
newWidth);
|
||||
_editNameInline->setVisible(editNameInlineVisible);
|
||||
}
|
||||
|
@ -210,12 +210,12 @@ int InfoWidget::LabeledWidget::naturalWidth() const {
|
||||
}
|
||||
|
||||
int InfoWidget::LabeledWidget::resizeGetHeight(int newWidth) {
|
||||
int marginLeft = st::settingsBlockOneLineTextPart.margin.left();
|
||||
int marginRight = st::settingsBlockOneLineTextPart.margin.right();
|
||||
|
||||
if (!_label) return 0;
|
||||
|
||||
_label->moveToLeft(0, st::settingsBlockOneLineTextPart.margin.top(), newWidth);
|
||||
_label->moveToLeft(
|
||||
0,
|
||||
st::settingsBlockOneLineTextPart.margin.top(),
|
||||
newWidth);
|
||||
_label->resizeToNaturalWidth(newWidth);
|
||||
|
||||
int textLeft = _label->width() + st::normalFont->spacew;
|
||||
@ -224,14 +224,20 @@ int InfoWidget::LabeledWidget::resizeGetHeight(int newWidth) {
|
||||
bool doesNotFit = (textWidth > availableWidth);
|
||||
accumulate_min(textWidth, availableWidth);
|
||||
accumulate_min(textWidth, st::msgMaxWidth);
|
||||
if (textWidth + marginLeft + marginRight < 0) {
|
||||
textWidth = -(marginLeft + marginRight);
|
||||
if (textWidth < 0) {
|
||||
textWidth = 0;
|
||||
}
|
||||
_text->resizeToWidth(textWidth + marginLeft + marginRight);
|
||||
_text->moveToLeft(textLeft - marginLeft, 0, newWidth);
|
||||
_text->resizeToWidth(textWidth);
|
||||
_text->moveToLeft(
|
||||
textLeft,
|
||||
st::settingsBlockOneLineTextPart.margin.top(),
|
||||
newWidth);
|
||||
if (_shortText) {
|
||||
_shortText->resizeToWidth(textWidth + marginLeft + marginRight);
|
||||
_shortText->moveToLeft(textLeft - marginLeft, 0, newWidth);
|
||||
_shortText->resizeToWidth(textWidth);
|
||||
_shortText->moveToLeft(
|
||||
textLeft,
|
||||
st::settingsBlockOneLineTextPart.margin.top(),
|
||||
newWidth);
|
||||
if (doesNotFit) {
|
||||
_shortText->show();
|
||||
_text->hide();
|
||||
@ -240,7 +246,9 @@ int InfoWidget::LabeledWidget::resizeGetHeight(int newWidth) {
|
||||
_text->show();
|
||||
}
|
||||
}
|
||||
return st::settingsBlockOneLineTextPart.margin.top() + qMax(_label->height(), _text->height() - st::settingsBlockOneLineTextPart.margin.top() - st::settingsBlockOneLineTextPart.margin.bottom()) + st::settingsBlockOneLineTextPart.margin.bottom();
|
||||
return st::settingsBlockOneLineTextPart.margin.top()
|
||||
+ qMax(_label->heightNoMargins(), _text->heightNoMargins())
|
||||
+ st::settingsBlockOneLineTextPart.margin.bottom();
|
||||
}
|
||||
|
||||
} // namespace Settings
|
||||
|
@ -26,11 +26,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class RpWidget : public TWidget {
|
||||
template <typename Parent>
|
||||
class RpWidgetWrap : public Parent {
|
||||
public:
|
||||
RpWidget(QWidget *parent = nullptr) : TWidget(parent) {
|
||||
setGeometry(0, 0, 0, 0);
|
||||
}
|
||||
using Parent::Parent;
|
||||
|
||||
rpl::producer<QRect> geometryValue() const {
|
||||
auto &stream = eventStreams().geometry;
|
||||
@ -79,11 +78,11 @@ public:
|
||||
}
|
||||
|
||||
rpl::lifetime &lifetime() {
|
||||
return _lifetime;
|
||||
return _lifetime.data;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override {
|
||||
bool event(QEvent *event) final override {
|
||||
switch (event->type()) {
|
||||
case QEvent::Move:
|
||||
case QEvent::Resize:
|
||||
@ -108,6 +107,9 @@ protected:
|
||||
break;
|
||||
}
|
||||
|
||||
return eventHook(event);
|
||||
}
|
||||
virtual bool eventHook(QEvent *event) {
|
||||
return TWidget::event(event);
|
||||
}
|
||||
|
||||
@ -117,6 +119,12 @@ private:
|
||||
rpl::event_stream<QRect> paint;
|
||||
rpl::event_stream<> alive;
|
||||
};
|
||||
struct LifetimeHolder {
|
||||
LifetimeHolder(QWidget *parent) {
|
||||
parent->setGeometry(0, 0, 0, 0);
|
||||
}
|
||||
rpl::lifetime data;
|
||||
};
|
||||
|
||||
EventStreams &eventStreams() const {
|
||||
if (!_eventStreams) {
|
||||
@ -127,7 +135,13 @@ private:
|
||||
|
||||
mutable std::unique_ptr<EventStreams> _eventStreams;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
LifetimeHolder _lifetime = { this };
|
||||
|
||||
};
|
||||
|
||||
class RpWidget : public RpWidgetWrap<TWidget> {
|
||||
public:
|
||||
using RpWidgetWrap<TWidget>::RpWidgetWrap;
|
||||
|
||||
};
|
||||
|
||||
|
@ -245,15 +245,21 @@ int FlatLabel::resizeGetHeight(int newWidth) {
|
||||
_allowedWidth = newWidth;
|
||||
int textWidth = countTextWidth();
|
||||
int textHeight = countTextHeight(textWidth);
|
||||
return _st.margin.top() + textHeight + _st.margin.bottom();
|
||||
return textHeight;
|
||||
}
|
||||
|
||||
int FlatLabel::naturalWidth() const {
|
||||
return _text.maxWidth();
|
||||
}
|
||||
|
||||
QMargins FlatLabel::getMargins() const {
|
||||
return _st.margin;
|
||||
}
|
||||
|
||||
int FlatLabel::countTextWidth() const {
|
||||
return _allowedWidth ? (_allowedWidth - _st.margin.left() - _st.margin.right()) : (_st.width ? _st.width : _text.maxWidth());
|
||||
return _allowedWidth
|
||||
? _allowedWidth
|
||||
: (_st.width ? _st.width : _text.maxWidth());
|
||||
}
|
||||
|
||||
int FlatLabel::countTextHeight(int textWidth) {
|
||||
@ -449,7 +455,7 @@ void FlatLabel::contextMenuEvent(QContextMenuEvent *e) {
|
||||
showContextMenu(e, ContextMenuReason::FromEvent);
|
||||
}
|
||||
|
||||
bool FlatLabel::event(QEvent *e) {
|
||||
bool FlatLabel::eventHook(QEvent *e) {
|
||||
if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) {
|
||||
QTouchEvent *ev = static_cast<QTouchEvent*>(e);
|
||||
if (ev->device()->type() == QTouchDevice::TouchScreen) {
|
||||
@ -457,7 +463,7 @@ bool FlatLabel::event(QEvent *e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return RpWidget::event(e);
|
||||
return RpWidget::eventHook(e);
|
||||
}
|
||||
|
||||
void FlatLabel::touchEvent(QTouchEvent *e) {
|
||||
|
@ -117,6 +117,7 @@ public:
|
||||
void setBreakEverywhere(bool breakEverywhere);
|
||||
|
||||
int naturalWidth() const override;
|
||||
QMargins getMargins() const override;
|
||||
|
||||
void setLink(uint16 lnkIndex, const ClickHandlerPtr &lnk);
|
||||
|
||||
@ -141,7 +142,7 @@ protected:
|
||||
void focusInEvent(QFocusEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
bool event(QEvent *e) override; // calls touchEvent when necessary
|
||||
bool eventHook(QEvent *e) override; // calls touchEvent when necessary
|
||||
void touchEvent(QTouchEvent *e);
|
||||
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
Loading…
Reference in New Issue
Block a user