diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 52d1171d2..0067c1531 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -33,7 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" #include "ui/toast/toast.h" -#include "ui/buttons/peer_avatar_button.h" +#include "ui/special_buttons.h" #include "mainwidget.h" #include "mainwindow.h" #include "apiwrap.h" diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 90f39c4d4..5314b3534 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -30,7 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "boxes/sharebox.h" #include "core/file_utilities.h" #include "ui/toast/toast.h" -#include "ui/buttons/history_down_button.h" +#include "ui/special_buttons.h" #include "ui/widgets/buttons.h" #include "ui/widgets/inner_dropdown.h" #include "ui/widgets/dropdown_menu.h" diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index 6cc53fbf2..8fbd70d6e 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -30,7 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" -#include "ui/buttons/peer_avatar_button.h" +#include "ui/special_buttons.h" namespace Intro { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index cd7174fc2..464733861 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -22,7 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "styles/style_dialogs.h" #include "styles/style_history.h" -#include "ui/buttons/peer_avatar_button.h" +#include "ui/special_buttons.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "window/section_memento.h" diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 89805c347..b70c6bb1e 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -41,7 +41,6 @@ class Panel; } // namespace Media namespace Ui { -class PeerAvatarButton; class PlainShadow; class DropdownMenu; } // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp b/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp deleted file mode 100644 index 86f86b594..000000000 --- a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -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-2017 John Preston, https://desktop.telegram.org -*/ -#include "ui/buttons/peer_avatar_button.h" - -#include "structs.h" -#include "ui/effects/ripple_animation.h" -#include "styles/style_boxes.h" - -namespace Ui { - -PeerAvatarButton::PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st) : AbstractButton(parent) -, _peer(peer) -, _st(st) { - resize(_st.size, _st.size); -} - -void PeerAvatarButton::paintEvent(QPaintEvent *e) { - if (_peer) { - Painter p(this); - _peer->paintUserpic(p, (_st.size - _st.photoSize) / 2, (_st.size - _st.photoSize) / 2, _st.photoSize); - } -} - -NewAvatarButton::NewAvatarButton(QWidget *parent, int size, QPoint position) : RippleButton(parent, st::defaultActiveButton.ripple) -, _position(position) { - resize(size, size); -} - -void NewAvatarButton::paintEvent(QPaintEvent *e) { - Painter p(this); - - if (!_image.isNull()) { - p.drawPixmap(0, 0, _image); - return; - } - - p.setPen(Qt::NoPen); - p.setBrush(isOver() ? st::defaultActiveButton.textBgOver : st::defaultActiveButton.textBg); - { - PainterHighQualityEnabler hq(p); - p.drawEllipse(rect()); - } - - paintRipple(p, 0, 0, getms()); - - st::newGroupPhotoIcon.paint(p, _position, width()); -} - -void NewAvatarButton::setImage(const QImage &image) { - auto small = image.scaled(size() * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - Images::prepareCircle(small); - _image = App::pixmapFromImageInPlace(std::move(small)); - _image.setDevicePixelRatio(cRetinaFactor()); - update(); -} - -QImage NewAvatarButton::prepareRippleMask() const { - return Ui::RippleAnimation::ellipseMask(size()); -} - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h b/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h deleted file mode 100644 index f9004d70b..000000000 --- a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -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-2017 John Preston, https://desktop.telegram.org -*/ -#pragma once - -#include "ui/widgets/buttons.h" -#include "styles/style_window.h" - -class PeerData; - -namespace Ui { - -class PeerAvatarButton : public AbstractButton { -public: - PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st); - - void setPeer(PeerData *peer) { - _peer = peer; - update(); - } - -protected: - void paintEvent(QPaintEvent *e) override; - -private: - PeerData *_peer; - const style::PeerAvatarButton &_st; - -}; - -class NewAvatarButton : public RippleButton { -public: - NewAvatarButton(QWidget *parent, int size, QPoint position); - - void setImage(const QImage &image); - -protected: - void paintEvent(QPaintEvent *e) override; - - QImage prepareRippleMask() const override; - -private: - QPixmap _image; - QPoint _position; - -}; - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 7f2fea803..bf06f1021 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -18,8 +18,9 @@ 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-2017 John Preston, https://desktop.telegram.org */ -#include "ui/buttons/history_down_button.h" +#include "ui/special_buttons.h" +#include "styles/style_boxes.h" #include "styles/style_history.h" #include "dialogs/dialogs_layout.h" #include "ui/effects/ripple_animation.h" @@ -288,4 +289,54 @@ void SendButton::recordAnimationCallback() { } } +PeerAvatarButton::PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st) : AbstractButton(parent) +, _peer(peer) +, _st(st) { + resize(_st.size, _st.size); +} + +void PeerAvatarButton::paintEvent(QPaintEvent *e) { + if (_peer) { + Painter p(this); + _peer->paintUserpic(p, (_st.size - _st.photoSize) / 2, (_st.size - _st.photoSize) / 2, _st.photoSize); + } +} + +NewAvatarButton::NewAvatarButton(QWidget *parent, int size, QPoint position) : RippleButton(parent, st::defaultActiveButton.ripple) +, _position(position) { + resize(size, size); +} + +void NewAvatarButton::paintEvent(QPaintEvent *e) { + Painter p(this); + + if (!_image.isNull()) { + p.drawPixmap(0, 0, _image); + return; + } + + p.setPen(Qt::NoPen); + p.setBrush(isOver() ? st::defaultActiveButton.textBgOver : st::defaultActiveButton.textBg); + { + PainterHighQualityEnabler hq(p); + p.drawEllipse(rect()); + } + + paintRipple(p, 0, 0, getms()); + + st::newGroupPhotoIcon.paint(p, _position, width()); +} + +void NewAvatarButton::setImage(const QImage &image) { + auto small = image.scaled(size() * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + Images::prepareCircle(small); + _image = App::pixmapFromImageInPlace(std::move(small)); + _image.setDevicePixelRatio(cRetinaFactor()); + update(); +} + +QImage NewAvatarButton::prepareRippleMask() const { + return Ui::RippleAnimation::ellipseMask(size()); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 5ddc299b4..1c5c91df3 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -21,8 +21,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "ui/widgets/buttons.h" +#include "styles/style_window.h" #include "styles/style_widgets.h" +class PeerData; + namespace Ui { class HistoryDownButton : public RippleButton { @@ -136,4 +139,39 @@ private: }; +class PeerAvatarButton : public AbstractButton { +public: + PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st); + + void setPeer(PeerData *peer) { + _peer = peer; + update(); + } + +protected: + void paintEvent(QPaintEvent *e) override; + +private: + PeerData *_peer; + const style::PeerAvatarButton &_st; + +}; + +class NewAvatarButton : public RippleButton { +public: + NewAvatarButton(QWidget *parent, int size, QPoint position); + + void setImage(const QImage &image); + +protected: + void paintEvent(QPaintEvent *e) override; + + QImage prepareRippleMask() const override; + +private: + QPixmap _image; + QPoint _position; + +}; + } // namespace Ui diff --git a/Telegram/SourceFiles/window/top_bar_widget.cpp b/Telegram/SourceFiles/window/top_bar_widget.cpp index 0ea166491..7e6ba28a4 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.cpp +++ b/Telegram/SourceFiles/window/top_bar_widget.cpp @@ -27,7 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "shortcuts.h" #include "lang.h" -#include "ui/buttons/peer_avatar_button.h" +#include "ui/special_buttons.h" #include "ui/widgets/buttons.h" #include "ui/widgets/dropdown_menu.h" #include "dialogs/dialogs_layout.h" diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index bd9bc5e2c..863ee00de 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -433,10 +433,6 @@ '<(src_loc)/storage/serialize_common.h', '<(src_loc)/storage/serialize_document.cpp', '<(src_loc)/storage/serialize_document.h', - '<(src_loc)/ui/buttons/history_down_button.cpp', - '<(src_loc)/ui/buttons/history_down_button.h', - '<(src_loc)/ui/buttons/peer_avatar_button.cpp', - '<(src_loc)/ui/buttons/peer_avatar_button.h', '<(src_loc)/ui/effects/cross_animation.cpp', '<(src_loc)/ui/effects/cross_animation.h', '<(src_loc)/ui/effects/panel_animation.cpp', @@ -515,6 +511,8 @@ '<(src_loc)/ui/emoji_config.h', '<(src_loc)/ui/images.cpp', '<(src_loc)/ui/images.h', + '<(src_loc)/ui/special_buttons.cpp', + '<(src_loc)/ui/special_buttons.h', '<(src_loc)/ui/twidget.cpp', '<(src_loc)/ui/twidget.h', '<(src_loc)/window/main_window.cpp',