2016-05-19 17:18:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ui/buttons/history_down_button.h"
|
|
|
|
|
|
|
|
#include "styles/style_history.h"
|
2016-06-03 12:45:33 +00:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2016-05-19 17:18:23 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
HistoryDownButton::HistoryDownButton(QWidget *parent, const style::TwoIconButton &st) : RippleButton(parent, st.ripple)
|
2016-12-07 13:32:25 +00:00
|
|
|
, _st(st) {
|
2016-11-16 16:04:25 +00:00
|
|
|
resize(_st.width, _st.height);
|
2016-05-19 17:18:23 +00:00
|
|
|
setCursor(style::cur_pointer);
|
2016-06-09 19:28:58 +00:00
|
|
|
|
|
|
|
hide();
|
2016-05-19 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
QImage HistoryDownButton::prepareRippleMask() const {
|
|
|
|
return Ui::RippleAnimation::ellipseMask(QSize(_st.rippleAreaSize, _st.rippleAreaSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint HistoryDownButton::prepareRippleStartPosition() const {
|
|
|
|
return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:18:23 +00:00
|
|
|
void HistoryDownButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2016-06-09 19:28:58 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
auto ms = getms();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto over = isOver();
|
|
|
|
auto down = isDown();
|
2016-11-16 16:04:25 +00:00
|
|
|
((over || down) ? _st.iconBelowOver : _st.iconBelow).paint(p, _st.iconPosition, width());
|
|
|
|
paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms);
|
|
|
|
((over || down) ? _st.iconAboveOver : _st.iconAbove).paint(p, _st.iconPosition, width());
|
2016-06-03 12:45:33 +00:00
|
|
|
if (_unreadCount > 0) {
|
|
|
|
auto unreadString = QString::number(_unreadCount);
|
|
|
|
if (unreadString.size() > 4) {
|
|
|
|
unreadString = qsl("..") + unreadString.mid(unreadString.size() - 4);
|
|
|
|
}
|
2016-06-21 15:58:07 +00:00
|
|
|
|
|
|
|
Dialogs::Layout::UnreadBadgeStyle st;
|
|
|
|
st.align = style::al_center;
|
|
|
|
st.font = st::historyToDownBadgeFont;
|
|
|
|
st.size = st::historyToDownBadgeSize;
|
|
|
|
st.sizeId = Dialogs::Layout::UnreadBadgeInHistoryToDown;
|
|
|
|
Dialogs::Layout::paintUnreadCount(p, unreadString, width(), 0, st, nullptr);
|
2016-06-03 12:45:33 +00:00
|
|
|
}
|
2016-05-19 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 12:45:33 +00:00
|
|
|
void HistoryDownButton::setUnreadCount(int unreadCount) {
|
|
|
|
_unreadCount = unreadCount;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
EmojiButton::EmojiButton(QWidget *parent, const style::IconButton &st) : RippleButton(parent, st.ripple)
|
2016-10-26 16:43:13 +00:00
|
|
|
, _st(st)
|
|
|
|
, _a_loading(animation(this, &EmojiButton::step_loading)) {
|
|
|
|
resize(_st.width, _st.height);
|
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-11-07 16:08:24 +00:00
|
|
|
auto ms = getms();
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(e->rect(), st::historyComposeAreaBg);
|
2016-12-05 11:01:08 +00:00
|
|
|
paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
auto loading = a_loading.current(ms, _loading ? 1 : 0);
|
2016-11-01 12:46:34 +00:00
|
|
|
p.setOpacity(1 - loading);
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto over = isOver();
|
2016-11-01 12:46:34 +00:00
|
|
|
auto icon = &(over ? _st.iconOver : _st.icon);
|
2016-11-16 16:04:25 +00:00
|
|
|
icon->paint(p, _st.iconPosition, width());
|
2016-10-26 16:43:13 +00:00
|
|
|
|
2016-11-01 12:46:34 +00:00
|
|
|
p.setOpacity(1.);
|
2016-11-28 13:42:37 +00:00
|
|
|
auto pen = (over ? st::historyEmojiCircleFgOver : st::historyEmojiCircleFg)->p;
|
|
|
|
pen.setWidth(st::historyEmojiCircleLine);
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
p.setPen(pen);
|
2016-10-26 16:43:13 +00:00
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
PainterHighQualityEnabler hq(p);
|
2016-10-26 16:43:13 +00:00
|
|
|
QRect inner(QPoint((width() - st::historyEmojiCircle.width()) / 2, st::historyEmojiCircleTop), st::historyEmojiCircle);
|
|
|
|
if (loading > 0) {
|
2016-12-01 19:20:33 +00:00
|
|
|
int32 full = FullArcLength;
|
|
|
|
int32 start = qRound(full * float64(ms % st::historyEmojiCirclePeriod) / st::historyEmojiCirclePeriod), part = qRound(loading * full / st::historyEmojiCirclePart);
|
2016-10-26 16:43:13 +00:00
|
|
|
p.drawArc(inner, start, full - part);
|
|
|
|
} else {
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiButton::setLoading(bool loading) {
|
|
|
|
if (_loading != loading) {
|
|
|
|
_loading = loading;
|
|
|
|
auto from = loading ? 0. : 1., to = loading ? 1. : 0.;
|
|
|
|
a_loading.start([this] { update(); }, from, to, st::historyEmojiCircleDuration);
|
|
|
|
if (loading) {
|
|
|
|
_a_loading.start();
|
|
|
|
} else {
|
|
|
|
_a_loading.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void EmojiButton::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
auto wasOver = static_cast<bool>(was & StateFlag::Over);
|
|
|
|
if (isOver() != wasOver) {
|
2016-11-01 12:46:34 +00:00
|
|
|
update();
|
2016-10-26 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
QPoint EmojiButton::prepareRippleStartPosition() const {
|
|
|
|
return mapFromGlobal(QCursor::pos()) - _st.rippleAreaPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage EmojiButton::prepareRippleMask() const {
|
|
|
|
return RippleAnimation::ellipseMask(QSize(_st.rippleAreaSize, _st.rippleAreaSize));
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:18:23 +00:00
|
|
|
} // namespace Ui
|