Replace different side enums with RectPart.

Including Ui::Shadow::Side, App::RectPart and ImportantTooltip::Side.
This commit is contained in:
John Preston 2017-05-24 15:20:50 +03:00
parent c91e29d15d
commit 25587d7e8e
21 changed files with 90 additions and 142 deletions

View File

@ -2731,11 +2731,11 @@ namespace {
void complexAdjustRect(ImageRoundCorners corners, QRect &rect, RectParts &parts) { void complexAdjustRect(ImageRoundCorners corners, QRect &rect, RectParts &parts) {
if (corners & ImageRoundCorner::TopLeft) { if (corners & ImageRoundCorner::TopLeft) {
if (!(corners & ImageRoundCorner::BottomLeft)) { if (!(corners & ImageRoundCorner::BottomLeft)) {
parts = RectPart::NoTopBottom | RectPart::TopFull; parts = RectPart::NoTopBottom | RectPart::FullTop;
rect.setHeight(rect.height() + msgRadius()); rect.setHeight(rect.height() + msgRadius());
} }
} else if (corners & ImageRoundCorner::BottomLeft) { } else if (corners & ImageRoundCorner::BottomLeft) {
parts = RectPart::NoTopBottom | RectPart::BottomFull; parts = RectPart::NoTopBottom | RectPart::FullBottom;
rect.setTop(rect.y() - msgRadius()); rect.setTop(rect.y() - msgRadius());
} else { } else {
parts = RectPart::NoTopBottom; parts = RectPart::NoTopBottom;

View File

@ -281,28 +281,6 @@ namespace App {
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY #endif // !TDESKTOP_DISABLE_NETWORK_PROXY
void setProxySettings(QTcpSocket &socket); void setProxySettings(QTcpSocket &socket);
enum class RectPart {
None = 0x000,
TopLeft = 0x001,
Top = 0x002,
TopRight = 0x004,
Left = 0x008,
Center = 0x010,
Right = 0x020,
BottomLeft = 0x040,
Bottom = 0x080,
BottomRight = 0x100,
TopFull = 0x007,
LeftFull = 0x049,
RightFull = 0x124,
BottomFull = 0x1c0,
NoTopBottom = 0x038,
NoLeftRight = 0x092,
Full = 0x1ff,
};
Q_DECLARE_FLAGS(RectParts, RectPart);
Q_DECLARE_OPERATORS_FOR_FLAGS(RectParts);
void complexOverlayRect(Painter &p, QRect rect, ImageRoundRadius radius, ImageRoundCorners corners); void complexOverlayRect(Painter &p, QRect rect, ImageRoundRadius radius, ImageRoundCorners corners);
void complexLocationRect(Painter &p, QRect rect, ImageRoundRadius radius, ImageRoundCorners corners); void complexLocationRect(Painter &p, QRect rect, ImageRoundRadius radius, ImageRoundCorners corners);

View File

@ -227,9 +227,9 @@ void AbstractBox::paintEvent(QPaintEvent *e) {
auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius));
auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius));
if (paintTopRounded || paintBottomRounded) { if (paintTopRounded || paintBottomRounded) {
auto parts = qFlags(App::RectPart::None); auto parts = qFlags(RectPart::None);
if (paintTopRounded) parts |= App::RectPart::TopFull; if (paintTopRounded) parts |= RectPart::FullTop;
if (paintBottomRounded) parts |= App::RectPart::BottomFull; if (paintBottomRounded) parts |= RectPart::FullBottom;
App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts); App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts);
} }
auto other = e->region().intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius)); auto other = e->region().intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius));

View File

@ -520,7 +520,7 @@ void Panel::createBottomImage() {
image.fill(Qt::transparent); image.fill(Qt::transparent);
{ {
Painter p(&image); Painter p(&image);
Ui::Shadow::paint(p, QRect(_padding.left(), 0, st::callWidth, bottomHeight - _padding.bottom()), width(), st::callShadow, Ui::Shadow::Side::Left | Ui::Shadow::Side::Right | Ui::Shadow::Side::Bottom); Ui::Shadow::paint(p, QRect(_padding.left(), 0, st::callWidth, bottomHeight - _padding.bottom()), width(), st::callShadow, RectPart::Left | RectPart::Right | RectPart::Bottom);
p.setCompositionMode(QPainter::CompositionMode_Source); p.setCompositionMode(QPainter::CompositionMode_Source);
p.setBrush(st::callBg); p.setBrush(st::callBg);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
@ -556,7 +556,7 @@ void Panel::refreshCacheImageUserPhoto() {
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
{ {
Painter p(&cache); Painter p(&cache);
Ui::Shadow::paint(p, QRect(_padding.left(), _padding.top(), st::callWidth, st::callWidth), width(), st::callShadow, Ui::Shadow::Side::Top | Ui::Shadow::Side::Left | Ui::Shadow::Side::Right); Ui::Shadow::paint(p, QRect(_padding.left(), _padding.top(), st::callWidth, st::callWidth), width(), st::callShadow, RectPart::Top | RectPart::Left | RectPart::Right);
p.drawPixmapLeft(_padding.left(), _padding.top(), width(), _userPhoto); p.drawPixmapLeft(_padding.left(), _padding.top(), width(), _userPhoto);
p.drawPixmapLeft(0, _padding.top() + st::callWidth, width(), _bottomCache); p.drawPixmapLeft(0, _padding.top() + st::callWidth, width(), _bottomCache);
} }

View File

@ -384,7 +384,7 @@ void TabbedSelector::paintEvent(QPaintEvent *e) {
void TabbedSelector::paintSlideFrame(Painter &p, TimeMs ms) { void TabbedSelector::paintSlideFrame(Painter &p, TimeMs ms) {
if (_roundRadius > 0) { if (_roundRadius > 0) {
auto topPart = QRect(0, 0, width(), _tabsSlider->height() + _roundRadius); auto topPart = QRect(0, 0, width(), _tabsSlider->height() + _roundRadius);
App::roundRect(p, topPart, st::emojiPanBg, ImageRoundRadius::Small, App::RectPart::TopFull | App::RectPart::NoTopBottom); App::roundRect(p, topPart, st::emojiPanBg, ImageRoundRadius::Small, RectPart::FullTop | RectPart::NoTopBottom);
} else { } else {
p.fillRect(0, 0, width(), _tabsSlider->height(), st::emojiPanBg); p.fillRect(0, 0, width(), _tabsSlider->height(), st::emojiPanBg);
} }
@ -398,10 +398,10 @@ void TabbedSelector::paintContent(Painter &p) {
auto &bottomBg = showSectionIcons ? st::emojiPanCategories : st::emojiPanBg; auto &bottomBg = showSectionIcons ? st::emojiPanCategories : st::emojiPanBg;
if (_roundRadius > 0) { if (_roundRadius > 0) {
auto topPart = QRect(0, 0, width(), _tabsSlider->height() + _roundRadius); auto topPart = QRect(0, 0, width(), _tabsSlider->height() + _roundRadius);
App::roundRect(p, topPart, st::emojiPanBg, ImageRoundRadius::Small, App::RectPart::TopFull | App::RectPart::NoTopBottom); App::roundRect(p, topPart, st::emojiPanBg, ImageRoundRadius::Small, RectPart::FullTop | RectPart::NoTopBottom);
auto bottomPart = QRect(0, _footerTop - _roundRadius, width(), st::emojiCategory.height + _roundRadius); auto bottomPart = QRect(0, _footerTop - _roundRadius, width(), st::emojiCategory.height + _roundRadius);
auto bottomParts = App::RectPart::NoTopBottom | App::RectPart::BottomFull; auto bottomParts = RectPart::NoTopBottom | RectPart::FullBottom;
App::roundRect(p, bottomPart, bottomBg, ImageRoundRadius::Small, bottomParts); App::roundRect(p, bottomPart, bottomBg, ImageRoundRadius::Small, bottomParts);
} else { } else {
p.fillRect(0, 0, width(), _tabsSlider->height(), st::emojiPanBg); p.fillRect(0, 0, width(), _tabsSlider->height(), st::emojiPanBg);

View File

@ -1336,7 +1336,7 @@ void HistoryMessage::draw(Painter &p, const QRect &r, TextSelection selection, T
auto r = QRect(left, top, width, height - top - marginBottom()); auto r = QRect(left, top, width, height - top - marginBottom());
auto skipTail = isAttachedToNext() || (_media && _media->skipBubbleTail()) || (keyboard != nullptr); auto skipTail = isAttachedToNext() || (_media && _media->skipBubbleTail()) || (keyboard != nullptr);
auto displayTail = skipTail ? HistoryLayout::BubbleTail::None : (outbg && !Adaptive::ChatWide()) ? HistoryLayout::BubbleTail::Right : HistoryLayout::BubbleTail::Left; auto displayTail = skipTail ? RectPart::None : (outbg && !Adaptive::ChatWide()) ? RectPart::Right : RectPart::Left;
HistoryLayout::paintBubble(p, r, _history->width, selected, outbg, displayTail); HistoryLayout::paintBubble(p, r, _history->width, selected, outbg, displayTail);
QRect trect(r.marginsAdded(-st::msgPadding)); QRect trect(r.marginsAdded(-st::msgPadding));

View File

@ -351,25 +351,25 @@ void serviceColorsUpdated() {
} }
} }
void paintBubble(Painter &p, QRect rect, int outerWidth, bool selected, bool outbg, BubbleTail tail) { void paintBubble(Painter &p, QRect rect, int outerWidth, bool selected, bool outbg, RectPart tailSide) {
auto &bg = selected ? (outbg ? st::msgOutBgSelected : st::msgInBgSelected) : (outbg ? st::msgOutBg : st::msgInBg); auto &bg = selected ? (outbg ? st::msgOutBgSelected : st::msgInBgSelected) : (outbg ? st::msgOutBg : st::msgInBg);
auto &sh = selected ? (outbg ? st::msgOutShadowSelected : st::msgInShadowSelected) : (outbg ? st::msgOutShadow : st::msgInShadow); auto &sh = selected ? (outbg ? st::msgOutShadowSelected : st::msgInShadowSelected) : (outbg ? st::msgOutShadow : st::msgInShadow);
auto cors = selected ? (outbg ? MessageOutSelectedCorners : MessageInSelectedCorners) : (outbg ? MessageOutCorners : MessageInCorners); auto cors = selected ? (outbg ? MessageOutSelectedCorners : MessageInSelectedCorners) : (outbg ? MessageOutCorners : MessageInCorners);
auto parts = App::RectPart::TopFull | App::RectPart::NoTopBottom | App::RectPart::Bottom; auto parts = RectPart::FullTop | RectPart::NoTopBottom | RectPart::Bottom;
if (tail == BubbleTail::Right) { if (tailSide == RectPart::Right) {
parts |= App::RectPart::BottomLeft; parts |= RectPart::BottomLeft;
p.fillRect(rect.x() + rect.width() - st::historyMessageRadius, rect.y() + rect.height() - st::historyMessageRadius, st::historyMessageRadius, st::historyMessageRadius, bg); p.fillRect(rect.x() + rect.width() - st::historyMessageRadius, rect.y() + rect.height() - st::historyMessageRadius, st::historyMessageRadius, st::historyMessageRadius, bg);
auto &tail = selected ? st::historyBubbleTailOutRightSelected : st::historyBubbleTailOutRight; auto &tail = selected ? st::historyBubbleTailOutRightSelected : st::historyBubbleTailOutRight;
tail.paint(p, rect.x() + rect.width(), rect.y() + rect.height() - tail.height(), outerWidth); tail.paint(p, rect.x() + rect.width(), rect.y() + rect.height() - tail.height(), outerWidth);
p.fillRect(rect.x() + rect.width() - st::historyMessageRadius, rect.y() + rect.height(), st::historyMessageRadius + tail.width(), st::msgShadow, sh); p.fillRect(rect.x() + rect.width() - st::historyMessageRadius, rect.y() + rect.height(), st::historyMessageRadius + tail.width(), st::msgShadow, sh);
} else if (tail == BubbleTail::Left) { } else if (tailSide == RectPart::Left) {
parts |= App::RectPart::BottomRight; parts |= RectPart::BottomRight;
p.fillRect(rect.x(), rect.y() + rect.height() - st::historyMessageRadius, st::historyMessageRadius, st::historyMessageRadius, bg); p.fillRect(rect.x(), rect.y() + rect.height() - st::historyMessageRadius, st::historyMessageRadius, st::historyMessageRadius, bg);
auto &tail = selected ? (outbg ? st::historyBubbleTailOutLeftSelected : st::historyBubbleTailInLeftSelected) : (outbg ? st::historyBubbleTailOutLeft : st::historyBubbleTailInLeft); auto &tail = selected ? (outbg ? st::historyBubbleTailOutLeftSelected : st::historyBubbleTailInLeftSelected) : (outbg ? st::historyBubbleTailOutLeft : st::historyBubbleTailInLeft);
tail.paint(p, rect.x() - tail.width(), rect.y() + rect.height() - tail.height(), outerWidth); tail.paint(p, rect.x() - tail.width(), rect.y() + rect.height() - tail.height(), outerWidth);
p.fillRect(rect.x() - tail.width(), rect.y() + rect.height(), st::historyMessageRadius + tail.width(), st::msgShadow, sh); p.fillRect(rect.x() - tail.width(), rect.y() + rect.height(), st::historyMessageRadius + tail.width(), st::msgShadow, sh);
} else { } else {
parts |= App::RectPart::BottomFull; parts |= RectPart::FullBottom;
} }
App::roundRect(p, rect, bg, cors, &sh, parts); App::roundRect(p, rect, bg, cors, &sh, parts);
} }

View File

@ -54,11 +54,6 @@ void paintEmpty(Painter &p, int width, int height);
void serviceColorsUpdated(); void serviceColorsUpdated();
enum class BubbleTail { void paintBubble(Painter &p, QRect rect, int outerWidth, bool selected, bool outbg, RectPart tailSide);
None,
Left,
Right,
};
void paintBubble(Painter &p, QRect rect, int outerWidth, bool selected, bool outbg, BubbleTail tail);
} // namespace HistoryLayout } // namespace HistoryLayout

View File

@ -778,7 +778,7 @@ void Widget::paintEvent(QPaintEvent *e) {
void Widget::paintContent(Painter &p) { void Widget::paintContent(Painter &p) {
auto inner = innerRect(); auto inner = innerRect();
App::roundRect(p, inner, st::emojiPanBg, ImageRoundRadius::Small, App::RectPart::TopFull | App::RectPart::BottomFull); App::roundRect(p, inner, st::emojiPanBg, ImageRoundRadius::Small, RectPart::FullTop | RectPart::FullBottom);
auto horizontal = horizontalRect(); auto horizontal = horizontalRect();
auto sidesTop = horizontal.y(); auto sidesTop = horizontal.y();

View File

@ -223,20 +223,20 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) {
if (_mainMenuCache.isNull() && mainMenuRight > 0) { if (_mainMenuCache.isNull() && mainMenuRight > 0) {
// All cache images are taken together with their shadows, // All cache images are taken together with their shadows,
// so we paint shadow only when there is no cache. // so we paint shadow only when there is no cache.
Ui::Shadow::paint(p, myrtlrect(0, 0, mainMenuRight, height()), width(), st::boxRoundShadow, Ui::Shadow::Side::Right); Ui::Shadow::paint(p, myrtlrect(0, 0, mainMenuRight, height()), width(), st::boxRoundShadow, RectPart::Right);
} }
if (_specialLayerCache.isNull() && !specialLayerBox.isEmpty()) { if (_specialLayerCache.isNull() && !specialLayerBox.isEmpty()) {
// All cache images are taken together with their shadows, // All cache images are taken together with their shadows,
// so we paint shadow only when there is no cache. // so we paint shadow only when there is no cache.
auto sides = Ui::Shadow::Side::Left | Ui::Shadow::Side::Right; auto sides = RectPart::Left | RectPart::Right;
auto topCorners = (specialLayerBox.y() > 0); auto topCorners = (specialLayerBox.y() > 0);
auto bottomCorners = (specialLayerBox.y() + specialLayerBox.height() < height()); auto bottomCorners = (specialLayerBox.y() + specialLayerBox.height() < height());
if (topCorners) { if (topCorners) {
sides |= Ui::Shadow::Side::Top; sides |= RectPart::Top;
} }
if (bottomCorners) { if (bottomCorners) {
sides |= Ui::Shadow::Side::Bottom; sides |= RectPart::Bottom;
} }
if (topCorners || bottomCorners) { if (topCorners || bottomCorners) {
p.setClipRegion(QRegion(rect()) - specialLayerBox.marginsRemoved(QMargins(st::boxRadius, 0, st::boxRadius, 0)) - specialLayerBox.marginsRemoved(QMargins(0, st::boxRadius, 0, st::boxRadius))); p.setClipRegion(QRegion(rect()) - specialLayerBox.marginsRemoved(QMargins(st::boxRadius, 0, st::boxRadius, 0)) - specialLayerBox.marginsRemoved(QMargins(0, st::boxRadius, 0, st::boxRadius)));
@ -247,8 +247,8 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) {
// In case of painting the shadow above the special layer we get // In case of painting the shadow above the special layer we get
// glitches in the corners, so we need to paint the corners once more. // glitches in the corners, so we need to paint the corners once more.
p.setClipping(false); p.setClipping(false);
auto parts = (topCorners ? (App::RectPart::TopLeft | App::RectPart::TopRight) : App::RectPart::None) auto parts = (topCorners ? (RectPart::TopLeft | RectPart::TopRight) : RectPart::None)
| (bottomCorners ? (App::RectPart::BottomLeft | App::RectPart::BottomRight) : App::RectPart::None); | (bottomCorners ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None);
App::roundRect(p, specialLayerBox, st::boxBg, BoxCorners, nullptr, parts); App::roundRect(p, specialLayerBox, st::boxBg, BoxCorners, nullptr, parts);
} }
} }
@ -387,12 +387,12 @@ void LayerStackWidget::setCacheImages() {
auto bodyCache = QPixmap(), mainMenuCache = QPixmap(); auto bodyCache = QPixmap(), mainMenuCache = QPixmap();
auto specialLayerCache = QPixmap(); auto specialLayerCache = QPixmap();
if (_specialLayer) { if (_specialLayer) {
auto sides = Ui::Shadow::Side::Left | Ui::Shadow::Side::Right; auto sides = RectPart::Left | RectPart::Right;
if (_specialLayer->y() > 0) { if (_specialLayer->y() > 0) {
sides |= Ui::Shadow::Side::Top; sides |= RectPart::Top;
} }
if (_specialLayer->y() + _specialLayer->height() < height()) { if (_specialLayer->y() + _specialLayer->height() < height()) {
sides |= Ui::Shadow::Side::Bottom; sides |= RectPart::Bottom;
} }
specialLayerCache = Ui::Shadow::grab(_specialLayer, st::boxRoundShadow, sides); specialLayerCache = Ui::Shadow::grab(_specialLayer, st::boxRoundShadow, sides);
} }
@ -408,7 +408,7 @@ void LayerStackWidget::setCacheImages() {
hideChildren(); hideChildren();
bodyCache = myGrab(App::wnd()->bodyWidget()); bodyCache = myGrab(App::wnd()->bodyWidget());
showChildren(); showChildren();
mainMenuCache = Ui::Shadow::grab(_mainMenu, st::boxRoundShadow, Ui::Shadow::Side::Right); mainMenuCache = Ui::Shadow::grab(_mainMenu, st::boxRoundShadow, RectPart::Right);
} }
setAttribute(Qt::WA_OpaquePaintEvent, !bodyCache.isNull()); setAttribute(Qt::WA_OpaquePaintEvent, !bodyCache.isNull());
updateLayerBoxes(); updateLayerBoxes();

View File

@ -79,9 +79,9 @@ void ConnectingWidget::set(const QString &text, const QString &reconnect) {
void ConnectingWidget::paintEvent(QPaintEvent *e) { void ConnectingWidget::paintEvent(QPaintEvent *e) {
Painter p(this); Painter p(this);
auto sides = Ui::Shadow::Side::Top | Ui::Shadow::Side::Right; auto sides = RectPart::Top | RectPart::Right;
Ui::Shadow::paint(p, QRect(0, st::boxRoundShadow.extend.top(), width() - st::boxRoundShadow.extend.right(), height() - st::boxRoundShadow.extend.top()), width(), st::boxRoundShadow, sides); Ui::Shadow::paint(p, QRect(0, st::boxRoundShadow.extend.top(), width() - st::boxRoundShadow.extend.right(), height() - st::boxRoundShadow.extend.top()), width(), st::boxRoundShadow, sides);
auto parts = App::RectPart::Top | App::RectPart::TopRight | App::RectPart::Center | App::RectPart::Right; auto parts = RectPart::Top | RectPart::TopRight | RectPart::Center | RectPart::Right;
App::roundRect(p, QRect(-st::boxRadius, st::boxRoundShadow.extend.top(), width() - st::boxRoundShadow.extend.right() + st::boxRadius, height() - st::boxRoundShadow.extend.top() + st::boxRadius), st::boxBg, BoxCorners, nullptr, parts); App::roundRect(p, QRect(-st::boxRadius, st::boxRoundShadow.extend.top(), width() - st::boxRoundShadow.extend.right() + st::boxRadius, height() - st::boxRoundShadow.extend.top() + st::boxRadius), st::boxBg, BoxCorners, nullptr, parts);
p.setFont(st::normalFont); p.setFont(st::normalFont);

View File

@ -165,14 +165,13 @@ void Panel::paintEvent(QPaintEvent *e) {
} }
// draw shadow // draw shadow
using Side = Ui::Shadow::Side;
auto shadowedRect = myrtlrect(contentLeft(), contentTop(), contentWidth(), contentHeight()); auto shadowedRect = myrtlrect(contentLeft(), contentTop(), contentWidth(), contentHeight());
auto shadowedSides = (rtl() ? Side::Right : Side::Left) | Side::Bottom; auto shadowedSides = (rtl() ? RectPart::Right : RectPart::Left) | RectPart::Bottom;
if (_layout != Layout::Full) { if (_layout != Layout::Full) {
shadowedSides |= (rtl() ? Side::Left : Side::Right) | Side::Top; shadowedSides |= (rtl() ? RectPart::Left : RectPart::Right) | RectPart::Top;
} }
Ui::Shadow::paint(p, shadowedRect, width(), st::defaultRoundShadow, shadowedSides); Ui::Shadow::paint(p, shadowedRect, width(), st::defaultRoundShadow, shadowedSides);
auto parts = App::RectPart::Full; auto parts = RectPart::Full;
App::roundRect(p, shadowedRect, st::menuBg, MenuCorners, nullptr, parts); App::roundRect(p, shadowedRect, st::menuBg, MenuCorners, nullptr, parts);
} }
@ -224,7 +223,7 @@ void Panel::ensureCreated() {
setPinCallback(std::move(_pinCallback)); setPinCallback(std::move(_pinCallback));
setCloseCallback(std::move(_closeCallback)); setCloseCallback(std::move(_closeCallback));
_scrollShadow.create(this, st::mediaPlayerScrollShadow, Ui::Shadow::Side::Bottom); _scrollShadow.create(this, st::mediaPlayerScrollShadow, RectPart::Bottom);
} }
auto list = object_ptr<ListWidget>(this); auto list = object_ptr<ListWidget>(this);
connect(list, SIGNAL(heightUpdated()), this, SLOT(onListHeightUpdated())); connect(list, SIGNAL(heightUpdated()), this, SLOT(onListHeightUpdated()));

View File

@ -141,10 +141,9 @@ void VolumeWidget::paintEvent(QPaintEvent *e) {
// draw shadow // draw shadow
auto shadowedRect = rect().marginsRemoved(getMargin()); auto shadowedRect = rect().marginsRemoved(getMargin());
using ShadowSide = Ui::Shadow::Side; auto shadowedSides = RectPart::Left | RectPart::Right | RectPart::Bottom;
auto shadowedSides = ShadowSide::Left | ShadowSide::Right | ShadowSide::Bottom;
Ui::Shadow::paint(p, shadowedRect, width(), st::defaultRoundShadow, shadowedSides); Ui::Shadow::paint(p, shadowedRect, width(), st::defaultRoundShadow, shadowedSides);
auto parts = App::RectPart::NoTopBottom | App::RectPart::BottomFull; auto parts = RectPart::NoTopBottom | RectPart::FullBottom;
App::roundRect(p, QRect(shadowedRect.x(), -st::buttonRadius, shadowedRect.width(), shadowedRect.y() + shadowedRect.height() + st::buttonRadius), st::menuBg, MenuCorners, nullptr, parts); App::roundRect(p, QRect(shadowedRect.x(), -st::buttonRadius, shadowedRect.width(), shadowedRect.y() + shadowedRect.height() + st::buttonRadius), st::menuBg, MenuCorners, nullptr, parts);
} }

View File

@ -48,22 +48,22 @@ void InnerWidget::createBlocks() {
auto channel = _peer->asChannel(); auto channel = _peer->asChannel();
auto megagroup = _peer->isMegagroup() ? channel : nullptr; auto megagroup = _peer->isMegagroup() ? channel : nullptr;
if (user || channel || megagroup) { if (user || channel || megagroup) {
_blocks.push_back({ new InfoWidget(this, _peer), BlockSide::Right }); _blocks.push_back({ new InfoWidget(this, _peer), RectPart::Right });
} }
_blocks.push_back({ new SettingsWidget(this, _peer), BlockSide::Right }); _blocks.push_back({ new SettingsWidget(this, _peer), RectPart::Right });
if (chat || channel || megagroup) { if (chat || channel || megagroup) {
_blocks.push_back({ new InviteLinkWidget(this, _peer), BlockSide::Right }); _blocks.push_back({ new InviteLinkWidget(this, _peer), RectPart::Right });
} }
_blocks.push_back({ new SharedMediaWidget(this, _peer), BlockSide::Right }); _blocks.push_back({ new SharedMediaWidget(this, _peer), RectPart::Right });
if (channel && !megagroup) { if (channel && !megagroup) {
_blocks.push_back({ new ChannelMembersWidget(this, _peer), BlockSide::Right }); _blocks.push_back({ new ChannelMembersWidget(this, _peer), RectPart::Right });
} }
_blocks.push_back({ new ActionsWidget(this, _peer), BlockSide::Right }); _blocks.push_back({ new ActionsWidget(this, _peer), RectPart::Right });
if (chat || megagroup) { if (chat || megagroup) {
auto membersWidget = new GroupMembersWidget(this, _peer); auto membersWidget = new GroupMembersWidget(this, _peer);
connect(membersWidget, SIGNAL(onlineCountUpdated(int)), _cover, SLOT(onOnlineCountUpdated(int))); connect(membersWidget, SIGNAL(onlineCountUpdated(int)), _cover, SLOT(onOnlineCountUpdated(int)));
_cover->onOnlineCountUpdated(membersWidget->onlineCount()); _cover->onOnlineCountUpdated(membersWidget->onlineCount());
_blocks.push_back({ membersWidget, BlockSide::Left }); _blocks.push_back({ membersWidget, RectPart::Left });
} }
for_const (auto &blockData, _blocks) { for_const (auto &blockData, _blocks) {
connect(blockData.block, SIGNAL(heightUpdated()), this, SLOT(onBlockHeightUpdated())); connect(blockData.block, SIGNAL(heightUpdated()), this, SLOT(onBlockHeightUpdated()));
@ -118,8 +118,8 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
p.fillRect(e->rect(), st::profileBg); p.fillRect(e->rect(), st::profileBg);
if (_mode == Mode::TwoColumn) { if (_mode == Mode::TwoColumn) {
int leftHeight = countBlocksHeight(BlockSide::Left); int leftHeight = countBlocksHeight(RectPart::Left);
int rightHeight = countBlocksHeight(BlockSide::Right); int rightHeight = countBlocksHeight(RectPart::Right);
int shadowHeight = rightHeight;// qMin(leftHeight, rightHeight); int shadowHeight = rightHeight;// qMin(leftHeight, rightHeight);
int shadowLeft = _blocksLeft + _leftColumnWidth + _columnDivider; int shadowLeft = _blocksLeft + _leftColumnWidth + _columnDivider;
@ -134,7 +134,7 @@ void InnerWidget::keyPressEvent(QKeyEvent *e) {
} }
} }
int InnerWidget::countBlocksHeight(BlockSide countSide) const { int InnerWidget::countBlocksHeight(RectPart countSide) const {
int result = 0; int result = 0;
for_const (auto &blockData, _blocks) { for_const (auto &blockData, _blocks) {
if (blockData.side != countSide || blockData.block->isHidden()) { if (blockData.side != countSide || blockData.block->isHidden()) {
@ -156,7 +156,7 @@ InnerWidget::Mode InnerWidget::countBlocksMode(int newWidth) const {
bool hasLeftWidget = false, hasRightWidget = false; bool hasLeftWidget = false, hasRightWidget = false;
for_const (auto &blockData, _blocks) { for_const (auto &blockData, _blocks) {
if (!blockData.block->isHidden()) { if (!blockData.block->isHidden()) {
if (blockData.side == BlockSide::Left) { if (blockData.side == RectPart::Left) {
hasLeftWidget = true; hasLeftWidget = true;
} else { } else {
hasRightWidget = true; hasRightWidget = true;
@ -187,7 +187,7 @@ int InnerWidget::countLeftColumnWidth(int newWidth) const {
} }
void InnerWidget::refreshBlocksPositions() { void InnerWidget::refreshBlocksPositions() {
auto layoutBlocks = [this](BlockSide layoutSide, int left) { auto layoutBlocks = [this](RectPart layoutSide, int left) {
int top = _blocksTop; int top = _blocksTop;
for_const (auto &blockData, _blocks) { for_const (auto &blockData, _blocks) {
if (_mode == Mode::TwoColumn && blockData.side != layoutSide) { if (_mode == Mode::TwoColumn && blockData.side != layoutSide) {
@ -202,9 +202,9 @@ void InnerWidget::refreshBlocksPositions() {
top += blockData.block->height(); top += blockData.block->height();
} }
}; };
layoutBlocks(BlockSide::Left, _blocksLeft); layoutBlocks(RectPart::Left, _blocksLeft);
if (_mode == Mode::TwoColumn) { if (_mode == Mode::TwoColumn) {
layoutBlocks(BlockSide::Right, _blocksLeft + _leftColumnWidth + _columnDivider); layoutBlocks(RectPart::Right, _blocksLeft + _leftColumnWidth + _columnDivider);
} }
} }
@ -214,7 +214,7 @@ void InnerWidget::resizeBlocks(int newWidth) {
if (_mode == Mode::OneColumn) { if (_mode == Mode::OneColumn) {
blockWidth -= _blocksLeft; blockWidth -= _blocksLeft;
} else { } else {
if (blockData.side == BlockSide::Left) { if (blockData.side == RectPart::Left) {
blockWidth = _leftColumnWidth; blockWidth = _leftColumnWidth;
} else { } else {
blockWidth -= _leftColumnWidth + _columnDivider; blockWidth -= _leftColumnWidth + _columnDivider;
@ -244,11 +244,11 @@ int InnerWidget::resizeGetHeight(int newWidth) {
} }
int InnerWidget::countHeight() const { int InnerWidget::countHeight() const {
int newHeight = _cover->height(); auto newHeight = _cover->height();
int leftHeight = countBlocksHeight(BlockSide::Left); auto leftHeight = countBlocksHeight(RectPart::Left);
int rightHeight = countBlocksHeight(BlockSide::Right); auto rightHeight = countBlocksHeight(RectPart::Right);
int blocksHeight = (_mode == Mode::OneColumn) ? (leftHeight + rightHeight) : qMax(leftHeight, rightHeight); auto blocksHeight = (_mode == Mode::OneColumn) ? (leftHeight + rightHeight) : qMax(leftHeight, rightHeight);
newHeight += st::profileBlocksTop + blocksHeight + st::profileBlocksBottom; newHeight += st::profileBlocksTop + blocksHeight + st::profileBlocksBottom;
return newHeight; return newHeight;

View File

@ -77,14 +77,10 @@ private:
OneColumn, OneColumn,
TwoColumn, TwoColumn,
}; };
enum class BlockSide {
Left,
Right,
};
int countBlocksLeft(int newWidth) const; int countBlocksLeft(int newWidth) const;
Mode countBlocksMode(int newWidth) const; Mode countBlocksMode(int newWidth) const;
int countLeftColumnWidth(int newWidth) const; int countLeftColumnWidth(int newWidth) const;
int countBlocksHeight(BlockSide countSide) const; int countBlocksHeight(RectPart countSide) const;
void resizeBlocks(int newWidth); void resizeBlocks(int newWidth);
void refreshBlocksPositions(); void refreshBlocksPositions();
@ -110,7 +106,7 @@ private:
int _leftColumnWidth = 0; // Caching countLeftColumnWidth() result. int _leftColumnWidth = 0; // Caching countLeftColumnWidth() result.
struct Block { struct Block {
BlockWidget *block; BlockWidget *block;
BlockSide side; RectPart side;
}; };
QList<Block> _blocks; QList<Block> _blocks;

View File

@ -89,9 +89,9 @@ void Layer::paintEvent(QPaintEvent *e) {
auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius));
auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius));
if (paintTopRounded || paintBottomRounded) { if (paintTopRounded || paintBottomRounded) {
auto parts = qFlags(App::RectPart::None); auto parts = qFlags(RectPart::None);
if (paintTopRounded) parts |= App::RectPart::TopFull; if (paintTopRounded) parts |= RectPart::FullTop;
if (paintBottomRounded) parts |= App::RectPart::BottomFull; if (paintBottomRounded) parts |= RectPart::FullBottom;
App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts); App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts);
} }
auto other = clip.intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius)); auto other = clip.intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius));

View File

@ -55,9 +55,10 @@ enum class RectPart {
CornersMask = TopLeft | TopRight | BottomLeft | BottomRight, CornersMask = TopLeft | TopRight | BottomLeft | BottomRight,
SidesMask = Top | Bottom | Left | Right, SidesMask = Top | Bottom | Left | Right,
All = FullTop | NoTop, Full = FullTop | NoTop,
}; };
Q_DECLARE_FLAGS(RectParts, RectPart); Q_DECLARE_FLAGS(RectParts, RectPart);
Q_DECLARE_OPERATORS_FOR_FLAGS(RectParts);
inline bool IsTopCorner(RectPart corner) { inline bool IsTopCorner(RectPart corner) {
return (corner == RectPart::TopLeft) || (corner == RectPart::TopRight); return (corner == RectPart::TopLeft) || (corner == RectPart::TopRight);

View File

@ -22,11 +22,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Ui { namespace Ui {
void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Shadow &st, Sides sides) { void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Shadow &st, RectParts sides) {
auto left = (sides & Side::Left); auto left = (sides & RectPart::Left);
auto top = (sides & Side::Top); auto top = (sides & RectPart::Top);
auto right = (sides & Side::Right); auto right = (sides & RectPart::Right);
auto bottom = (sides & Side::Bottom); auto bottom = (sides & RectPart::Bottom);
if (left) { if (left) {
auto from = box.y(); auto from = box.y();
auto to = from + box.height(); auto to = from + box.height();
@ -77,14 +77,14 @@ void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Sh
} }
} }
QPixmap Shadow::grab(TWidget *target, const style::Shadow &shadow, Sides sides) { QPixmap Shadow::grab(TWidget *target, const style::Shadow &shadow, RectParts sides) {
myEnsureResized(target); myEnsureResized(target);
auto rect = target->rect(); auto rect = target->rect();
auto extend = QMargins( auto extend = QMargins(
(sides & Side::Left) ? shadow.extend.left() : 0, (sides & RectPart::Left) ? shadow.extend.left() : 0,
(sides & Side::Top) ? shadow.extend.top() : 0, (sides & RectPart::Top) ? shadow.extend.top() : 0,
(sides & Side::Right) ? shadow.extend.right() : 0, (sides & RectPart::Right) ? shadow.extend.right() : 0,
(sides & Side::Bottom) ? shadow.extend.bottom() : 0 (sides & RectPart::Bottom) ? shadow.extend.bottom() : 0
); );
auto full = QRect(0, 0, extend.left() + rect.width() + extend.right(), extend.top() + rect.height() + extend.bottom()); auto full = QRect(0, 0, extend.left() + rect.width() + extend.right(), extend.top() + rect.height() + extend.bottom());
auto result = QPixmap(full.size() * cIntRetinaFactor()); auto result = QPixmap(full.size() * cIntRetinaFactor());

View File

@ -38,23 +38,14 @@ private:
class Shadow : public TWidget { class Shadow : public TWidget {
public: public:
enum class Side { Shadow(QWidget *parent, const style::Shadow &st, RectParts sides = RectPart::Left | RectPart::Top | RectPart::Right | RectPart::Bottom) : TWidget(parent)
Left = 0x01,
Top = 0x02,
Right = 0x04,
Bottom = 0x08,
};
Q_DECLARE_FLAGS(Sides, Side);
Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(Sides);
Shadow(QWidget *parent, const style::Shadow &st, Sides sides = Side::Left | Side::Top | Side::Right | Side::Bottom) : TWidget(parent)
, _st(st) , _st(st)
, _sides(sides) { , _sides(sides) {
} }
static void paint(Painter &p, const QRect &box, int outerWidth, const style::Shadow &st, Sides sides = Side::Left | Side::Top | Side::Right | Side::Bottom); static void paint(Painter &p, const QRect &box, int outerWidth, const style::Shadow &st, RectParts sides = RectPart::Left | RectPart::Top | RectPart::Right | RectPart::Bottom);
static QPixmap grab(TWidget *target, const style::Shadow &shadow, Sides sides = Side::Left | Side::Top | Side::Right | Side::Bottom); static QPixmap grab(TWidget *target, const style::Shadow &shadow, RectParts sides = RectPart::Left | RectPart::Top | RectPart::Right | RectPart::Bottom);
protected: protected:
void paintEvent(QPaintEvent *e) override { void paintEvent(QPaintEvent *e) override {
@ -64,9 +55,8 @@ protected:
private: private:
const style::Shadow &_st; const style::Shadow &_st;
Sides _sides; RectParts _sides;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(Shadow::Sides);
} // namespace Ui } // namespace Ui

View File

@ -208,7 +208,7 @@ ImportantTooltip::ImportantTooltip(QWidget *parent, object_ptr<TWidget> content,
hide(); hide();
} }
void ImportantTooltip::pointAt(QRect area, Side side) { void ImportantTooltip::pointAt(QRect area, RectParts side) {
if (_area == area && _side == side) { if (_area == area && _side == side) {
return; return;
} }
@ -239,7 +239,7 @@ void ImportantTooltip::setArea(QRect area) {
resize(size); resize(size);
} }
void ImportantTooltip::countApproachSide(Side preferSide) { void ImportantTooltip::countApproachSide(RectParts preferSide) {
Expects(parentWidget() != nullptr); Expects(parentWidget() != nullptr);
auto requiredSpace = countInner().height() + _st.shift; auto requiredSpace = countInner().height() + _st.shift;
if (_useTransparency) { if (_useTransparency) {
@ -253,7 +253,7 @@ void ImportantTooltip::countApproachSide(Side preferSide) {
if ((allowedAbove && allowedBelow) || (!allowedAbove && !allowedBelow)) { if ((allowedAbove && allowedBelow) || (!allowedAbove && !allowedBelow)) {
_side = preferSide; _side = preferSide;
} else { } else {
_side = (allowedAbove ? SideFlag::Up : SideFlag::Down) | (preferSide & (SideFlag::Left | SideFlag::Center | SideFlag::Right)); _side = (allowedAbove ? RectPart::Top : RectPart::Bottom) | (preferSide & (RectPart::Left | RectPart::Center | RectPart::Right));
} }
if (_useTransparency) { if (_useTransparency) {
auto arrow = QImage(QSize(_st.arrow * 2, _st.arrow) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); auto arrow = QImage(QSize(_st.arrow * 2, _st.arrow) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
@ -270,7 +270,7 @@ void ImportantTooltip::countApproachSide(Side preferSide) {
path.lineTo(0, 0); path.lineTo(0, 0);
p.fillPath(path, _st.bg); p.fillPath(path, _st.bg);
} }
if (_side & SideFlag::Down) { if (_side & RectPart::Bottom) {
arrow = std::move(arrow).transformed(QTransform(1, 0, 0, -1, 0, 0)); arrow = std::move(arrow).transformed(QTransform(1, 0, 0, -1, 0, 0));
} }
_arrow = App::pixmapFromImageInPlace(std::move(arrow)); _arrow = App::pixmapFromImageInPlace(std::move(arrow));
@ -345,9 +345,9 @@ void ImportantTooltip::updateGeometry() {
auto parent = parentWidget(); auto parent = parentWidget();
auto areaMiddle = _area.x() + (_area.width() / 2); auto areaMiddle = _area.x() + (_area.width() / 2);
auto left = areaMiddle - (width() / 2); auto left = areaMiddle - (width() / 2);
if (_side & SideFlag::Left) { if (_side & RectPart::Left) {
left = areaMiddle + _st.arrowSkip - width(); left = areaMiddle + _st.arrowSkip - width();
} else if (_side & SideFlag::Right) { } else if (_side & RectPart::Right) {
left = areaMiddle - _st.arrowSkip; left = areaMiddle - _st.arrowSkip;
} }
accumulate_min(left, parent->width() - _st.margin.right() - width()); accumulate_min(left, parent->width() - _st.margin.right() - width());
@ -357,7 +357,7 @@ void ImportantTooltip::updateGeometry() {
auto countTop = [this] { auto countTop = [this] {
auto shift = anim::interpolate(_st.shift, 0, _visibleAnimation.current(_visible ? 1. : 0.)); auto shift = anim::interpolate(_st.shift, 0, _visibleAnimation.current(_visible ? 1. : 0.));
if (_side & SideFlag::Up) { if (_side & RectPart::Top) {
return _area.y() - height() - shift; return _area.y() - height() - shift;
} }
return _area.y() + _area.height() + shift; return _area.y() + _area.height() + shift;
@ -368,7 +368,7 @@ void ImportantTooltip::updateGeometry() {
void ImportantTooltip::resizeEvent(QResizeEvent *e) { void ImportantTooltip::resizeEvent(QResizeEvent *e) {
auto inner = countInner(); auto inner = countInner();
auto contentTop = _st.padding.top(); auto contentTop = _st.padding.top();
if (_useTransparency && (_side & SideFlag::Down)) { if (_useTransparency && (_side & RectPart::Bottom)) {
contentTop += _st.arrow; contentTop += _st.arrow;
} }
_content->moveToLeft(_st.padding.left(), contentTop); _content->moveToLeft(_st.padding.left(), contentTop);
@ -399,7 +399,7 @@ void ImportantTooltip::paintEvent(QPaintEvent *e) {
} }
auto areaMiddle = _area.x() + (_area.width() / 2) - x(); auto areaMiddle = _area.x() + (_area.width() / 2) - x();
auto arrowLeft = areaMiddle - _st.arrow; auto arrowLeft = areaMiddle - _st.arrow;
if (_side & SideFlag::Up) { if (_side & RectPart::Top) {
p.drawPixmapLeft(arrowLeft, inner.y() + inner.height(), width(), _arrow); p.drawPixmapLeft(arrowLeft, inner.y() + inner.height(), width(), _arrow);
} else { } else {
p.drawPixmapLeft(arrowLeft, inner.y() - _st.arrow, width(), _arrow); p.drawPixmapLeft(arrowLeft, inner.y() - _st.arrow, width(), _arrow);

View File

@ -79,15 +79,7 @@ class ImportantTooltip : public TWidget {
public: public:
ImportantTooltip(QWidget *parent, object_ptr<TWidget> content, const style::ImportantTooltip &st); ImportantTooltip(QWidget *parent, object_ptr<TWidget> content, const style::ImportantTooltip &st);
enum class SideFlag { void pointAt(QRect area, RectParts preferSide = RectPart::Top | RectPart::Left);
Up = 0x01,
Down = 0x02,
Left = 0x04,
Center = 0x08,
Right = 0x0c,
};
Q_DECLARE_FLAGS(Side, SideFlag);
void pointAt(QRect area, Side preferSide = Side(SideFlag::Up) | SideFlag::Left);
void toggleAnimated(bool visible); void toggleAnimated(bool visible);
void toggleFast(bool visible); void toggleFast(bool visible);
@ -105,7 +97,7 @@ private:
void animationCallback(); void animationCallback();
QRect countInner() const; QRect countInner() const;
void setArea(QRect area); void setArea(QRect area);
void countApproachSide(Side preferSide); void countApproachSide(RectParts preferSide);
void updateGeometry(); void updateGeometry();
void checkAnimationFinish(); void checkAnimationFinish();
void refreshAnimationCache(); void refreshAnimationCache();
@ -114,7 +106,7 @@ private:
const style::ImportantTooltip &_st; const style::ImportantTooltip &_st;
object_ptr<TWidget> _content; object_ptr<TWidget> _content;
QRect _area; QRect _area;
Side _side = Side(SideFlag::Up) | SideFlag::Left; RectParts _side = RectPart::Top | RectPart::Left;
QPixmap _arrow; QPixmap _arrow;
Animation _visibleAnimation; Animation _visibleAnimation;
@ -125,6 +117,4 @@ private:
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(ImportantTooltip::Side);
} // namespace Ui } // namespace Ui