Beta version 1.8.6: Improve theme preview.

This commit is contained in:
John Preston 2019-09-09 16:13:16 +03:00
parent 61c7bf2f5e
commit 90b955534a
6 changed files with 42 additions and 4 deletions

View File

@ -1566,6 +1566,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_theme_preview_generating" = "Generating color theme preview...";
"lng_theme_preview_invalid" = "Invalid data in this theme file.";
"lng_theme_preview_apply" = "Apply this theme";
"lng_theme_preview_users#one" = "{count} person is using this theme";
"lng_theme_preview_users#other" = "{count} people are using this theme";
"lng_new_authorization" = "{name},\nWe detected a login into your account from a new device on {day}, {date} at {time}\n\nDevice: {device}\nLocation: {location}\n\nIf this wasn't you, you can go to Settings — Show all sessions and terminate that session.\n\nIf you think that somebody logged in to your account against your will, you can enable two-step verification in Settings.\n\nSincerely,\nThe Telegram Team";

View File

@ -41,7 +41,8 @@ CloudTheme CloudTheme::Parse(
(document
? session->data().processDocument(*document)->id
: DocumentId(0)),
data.is_creator() ? session->userId() : UserId(0)
data.is_creator() ? session->userId() : UserId(0),
data.vinstalls_count().v
};
}

View File

@ -24,6 +24,7 @@ struct CloudTheme {
QString title;
DocumentId documentId = 0;
UserId createdBy = 0;
int usersCount = 0;
static CloudTheme Parse(
not_null<Main::Session*> session,

View File

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/image/image.h"
#include "ui/text/text_utilities.h"
#include "ui/toast/toast.h"
#include "ui/text_options.h"
#include "boxes/confirm_box.h"
#include "media/audio/media_audio.h"
@ -1811,6 +1812,7 @@ void OverlayWidget::destroyThemePreview() {
_themePreview.reset();
_themeApply.destroy();
_themeCancel.destroy();
_themeShare.destroy();
}
void OverlayWidget::redisplayContent() {
@ -1956,6 +1958,9 @@ void OverlayWidget::updateThemePreviewGeometry() {
_themeApply->moveToRight(right, bottom - st::themePreviewMargin.bottom() + (st::themePreviewMargin.bottom() - _themeApply->height()) / 2);
right += _themeApply->width() + st::themePreviewButtonsSkip;
_themeCancel->moveToRight(right, _themeApply->y());
if (_themeShare) {
_themeShare->moveToLeft(previewRect.x(), _themeApply->y());
}
}
// For context menu event.
@ -2286,6 +2291,22 @@ void OverlayWidget::initThemePreview() {
st::themePreviewCancelButton);
_themeCancel->show();
_themeCancel->setClickedCallback([this] { close(); });
if (const auto slug = _themeCloudData.slug; !slug.isEmpty()) {
_themeShare.create(
this,
tr::lng_theme_share(),
st::themePreviewCancelButton);
_themeShare->show();
_themeShare->setClickedCallback([=] {
QGuiApplication::clipboard()->setText(
Core::App().createInternalLinkFull("addtheme/" + slug));
auto config = Ui::Toast::Config();
config.text = tr::lng_background_link_copied(tr::now);
Ui::Toast::Show(this, config);
});
} else {
_themeShare.destroy();
}
updateControls();
}
update();
@ -2946,7 +2967,11 @@ void OverlayWidget::paintThemePreview(Painter &p, QRect clip) {
if (titleRect.intersects(clip)) {
p.setFont(st::themePreviewTitleFont);
p.setPen(st::themePreviewTitleFg);
p.drawTextLeft(titleRect.x(), titleRect.y(), width(), tr::lng_theme_preview_title(tr::now));
const auto title = _themeCloudData.title.isEmpty()
? tr::lng_theme_preview_title(tr::now)
: _themeCloudData.title;
const auto elided = st::themePreviewTitleFont->elided(title, titleRect.width());
p.drawTextLeft(titleRect.x(), titleRect.y(), width(), elided);
}
auto buttonsRect = QRect(_themePreviewRect.x(), _themePreviewRect.y() + _themePreviewRect.height() - st::themePreviewMargin.bottom(), _themePreviewRect.width(), st::themePreviewMargin.bottom());
@ -2954,6 +2979,13 @@ void OverlayWidget::paintThemePreview(Painter &p, QRect clip) {
buttonsRect.moveTop(height() - buttonsRect.height());
fillOverlay(buttonsRect);
}
if (_themeShare && _themeCloudData.usersCount > 0) {
p.setFont(st::boxTextFont);
p.setPen(st::windowSubTextFg);
const auto left = _themeShare->x() + _themeShare->width() - (st::themePreviewCancelButton.width / 2);
const auto baseline = _themeShare->y() + st::themePreviewCancelButton.padding.top() + +st::themePreviewCancelButton.textTop + st::themePreviewCancelButton.font->ascent;
p.drawText(left, baseline, tr::lng_theme_preview_users(tr::now, lt_count, _themeCloudData.usersCount));
}
}
void OverlayWidget::keyPressEvent(QKeyEvent *e) {
@ -3703,6 +3735,7 @@ void OverlayWidget::setVisibleHook(bool visible) {
_themePreview = nullptr;
_themeApply.destroyDelayed();
_themeCancel.destroyDelayed();
_themeShare.destroyDelayed();
}
}

View File

@ -468,6 +468,7 @@ private:
std::unique_ptr<Window::Theme::Preview> _themePreview;
object_ptr<Ui::RoundButton> _themeApply = { nullptr };
object_ptr<Ui::RoundButton> _themeCancel = { nullptr };
object_ptr<Ui::RoundButton> _themeShare = { nullptr };
Data::CloudTheme _themeCloudData;
bool _wasRepainted = false;

View File

@ -196,8 +196,8 @@ mediaviewStreamingRadial: InfiniteRadialAnimation(defaultInfiniteRadialAnimation
themePreviewSize: size(903px, 584px);
themePreviewBg: windowBg;
themePreviewOverlayOpacity: 0.8;
themePreviewMargin: margins(36px, 52px, 36px, 88px);
themePreviewTitleTop: 14px;
themePreviewMargin: margins(36px, 72px, 36px, 88px);
themePreviewTitleTop: 24px;
themePreviewTitleFg: windowBoldFg;
themePreviewTitleFont: font(17px semibold);
themePreviewLoadingFont: font(16px);