mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Slightly improved style of top bar in admin log section.
This commit is contained in:
@@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "profile/profile_back_button.h"
|
||||
|
||||
//#include "history/view/history_view_top_bar_widget.h"
|
||||
#include "main/main_session.h"
|
||||
#include "data/data_session.h"
|
||||
#include "ui/painter.h"
|
||||
@@ -15,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_profile.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_chat.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
|
||||
#include <QGraphicsOpacityEffect>
|
||||
|
||||
namespace Profile {
|
||||
|
||||
@@ -48,22 +51,106 @@ BackButton::BackButton(
|
||||
|
||||
void BackButton::setText(const QString &text) {
|
||||
_text = text;
|
||||
_cachedWidth = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void BackButton::setSubtext(const QString &subtext) {
|
||||
_subtext = subtext;
|
||||
_cachedWidth = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void BackButton::setWidget(not_null<Ui::RpWidget*> widget) {
|
||||
_widget = widget;
|
||||
_widget->setParent(this);
|
||||
_widget->show();
|
||||
_widget->move(
|
||||
st::historyAdminLogTopBarLeft + st::historyAdminLogTopBarUserpicSkip,
|
||||
(st::profileTopBarHeight - _widget->height()) / 2);
|
||||
_cachedWidth = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void BackButton::setOpacity(float64 opacity) {
|
||||
_opacity = opacity;
|
||||
if (_widget) {
|
||||
if (opacity < 1.) {
|
||||
if (!_opacityEffect) {
|
||||
_opacityEffect = Ui::CreateChild<QGraphicsOpacityEffect>(
|
||||
_widget);
|
||||
_widget->setGraphicsEffect(_opacityEffect);
|
||||
}
|
||||
_opacityEffect->setOpacity(opacity);
|
||||
} else {
|
||||
_widget->setGraphicsEffect(nullptr);
|
||||
_opacityEffect = nullptr;
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
int BackButton::resizeGetHeight(int newWidth) {
|
||||
_cachedWidth = -1;
|
||||
return st::profileTopBarHeight;
|
||||
}
|
||||
|
||||
void BackButton::updateCache() {
|
||||
if (_cachedWidth == width()) {
|
||||
return;
|
||||
}
|
||||
_cachedWidth = width();
|
||||
const auto widgetWidth = _widget
|
||||
? _widget->width() + st::historyAdminLogTopBarUserpicSkip
|
||||
: 0;
|
||||
const auto availableWidth = width()
|
||||
- st::historyAdminLogTopBarLeft
|
||||
- widgetWidth;
|
||||
_cachedElidedText = st::semiboldFont->elided(
|
||||
_text,
|
||||
availableWidth);
|
||||
_cachedElidedSubtext = st::dialogsTextFont->elided(
|
||||
_subtext,
|
||||
availableWidth);
|
||||
}
|
||||
|
||||
void BackButton::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
updateCache();
|
||||
|
||||
auto p = Painter(this);
|
||||
p.setOpacity(_opacity);
|
||||
|
||||
p.fillRect(e->rect(), st::profileBg);
|
||||
st::topBarBack.paint(p, (st::topBarArrowPadding.left() - st::topBarBack.width()) / 2, (st::topBarHeight - st::topBarBack.height()) / 2, width());
|
||||
st::topBarBack.paint(
|
||||
p,
|
||||
st::historyAdminLogTopBarLeft,
|
||||
(st::topBarHeight - st::topBarBack.height()) / 2,
|
||||
width());
|
||||
|
||||
p.setFont(st::topBarButton.style.font);
|
||||
p.setPen(st::topBarButton.textFg);
|
||||
p.drawTextLeft(st::topBarArrowPadding.left(), st::topBarButton.padding.top() + st::topBarButton.textTop, width(), _text);
|
||||
const auto textHeight = st::semiboldFont->height;
|
||||
const auto subtextHeight = st::dialogsTextFont->height;
|
||||
const auto totalHeight = _subtext.isEmpty()
|
||||
? textHeight
|
||||
: textHeight + subtextHeight;
|
||||
const auto startY = (height() - totalHeight) / 2 - st::lineWidth;
|
||||
const auto widgetWidth = _widget
|
||||
? _widget->width() + st::historyAdminLogTopBarUserpicSkip
|
||||
: 0;
|
||||
const auto textX = st::historyAdminLogTopBarLeft + widgetWidth;
|
||||
|
||||
p.setFont(st::semiboldFont);
|
||||
p.setPen(st::dialogsNameFg);
|
||||
p.drawTextLeft(textX, startY, width(), _cachedElidedText);
|
||||
|
||||
if (!_subtext.isEmpty()) {
|
||||
p.setFont(st::dialogsTextFont);
|
||||
p.setPen(st::historyStatusFg);
|
||||
p.drawTextLeft(
|
||||
textX,
|
||||
startY + textHeight + st::lineWidth * 2,
|
||||
width(),
|
||||
_cachedElidedSubtext);
|
||||
}
|
||||
}
|
||||
|
||||
void BackButton::onStateChanged(State was, StateChangeSource source) {
|
||||
|
||||
@@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "ui/abstract_button.h"
|
||||
|
||||
class QGraphicsOpacityEffect;
|
||||
|
||||
namespace Main {
|
||||
class Session;
|
||||
} // namespace Main
|
||||
@@ -24,6 +26,9 @@ public:
|
||||
rpl::producer<bool> oneColumnValue);
|
||||
|
||||
void setText(const QString &text);
|
||||
void setSubtext(const QString &subtext);
|
||||
void setWidget(not_null<Ui::RpWidget*> widget);
|
||||
void setOpacity(float64 opacity);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
@@ -32,10 +37,21 @@ protected:
|
||||
void onStateChanged(State was, StateChangeSource source) override;
|
||||
|
||||
private:
|
||||
void updateCache();
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
rpl::lifetime _unreadBadgeLifetime;
|
||||
QString _text;
|
||||
QString _subtext;
|
||||
Ui::RpWidget *_widget = nullptr;
|
||||
|
||||
int _cachedWidth = -1;
|
||||
QString _cachedElidedText;
|
||||
QString _cachedElidedSubtext;
|
||||
|
||||
float64 _opacity = 1.0;
|
||||
QGraphicsOpacityEffect *_opacityEffect = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user