2016-04-11 11:23:44 +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/peer_avatar_button.h"
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "structs.h"
|
2016-11-19 14:47:28 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
PeerAvatarButton::PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st) : AbstractButton(parent)
|
2016-04-11 11:23:44 +00:00
|
|
|
, _peer(peer)
|
|
|
|
, _st(st) {
|
|
|
|
resize(_st.size, _st.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerAvatarButton::paintEvent(QPaintEvent *e) {
|
|
|
|
if (_peer) {
|
|
|
|
Painter p(this);
|
|
|
|
_peer->paintUserpic(p, _st.photoSize, (_st.size - _st.photoSize) / 2, (_st.size - _st.photoSize) / 2);
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
NewAvatarButton::NewAvatarButton(QWidget *parent, int size, QPoint position) : RippleButton(parent, st::defaultActiveButton.ripple)
|
|
|
|
, _position(position) {
|
2016-11-19 14:47:28 +00:00
|
|
|
resize(size, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewAvatarButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (!_image.isNull()) {
|
|
|
|
p.drawPixmap(0, 0, _image);
|
|
|
|
return;
|
|
|
|
}
|
2016-12-03 12:10:35 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2016-12-05 11:01:08 +00:00
|
|
|
p.setBrush(isOver() ? st::defaultActiveButton.textBgOver : st::defaultActiveButton.textBg);
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(rect());
|
|
|
|
}
|
2016-11-19 14:47:28 +00:00
|
|
|
|
|
|
|
paintRipple(p, 0, 0, getms());
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
st::newGroupPhotoIcon.paint(p, _position, width());
|
2016-11-19 14:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewAvatarButton::setImage(const QImage &image) {
|
|
|
|
auto small = image.scaled(size() * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
2016-11-28 15:45:07 +00:00
|
|
|
Images::prepareCircle(small);
|
2016-11-19 14:47:28 +00:00
|
|
|
_image = App::pixmapFromImageInPlace(std_::move(small));
|
|
|
|
_image.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage NewAvatarButton::prepareRippleMask() const {
|
|
|
|
return Ui::RippleAnimation::ellipseMask(size());
|
|
|
|
}
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
} // namespace Ui
|