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
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-05-19 17:18:23 +00:00
|
|
|
*/
|
|
|
|
#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-12-26 22:46:36 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kWideScale = 5;
|
|
|
|
|
|
|
|
} // namespace
|
2016-05-19 17:18:23 +00:00
|
|
|
|
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-12-26 22:46:36 +00:00
|
|
|
SendButton::SendButton(QWidget *parent) : RippleButton(parent, st::historyReplyCancel.ripple) {
|
|
|
|
resize(st::historySendSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::setType(Type type) {
|
|
|
|
if (_type != type) {
|
|
|
|
_contentFrom = grabContent();
|
|
|
|
_type = type;
|
|
|
|
_a_typeChanged.finish();
|
|
|
|
_contentTo = grabContent();
|
|
|
|
_a_typeChanged.start([this] { update(); }, 0., 1., st::historyRecordVoiceDuration);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
if (_type != Type::Record) {
|
|
|
|
_recordActive = false;
|
|
|
|
_a_recordActive.finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::setRecordActive(bool recordActive) {
|
|
|
|
if (_recordActive != recordActive) {
|
|
|
|
_recordActive = recordActive;
|
|
|
|
_a_recordActive.start([this] { recordAnimationCallback(); }, _recordActive ? 0. : 1., _recordActive ? 1. : 0, st::historyRecordVoiceDuration);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::finishAnimation() {
|
|
|
|
_a_typeChanged.finish();
|
|
|
|
_a_recordActive.finish();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
AbstractButton::mouseMoveEvent(e);
|
|
|
|
if (_recording) {
|
|
|
|
if (_recordUpdateCallback) {
|
|
|
|
_recordUpdateCallback(e->globalPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
auto ms = getms();
|
|
|
|
auto over = (isDown() || isOver());
|
|
|
|
auto changed = _a_typeChanged.current(ms, 1.);
|
|
|
|
if (changed < 1.) {
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setOpacity(1. - changed);
|
|
|
|
auto targetRect = QRect((1 - kWideScale) / 2 * width(), (1 - kWideScale) / 2 * height(), kWideScale * width(), kWideScale * height());
|
|
|
|
auto hiddenWidth = anim::interpolate(0, (1 - kWideScale) / 2 * width(), changed);
|
|
|
|
auto hiddenHeight = anim::interpolate(0, (1 - kWideScale) / 2 * height(), changed);
|
|
|
|
p.drawPixmap(targetRect.marginsAdded(QMargins(hiddenWidth, hiddenHeight, hiddenWidth, hiddenHeight)), _contentFrom);
|
|
|
|
p.setOpacity(changed);
|
|
|
|
auto shownWidth = anim::interpolate((1 - kWideScale) / 2 * width(), 0, changed);
|
|
|
|
auto shownHeight = anim::interpolate((1 - kWideScale) / 2 * height(), 0, changed);
|
|
|
|
p.drawPixmap(targetRect.marginsAdded(QMargins(shownWidth, shownHeight, shownWidth, shownHeight)), _contentTo);
|
|
|
|
} else if (_type == Type::Record) {
|
|
|
|
auto recordActive = recordActiveRatio();
|
|
|
|
auto rippleColor = anim::color(st::historyAttachEmoji.ripple.color, st::historyRecordVoiceRippleBgActive, recordActive);
|
|
|
|
paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), ms, &rippleColor);
|
|
|
|
|
|
|
|
auto fastIcon = [recordActive, over, this] {
|
|
|
|
if (recordActive == 1.) {
|
|
|
|
return &st::historyRecordVoiceActive;
|
|
|
|
} else if (over) {
|
|
|
|
return &st::historyRecordVoiceOver;
|
|
|
|
}
|
|
|
|
return &st::historyRecordVoice;
|
|
|
|
};
|
|
|
|
fastIcon()->paintInCenter(p, rect());
|
|
|
|
if (recordActive > 0. && recordActive < 1.) {
|
|
|
|
p.setOpacity(recordActive);
|
|
|
|
st::historyRecordVoiceActive.paintInCenter(p, rect());
|
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
} else if (_type == Type::Save) {
|
|
|
|
auto &saveIcon = over ? st::historyEditSaveIconOver : st::historyEditSaveIcon;
|
|
|
|
saveIcon.paint(p, st::historySendIconPosition, width());
|
|
|
|
} else if (_type == Type::Cancel) {
|
|
|
|
paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), ms);
|
|
|
|
|
|
|
|
auto &cancelIcon = over ? st::historyReplyCancelIconOver : st::historyReplyCancelIcon;
|
|
|
|
cancelIcon.paintInCenter(p, rect());
|
|
|
|
} else {
|
|
|
|
auto &sendIcon = over ? st::historySendIconOver : st::historySendIcon;
|
|
|
|
sendIcon.paint(p, st::historySendIconPosition, width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
|
|
|
|
auto down = (state() & StateFlag::Down);
|
|
|
|
if ((was & StateFlag::Down) != down) {
|
|
|
|
if (down) {
|
|
|
|
if (_type == Type::Record) {
|
|
|
|
_recording = true;
|
|
|
|
if (_recordStartCallback) {
|
|
|
|
_recordStartCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (_recording) {
|
|
|
|
_recording = false;
|
|
|
|
if (_recordStopCallback) {
|
|
|
|
_recordStopCallback(_recordActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap SendButton::grabContent() {
|
|
|
|
auto result = QImage(kWideScale * size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
Painter p(&result);
|
|
|
|
p.drawPixmap((kWideScale - 1) / 2 * width(), (kWideScale - 1) / 2 * height(), myGrab(this));
|
|
|
|
}
|
|
|
|
return App::pixmapFromImageInPlace(std_::move(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage SendButton::prepareRippleMask() const {
|
|
|
|
auto size = (_type == Type::Record) ? st::historyAttachEmoji.rippleAreaSize : st::historyReplyCancel.rippleAreaSize;
|
|
|
|
return Ui::RippleAnimation::ellipseMask(QSize(size, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SendButton::prepareRippleStartPosition() const {
|
|
|
|
auto real = mapFromGlobal(QCursor::pos());
|
|
|
|
auto size = (_type == Type::Record) ? st::historyAttachEmoji.rippleAreaSize : st::historyReplyCancel.rippleAreaSize;
|
|
|
|
auto y = (_type == Type::Record) ? st::historyAttachEmoji.rippleAreaPosition.y() : (height() - st::historyReplyCancel.rippleAreaSize) / 2;
|
|
|
|
return real - QPoint((width() - size) / 2, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendButton::recordAnimationCallback() {
|
|
|
|
update();
|
|
|
|
if (_recordAnimationCallback) {
|
|
|
|
_recordAnimationCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 17:18:23 +00:00
|
|
|
} // namespace Ui
|