From 807bebb3cf029a4a3f064cd0145590bc8b33edd9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Nov 2016 16:46:04 +0300 Subject: [PATCH] Buttons moved to ui/widgets/buttons module, BoxButton removed. --- Telegram/Resources/basic.style | 78 ----- Telegram/Resources/basic_types.style | 28 -- Telegram/SourceFiles/boxes/aboutbox.cpp | 30 +- Telegram/SourceFiles/boxes/aboutbox.h | 13 +- Telegram/SourceFiles/boxes/abstractbox.cpp | 2 +- Telegram/SourceFiles/boxes/addcontactbox.cpp | 9 +- Telegram/SourceFiles/boxes/addcontactbox.h | 28 +- Telegram/SourceFiles/boxes/autolockbox.cpp | 11 +- Telegram/SourceFiles/boxes/autolockbox.h | 3 +- Telegram/SourceFiles/boxes/boxes.style | 31 ++ Telegram/SourceFiles/boxes/confirmbox.cpp | 5 +- Telegram/SourceFiles/boxes/confirmbox.h | 25 +- .../SourceFiles/boxes/confirmphonebox.cpp | 5 +- Telegram/SourceFiles/boxes/confirmphonebox.h | 8 +- Telegram/SourceFiles/boxes/connectionbox.cpp | 3 +- Telegram/SourceFiles/boxes/connectionbox.h | 9 +- Telegram/SourceFiles/boxes/contactsbox.cpp | 4 +- Telegram/SourceFiles/boxes/contactsbox.h | 8 +- .../SourceFiles/boxes/downloadpathbox.cpp | 6 +- Telegram/SourceFiles/boxes/downloadpathbox.h | 8 +- Telegram/SourceFiles/boxes/languagebox.cpp | 11 +- Telegram/SourceFiles/boxes/languagebox.h | 3 +- .../SourceFiles/boxes/localstoragebox.cpp | 4 +- Telegram/SourceFiles/boxes/localstoragebox.h | 8 +- Telegram/SourceFiles/boxes/members_box.cpp | 8 +- .../SourceFiles/boxes/notifications_box.cpp | 3 +- .../SourceFiles/boxes/notifications_box.h | 7 +- Telegram/SourceFiles/boxes/passcodebox.cpp | 281 ++++++++-------- Telegram/SourceFiles/boxes/passcodebox.h | 22 +- Telegram/SourceFiles/boxes/photocropbox.cpp | 15 +- Telegram/SourceFiles/boxes/photocropbox.h | 7 +- Telegram/SourceFiles/boxes/photosendbox.cpp | 3 +- Telegram/SourceFiles/boxes/photosendbox.h | 9 +- Telegram/SourceFiles/boxes/report_box.cpp | 3 +- Telegram/SourceFiles/boxes/report_box.h | 3 +- Telegram/SourceFiles/boxes/sessionsbox.cpp | 34 +- Telegram/SourceFiles/boxes/sessionsbox.h | 6 +- Telegram/SourceFiles/boxes/sharebox.cpp | 1 + Telegram/SourceFiles/boxes/sharebox.h | 7 +- Telegram/SourceFiles/boxes/stickers_box.cpp | 8 +- Telegram/SourceFiles/boxes/stickers_box.h | 5 +- Telegram/SourceFiles/boxes/stickersetbox.cpp | 63 ++-- Telegram/SourceFiles/boxes/stickersetbox.h | 6 +- Telegram/SourceFiles/boxes/usernamebox.cpp | 78 ++--- Telegram/SourceFiles/boxes/usernamebox.h | 12 +- Telegram/SourceFiles/dialogs/dialogs.style | 2 +- Telegram/SourceFiles/dialogswidget.cpp | 14 +- Telegram/SourceFiles/dialogswidget.h | 6 +- Telegram/SourceFiles/history/history.style | 39 ++- Telegram/SourceFiles/historywidget.cpp | 25 +- Telegram/SourceFiles/historywidget.h | 46 +-- Telegram/SourceFiles/intro/intro.style | 10 +- Telegram/SourceFiles/intro/introcode.cpp | 3 +- Telegram/SourceFiles/intro/introcode.h | 8 +- Telegram/SourceFiles/intro/introphone.cpp | 3 +- Telegram/SourceFiles/intro/introphone.h | 1 - Telegram/SourceFiles/intro/intropwdcheck.cpp | 5 +- Telegram/SourceFiles/intro/intropwdcheck.h | 10 +- Telegram/SourceFiles/intro/introsignup.cpp | 3 +- Telegram/SourceFiles/intro/introsignup.h | 1 - Telegram/SourceFiles/intro/introstart.cpp | 5 +- Telegram/SourceFiles/intro/introstart.h | 6 +- Telegram/SourceFiles/intro/introwidget.cpp | 2 +- Telegram/SourceFiles/intro/introwidget.h | 5 +- Telegram/SourceFiles/mainwidget.cpp | 2 +- Telegram/SourceFiles/mainwindow.cpp | 13 +- Telegram/SourceFiles/mainwindow.h | 6 +- .../media/player/media_player_button.h | 2 +- .../media/player/media_player_cover.cpp | 6 +- .../player/media_player_volume_controller.cpp | 2 +- .../media/player/media_player_widget.cpp | 6 +- .../media/view/media_clip_controller.cpp | 2 +- .../SourceFiles/media/view/mediaview.style | 2 +- Telegram/SourceFiles/mediaview.cpp | 41 +-- Telegram/SourceFiles/mediaview.h | 5 +- Telegram/SourceFiles/overviewwidget.cpp | 2 +- Telegram/SourceFiles/passcodewidget.cpp | 3 +- Telegram/SourceFiles/passcodewidget.h | 3 +- .../platform/win/window_title_win.cpp | 2 +- .../SourceFiles/profile/profile_cover.cpp | 6 +- Telegram/SourceFiles/profile/profile_cover.h | 4 +- .../SourceFiles/profile/profile_fixed_bar.cpp | 11 +- .../profile/profile_settings_widget.cpp | 2 +- .../profile/profile_userpic_button.cpp | 2 +- .../profile/profile_userpic_button.h | 3 +- .../settings/settings_advanced_widget.cpp | 1 + .../settings/settings_advanced_widget.h | 10 +- .../settings/settings_background_widget.cpp | 7 +- .../settings/settings_background_widget.h | 12 +- .../settings/settings_block_widget.cpp | 11 +- .../settings/settings_block_widget.h | 6 +- .../settings_chat_settings_widget.cpp | 10 +- .../settings/settings_chat_settings_widget.h | 12 +- .../SourceFiles/settings/settings_cover.cpp | 7 +- .../SourceFiles/settings/settings_cover.h | 4 +- .../settings/settings_fixed_bar.cpp | 2 +- .../settings/settings_general_widget.cpp | 8 +- .../settings/settings_general_widget.h | 14 +- .../settings_notifications_widget.cpp | 3 +- .../settings/settings_notifications_widget.h | 2 +- .../settings/settings_privacy_widget.cpp | 9 +- .../settings/settings_privacy_widget.h | 10 +- .../settings/settings_scale_widget.cpp | 2 +- Telegram/SourceFiles/stdafx.h | 1 - Telegram/SourceFiles/stickers/emoji_pan.cpp | 18 +- Telegram/SourceFiles/stickers/emoji_pan.h | 9 +- .../ui/{button.cpp => abstract_button.cpp} | 52 ++- .../ui/{button.h => abstract_button.h} | 35 +- .../ui/buttons/history_down_button.cpp | 10 +- .../ui/buttons/history_down_button.h | 10 +- .../SourceFiles/ui/buttons/icon_button.cpp | 124 ------- Telegram/SourceFiles/ui/buttons/icon_button.h | 65 ---- .../ui/buttons/left_outline_button.cpp | 6 +- .../ui/buttons/left_outline_button.h | 6 +- .../ui/buttons/peer_avatar_button.cpp | 2 +- .../ui/buttons/peer_avatar_button.h | 4 +- .../SourceFiles/ui/buttons/round_button.cpp | 131 -------- .../SourceFiles/ui/buttons/round_button.h | 67 ---- Telegram/SourceFiles/ui/countryinput.h | 1 - Telegram/SourceFiles/ui/flatbutton.cpp | 203 ------------ Telegram/SourceFiles/ui/flatbutton.h | 108 ------ Telegram/SourceFiles/ui/widgets/buttons.cpp | 311 ++++++++++++++++++ Telegram/SourceFiles/ui/widgets/buttons.h | 139 ++++++++ .../ui/{buttons => widgets}/checkbox.cpp | 12 +- .../ui/{buttons => widgets}/checkbox.h | 21 +- .../SourceFiles/ui/widgets/multi_select.cpp | 2 +- Telegram/SourceFiles/ui/widgets/widgets.style | 58 ++-- .../window/notifications_manager_default.cpp | 6 +- .../window/notifications_manager_default.h | 3 +- .../SourceFiles/window/top_bar_widget.cpp | 8 +- .../window/window_theme_warning.cpp | 2 +- .../SourceFiles/window/window_theme_warning.h | 8 +- Telegram/gyp/Telegram.gyp | 16 +- 133 files changed, 1300 insertions(+), 1508 deletions(-) rename Telegram/SourceFiles/ui/{button.cpp => abstract_button.cpp} (64%) rename Telegram/SourceFiles/ui/{button.h => abstract_button.h} (76%) delete mode 100644 Telegram/SourceFiles/ui/buttons/icon_button.cpp delete mode 100644 Telegram/SourceFiles/ui/buttons/icon_button.h delete mode 100644 Telegram/SourceFiles/ui/buttons/round_button.cpp delete mode 100644 Telegram/SourceFiles/ui/buttons/round_button.h delete mode 100644 Telegram/SourceFiles/ui/flatbutton.cpp delete mode 100644 Telegram/SourceFiles/ui/flatbutton.h create mode 100644 Telegram/SourceFiles/ui/widgets/buttons.cpp create mode 100644 Telegram/SourceFiles/ui/widgets/buttons.h rename Telegram/SourceFiles/ui/{buttons => widgets}/checkbox.cpp (95%) rename Telegram/SourceFiles/ui/{buttons => widgets}/checkbox.h (87%) diff --git a/Telegram/Resources/basic.style b/Telegram/Resources/basic.style index 13f2e1c65..eaf924394 100644 --- a/Telegram/Resources/basic.style +++ b/Telegram/Resources/basic.style @@ -83,18 +83,6 @@ attentionBoxButton: RoundButton(defaultBoxButton) { textBgOver: #fff0ed; } boxButtonPadding: margins(12px, 16px, 22px, 16px); -defaultBoxLinkButton: linkButton { - color: #0080c0; - overColor: #0080c0; - downColor: #0073ad; - font: boxTextFont; - overFont: font(boxFontSize underline); -} -redBoxLinkButton: linkButton(defaultBoxLinkButton) { - color: #d15948; - overColor: #d15948; - downColor: #db6352; -} boxLabel: flatLabel(labelDefFlat) { font: font(boxFontSize); align: align(topleft); @@ -290,13 +278,6 @@ btnNoHover: #777777; linkCropLimit: 360px; linkFont: normalFont; linkOverFont: font(fsize underline); -btnDefLink: linkButton { - color: btnYesColor; - overColor: btnYesColor; - downColor: btnYesHover; - font: linkFont; - overFont: linkOverFont; -} inpDefFont: font(17px); inpDefFlat: flatInput { @@ -368,11 +349,6 @@ boxShadow: icon {{ "box_shadow", windowShadowFg }}; boxShadowShift: 2px; btnSelectSep: #e0e0e0; -btnRedLink: linkButton(btnDefLink) { - color: #d15948; - overColor: #d15948; - downColor: #db6352; -} countryRowHeight: 36px; countryRowNameFont: semiboldFont; @@ -699,41 +675,6 @@ historyScroll: flatScroll(scrollDef) { } textRectMargins: margins(-2px, -1px, -2px, -1px); -reportSpamHide: flatButton { - duration: 200; - cursor: cursor(pointer); - - color: btnYesColor; - overColor: btnYesHover; - - bgColor: transparent; - overBgColor: transparent; - - width: -40px; - height: 46px; - - textTop: 15px; - overTextTop: 15px; - downTextTop: 16px; - - font: font(fsize); - overFont: font(fsize underline); -} -reportSpamButton: flatButton(reportSpamHide) { - textTop: 6px; - overTextTop: 6px; - downTextTop: 7px; - - width: -50px; - height: 30px; - - bgColor: #888888; - overBgColor: #7b7b7b; -} -reportSpamSeparator: 30px; -reportSpamBg: #fffffff0; -reportSpamFg: #000000; - newMsgSound: ":/gui/art/newmsg.wav"; unreadBarHeight: 32px; @@ -798,25 +739,6 @@ connectionPasswordInputField: InputField(defaultInputField) { } connectionIPv6Skip: 11px; -aboutIcon: icon {{ "intro_logo", #008ed5 }}; -aboutWidth: 390px; -aboutVersionTop: -3px; -aboutVersionLink: linkButton(btnDefLink) { - color: #999999; - overColor: #999999; - downColor: #999999; -} -aboutTextTop: 34px; -aboutSkip: 14px; -aboutLabel: flatLabel(labelDefFlat) { - font: normalFont; - width: 330px; - align: align(topleft); -} -aboutTextStyle: textStyle(defaultTextStyle) { - lineHeight: 22px; -} - emojiTextFont: font(15px); emojiReplaceWidth: 52px; emojiReplaceHeight: 56px; diff --git a/Telegram/Resources/basic_types.style b/Telegram/Resources/basic_types.style index fdf78866f..82a6f294e 100644 --- a/Telegram/Resources/basic_types.style +++ b/Telegram/Resources/basic_types.style @@ -30,34 +30,6 @@ textStyle { lineHeight: pixels; } -linkButton { - color: color; - overColor: color; - downColor: color; - font: font; - overFont: font; -} - -flatButton { - color: color; - overColor: color; - - bgColor: color; - overBgColor: color; - - width: pixels; - height: pixels; - - textTop: pixels; - overTextTop: pixels; - downTextTop: pixels; - - font: font; - overFont: font; - duration: int; - cursor: cursor; -} - flatInput { textColor: color; bgColor: color; diff --git a/Telegram/SourceFiles/boxes/aboutbox.cpp b/Telegram/SourceFiles/boxes/aboutbox.cpp index dc49c5068..a646a91af 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.cpp +++ b/Telegram/SourceFiles/boxes/aboutbox.cpp @@ -27,6 +27,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "autoupdater.h" #include "boxes/confirmbox.h" #include "application.h" +#include "ui/widgets/buttons.h" +#include "styles/style_boxes.h" AboutBox::AboutBox() : AbstractBox(st::aboutWidth) , _version(this, lng_about_version(lt_version, QString::fromLatin1(AppVersionStr.c_str()) + (cAlphaVersion() ? " alpha" : "") + (cBetaVersion() ? qsl(" beta %1").arg(cBetaVersion()) : QString())), st::aboutVersionLink) @@ -34,12 +36,12 @@ AboutBox::AboutBox() : AbstractBox(st::aboutWidth) , _text2(this, lang(lng_about_text_2), FlatLabel::InitType::Rich, st::aboutLabel, st::aboutTextStyle) , _text3(this,st::aboutLabel, st::aboutTextStyle) , _done(this, lang(lng_close), st::defaultBoxButton) { - _text3.setRichText(lng_about_text_3(lt_faq_open, qsl("[a href=\"%1\"]").arg(telegramFaqLink()), lt_faq_close, qsl("[/a]"))); + _text3->setRichText(lng_about_text_3(lt_faq_open, qsl("[a href=\"%1\"]").arg(telegramFaqLink()), lt_faq_close, qsl("[/a]"))); - setMaxHeight(titleHeight() + st::aboutTextTop + _text1.height() + st::aboutSkip + _text2.height() + st::aboutSkip + _text3.height() + st::boxButtonPadding.top() + _done.height() + st::boxButtonPadding.bottom()); + setMaxHeight(titleHeight() + st::aboutTextTop + _text1->height() + st::aboutSkip + _text2->height() + st::aboutSkip + _text3->height() + st::boxButtonPadding.top() + _done->height() + st::boxButtonPadding.bottom()); - connect(&_version, SIGNAL(clicked()), this, SLOT(onVersion())); - connect(&_done, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_version, SIGNAL(clicked()), this, SLOT(onVersion())); + connect(_done, SIGNAL(clicked()), this, SLOT(onClose())); prepare(); @@ -47,19 +49,19 @@ AboutBox::AboutBox() : AbstractBox(st::aboutWidth) } void AboutBox::showAll() { - _version.show(); - _text1.show(); - _text2.show(); - _text3.show(); - _done.show(); + _version->show(); + _text1->show(); + _text2->show(); + _text3->show(); + _done->show(); } void AboutBox::resizeEvent(QResizeEvent *e) { - _version.moveToLeft(st::boxPadding.left(), titleHeight() + st::aboutVersionTop); - _text1.moveToLeft(st::boxPadding.left(), titleHeight() + st::aboutTextTop); - _text2.moveToLeft(st::boxPadding.left(), _text1.y() + _text1.height() + st::aboutSkip); - _text3.moveToLeft(st::boxPadding.left(), _text2.y() + _text2.height() + st::aboutSkip); - _done.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done.height()); + _version->moveToLeft(st::boxPadding.left(), titleHeight() + st::aboutVersionTop); + _text1->moveToLeft(st::boxPadding.left(), titleHeight() + st::aboutTextTop); + _text2->moveToLeft(st::boxPadding.left(), _text1->y() + _text1->height() + st::aboutSkip); + _text3->moveToLeft(st::boxPadding.left(), _text2->y() + _text2->height() + st::aboutSkip); + _done->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done->height()); AbstractBox::resizeEvent(e); } diff --git a/Telegram/SourceFiles/boxes/aboutbox.h b/Telegram/SourceFiles/boxes/aboutbox.h index 99d5571f5..d05cedbdb 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.h +++ b/Telegram/SourceFiles/boxes/aboutbox.h @@ -23,6 +23,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" #include "ui/flatlabel.h" +namespace Ui { +class RoundButton; +class LinkButton; +} // namespace Ui + class AboutBox : public AbstractBox { Q_OBJECT @@ -42,9 +47,11 @@ protected: void showAll() override; private: - LinkButton _version; - FlatLabel _text1, _text2, _text3; - BoxButton _done; + ChildWidget _version; + ChildWidget _text1; + ChildWidget _text2; + ChildWidget _text3; + ChildWidget _done; }; diff --git a/Telegram/SourceFiles/boxes/abstractbox.cpp b/Telegram/SourceFiles/boxes/abstractbox.cpp index fdafb714f..31c5d348d 100644 --- a/Telegram/SourceFiles/boxes/abstractbox.cpp +++ b/Telegram/SourceFiles/boxes/abstractbox.cpp @@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_boxes.h" #include "localstorage.h" #include "lang.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "mainwidget.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index fedcb3376..4e63886b7 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -29,7 +29,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/confirmbox.h" #include "boxes/photocropbox.h" #include "ui/filedialog.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "mainwidget.h" #include "mainwindow.h" #include "apiwrap.h" @@ -627,7 +628,7 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) { QTextOption option(style::al_left); option.setWrapMode(QTextOption::WrapAnywhere); p.setFont(_linkOver ? st::boxTextFont->underline() : st::boxTextFont); - p.setPen(st::btnDefLink.color); + p.setPen(st::defaultLinkButton.color); p.drawText(_invitationLink, _channel->inviteLink(), option); if (!_goodTextLink.isEmpty() && a_goodOpacity.current() > 0) { p.setOpacity(a_goodOpacity.current()); @@ -1085,7 +1086,7 @@ EditChannelBox::EditChannelBox(ChannelData *channel) : AbstractBox() , _title(this, st::defaultInputField, lang(lng_dlg_new_channel_name), _channel->name) , _description(this, st::newGroupDescription, lang(lng_create_group_description), _channel->about()) , _sign(this, lang(lng_edit_sign_messages), channel->addsSignature(), st::defaultBoxCheckbox) -, _publicLink(this, lang(channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link), st::defaultBoxLinkButton) +, _publicLink(this, lang(channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link), st::boxLinkButton) , _save(this, lang(lng_settings_save), st::defaultBoxButton) , _cancel(this, lang(lng_cancel), st::cancelBoxButton) { connect(App::main(), SIGNAL(peerNameChanged(PeerData*,const PeerData::Names&,const PeerData::NameFirstChars&)), this, SLOT(peerUpdated(PeerData*))); @@ -1404,7 +1405,7 @@ void RevokePublicLinkBox::paintChat(Painter &p, const ChatRow &row, bool selecte row.name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width()); p.setFont(selected ? st::linkOverFont : st::linkFont); - p.setPen(pressed ? st::btnDefLink.downColor : st::btnDefLink.color->p); + p.setPen(pressed ? st::defaultLinkButton.downColor : st::defaultLinkButton.color); p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), lang(lng_channels_too_much_public_revoke), _revokeWidth); p.setPen(st::contactsStatusFg); diff --git a/Telegram/SourceFiles/boxes/addcontactbox.h b/Telegram/SourceFiles/boxes/addcontactbox.h index 805426311..6ce931baa 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.h +++ b/Telegram/SourceFiles/boxes/addcontactbox.h @@ -30,6 +30,8 @@ class ConfirmBox; namespace Ui { class Checkbox; class Radiobutton; +class LinkButton; +class RoundButton; } // namespace Ui class AddContactBox : public AbstractBox, public RPCSender { @@ -66,9 +68,9 @@ private: ChildWidget _last; ChildWidget _phone; - ChildWidget _save; - ChildWidget _cancel; - ChildWidget _retry; + ChildWidget _save; + ChildWidget _cancel; + ChildWidget _retry; bool _invertOrder; @@ -123,8 +125,8 @@ private: QImage _photoBig; QPixmap _photoSmall; - ChildWidget _next; - ChildWidget _cancel; + ChildWidget _next; + ChildWidget _cancel; // channel creation int32 _creationRequestId; @@ -190,8 +192,8 @@ private: QRect _invitationLink; bool _linkOver; - ChildWidget _save; - ChildWidget _skip; + ChildWidget _save; + ChildWidget _skip; bool _tooMuchUsernames = false; @@ -237,8 +239,8 @@ private: ChildWidget _first; ChildWidget _last; - ChildWidget _save; - ChildWidget _cancel; + ChildWidget _save; + ChildWidget _cancel; bool _invertOrder = false; @@ -285,10 +287,10 @@ private: ChildWidget _description; ChildWidget _sign; - ChildWidget _publicLink; + ChildWidget _publicLink; - ChildWidget _save; - ChildWidget _cancel; + ChildWidget _save; + ChildWidget _cancel; mtpRequestId _saveTitleRequestId = 0; mtpRequestId _saveDescriptionRequestId = 0; @@ -337,7 +339,7 @@ private: int _revokeWidth = 0; ChildWidget _aboutRevoke; - ChildWidget _cancel; + ChildWidget _cancel; base::lambda_unique _revokeCallback; mtpRequestId _revokeRequestId = 0; diff --git a/Telegram/SourceFiles/boxes/autolockbox.cpp b/Telegram/SourceFiles/boxes/autolockbox.cpp index e6310cda0..f2b025c07 100644 --- a/Telegram/SourceFiles/boxes/autolockbox.cpp +++ b/Telegram/SourceFiles/boxes/autolockbox.cpp @@ -26,7 +26,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/confirmbox.h" #include "mainwidget.h" #include "mainwindow.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" AutoLockBox::AutoLockBox() : _close(this, lang(lng_box_ok), st::defaultBoxButton) { @@ -35,7 +36,7 @@ _close(this, lang(lng_box_ok), st::defaultBoxButton) { int32 opts[] = { 60, 300, 3600, 18000 }, cnt = sizeof(opts) / sizeof(opts[0]); - resizeMaxHeight(st::langsWidth, titleHeight() + cnt * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close.height() + st::boxButtonPadding.bottom()); + resizeMaxHeight(st::langsWidth, titleHeight() + cnt * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close->height() + st::boxButtonPadding.bottom()); int32 y = titleHeight() + st::boxOptionListPadding.top(); _options.reserve(cnt); @@ -47,14 +48,14 @@ _close(this, lang(lng_box_ok), st::defaultBoxButton) { connect(_options.back(), SIGNAL(changed()), this, SLOT(onChange())); } - connect(&_close, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_close, SIGNAL(clicked()), this, SLOT(onClose())); - _close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height()); + _close->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close->height()); prepare(); } void AutoLockBox::showAll() { - _close.show(); + _close->show(); for (int32 i = 0, l = _options.size(); i < l; ++i) { _options[i]->show(); } diff --git a/Telegram/SourceFiles/boxes/autolockbox.h b/Telegram/SourceFiles/boxes/autolockbox.h index b542042e4..e5b6e6c92 100644 --- a/Telegram/SourceFiles/boxes/autolockbox.h +++ b/Telegram/SourceFiles/boxes/autolockbox.h @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Radiobutton; +class RoundButton; } // namespace Ui class AutoLockBox : public AbstractBox { @@ -42,6 +43,6 @@ protected: private: QVector _options; - BoxButton _close; + ChildWidget _close; }; diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index b4a82f04d..3db3c34c3 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -38,6 +38,14 @@ boxBlockTitleClose: IconButton(defaultIconButton) { iconOver: boxBlockTitleCloseIconOver; } +boxLinkButton: LinkButton { + color: #0080c0; + overColor: #0080c0; + downColor: #0073ad; + font: boxTextFont; + overFont: font(boxFontSize underline); +} + confirmInviteTitle: flatLabel(labelDefFlat) { font: font(16px semibold); align: align(center); @@ -265,6 +273,11 @@ sessionTerminate: IconButton { iconPosition: point(3px, 3px); iconPositionDown: point(3px, 4px); } +sessionTerminateAllButton: LinkButton(boxLinkButton) { + color: #d15948; + overColor: #d15948; + downColor: #db6352; +} passcodeHeaderFont: font(19px); passcodeHeaderHeight: 80px; @@ -309,3 +322,21 @@ themeWarningHeight: 150px; themeWarningShadow: boxShadow; themeWarningShadowShift: boxShadowShift; themeWarningTextTop: 60px; + +aboutWidth: 390px; +aboutVersionTop: -3px; +aboutVersionLink: LinkButton(defaultLinkButton) { + color: #999999; + overColor: #999999; + downColor: #999999; +} +aboutTextTop: 34px; +aboutSkip: 14px; +aboutLabel: flatLabel(labelDefFlat) { + font: normalFont; + width: 330px; + align: align(topleft); +} +aboutTextStyle: textStyle(defaultTextStyle) { + lineHeight: 22px; +} diff --git a/Telegram/SourceFiles/boxes/confirmbox.cpp b/Telegram/SourceFiles/boxes/confirmbox.cpp index 951fc3d15..2e2a6bc69 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.cpp +++ b/Telegram/SourceFiles/boxes/confirmbox.cpp @@ -27,7 +27,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "apiwrap.h" #include "application.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "core/click_handler_types.h" #include "localstorage.h" @@ -282,7 +283,7 @@ void MaxInviteBox::paintEvent(QPaintEvent *e) { QTextOption option(style::al_left); option.setWrapMode(QTextOption::WrapAnywhere); p.setFont(_linkOver ? st::defaultInputField.font->underline() : st::defaultInputField.font); - p.setPen(st::btnDefLink.color); + p.setPen(st::defaultLinkButton.color); p.drawText(_invitationLink, _link, option); if (!_goodTextLink.isEmpty() && a_goodOpacity.current() > 0) { p.setOpacity(a_goodOpacity.current()); diff --git a/Telegram/SourceFiles/boxes/confirmbox.h b/Telegram/SourceFiles/boxes/confirmbox.h index 38b545cdd..e713528af 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.h +++ b/Telegram/SourceFiles/boxes/confirmbox.h @@ -26,6 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Checkbox; +class RoundButton; } // namespace Ui class InformBox; @@ -85,8 +86,8 @@ private: QPoint _lastMousePos; - ChildWidget _confirm; - ChildWidget _cancel; + ChildWidget _confirm; + ChildWidget _cancel; base::lambda_unique _confirmedCallback; @@ -164,7 +165,7 @@ private: void updateSelected(const QPoint &cursorGlobalPosition); void step_good(float64 ms, bool timer); - ChildWidget _close; + ChildWidget _close; Text _text; int32 _textWidth, _textHeight; @@ -205,8 +206,8 @@ private: Text _text, _note; int32 _textWidth, _textHeight; - ChildWidget _convert; - ChildWidget _cancel; + ChildWidget _convert; + ChildWidget _cancel; }; @@ -234,8 +235,8 @@ private: ChildWidget _text; ChildWidget _notify; - ChildWidget _pin; - ChildWidget _cancel; + ChildWidget _pin; + ChildWidget _cancel; mtpRequestId _requestId = 0; @@ -265,8 +266,8 @@ private: ChildWidget _reportSpam; ChildWidget _deleteAll; - ChildWidget _delete; - ChildWidget _cancel; + ChildWidget _delete; + ChildWidget _cancel; }; @@ -298,11 +299,13 @@ protected: void showAll() override; private: - ChildWidget _title, _status; + ChildWidget _title; + ChildWidget _status; ImagePtr _photo; QVector _participants; - ChildWidget _join, _cancel; + ChildWidget _join; + ChildWidget _cancel; int _userWidth = 0; }; diff --git a/Telegram/SourceFiles/boxes/confirmphonebox.cpp b/Telegram/SourceFiles/boxes/confirmphonebox.cpp index 23ca5c067..36d0871a0 100644 --- a/Telegram/SourceFiles/boxes/confirmphonebox.cpp +++ b/Telegram/SourceFiles/boxes/confirmphonebox.cpp @@ -23,6 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_boxes.h" #include "boxes/confirmbox.h" +#include "ui/widgets/buttons.h" #include "mainwidget.h" #include "lang.h" @@ -107,8 +108,8 @@ void ConfirmPhoneBox::launch() { _code = new InputField(this, st::confirmPhoneCodeField, lang(lng_code_ph)); - _send = new BoxButton(this, lang(lng_confirm_phone_send), st::defaultBoxButton); - _cancel = new BoxButton(this, lang(lng_cancel), st::cancelBoxButton); + _send.create(this, lang(lng_confirm_phone_send), st::defaultBoxButton); + _cancel.create(this, lang(lng_cancel), st::cancelBoxButton); setMaxHeight(titleHeight() + st::usernamePadding.top() + _code->height() + st::usernameSkip + _about->height() + st::usernameSkip + _send->height() + st::boxButtonPadding.bottom()); diff --git a/Telegram/SourceFiles/boxes/confirmphonebox.h b/Telegram/SourceFiles/boxes/confirmphonebox.h index f759824e9..6c3788262 100644 --- a/Telegram/SourceFiles/boxes/confirmphonebox.h +++ b/Telegram/SourceFiles/boxes/confirmphonebox.h @@ -24,6 +24,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org class FlatLabel; +namespace Ui { +class RoundButton; +} // namespace Ui + class ConfirmPhoneBox : public AbstractBox, public RPCSender { Q_OBJECT @@ -90,8 +94,8 @@ private: mtpRequestId _checkCodeRequestId = 0; ChildWidget _about = { nullptr }; - ChildWidget _send = { nullptr }; - ChildWidget _cancel = { nullptr }; + ChildWidget _send = { nullptr }; + ChildWidget _cancel = { nullptr }; ChildWidget _code = { nullptr }; // Flag for not calling onTextChanged() recursively. diff --git a/Telegram/SourceFiles/boxes/connectionbox.cpp b/Telegram/SourceFiles/boxes/connectionbox.cpp index 5fc825fbd..cd481d302 100644 --- a/Telegram/SourceFiles/boxes/connectionbox.cpp +++ b/Telegram/SourceFiles/boxes/connectionbox.cpp @@ -25,7 +25,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "localstorage.h" #include "mainwidget.h" #include "mainwindow.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "history/history_location_manager.h" ConnectionBox::ConnectionBox() : AbstractBox(st::boxWidth) diff --git a/Telegram/SourceFiles/boxes/connectionbox.h b/Telegram/SourceFiles/boxes/connectionbox.h index 6d66477e6..9e0e3de88 100644 --- a/Telegram/SourceFiles/boxes/connectionbox.h +++ b/Telegram/SourceFiles/boxes/connectionbox.h @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Checkbox; class Radiobutton; +class RoundButton; } // namespace Ui class ConnectionBox : public AbstractBox { @@ -55,8 +56,8 @@ private: ChildWidget _tcpProxyRadio; ChildWidget _tryIPv6; - ChildWidget _save; - ChildWidget _cancel; + ChildWidget _save; + ChildWidget _cancel; }; @@ -86,7 +87,7 @@ private: int _sectionHeight; - ChildWidget _save; - ChildWidget _cancel; + ChildWidget _save; + ChildWidget _cancel; }; diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index 517d9e8f7..9bd4c5119 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -30,8 +30,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "mainwindow.h" #include "application.h" -#include "ui/buttons/checkbox.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "ui/filedialog.h" #include "ui/widgets/multi_select.h" #include "ui/effects/widget_slide_wrap.h" diff --git a/Telegram/SourceFiles/boxes/contactsbox.h b/Telegram/SourceFiles/boxes/contactsbox.h index 93807e328..41d9520d9 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.h +++ b/Telegram/SourceFiles/boxes/contactsbox.h @@ -31,6 +31,8 @@ class IndexedList; } // namespace Dialogs namespace Ui { +class RoundButton; +class LinkButton; class Checkbox; class MultiSelect; template @@ -93,8 +95,8 @@ private: ChildWidget> _select; ChildWidget _add = { nullptr }; - ChildWidget _next; - ChildWidget _cancel; + ChildWidget _next; + ChildWidget _cancel; MembersFilter _membersFilter; ChildWidget _topShadow; @@ -300,7 +302,7 @@ private: int _byUsernameSel = -1; QPoint _lastMousePos; - ChildWidget _addContactLnk; + ChildWidget _addContactLnk; bool _saving = false; bool _allAdminsChecked = false; diff --git a/Telegram/SourceFiles/boxes/downloadpathbox.cpp b/Telegram/SourceFiles/boxes/downloadpathbox.cpp index 704c916de..8f3051691 100644 --- a/Telegram/SourceFiles/boxes/downloadpathbox.cpp +++ b/Telegram/SourceFiles/boxes/downloadpathbox.cpp @@ -24,8 +24,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "lang.h" #include "localstorage.h" #include "ui/filedialog.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "pspecific.h" +#include "styles/style_boxes.h" DownloadPathBox::DownloadPathBox() : AbstractBox() , _path(Global::DownloadPath()) @@ -33,7 +35,7 @@ DownloadPathBox::DownloadPathBox() : AbstractBox() , _default(this, qsl("dir_type"), 0, lang(lng_download_path_default_radio), _path.isEmpty()) , _temp(this, qsl("dir_type"), 1, lang(lng_download_path_temp_radio), _path == qsl("tmp")) , _dir(this, qsl("dir_type"), 2, lang(lng_download_path_dir_radio), !_path.isEmpty() && _path != qsl("tmp")) -, _pathLink(this, QString(), st::defaultBoxLinkButton) +, _pathLink(this, QString(), st::boxLinkButton) , _save(this, lang(lng_connection_save), st::defaultBoxButton) , _cancel(this, lang(lng_cancel), st::cancelBoxButton) { diff --git a/Telegram/SourceFiles/boxes/downloadpathbox.h b/Telegram/SourceFiles/boxes/downloadpathbox.h index a0fdfe5fd..070e8889b 100644 --- a/Telegram/SourceFiles/boxes/downloadpathbox.h +++ b/Telegram/SourceFiles/boxes/downloadpathbox.h @@ -25,6 +25,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Radiobutton; +class LinkButton; +class RoundButton; } // namespace Ui class DownloadPathBox : public AbstractBox { @@ -53,9 +55,9 @@ private: ChildWidget _default; ChildWidget _temp; ChildWidget _dir; - ChildWidget _pathLink; + ChildWidget _pathLink; - ChildWidget _save; - ChildWidget _cancel; + ChildWidget _save; + ChildWidget _cancel; }; diff --git a/Telegram/SourceFiles/boxes/languagebox.cpp b/Telegram/SourceFiles/boxes/languagebox.cpp index 4795030f9..3ac63ad6c 100644 --- a/Telegram/SourceFiles/boxes/languagebox.cpp +++ b/Telegram/SourceFiles/boxes/languagebox.cpp @@ -22,7 +22,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/languagebox.h" #include "lang.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "localstorage.h" #include "boxes/confirmbox.h" #include "mainwidget.h" @@ -56,16 +57,16 @@ _close(this, lang(lng_box_ok), st::defaultBoxButton) { connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange())); } - resizeMaxHeight(st::langsWidth, titleHeight() + (languageCount + (haveTestLang ? 1 : 0)) * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close.height() + st::boxButtonPadding.bottom()); + resizeMaxHeight(st::langsWidth, titleHeight() + (languageCount + (haveTestLang ? 1 : 0)) * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close->height() + st::boxButtonPadding.bottom()); - connect(&_close, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_close, SIGNAL(clicked()), this, SLOT(onClose())); - _close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height()); + _close->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close->height()); prepare(); } void LanguageBox::showAll() { - _close.show(); + _close->show(); for (int32 i = 0, l = _langs.size(); i < l; ++i) { _langs[i]->show(); } diff --git a/Telegram/SourceFiles/boxes/languagebox.h b/Telegram/SourceFiles/boxes/languagebox.h index 9714fcde7..53a5852e0 100644 --- a/Telegram/SourceFiles/boxes/languagebox.h +++ b/Telegram/SourceFiles/boxes/languagebox.h @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Radiobutton; +class RoundButton; } // namespace Ui class LanguageBox : public AbstractBox { @@ -45,6 +46,6 @@ protected: private: QVector _langs; - BoxButton _close; + ChildWidget _close; }; diff --git a/Telegram/SourceFiles/boxes/localstoragebox.cpp b/Telegram/SourceFiles/boxes/localstoragebox.cpp index 2c459fa57..f23f53b7c 100644 --- a/Telegram/SourceFiles/boxes/localstoragebox.cpp +++ b/Telegram/SourceFiles/boxes/localstoragebox.cpp @@ -22,13 +22,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/localstoragebox.h" #include "styles/style_boxes.h" +#include "ui/widgets/buttons.h" #include "localstorage.h" -#include "ui/flatbutton.h" #include "lang.h" #include "mainwindow.h" LocalStorageBox::LocalStorageBox() : AbstractBox() -, _clear(this, lang(lng_local_storage_clear), st::defaultBoxLinkButton) +, _clear(this, lang(lng_local_storage_clear), st::boxLinkButton) , _close(this, lang(lng_box_ok), st::defaultBoxButton) { connect(_clear, SIGNAL(clicked()), this, SLOT(onClear())); connect(_close, SIGNAL(clicked()), this, SLOT(onClose())); diff --git a/Telegram/SourceFiles/boxes/localstoragebox.h b/Telegram/SourceFiles/boxes/localstoragebox.h index ef175bfec..178135d9e 100644 --- a/Telegram/SourceFiles/boxes/localstoragebox.h +++ b/Telegram/SourceFiles/boxes/localstoragebox.h @@ -22,8 +22,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" -class BoxButton; +namespace Ui { +class RoundButton; class LinkButton; +} // namespace Ui class LocalStorageBox : public AbstractBox { Q_OBJECT @@ -53,8 +55,8 @@ private: }; State _state = State::Normal; - ChildWidget _clear; - ChildWidget _close; + ChildWidget _clear; + ChildWidget _close; int _imagesCount = -1; int _audiosCount = -1; diff --git a/Telegram/SourceFiles/boxes/members_box.cpp b/Telegram/SourceFiles/boxes/members_box.cpp index 5dbedd23c..4f0a12f37 100644 --- a/Telegram/SourceFiles/boxes/members_box.cpp +++ b/Telegram/SourceFiles/boxes/members_box.cpp @@ -28,7 +28,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "boxes/contactsbox.h" #include "boxes/confirmbox.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "observer_peer.h" MembersBox::MembersBox(ChannelData *channel, MembersFilter filter) : ItemListBox(st::boxScroll) @@ -248,11 +248,7 @@ void MembersBox::Inner::paintDialog(Painter &p, PeerData *peer, MemberData *data if (data->canKick) { p.setFont((kickSel ? st::linkOverFont : st::linkFont)->f); - if (kickDown) { - p.setPen(st::btnDefLink.downColor->p); - } else { - p.setPen(st::btnDefLink.color->p); - } + p.setPen(kickDown ? st::defaultLinkButton.downColor : st::defaultLinkButton.color); p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), _kickText, _kickWidth); } diff --git a/Telegram/SourceFiles/boxes/notifications_box.cpp b/Telegram/SourceFiles/boxes/notifications_box.cpp index d6312f588..4901b6737 100644 --- a/Telegram/SourceFiles/boxes/notifications_box.cpp +++ b/Telegram/SourceFiles/boxes/notifications_box.cpp @@ -22,8 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/notifications_box.h" #include "lang.h" -#include "ui/buttons/round_button.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/discrete_slider.h" #include "styles/style_boxes.h" #include "styles/style_dialogs.h" diff --git a/Telegram/SourceFiles/boxes/notifications_box.h b/Telegram/SourceFiles/boxes/notifications_box.h index 36bcfdbce..cd9114483 100644 --- a/Telegram/SourceFiles/boxes/notifications_box.h +++ b/Telegram/SourceFiles/boxes/notifications_box.h @@ -22,10 +22,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" -class BoxButton; -class LinkButton; - namespace Ui { +class RoundButton; +class LinkButton; class DiscreteSlider; } // namespace Ui @@ -72,7 +71,7 @@ private: int _oldCount; ChildWidget _countSlider; - ChildWidget _done; + ChildWidget _done; QVector _cornerSamples[4]; diff --git a/Telegram/SourceFiles/boxes/passcodebox.cpp b/Telegram/SourceFiles/boxes/passcodebox.cpp index ab956eb0f..92a8a2ebf 100644 --- a/Telegram/SourceFiles/boxes/passcodebox.cpp +++ b/Telegram/SourceFiles/boxes/passcodebox.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "localstorage.h" #include "styles/style_boxes.h" +#include "ui/widgets/buttons.h" PasscodeBox::PasscodeBox(bool turningOff) : AbstractBox(st::boxWidth) , _replacedBy(0) @@ -82,114 +83,114 @@ void PasscodeBox::init() { _aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5); textstyleRestore(); if (_turningOff) { - _oldPasscode.show(); + _oldPasscode->show(); _boxTitle = lang(_cloudPwd ? lng_cloud_password_remove : lng_passcode_remove); - setMaxHeight(titleHeight() + st::passcodePadding.top() + _oldPasscode.height() + st::passcodeSkip + ((_hasRecovery && !_hintText.isEmpty()) ? st::passcodeSkip : 0) + _aboutHeight + st::passcodePadding.bottom() + st::boxButtonPadding.top() + _saveButton.height() + st::boxButtonPadding.bottom()); + setMaxHeight(titleHeight() + st::passcodePadding.top() + _oldPasscode->height() + st::passcodeSkip + ((_hasRecovery && !_hintText.isEmpty()) ? st::passcodeSkip : 0) + _aboutHeight + st::passcodePadding.bottom() + st::boxButtonPadding.top() + _saveButton->height() + st::boxButtonPadding.bottom()); } else { bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode(); if (has) { - _oldPasscode.show(); + _oldPasscode->show(); _boxTitle = lang(_cloudPwd ? lng_cloud_password_change : lng_passcode_change); - setMaxHeight(titleHeight() + st::passcodePadding.top() + _oldPasscode.height() + st::passcodeSkip + ((_hasRecovery && !_hintText.isEmpty()) ? st::passcodeSkip : 0) + _newPasscode.height() + st::contactSkip + _reenterPasscode.height() + st::passcodeSkip + (_cloudPwd ? _passwordHint.height() + st::contactSkip : 0) + _aboutHeight + st::passcodePadding.bottom() + st::boxButtonPadding.top() + _saveButton.height() + st::boxButtonPadding.bottom()); + setMaxHeight(titleHeight() + st::passcodePadding.top() + _oldPasscode->height() + st::passcodeSkip + ((_hasRecovery && !_hintText.isEmpty()) ? st::passcodeSkip : 0) + _newPasscode->height() + st::contactSkip + _reenterPasscode->height() + st::passcodeSkip + (_cloudPwd ? _passwordHint->height() + st::contactSkip : 0) + _aboutHeight + st::passcodePadding.bottom() + st::boxButtonPadding.top() + _saveButton->height() + st::boxButtonPadding.bottom()); } else { - _oldPasscode.hide(); + _oldPasscode->hide(); _boxTitle = lang(_cloudPwd ? lng_cloud_password_create : lng_passcode_create); - setMaxHeight(titleHeight() + st::passcodePadding.top() + _newPasscode.height() + st::contactSkip + _reenterPasscode.height() + st::passcodeSkip + (_cloudPwd ? _passwordHint.height() + st::contactSkip : 0) + _aboutHeight + (_cloudPwd ? st::contactSkip + _recoverEmail.height() + st::passcodeSkip : st::passcodePadding.bottom()) + st::boxButtonPadding.top() + _saveButton.height() + st::boxButtonPadding.bottom()); + setMaxHeight(titleHeight() + st::passcodePadding.top() + _newPasscode->height() + st::contactSkip + _reenterPasscode->height() + st::passcodeSkip + (_cloudPwd ? _passwordHint->height() + st::contactSkip : 0) + _aboutHeight + (_cloudPwd ? st::contactSkip + _recoverEmail->height() + st::passcodeSkip : st::passcodePadding.bottom()) + st::boxButtonPadding.top() + _saveButton->height() + st::boxButtonPadding.bottom()); } } - connect(&_saveButton, SIGNAL(clicked()), this, SLOT(onSave())); - connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_saveButton, SIGNAL(clicked()), this, SLOT(onSave())); + connect(_cancelButton, SIGNAL(clicked()), this, SLOT(onClose())); - connect(&_oldPasscode, SIGNAL(changed()), this, SLOT(onOldChanged())); - connect(&_newPasscode, SIGNAL(changed()), this, SLOT(onNewChanged())); - connect(&_reenterPasscode, SIGNAL(changed()), this, SLOT(onNewChanged())); - connect(&_passwordHint, SIGNAL(changed()), this, SLOT(onNewChanged())); - connect(&_recoverEmail, SIGNAL(changed()), this, SLOT(onEmailChanged())); + connect(_oldPasscode, SIGNAL(changed()), this, SLOT(onOldChanged())); + connect(_newPasscode, SIGNAL(changed()), this, SLOT(onNewChanged())); + connect(_reenterPasscode, SIGNAL(changed()), this, SLOT(onNewChanged())); + connect(_passwordHint, SIGNAL(changed()), this, SLOT(onNewChanged())); + connect(_recoverEmail, SIGNAL(changed()), this, SLOT(onEmailChanged())); - connect(&_oldPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - connect(&_newPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - connect(&_reenterPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - connect(&_passwordHint, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - connect(&_recoverEmail, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); + connect(_oldPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); + connect(_newPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); + connect(_reenterPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); + connect(_passwordHint, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); + connect(_recoverEmail, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - connect(&_recover, SIGNAL(clicked()), this, SLOT(onRecoverByEmail())); + connect(_recover, SIGNAL(clicked()), this, SLOT(onRecoverByEmail())); } void PasscodeBox::showAll() { bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode(); if (_turningOff) { - _oldPasscode.show(); + _oldPasscode->show(); if (_cloudPwd && _hasRecovery) { - _recover.show(); + _recover->show(); } else { - _recover.hide(); + _recover->hide(); } - _newPasscode.hide(); - _reenterPasscode.hide(); - _passwordHint.hide(); - _recoverEmail.hide(); + _newPasscode->hide(); + _reenterPasscode->hide(); + _passwordHint->hide(); + _recoverEmail->hide(); } else { if (has) { - _oldPasscode.show(); + _oldPasscode->show(); if (_cloudPwd && _hasRecovery) { - _recover.show(); + _recover->show(); } else { - _recover.hide(); + _recover->hide(); } } else { - _oldPasscode.hide(); - _recover.hide(); + _oldPasscode->hide(); + _recover->hide(); } - _newPasscode.show(); - _reenterPasscode.show(); + _newPasscode->show(); + _reenterPasscode->show(); if (_cloudPwd) { - _passwordHint.show(); + _passwordHint->show(); } else { - _passwordHint.hide(); + _passwordHint->hide(); } if (_cloudPwd && _curSalt.isEmpty()) { - _recoverEmail.show(); + _recoverEmail->show(); } else { - _recoverEmail.hide(); + _recoverEmail->hide(); } } - _saveButton.show(); - _cancelButton.show(); + _saveButton->show(); + _cancelButton->show(); AbstractBox::showAll(); } void PasscodeBox::onSubmit() { bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode(); - if (_oldPasscode.hasFocus()) { + if (_oldPasscode->hasFocus()) { if (_turningOff) { onSave(); } else { - _newPasscode.setFocus(); + _newPasscode->setFocus(); } - } else if (_newPasscode.hasFocus()) { - _reenterPasscode.setFocus(); - } else if (_reenterPasscode.hasFocus()) { - if (has && _oldPasscode.text().isEmpty()) { - _oldPasscode.setFocus(); - _oldPasscode.showError(); - } else if (_newPasscode.text().isEmpty()) { - _newPasscode.setFocus(); - _newPasscode.showError(); - } else if (_reenterPasscode.text().isEmpty()) { - _reenterPasscode.showError(); - } else if (!_passwordHint.isHidden()) { - _passwordHint.setFocus(); + } else if (_newPasscode->hasFocus()) { + _reenterPasscode->setFocus(); + } else if (_reenterPasscode->hasFocus()) { + if (has && _oldPasscode->text().isEmpty()) { + _oldPasscode->setFocus(); + _oldPasscode->showError(); + } else if (_newPasscode->text().isEmpty()) { + _newPasscode->setFocus(); + _newPasscode->showError(); + } else if (_reenterPasscode->text().isEmpty()) { + _reenterPasscode->showError(); + } else if (!_passwordHint->isHidden()) { + _passwordHint->setFocus(); } else { onSave(); } - } else if (_passwordHint.hasFocus()) { - if (_recoverEmail.isHidden()) { + } else if (_passwordHint->hasFocus()) { + if (_recoverEmail->isHidden()) { onSave(); } else { - _recoverEmail.setFocus(); + _recoverEmail->setFocus(); } - } else if (_recoverEmail.hasFocus()) { + } else if (_recoverEmail->hasFocus()) { onSave(); } } @@ -203,27 +204,27 @@ void PasscodeBox::paintEvent(QPaintEvent *e) { textstyleSet(&st::usernameTextStyle); int32 w = st::boxWidth - st::boxPadding.left() * 1.5; - int32 abouty = (_passwordHint.isHidden() ? (_reenterPasscode.isHidden() ? (_oldPasscode.y() + (_hasRecovery && !_hintText.isEmpty() ? st::passcodeSkip : 0)) : _reenterPasscode.y()) + st::passcodeSkip : _passwordHint.y() + st::contactSkip) + _oldPasscode.height(); + int32 abouty = (_passwordHint->isHidden() ? (_reenterPasscode->isHidden() ? (_oldPasscode->y() + (_hasRecovery && !_hintText.isEmpty() ? st::passcodeSkip : 0)) : _reenterPasscode->y()) + st::passcodeSkip : _passwordHint->y() + st::contactSkip) + _oldPasscode->height(); p.setPen(st::boxTextFg); _about.drawLeft(p, st::boxPadding.left(), abouty, w, width()); if (!_hintText.isEmpty() && _oldError.isEmpty()) { - _hintText.drawLeftElided(p, st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height() + ((st::passcodeSkip - st::normalFont->height) / 2), w, width(), 1, style::al_topleft); + _hintText.drawLeftElided(p, st::boxPadding.left(), _oldPasscode->y() + _oldPasscode->height() + ((st::passcodeSkip - st::normalFont->height) / 2), w, width(), 1, style::al_topleft); } if (!_oldError.isEmpty()) { p.setPen(st::boxTextFgError); - p.drawText(QRect(st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height(), w, st::passcodeSkip), _oldError, style::al_left); + p.drawText(QRect(st::boxPadding.left(), _oldPasscode->y() + _oldPasscode->height(), w, st::passcodeSkip), _oldError, style::al_left); } if (!_newError.isEmpty()) { p.setPen(st::boxTextFgError); - p.drawText(QRect(st::boxPadding.left(), _reenterPasscode.y() + _reenterPasscode.height(), w, st::passcodeSkip), _newError, style::al_left); + p.drawText(QRect(st::boxPadding.left(), _reenterPasscode->y() + _reenterPasscode->height(), w, st::passcodeSkip), _newError, style::al_left); } if (!_emailError.isEmpty()) { p.setPen(st::boxTextFgError); - p.drawText(QRect(st::boxPadding.left(), _recoverEmail.y() + _recoverEmail.height(), w, st::passcodeSkip), _emailError, style::al_left); + p.drawText(QRect(st::boxPadding.left(), _recoverEmail->y() + _recoverEmail->height(), w, st::passcodeSkip), _emailError, style::al_left); } textstyleRestore(); @@ -232,57 +233,57 @@ void PasscodeBox::paintEvent(QPaintEvent *e) { void PasscodeBox::resizeEvent(QResizeEvent *e) { bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode(); int32 w = st::boxWidth - st::boxPadding.left() - st::boxPadding.right(); - _oldPasscode.resize(w, _oldPasscode.height()); - _oldPasscode.moveToLeft(st::boxPadding.left(), titleHeight() + st::passcodePadding.top()); - _newPasscode.resize(w, _newPasscode.height()); - _newPasscode.moveToLeft(st::boxPadding.left(), _oldPasscode.y() + ((_turningOff || has) ? (_oldPasscode.height() + st::passcodeSkip + ((_hasRecovery && !_hintText.isEmpty()) ? st::passcodeSkip : 0)) : 0)); - _reenterPasscode.resize(w, _reenterPasscode.height()); - _reenterPasscode.moveToLeft(st::boxPadding.left(), _newPasscode.y() + _newPasscode.height() + st::contactSkip); - _passwordHint.resize(w, _passwordHint.height()); - _passwordHint.moveToLeft(st::boxPadding.left(), _reenterPasscode.y() + _reenterPasscode.height() + st::passcodeSkip); - _recoverEmail.resize(w, _passwordHint.height()); - _recoverEmail.moveToLeft(st::boxPadding.left(), _passwordHint.y() + _passwordHint.height() + st::contactSkip + _aboutHeight + st::contactSkip); + _oldPasscode->resize(w, _oldPasscode->height()); + _oldPasscode->moveToLeft(st::boxPadding.left(), titleHeight() + st::passcodePadding.top()); + _newPasscode->resize(w, _newPasscode->height()); + _newPasscode->moveToLeft(st::boxPadding.left(), _oldPasscode->y() + ((_turningOff || has) ? (_oldPasscode->height() + st::passcodeSkip + ((_hasRecovery && !_hintText.isEmpty()) ? st::passcodeSkip : 0)) : 0)); + _reenterPasscode->resize(w, _reenterPasscode->height()); + _reenterPasscode->moveToLeft(st::boxPadding.left(), _newPasscode->y() + _newPasscode->height() + st::contactSkip); + _passwordHint->resize(w, _passwordHint->height()); + _passwordHint->moveToLeft(st::boxPadding.left(), _reenterPasscode->y() + _reenterPasscode->height() + st::passcodeSkip); + _recoverEmail->resize(w, _passwordHint->height()); + _recoverEmail->moveToLeft(st::boxPadding.left(), _passwordHint->y() + _passwordHint->height() + st::contactSkip + _aboutHeight + st::contactSkip); - if (!_recover.isHidden()) { - _recover.moveToLeft(st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height() + (_hintText.isEmpty() ? ((st::passcodeSkip - _recover.height()) / 2) : st::passcodeSkip)); + if (!_recover->isHidden()) { + _recover->moveToLeft(st::boxPadding.left(), _oldPasscode->y() + _oldPasscode->height() + (_hintText.isEmpty() ? ((st::passcodeSkip - _recover->height()) / 2) : st::passcodeSkip)); } - _saveButton.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _saveButton.height()); - _cancelButton.moveToRight(st::boxButtonPadding.right() + _saveButton.width() + st::boxButtonPadding.left(), _saveButton.y()); + _saveButton->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _saveButton->height()); + _cancelButton->moveToRight(st::boxButtonPadding.right() + _saveButton->width() + st::boxButtonPadding.left(), _saveButton->y()); AbstractBox::resizeEvent(e); } void PasscodeBox::doSetInnerFocus() { - if (_skipEmailWarning && !_recoverEmail.isHidden()) { - _recoverEmail.setFocus(); - } else if (_oldPasscode.isHidden()) { - _newPasscode.setFocus(); + if (_skipEmailWarning && !_recoverEmail->isHidden()) { + _recoverEmail->setFocus(); + } else if (_oldPasscode->isHidden()) { + _newPasscode->setFocus(); } else { - _oldPasscode.setFocus(); + _oldPasscode->setFocus(); } } void PasscodeBox::setPasswordDone(const MTPBool &result) { _setRequest = 0; emit reloadPassword(); - ConfirmBox *box = new InformBox(lang(_reenterPasscode.isHidden() ? lng_cloud_password_removed : (_oldPasscode.isHidden() ? lng_cloud_password_was_set : lng_cloud_password_updated))); + ConfirmBox *box = new InformBox(lang(_reenterPasscode->isHidden() ? lng_cloud_password_removed : (_oldPasscode->isHidden() ? lng_cloud_password_was_set : lng_cloud_password_updated))); Ui::showLayer(box); } bool PasscodeBox::setPasswordFail(const RPCError &error) { if (MTP::isFloodError(error)) { - if (_oldPasscode.isHidden()) return false; + if (_oldPasscode->isHidden()) return false; if (isHidden() && _replacedBy && !_replacedBy->isHidden()) _replacedBy->onClose(); _setRequest = 0; - _oldPasscode.selectAll(); - _oldPasscode.setFocus(); - _oldPasscode.showError(); + _oldPasscode->selectAll(); + _oldPasscode->setFocus(); + _oldPasscode->showError(); _oldError = lang(lng_flood_error); if (_hasRecovery && _hintText.isEmpty()) { - _recover.hide(); + _recover->hide(); } update(); return true; @@ -293,15 +294,15 @@ bool PasscodeBox::setPasswordFail(const RPCError &error) { _setRequest = 0; QString err = error.type(); if (err == qstr("PASSWORD_HASH_INVALID")) { - if (_oldPasscode.isHidden()) { + if (_oldPasscode->isHidden()) { emit reloadPassword(); onClose(); } else { onBadOldPasscode(); } } else if (err == qstr("NEW_PASSWORD_BAD")) { - _newPasscode.setFocus(); - _newPasscode.showError(); + _newPasscode->setFocus(); + _newPasscode->showError(); _newError = lang(lng_cloud_password_bad); update(); } else if (err == qstr("NEW_SALT_INVALID")) { @@ -309,8 +310,8 @@ bool PasscodeBox::setPasswordFail(const RPCError &error) { onClose(); } else if (err == qstr("EMAIL_INVALID")) { _emailError = lang(lng_cloud_password_bad_email); - _recoverEmail.setFocus(); - _recoverEmail.showError(); + _recoverEmail->setFocus(); + _recoverEmail->showError(); update(); } else if (err == qstr("EMAIL_UNCONFIRMED")) { Ui::showLayer(new InformBox(lang(lng_cloud_password_almost))); @@ -322,13 +323,13 @@ bool PasscodeBox::setPasswordFail(const RPCError &error) { void PasscodeBox::onSave(bool force) { if (_setRequest) return; - QString old = _oldPasscode.text(), pwd = _newPasscode.text(), conf = _reenterPasscode.text(); + QString old = _oldPasscode->text(), pwd = _newPasscode->text(), conf = _reenterPasscode->text(); bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode(); if (!_cloudPwd && (_turningOff || has)) { if (!passcodeCanTry()) { _oldError = lang(lng_flood_error); - _oldPasscode.setFocus(); - _oldPasscode.showError(); + _oldPasscode->setFocus(); + _oldPasscode->showError(); update(); return; } @@ -344,37 +345,37 @@ void PasscodeBox::onSave(bool force) { } } if (!_turningOff && pwd.isEmpty()) { - _newPasscode.setFocus(); - _newPasscode.showError(); + _newPasscode->setFocus(); + _newPasscode->showError(); if (isHidden() && _replacedBy && !_replacedBy->isHidden()) _replacedBy->onClose(); return; } if (pwd != conf) { - _reenterPasscode.selectAll(); - _reenterPasscode.setFocus(); - _reenterPasscode.showError(); + _reenterPasscode->selectAll(); + _reenterPasscode->setFocus(); + _reenterPasscode->showError(); if (!conf.isEmpty()) { _newError = lang(_cloudPwd ? lng_cloud_password_differ : lng_passcode_differ); update(); } if (isHidden() && _replacedBy && !_replacedBy->isHidden()) _replacedBy->onClose(); } else if (!_turningOff && has && old == pwd) { - _newPasscode.setFocus(); - _newPasscode.showError(); + _newPasscode->setFocus(); + _newPasscode->showError(); _newError = lang(_cloudPwd ? lng_cloud_password_is_same : lng_passcode_is_same); update(); if (isHidden() && _replacedBy && !_replacedBy->isHidden()) _replacedBy->onClose(); } else if (_cloudPwd) { - QString hint = _passwordHint.getLastText(), email = _recoverEmail.getLastText().trimmed(); - if (_cloudPwd && pwd == hint && !_passwordHint.isHidden() && !_newPasscode.isHidden()) { - _newPasscode.setFocus(); - _newPasscode.showError(); + QString hint = _passwordHint->getLastText(), email = _recoverEmail->getLastText().trimmed(); + if (_cloudPwd && pwd == hint && !_passwordHint->isHidden() && !_newPasscode->isHidden()) { + _newPasscode->setFocus(); + _newPasscode->showError(); _newError = lang(lng_cloud_password_bad); update(); if (isHidden() && _replacedBy && !_replacedBy->isHidden()) _replacedBy->onClose(); return; } - if (!_recoverEmail.isHidden() && email.isEmpty() && !force) { + if (!_recoverEmail->isHidden() && email.isEmpty() && !force) { _skipEmailWarning = true; _replacedBy = new ConfirmBox(lang(lng_cloud_password_about_recover), lang(lng_cloud_password_skip_email), st::attentionBoxButton); connect(_replacedBy, SIGNAL(confirmed()), this, SLOT(onForceNoMail())); @@ -389,13 +390,13 @@ void PasscodeBox::onSave(bool force) { } else { hashSha256(newPasswordData.constData(), newPasswordData.size(), newPasswordHash.data()); } - QByteArray oldPasswordData = _oldPasscode.isHidden() ? QByteArray() : (_curSalt + old.toUtf8() + _curSalt); - QByteArray oldPasswordHash = _oldPasscode.isHidden() ? QByteArray() : QByteArray(32, Qt::Uninitialized); - if (!_oldPasscode.isHidden()) { + QByteArray oldPasswordData = _oldPasscode->isHidden() ? QByteArray() : (_curSalt + old.toUtf8() + _curSalt); + QByteArray oldPasswordHash = _oldPasscode->isHidden() ? QByteArray() : QByteArray(32, Qt::Uninitialized); + if (!_oldPasscode->isHidden()) { hashSha256(oldPasswordData.constData(), oldPasswordData.size(), oldPasswordHash.data()); } MTPDaccount_passwordInputSettings::Flags flags = MTPDaccount_passwordInputSettings::Flag::f_new_salt | MTPDaccount_passwordInputSettings::Flag::f_new_password_hash | MTPDaccount_passwordInputSettings::Flag::f_hint; - if (_oldPasscode.isHidden() || _newPasscode.isHidden()) { + if (_oldPasscode->isHidden() || _newPasscode->isHidden()) { flags |= MTPDaccount_passwordInputSettings::Flag::f_email; } MTPaccount_PasswordInputSettings settings(MTP_account_passwordInputSettings(MTP_flags(flags), MTP_bytes(_newSalt), MTP_bytes(newPasswordHash), MTP_string(hint), MTP_string(email))); @@ -410,12 +411,12 @@ void PasscodeBox::onSave(bool force) { } void PasscodeBox::onBadOldPasscode() { - _oldPasscode.selectAll(); - _oldPasscode.setFocus(); - _oldPasscode.showError(); + _oldPasscode->selectAll(); + _oldPasscode->setFocus(); + _oldPasscode->showError(); _oldError = lang(_cloudPwd ? lng_cloud_password_wrong : lng_passcode_wrong); if (_hasRecovery && _hintText.isEmpty()) { - _recover.hide(); + _recover->hide(); } update(); } @@ -424,7 +425,7 @@ void PasscodeBox::onOldChanged() { if (!_oldError.isEmpty()) { _oldError = QString(); if (_hasRecovery && _hintText.isEmpty()) { - _recover.show(); + _recover->show(); } update(); } @@ -498,21 +499,21 @@ RecoverBox::RecoverBox(const QString &pattern) : AbstractBox(st::boxWidth) , _recoverCode(this, st::defaultInputField, lang(lng_signin_code)) { setBlockTitle(true); - setMaxHeight(titleHeight() + st::passcodePadding.top() + st::passcodeSkip + _recoverCode.height() + st::passcodeSkip + st::passcodePadding.bottom() + st::boxButtonPadding.top() + _saveButton.height() + st::boxButtonPadding.bottom()); + setMaxHeight(titleHeight() + st::passcodePadding.top() + st::passcodeSkip + _recoverCode->height() + st::passcodeSkip + st::passcodePadding.bottom() + st::boxButtonPadding.top() + _saveButton->height() + st::boxButtonPadding.bottom()); - connect(&_saveButton, SIGNAL(clicked()), this, SLOT(onSubmit())); - connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_saveButton, SIGNAL(clicked()), this, SLOT(onSubmit())); + connect(_cancelButton, SIGNAL(clicked()), this, SLOT(onClose())); - connect(&_recoverCode, SIGNAL(changed()), this, SLOT(onCodeChanged())); - connect(&_recoverCode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); + connect(_recoverCode, SIGNAL(changed()), this, SLOT(onCodeChanged())); + connect(_recoverCode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); prepare(); } void RecoverBox::showAll() { - _recoverCode.show(); - _saveButton.show(); - _cancelButton.show(); + _recoverCode->show(); + _saveButton->show(); + _cancelButton->show(); AbstractBox::showAll(); } @@ -525,35 +526,35 @@ void RecoverBox::paintEvent(QPaintEvent *e) { p.setFont(st::normalFont); p.setPen(st::boxTextFg); int32 w = st::boxWidth - st::boxPadding.left() * 1.5; - p.drawText(QRect(st::boxPadding.left(), _recoverCode.y() - st::passcodeSkip - st::passcodePadding.top(), w, st::passcodePadding.top() + st::passcodeSkip), _pattern, style::al_left); + p.drawText(QRect(st::boxPadding.left(), _recoverCode->y() - st::passcodeSkip - st::passcodePadding.top(), w, st::passcodePadding.top() + st::passcodeSkip), _pattern, style::al_left); if (!_error.isEmpty()) { p.setPen(st::boxTextFgError); - p.drawText(QRect(st::boxPadding.left(), _recoverCode.y() + _recoverCode.height(), w, st::passcodeSkip), _error, style::al_left); + p.drawText(QRect(st::boxPadding.left(), _recoverCode->y() + _recoverCode->height(), w, st::passcodeSkip), _error, style::al_left); } } void RecoverBox::resizeEvent(QResizeEvent *e) { - _recoverCode.resize(st::boxWidth - st::boxPadding.left() - st::boxPadding.right(), _recoverCode.height()); - _recoverCode.moveToLeft(st::boxPadding.left(), titleHeight() + st::passcodePadding.top() + st::passcodeSkip); + _recoverCode->resize(st::boxWidth - st::boxPadding.left() - st::boxPadding.right(), _recoverCode->height()); + _recoverCode->moveToLeft(st::boxPadding.left(), titleHeight() + st::passcodePadding.top() + st::passcodeSkip); - _saveButton.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _saveButton.height()); - _cancelButton.moveToRight(st::boxButtonPadding.right() + _saveButton.width() + st::boxButtonPadding.left(), _saveButton.y()); + _saveButton->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _saveButton->height()); + _cancelButton->moveToRight(st::boxButtonPadding.right() + _saveButton->width() + st::boxButtonPadding.left(), _saveButton->y()); AbstractBox::resizeEvent(e); } void RecoverBox::doSetInnerFocus() { - _recoverCode.setFocus(); + _recoverCode->setFocus(); } void RecoverBox::onSubmit() { if (_submitRequest) return; - QString code = _recoverCode.getLastText().trimmed(); + QString code = _recoverCode->getLastText().trimmed(); if (code.isEmpty()) { - _recoverCode.setFocus(); - _recoverCode.showError(); + _recoverCode->setFocus(); + _recoverCode->showError(); return; } @@ -577,7 +578,7 @@ bool RecoverBox::codeSubmitFail(const RPCError &error) { _submitRequest = 0; _error = lang(lng_flood_error); update(); - _recoverCode.showError(); + _recoverCode->showError(); return true; } if (MTP::isDefaultHandledError(error)) return false; @@ -599,9 +600,9 @@ bool RecoverBox::codeSubmitFail(const RPCError &error) { } else if (err == qstr("CODE_INVALID")) { _error = lang(lng_signin_wrong_code); update(); - _recoverCode.selectAll(); - _recoverCode.setFocus(); - _recoverCode.showError(); + _recoverCode->selectAll(); + _recoverCode->setFocus(); + _recoverCode->showError(); return true; } if (cDebug()) { // internal server error @@ -610,6 +611,6 @@ bool RecoverBox::codeSubmitFail(const RPCError &error) { _error = lang(lng_server_error); } update(); - _recoverCode.setFocus(); + _recoverCode->setFocus(); return false; } diff --git a/Telegram/SourceFiles/boxes/passcodebox.h b/Telegram/SourceFiles/boxes/passcodebox.h index 4e1c212df..53ce16438 100644 --- a/Telegram/SourceFiles/boxes/passcodebox.h +++ b/Telegram/SourceFiles/boxes/passcodebox.h @@ -22,6 +22,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" +namespace Ui { +class LinkButton; +class RoundButton; +} // namespace Ui + class PasscodeBox : public AbstractBox, public RPCSender { Q_OBJECT @@ -74,10 +79,14 @@ private: QString _boxTitle; Text _about, _hintText; - BoxButton _saveButton, _cancelButton; - PasswordField _oldPasscode, _newPasscode, _reenterPasscode; - InputField _passwordHint, _recoverEmail; - LinkButton _recover; + ChildWidget _saveButton; + ChildWidget _cancelButton; + ChildWidget _oldPasscode; + ChildWidget _newPasscode; + ChildWidget _reenterPasscode; + ChildWidget _passwordHint; + ChildWidget _recoverEmail; + ChildWidget _recover; QString _oldError, _newError, _emailError; @@ -112,8 +121,9 @@ private: QString _pattern; - BoxButton _saveButton, _cancelButton; - InputField _recoverCode; + ChildWidget _saveButton; + ChildWidget _cancelButton; + ChildWidget _recoverCode; QString _error; diff --git a/Telegram/SourceFiles/boxes/photocropbox.cpp b/Telegram/SourceFiles/boxes/photocropbox.cpp index 34dc05bf1..755c36dc0 100644 --- a/Telegram/SourceFiles/boxes/photocropbox.cpp +++ b/Telegram/SourceFiles/boxes/photocropbox.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "photocropbox.h" #include "fileuploader.h" +#include "ui/widgets/buttons.h" PhotoCropBox::PhotoCropBox(const QImage &img, const PeerId &peer) : AbstractBox() , _downState(0) @@ -54,8 +55,8 @@ void PhotoCropBox::init(const QImage &img, PeerData *peer) { _title = lang(lng_settings_crop_profile); } - connect(&_done, SIGNAL(clicked()), this, SLOT(onSend())); - connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_done, SIGNAL(clicked()), this, SLOT(onSend())); + connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose())); if (peerToBareInt(_peerId)) { connect(this, SIGNAL(ready(const QImage&)), this, SLOT(onReady(const QImage&))); } @@ -77,7 +78,7 @@ void PhotoCropBox::init(const QImage &img, PeerData *peer) { _thumby = st::boxPhotoPadding.top(); setMouseTracking(true); - resizeMaxHeight(st::boxWideWidth, st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxTextFont->height + st::cropSkip + st::boxButtonPadding.top() + _done.height() + st::boxButtonPadding.bottom()); + resizeMaxHeight(st::boxWideWidth, st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxTextFont->height + st::cropSkip + st::boxButtonPadding.top() + _done->height() + st::boxButtonPadding.bottom()); } void PhotoCropBox::mousePressEvent(QMouseEvent *e) { @@ -257,8 +258,8 @@ void PhotoCropBox::paintEvent(QPaintEvent *e) { } void PhotoCropBox::resizeEvent(QResizeEvent *e) { - _done.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done.height()); - _cancel.moveToRight(st::boxButtonPadding.right() + _done.width() + st::boxButtonPadding.left(), _done.y()); + _done->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done->height()); + _cancel->moveToRight(st::boxButtonPadding.right() + _done->width() + st::boxButtonPadding.left(), _done->y()); AbstractBox::resizeEvent(e); } @@ -304,6 +305,6 @@ void PhotoCropBox::onReady(const QImage &tosend) { } void PhotoCropBox::showAll() { - _done.show(); - _cancel.show(); + _done->show(); + _cancel->show(); } diff --git a/Telegram/SourceFiles/boxes/photocropbox.h b/Telegram/SourceFiles/boxes/photocropbox.h index 2a424bf5e..470344acd 100644 --- a/Telegram/SourceFiles/boxes/photocropbox.h +++ b/Telegram/SourceFiles/boxes/photocropbox.h @@ -22,6 +22,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" +namespace Ui { +class RoundButton; +} // namespace Ui + class PhotoCropBox : public AbstractBox { Q_OBJECT @@ -56,7 +60,8 @@ private: int32 _thumbx, _thumby, _thumbw, _thumbh; int32 _cropx, _cropy, _cropw; int32 _fromposx, _fromposy, _fromcropx, _fromcropy, _fromcropw; - BoxButton _done, _cancel; + ChildWidget _done; + ChildWidget _cancel; QImage _img; QPixmap _thumb; PeerId _peerId; diff --git a/Telegram/SourceFiles/boxes/photosendbox.cpp b/Telegram/SourceFiles/boxes/photosendbox.cpp index 31395b637..3ebb1446a 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.cpp +++ b/Telegram/SourceFiles/boxes/photosendbox.cpp @@ -26,7 +26,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "photosendbox.h" #include "history/history_media_types.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "styles/style_history.h" PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth) diff --git a/Telegram/SourceFiles/boxes/photosendbox.h b/Telegram/SourceFiles/boxes/photosendbox.h index 8c41c31f1..04b424e4a 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.h +++ b/Telegram/SourceFiles/boxes/photosendbox.h @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Checkbox; +class RoundButton; } // namespace Ui class PhotoSendBox : public AbstractBox { @@ -60,8 +61,8 @@ private: bool _compressedFromSettings; ChildWidget _compressed; - ChildWidget _send; - ChildWidget _cancel; + ChildWidget _send; + ChildWidget _cancel; int32 _thumbx, _thumby, _thumbw, _thumbh; Text _name; @@ -108,8 +109,8 @@ private: QPixmap _thumb; ChildWidget _field = { nullptr }; - ChildWidget _save; - ChildWidget _cancel; + ChildWidget _save; + ChildWidget _cancel; int32 _thumbx, _thumby, _thumbw, _thumbh; Text _name; diff --git a/Telegram/SourceFiles/boxes/report_box.cpp b/Telegram/SourceFiles/boxes/report_box.cpp index 8da5e09ac..4b56c3f16 100644 --- a/Telegram/SourceFiles/boxes/report_box.cpp +++ b/Telegram/SourceFiles/boxes/report_box.cpp @@ -25,7 +25,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_boxes.h" #include "styles/style_profile.h" #include "boxes/confirmbox.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "mainwindow.h" ReportBox::ReportBox(ChannelData *channel) : AbstractBox(st::boxWidth) diff --git a/Telegram/SourceFiles/boxes/report_box.h b/Telegram/SourceFiles/boxes/report_box.h index c4f81d358..8e631eb38 100644 --- a/Telegram/SourceFiles/boxes/report_box.h +++ b/Telegram/SourceFiles/boxes/report_box.h @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class Radiobutton; +class RoundButton; } // namespace Ui class ReportBox : public AbstractBox, public RPCSender { @@ -60,7 +61,7 @@ private: ChildWidget _reasonOther; ChildWidget _reasonOtherText = { nullptr }; - ChildWidget _report, _cancel; + ChildWidget _report, _cancel; enum Reason { ReasonSpam, diff --git a/Telegram/SourceFiles/boxes/sessionsbox.cpp b/Telegram/SourceFiles/boxes/sessionsbox.cpp index 3898aecdd..fb2218d7d 100644 --- a/Telegram/SourceFiles/boxes/sessionsbox.cpp +++ b/Telegram/SourceFiles/boxes/sessionsbox.cpp @@ -27,7 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "countries.h" #include "boxes/confirmbox.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "styles/style_boxes.h" SessionsBox::SessionsBox() : ScrollableBox(st::sessionsScroll) @@ -38,14 +38,14 @@ SessionsBox::SessionsBox() : ScrollableBox(st::sessionsScroll) , _shortPollRequest(0) { setMaxHeight(st::sessionsHeight); - connect(&_done, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_done, SIGNAL(clicked()), this, SLOT(onClose())); connect(_inner, SIGNAL(oneTerminated()), this, SLOT(onOneTerminated())); connect(_inner, SIGNAL(allTerminated()), this, SLOT(onAllTerminated())); connect(_inner, SIGNAL(terminateAll()), this, SLOT(onTerminateAll())); connect(App::wnd(), SIGNAL(newAuthorization()), this, SLOT(onNewAuthorization())); connect(&_shortPollTimer, SIGNAL(timeout()), this, SLOT(onShortPollAuthorizations())); - init(_inner, st::boxButtonPadding.bottom() + _done.height() + st::boxButtonPadding.top(), titleHeight()); + init(_inner, st::boxButtonPadding.bottom() + _done->height() + st::boxButtonPadding.top(), titleHeight()); _inner->resize(width(), st::noContactsHeight); prepare(); @@ -55,12 +55,12 @@ SessionsBox::SessionsBox() : ScrollableBox(st::sessionsScroll) void SessionsBox::resizeEvent(QResizeEvent *e) { ScrollableBox::resizeEvent(e); - _shadow.setGeometry(0, height() - st::boxButtonPadding.bottom() - _done.height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth); - _done.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done.height()); + _shadow.setGeometry(0, height() - st::boxButtonPadding.bottom() - _done->height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth); + _done->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done->height()); } void SessionsBox::showAll() { - _done.show(); + _done->show(); if (_loading) { scrollArea()->hide(); _shadow.hide(); @@ -194,7 +194,7 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) { } } _inner->listUpdated(); - if (!_done.isHidden()) { + if (!_done->isHidden()) { showAll(); update(); } @@ -204,7 +204,7 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) { void SessionsBox::onOneTerminated() { if (_list.isEmpty()) { - if (!_done.isHidden()) { + if (!_done->isHidden()) { showAll(); update(); } @@ -214,7 +214,7 @@ void SessionsBox::onOneTerminated() { void SessionsBox::onShortPollAuthorizations() { if (!_shortPollRequest) { _shortPollRequest = MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations)); - if (!_done.isHidden()) { + if (!_done->isHidden()) { showAll(); update(); } @@ -236,7 +236,7 @@ void SessionsBox::onAllTerminated() { void SessionsBox::onTerminateAll() { _loading = true; - if (!_done.isHidden()) { + if (!_done->isHidden()) { showAll(); update(); } @@ -246,10 +246,10 @@ SessionsBox::Inner::Inner(QWidget *parent, SessionsBox::List *list, SessionsBox: , _list(list) , _current(current) , _terminating(0) -, _terminateAll(this, lang(lng_sessions_terminate_all), st::redBoxLinkButton) +, _terminateAll(this, lang(lng_sessions_terminate_all), st::sessionTerminateAllButton) , _terminateBox(0) { - connect(&_terminateAll, SIGNAL(clicked()), this, SLOT(onTerminateAll())); - _terminateAll.hide(); + connect(_terminateAll, SIGNAL(clicked()), this, SLOT(onTerminateAll())); + _terminateAll->hide(); setAttribute(Qt::WA_OpaquePaintEvent); } @@ -320,7 +320,7 @@ void SessionsBox::Inner::paintEvent(QPaintEvent *e) { void SessionsBox::Inner::onTerminate() { for (TerminateButtons::iterator i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) { - if (i.value()->getState() & Button::StateOver) { + if (i.value()->getState() & Ui::AbstractButton::StateOver) { _terminating = i.key(); if (_terminateBox) _terminateBox->deleteLater(); @@ -399,14 +399,14 @@ bool SessionsBox::Inner::terminateAllFail(const RPCError &error) { } void SessionsBox::Inner::resizeEvent(QResizeEvent *e) { - _terminateAll.moveToLeft(st::sessionPadding.left(), st::sessionCurrentPadding.top() + st::sessionHeight + st::sessionCurrentPadding.bottom()); + _terminateAll->moveToLeft(st::sessionPadding.left(), st::sessionCurrentPadding.top() + st::sessionHeight + st::sessionCurrentPadding.bottom()); } void SessionsBox::Inner::listUpdated() { if (_list->isEmpty()) { - _terminateAll.hide(); + _terminateAll->hide(); } else { - _terminateAll.show(); + _terminateAll->show(); } for (TerminateButtons::iterator i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) { i.value()->move(0, -1); diff --git a/Telegram/SourceFiles/boxes/sessionsbox.h b/Telegram/SourceFiles/boxes/sessionsbox.h index 0b32c9bad..b3d8c96df 100644 --- a/Telegram/SourceFiles/boxes/sessionsbox.h +++ b/Telegram/SourceFiles/boxes/sessionsbox.h @@ -27,6 +27,8 @@ class ConfirmBox; namespace Ui { class IconButton; +class LinkButton; +class RoundButton; } // namespace Ui class SessionsBox : public ScrollableBox, public RPCSender { @@ -68,7 +70,7 @@ private: class Inner; ChildWidget _inner; ScrollableBoxShadow _shadow; - BoxButton _done; + ChildWidget _done; SingleTimer _shortPollTimer; mtpRequestId _shortPollRequest; @@ -114,7 +116,7 @@ private: TerminateButtons _terminateButtons; uint64 _terminating; - LinkButton _terminateAll; + ChildWidget _terminateAll; ConfirmBox *_terminateBox; }; diff --git a/Telegram/SourceFiles/boxes/sharebox.cpp b/Telegram/SourceFiles/boxes/sharebox.cpp index 6969a24b0..f0d1ee119 100644 --- a/Telegram/SourceFiles/boxes/sharebox.cpp +++ b/Telegram/SourceFiles/boxes/sharebox.cpp @@ -35,6 +35,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/toast/toast.h" #include "ui/widgets/multi_select.h" #include "history/history_media_types.h" +#include "ui/widgets/buttons.h" #include "boxes/contactsbox.h" ShareBox::ShareBox(CopyCallback &©Callback, SubmitCallback &&submitCallback, FilterCallback &&filterCallback) : ItemListBox(st::boxScroll) diff --git a/Telegram/SourceFiles/boxes/sharebox.h b/Telegram/SourceFiles/boxes/sharebox.h index 196a6912b..f986e14b6 100644 --- a/Telegram/SourceFiles/boxes/sharebox.h +++ b/Telegram/SourceFiles/boxes/sharebox.h @@ -37,6 +37,7 @@ struct PeerUpdate; namespace Ui { class MultiSelect; +class RoundButton; } // namespace Ui QString appendShareGameScoreUrl(const QString &url, const FullMsgId &fullId); @@ -90,9 +91,9 @@ private: ChildWidget _inner; ChildWidget _select; - ChildWidget _copy; - ChildWidget _share; - ChildWidget _cancel; + ChildWidget _copy; + ChildWidget _share; + ChildWidget _cancel; ChildWidget _topShadow; ChildWidget _bottomShadow; diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index c0093b7ce..9fe45983f 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -31,6 +31,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "dialogs/dialogs_layout.h" #include "styles/style_boxes.h" #include "styles/style_stickers.h" +#include "ui/widgets/buttons.h" namespace { @@ -611,11 +612,8 @@ void StickersBox::Inner::paintRow(Painter &p, int32 index) { bool removeDown = removeSel && (index == _actionDown); p.setFont(removeSel ? st::linkOverFont : st::linkFont); - if (removeDown) { - p.setPen(st::btnDefLink.downColor); - } else { - p.setPen(st::btnDefLink.color); - } + p.setPen(removeDown ? st::defaultLinkButton.downColor : st::defaultLinkButton.color); + int32 remWidth = s->recent ? _clearWidth : (s->disabled ? (s->official ? _restoreWidth : _returnWidth) : _removeWidth); QString remText = lang(s->recent ? lng_stickers_clear_recent : (s->disabled ? (s->official ? lng_stickers_restore : lng_stickers_return) : lng_stickers_remove)); p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), remText, remWidth); diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 31bc703b1..aed6e99f6 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -26,6 +26,7 @@ class ConfirmBox; namespace Ui { class PlainShadow; +class RoundButton; } // namespace Ui class StickersBox : public ItemListBox, public RPCSender { @@ -81,8 +82,8 @@ private: class Inner; ChildWidget _inner; - ChildWidget _save = { nullptr }; - ChildWidget _cancel = { nullptr }; + ChildWidget _save = { nullptr }; + ChildWidget _cancel = { nullptr }; OrderedSet _disenableRequests; mtpRequestId _reorderRequest = 0; ChildWidget _topShadow = { nullptr }; diff --git a/Telegram/SourceFiles/boxes/stickersetbox.cpp b/Telegram/SourceFiles/boxes/stickersetbox.cpp index 831962c75..1c4396e3a 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.cpp +++ b/Telegram/SourceFiles/boxes/stickersetbox.cpp @@ -31,6 +31,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "dialogs/dialogs_layout.h" #include "styles/style_boxes.h" #include "styles/style_stickers.h" +#include "ui/widgets/buttons.h" StickerSetBox::StickerSetBox(const MTPInputStickerSet &set) : ScrollableBox(st::stickersScroll) , _inner(this, set) @@ -42,12 +43,12 @@ StickerSetBox::StickerSetBox(const MTPInputStickerSet &set) : ScrollableBox(st:: setMaxHeight(st::stickersMaxHeight); connect(App::main(), SIGNAL(stickersUpdated()), this, SLOT(onStickersUpdated())); - init(_inner, st::boxButtonPadding.bottom() + _cancel.height() + st::boxButtonPadding.top()); + init(_inner, st::boxButtonPadding.bottom() + _cancel->height() + st::boxButtonPadding.top()); - connect(&_add, SIGNAL(clicked()), this, SLOT(onAddStickers())); - connect(&_share, SIGNAL(clicked()), this, SLOT(onShareStickers())); - connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose())); - connect(&_done, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_add, SIGNAL(clicked()), this, SLOT(onAddStickers())); + connect(_share, SIGNAL(clicked()), this, SLOT(onShareStickers())); + connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_done, SIGNAL(clicked()), this, SLOT(onClose())); connect(_inner, SIGNAL(updateButtons()), this, SLOT(onUpdateButtons())); connect(scrollArea(), SIGNAL(scrolled()), this, SLOT(onScroll())); @@ -81,7 +82,7 @@ void StickerSetBox::onShareStickers() { } void StickerSetBox::onUpdateButtons() { - if (!_cancel.isHidden() || !_done.isHidden()) { + if (!_cancel->isHidden() || !_done->isHidden()) { showAll(); } } @@ -98,27 +99,27 @@ void StickerSetBox::showAll() { if (_inner->loaded()) { _shadow.show(); if (_inner->notInstalled()) { - _add.show(); - _cancel.show(); - _share.hide(); - _done.hide(); + _add->show(); + _cancel->show(); + _share->hide(); + _done->hide(); } else if (_inner->official()) { - _add.hide(); - _share.hide(); - _cancel.hide(); - _done.show(); + _add->hide(); + _share->hide(); + _cancel->hide(); + _done->show(); } else { - _share.show(); - _cancel.show(); - _add.hide(); - _done.hide(); + _share->show(); + _cancel->show(); + _add->hide(); + _done->hide(); } } else { _shadow.hide(); - _add.hide(); - _share.hide(); - _cancel.show(); - _done.hide(); + _add->hide(); + _share->hide(); + _cancel->show(); + _done->hide(); } resizeEvent(0); update(); @@ -134,16 +135,16 @@ void StickerSetBox::paintEvent(QPaintEvent *e) { void StickerSetBox::resizeEvent(QResizeEvent *e) { ScrollableBox::resizeEvent(e); _inner->resize(width(), _inner->height()); - _shadow.setGeometry(0, height() - st::boxButtonPadding.bottom() - _cancel.height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth); - _add.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _add.height()); - _share.moveToRight(st::boxButtonPadding.right(), _add.y()); - _done.moveToRight(st::boxButtonPadding.right(), _add.y()); - if (_add.isHidden() && _share.isHidden()) { - _cancel.moveToRight(st::boxButtonPadding.right(), _add.y()); - } else if (_add.isHidden()) { - _cancel.moveToRight(st::boxButtonPadding.right() + _share.width() + st::boxButtonPadding.left(), _add.y()); + _shadow.setGeometry(0, height() - st::boxButtonPadding.bottom() - _cancel->height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth); + _add->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _add->height()); + _share->moveToRight(st::boxButtonPadding.right(), _add->y()); + _done->moveToRight(st::boxButtonPadding.right(), _add->y()); + if (_add->isHidden() && _share->isHidden()) { + _cancel->moveToRight(st::boxButtonPadding.right(), _add->y()); + } else if (_add->isHidden()) { + _cancel->moveToRight(st::boxButtonPadding.right() + _share->width() + st::boxButtonPadding.left(), _add->y()); } else { - _cancel.moveToRight(st::boxButtonPadding.right() + _add.width() + st::boxButtonPadding.left(), _add.y()); + _cancel->moveToRight(st::boxButtonPadding.right() + _add->width() + st::boxButtonPadding.left(), _add->y()); } } diff --git a/Telegram/SourceFiles/boxes/stickersetbox.h b/Telegram/SourceFiles/boxes/stickersetbox.h index 53932eff3..7c052f622 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.h +++ b/Telegram/SourceFiles/boxes/stickersetbox.h @@ -27,6 +27,7 @@ class ConfirmBox; namespace Ui { class PlainShadow; +class RoundButton; } // namespace Ui class StickerSetBox : public ScrollableBox, public RPCSender { @@ -59,7 +60,10 @@ private: class Inner; ChildWidget _inner; ScrollableBoxShadow _shadow; - BoxButton _add, _share, _cancel, _done; + ChildWidget _add; + ChildWidget _share; + ChildWidget _cancel; + ChildWidget _done; QString _title; }; diff --git a/Telegram/SourceFiles/boxes/usernamebox.cpp b/Telegram/SourceFiles/boxes/usernamebox.cpp index aa4365cf6..d4c1a964c 100644 --- a/Telegram/SourceFiles/boxes/usernamebox.cpp +++ b/Telegram/SourceFiles/boxes/usernamebox.cpp @@ -19,18 +19,20 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #include "stdafx.h" -#include "lang.h" +#include "boxes/usernamebox.h" +#include "lang.h" #include "application.h" -#include "usernamebox.h" #include "mainwidget.h" #include "mainwindow.h" +#include "ui/widgets/buttons.h" +#include "styles/style_boxes.h" UsernameBox::UsernameBox() : AbstractBox(st::boxWidth), _save(this, lang(lng_settings_save), st::defaultBoxButton), _cancel(this, lang(lng_cancel), st::cancelBoxButton), _username(this, st::defaultInputField, qsl("@username"), App::self()->username, false), -_link(this, QString(), st::defaultBoxLinkButton), +_link(this, QString(), st::boxLinkButton), _saveRequestId(0), _checkRequestId(0), _about(st::boxWidth - st::usernamePadding.left()) { setBlockTitle(true); @@ -39,15 +41,15 @@ _about(st::boxWidth - st::usernamePadding.left()) { textstyleSet(&st::usernameTextStyle); _about.setRichText(st::boxTextFont, lang(lng_username_about)); - resizeMaxHeight(st::boxWidth, titleHeight() + st::usernamePadding.top() + _username.height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom()); + resizeMaxHeight(st::boxWidth, titleHeight() + st::usernamePadding.top() + _username->height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom() + st::boxButtonPadding.top() + _save->height() + st::boxButtonPadding.bottom()); textstyleRestore(); - connect(&_save, SIGNAL(clicked()), this, SLOT(onSave())); - connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose())); - connect(&_username, SIGNAL(changed()), this, SLOT(onChanged())); - connect(&_username, SIGNAL(submitted(bool)), this, SLOT(onSave())); + connect(_save, SIGNAL(clicked()), this, SLOT(onSave())); + connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose())); + connect(_username, SIGNAL(changed()), this, SLOT(onChanged())); + connect(_username, SIGNAL(submitted(bool)), this, SLOT(onSave())); - connect(&_link, SIGNAL(clicked()), this, SLOT(onLinkClick())); + connect(_link, SIGNAL(clicked()), this, SLOT(onLinkClick())); _checkTimer.setSingleShot(true); connect(&_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck())); @@ -56,16 +58,16 @@ _about(st::boxWidth - st::usernamePadding.left()) { } void UsernameBox::showAll() { - _username.show(); - _save.show(); - _cancel.show(); + _username->show(); + _save->show(); + _cancel->show(); updateLinkText(); AbstractBox::showAll(); } void UsernameBox::doSetInnerFocus() { - _username.setFocus(); + _username->setFocus(); } void UsernameBox::paintEvent(QPaintEvent *e) { @@ -77,25 +79,25 @@ void UsernameBox::paintEvent(QPaintEvent *e) { p.setFont(st::boxTextFont); if (!_copiedTextLink.isEmpty()) { p.setPen(st::usernameDefaultFg); - p.drawTextLeft(st::usernamePadding.left(), _username.y() + _username.height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), _copiedTextLink); + p.drawTextLeft(st::usernamePadding.left(), _username->y() + _username->height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), _copiedTextLink); } else if (!_errorText.isEmpty()) { p.setPen(st::boxTextFgError); - p.drawTextLeft(st::usernamePadding.left(), _username.y() + _username.height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), _errorText); + p.drawTextLeft(st::usernamePadding.left(), _username->y() + _username->height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), _errorText); } else if (!_goodText.isEmpty()) { p.setPen(st::boxTextFgGood); - p.drawTextLeft(st::usernamePadding.left(), _username.y() + _username.height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), _goodText); + p.drawTextLeft(st::usernamePadding.left(), _username->y() + _username->height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), _goodText); } else { p.setPen(st::usernameDefaultFg); - p.drawTextLeft(st::usernamePadding.left(), _username.y() + _username.height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), lang(lng_username_choose)); + p.drawTextLeft(st::usernamePadding.left(), _username->y() + _username->height() + ((st::usernameSkip - st::boxTextFont->height) / 2), width(), lang(lng_username_choose)); } p.setPen(st::boxTextFg); textstyleSet(&st::usernameTextStyle); int32 availw = st::boxWidth - st::usernamePadding.left(), h = _about.countHeight(availw); - _about.drawLeft(p, st::usernamePadding.left(), _username.y() + _username.height() + st::usernameSkip, availw, width()); + _about.drawLeft(p, st::usernamePadding.left(), _username->y() + _username->height() + st::usernameSkip, availw, width()); textstyleRestore(); - int32 linky = _username.y() + _username.height() + st::usernameSkip + h + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2); - if (_link.isHidden()) { + int32 linky = _username->y() + _username->height() + st::usernameSkip + h + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2); + if (_link->isHidden()) { p.drawTextLeft(st::usernamePadding.left(), linky, width(), lang(lng_username_link_willbe)); p.setPen(st::usernameDefaultFg); p.drawTextLeft(st::usernamePadding.left(), linky + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2), width(), qsl("https://telegram.me/username")); @@ -105,17 +107,17 @@ void UsernameBox::paintEvent(QPaintEvent *e) { } void UsernameBox::resizeEvent(QResizeEvent *e) { - _username.resize(width() - st::usernamePadding.left() - st::usernamePadding.right(), _username.height()); - _username.moveToLeft(st::usernamePadding.left(), titleHeight() + st::usernamePadding.top()); + _username->resize(width() - st::usernamePadding.left() - st::usernamePadding.right(), _username->height()); + _username->moveToLeft(st::usernamePadding.left(), titleHeight() + st::usernamePadding.top()); textstyleSet(&st::usernameTextStyle); int32 availw = st::boxWidth - st::usernamePadding.left(), h = _about.countHeight(availw); textstyleRestore(); - int32 linky = _username.y() + _username.height() + st::usernameSkip + h + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2); - _link.moveToLeft(st::usernamePadding.left(), linky + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2)); + int32 linky = _username->y() + _username->height() + st::usernameSkip + h + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2); + _link->moveToLeft(st::usernamePadding.left(), linky + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2)); - _save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height()); - _cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y()); + _save->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save->height()); + _cancel->moveToRight(st::boxButtonPadding.right() + _save->width() + st::boxButtonPadding.left(), _save->y()); AbstractBox::resizeEvent(e); } @@ -199,21 +201,21 @@ bool UsernameBox::onUpdateFail(const RPCError &error) { onClose(); return true; } else if (err == qstr("USERNAME_INVALID")) { - _username.setFocus(); - _username.showError(); + _username->setFocus(); + _username->showError(); _copiedTextLink = QString(); _errorText = lang(lng_username_invalid); update(); return true; } else if (err == qstr("USERNAME_OCCUPIED") || err == qstr("USERNAMES_UNAVAILABLE")) { - _username.setFocus(); - _username.showError(); + _username->setFocus(); + _username->showError(); _copiedTextLink = QString(); _errorText = lang(lng_username_occupied); update(); return true; } - _username.setFocus(); + _username->setFocus(); return true; } @@ -245,25 +247,25 @@ bool UsernameBox::onCheckFail(const RPCError &error) { } _goodText = QString(); _copiedTextLink = QString(); - _username.setFocus(); + _username->setFocus(); return true; } QString UsernameBox::getName() const { - return _username.text().replace('@', QString()).trimmed(); + return _username->text().replace('@', QString()).trimmed(); } void UsernameBox::updateLinkText() { QString uname = getName(); - _link.setText(st::boxTextFont->elided(qsl("https://telegram.me/") + uname, st::boxWidth - st::usernamePadding.left() - st::usernamePadding.right())); + _link->setText(st::boxTextFont->elided(qsl("https://telegram.me/") + uname, st::boxWidth - st::usernamePadding.left() - st::usernamePadding.right())); if (uname.isEmpty()) { - if (!_link.isHidden()) { - _link.hide(); + if (!_link->isHidden()) { + _link->hide(); update(); } } else { - if (_link.isHidden()) { - _link.show(); + if (_link->isHidden()) { + _link->show(); update(); } } diff --git a/Telegram/SourceFiles/boxes/usernamebox.h b/Telegram/SourceFiles/boxes/usernamebox.h index 1af61399d..05beb5067 100644 --- a/Telegram/SourceFiles/boxes/usernamebox.h +++ b/Telegram/SourceFiles/boxes/usernamebox.h @@ -22,6 +22,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" +namespace Ui { +class RoundButton; +class LinkButton; +} // namespace Ui + class UsernameBox : public AbstractBox, public RPCSender { Q_OBJECT @@ -53,9 +58,10 @@ private: QString getName() const; void updateLinkText(); - BoxButton _save, _cancel; - UsernameInput _username; - LinkButton _link; + ChildWidget _save; + ChildWidget _cancel; + ChildWidget _username; + ChildWidget _link; mtpRequestId _saveRequestId, _checkRequestId; QString _sentUsername, _checkUsername, _errorText, _goodText, _copiedTextLink; diff --git a/Telegram/SourceFiles/dialogs/dialogs.style b/Telegram/SourceFiles/dialogs/dialogs.style index a50ba0084..79226dfb5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs.style +++ b/Telegram/SourceFiles/dialogs/dialogs.style @@ -162,7 +162,7 @@ historySendingInvertedIcon: icon {{ "dialogs_sending", #ffffffc8, point(5px, 5px historyViewsSendingIcon: icon {{ "dialogs_sending", #a0adb5, point(3px, 0px) }}; historyViewsSendingInvertedIcon: icon {{ "dialogs_sending", #ffffffc8, point(3px, 0px) }}; -dialogsUpdateButton: flatButton { +dialogsUpdateButton: FlatButton { duration: 0; cursor: cursor(pointer); diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 780e1355e..779b7a2a1 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "dialogs/dialogs_layout.h" #include "styles/style_dialogs.h" #include "styles/style_stickers.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" #include "data/data_drafts.h" #include "lang.h" @@ -54,7 +54,7 @@ DialogsInner::DialogsInner(QWidget *parent, QWidget *main) : SplittedWidget(pare connect(main, SIGNAL(peerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&))); connect(main, SIGNAL(peerPhotoChanged(PeerData*)), this, SLOT(onPeerPhotoChanged(PeerData*))); connect(main, SIGNAL(dialogRowReplaced(Dialogs::Row*,Dialogs::Row*)), this, SLOT(onDialogRowReplaced(Dialogs::Row*,Dialogs::Row*))); - connect(&_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact())); + connect(_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact())); connect(_cancelSearchInPeer, SIGNAL(clicked()), this, SIGNAL(cancelSearchInPeer())); _cancelSearchInPeer->hide(); @@ -410,7 +410,7 @@ void DialogsInner::mousePressEvent(QMouseEvent *e) { } void DialogsInner::resizeEvent(QResizeEvent *e) { - _addContactLnk.move((width() - _addContactLnk.width()) / 2, (st::noContactsHeight + st::noContactsFont->height) / 2); + _addContactLnk->move((width() - _addContactLnk->width()) / 2, (st::noContactsHeight + st::noContactsFont->height) / 2); _cancelSearchInPeer->move(width() - st::dialogsPadding.x() - st::dialogsCancelSearch.width, (st::dialogsRowHeight - st::dialogsCancelSearch.height) / 2); } @@ -1092,16 +1092,16 @@ void DialogsInner::refresh(bool toTop) { if (shownDialogs()->isEmpty()) { h = st::noContactsHeight; if (cContactsReceived()) { - if (_addContactLnk.isHidden()) _addContactLnk.show(); + if (_addContactLnk->isHidden()) _addContactLnk->show(); } else { - if (!_addContactLnk.isHidden()) _addContactLnk.hide(); + if (!_addContactLnk->isHidden()) _addContactLnk->hide(); } } else { h = dialogsOffset() + shownDialogs()->size() * st::dialogsRowHeight; - if (!_addContactLnk.isHidden()) _addContactLnk.hide(); + if (!_addContactLnk->isHidden()) _addContactLnk->hide(); } } else { - if (!_addContactLnk.isHidden()) _addContactLnk.hide(); + if (!_addContactLnk->isHidden()) _addContactLnk->hide(); if (_state == FilteredState) { h = searchedOffset() + (_searchResults.count() * st::dialogsRowHeight) + ((_searchResults.isEmpty() && !_searchInPeer) ? -st::searchedBarHeight : 0); } else if (_state == SearchedState) { diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index cac76a09b..a708116ca 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -32,6 +32,8 @@ namespace Ui { class IconButton; class PopupMenu; class DropdownMenu; +class FlatButton; +class LinkButton; } // namespace Ui enum DialogsSearchRequestType { @@ -206,7 +208,7 @@ private: void paintDialog(QPainter &p, Dialogs::Row *dialog); - LinkButton _addContactLnk; + ChildWidget _addContactLnk; ChildWidget _cancelSearchInPeer; bool _overDelete = false; @@ -335,7 +337,7 @@ private: ChildWidget _lockUnlock; ChildWidget _scroll; ChildWidget _inner; - ChildWidget _updateTelegram = { nullptr }; + ChildWidget _updateTelegram = { nullptr }; Animation _a_show; QPixmap _cacheUnder, _cacheOver; diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index 961d89d65..70b84ef5b 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -157,7 +157,7 @@ historyComposeFieldMaxHeight: 224px; historySendPadding: 9px; historySendRight: 2px; -historyComposeButton: flatButton { +historyComposeButton: FlatButton { duration: 200; cursor: cursor(pointer); @@ -177,7 +177,7 @@ historyComposeButton: flatButton { font: semiboldFont; overFont: semiboldFont; } -historyUnblock: flatButton(historyComposeButton) { +historyUnblock: FlatButton(historyComposeButton) { color: #d15948; overColor: #d15948; } @@ -307,3 +307,38 @@ topBarMenuToggle: IconButton(topBarSearch) { iconPosition: point(18px, 17px); iconPositionDown: point(18px, 17px); } +reportSpamHide: FlatButton { + duration: 200; + cursor: cursor(pointer); + + color: btnYesColor; + overColor: btnYesHover; + + bgColor: transparent; + overBgColor: transparent; + + width: -40px; + height: 46px; + + textTop: 15px; + overTextTop: 15px; + downTextTop: 16px; + + font: font(fsize); + overFont: font(fsize underline); +} +reportSpamButton: FlatButton(reportSpamHide) { + textTop: 6px; + overTextTop: 6px; + downTextTop: 7px; + + width: -50px; + height: 30px; + + bgColor: #888888; + overBgColor: #7b7b7b; +} +reportSpamSeparator: 30px; +reportSpamBg: #fffffff0; +reportSpamFg: #000000; + diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index cceba28e3..e250eb2bb 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -29,7 +29,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/filedialog.h" #include "ui/toast/toast.h" #include "ui/buttons/history_down_button.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/inner_dropdown.h" #include "ui/widgets/dropdown_menu.h" #include "inline_bots/inline_bot_result.h" @@ -2911,6 +2911,29 @@ HistoryHider::~HistoryHider() { parent()->noHider(this); } +class SilentToggle : public Ui::IconButton, public Ui::AbstractTooltipShower { +public: + SilentToggle(QWidget *parent); + + void setChecked(bool checked); + bool checked() const { + return _checked; + } + + // AbstractTooltipShower interface + QString tooltipText() const override; + QPoint tooltipPos() const override; + +protected: + void mouseMoveEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void leaveEvent(QEvent *e) override; + +private: + bool _checked = false; + +}; + SilentToggle::SilentToggle(QWidget *parent) : IconButton(parent, st::historySilentToggle) { setMouseTracking(true); } diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 37df22358..0224b08ed 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -23,7 +23,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "localimageloader.h" #include "ui/effects/rect_shadow.h" #include "ui/widgets/tooltip.h" -#include "ui/buttons/icon_button.h" #include "history/history_common.h" #include "history/field_autocomplete.h" #include "window/section_widget.h" @@ -44,10 +43,14 @@ class PopupMenu; class IconButton; class HistoryDownButton; class EmojiButton; +class FlatButton; +class LinkButton; +class RoundButton; } // namespace Ui class DragArea; class EmojiPan; +class SilentToggle; class HistoryWidget; class HistoryInner : public TWidget, public Ui::AbstractTooltipShower, private base::Subscriber { @@ -350,9 +353,9 @@ protected: void paintEvent(QPaintEvent *e) override; private: - ChildWidget _report; - ChildWidget _hide; - ChildWidget _clear; + ChildWidget _report; + ChildWidget _hide; + ChildWidget _clear; }; @@ -489,8 +492,8 @@ private: QString _shareUrl, _shareText; QString _botAndQuery; - ChildWidget _send; - ChildWidget _cancel; + ChildWidget _send; + ChildWidget _cancel; PeerData *_offered = nullptr; anim::fvalue a_opacity; @@ -511,29 +514,6 @@ private: }; -class SilentToggle : public Ui::IconButton, public Ui::AbstractTooltipShower { -public: - SilentToggle(QWidget *parent); - - void setChecked(bool checked); - bool checked() const { - return _checked; - } - - // AbstractTooltipShower interface - QString tooltipText() const override; - QPoint tooltipPos() const override; - -protected: - void mouseMoveEvent(QMouseEvent *e) override; - void mouseReleaseEvent(QMouseEvent *e) override; - void leaveEvent(QEvent *e) override; - -private: - bool _checked = false; - -}; - EntitiesInText entitiesFromTextTags(const TextWithTags::Tags &tags); TextWithTags::Tags textTagsFromEntities(const EntitiesInText &entities); @@ -1099,10 +1079,10 @@ private: ReportSpamPanel _reportSpamPanel; ChildWidget _send; - ChildWidget _unblock; - ChildWidget _botStart; - ChildWidget _joinChannel; - ChildWidget _muteUnmute; + ChildWidget _unblock; + ChildWidget _botStart; + ChildWidget _joinChannel; + ChildWidget _muteUnmute; mtpRequestId _unblockRequest = 0; mtpRequestId _reportSpamRequest = 0; ChildWidget _attachToggle; diff --git a/Telegram/SourceFiles/intro/intro.style b/Telegram/SourceFiles/intro/intro.style index 22709b21b..70881640b 100644 --- a/Telegram/SourceFiles/intro/intro.style +++ b/Telegram/SourceFiles/intro/intro.style @@ -43,6 +43,14 @@ introCountry: countryInput { align: align(left); } +introIcon: icon {{ "intro_logo", #008ed5 }}; + +introResetLink: LinkButton(defaultLinkButton) { + color: #d15948; + overColor: #d15948; + downColor: #db6352; +} + introBtnTop: 288px; introSkip: 25px; introFinishSkip: 15px; @@ -51,7 +59,7 @@ introHeaderFont: font(24px); introHeaderSkip: 14px; introIconSkip: 50px; introFont: font(16px); -introLink: linkButton(btnDefLink) { +introLink: LinkButton(defaultLinkButton) { font: introFont; overFont: font(16px underline); } diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index 0c403eb5a..982fe678d 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "intro/introsignup.h" #include "intro/intropwdcheck.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" #include "styles/style_intro.h" CodeInput::CodeInput(QWidget *parent, const style::flatInput &st, const QString &ph) : FlatInput(parent, st, ph) { @@ -86,7 +86,6 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent) , _checkRequest(this) { setGeometry(parent->innerRect()); - _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitCode())); connect(_code, SIGNAL(changed()), this, SLOT(onInputChange())); connect(_callTimer, SIGNAL(timeout()), this, SLOT(onSendCall())); diff --git a/Telegram/SourceFiles/intro/introcode.h b/Telegram/SourceFiles/intro/introcode.h index 49e049bcd..d3f894ccb 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -20,13 +20,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include -#include "ui/flatbutton.h" -#include "ui/flatinput.h" #include "intro/introwidget.h" +class FlatInput; + namespace Ui { class RoundButton; +class LinkButton; } // namespace Ui class CodeInput final : public FlatInput { @@ -91,7 +91,7 @@ private: ChildWidget _next; Text _desc; - ChildWidget _noTelegramCode; + ChildWidget _noTelegramCode; mtpRequestId _noTelegramCodeRequestId; QRect _textRect; diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 9f68aacd5..11c3311b6 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "intro/introcode.h" #include "styles/style_intro.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" namespace { class SignUpClickHandler : public LeftButtonClickHandler { @@ -56,7 +56,6 @@ IntroPhone::IntroPhone(IntroWidget *parent) : IntroStep(parent) setVisible(false); setGeometry(parent->innerRect()); - _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPhone())); connect(_phone, SIGNAL(voidBackspace(QKeyEvent*)), _code, SLOT(startErasing(QKeyEvent*))); connect(_country, SIGNAL(codeChanged(const QString &)), _code, SLOT(codeSelected(const QString &))); diff --git a/Telegram/SourceFiles/intro/introphone.h b/Telegram/SourceFiles/intro/introphone.h index cf4786e73..019251705 100644 --- a/Telegram/SourceFiles/intro/introphone.h +++ b/Telegram/SourceFiles/intro/introphone.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/flatbutton.h" #include "ui/countryinput.h" #include "ui/flatlabel.h" #include "intro/introwidget.h" diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index d04c3dadd..0dc6ee140 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -27,7 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "lang.h" #include "application.h" #include "intro/introsignup.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) @@ -40,12 +40,11 @@ IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent) , _codeField(this, st::inpIntroPassword, lang(lng_signin_code)) , _toRecover(this, lang(lng_signin_recover)) , _toPassword(this, lang(lng_signin_try_password)) -, _reset(this, lang(lng_signin_reset_account), st::btnRedLink) +, _reset(this, lang(lng_signin_reset_account), st::introResetLink) , _checkRequest(this) { setVisible(false); setGeometry(parent->innerRect()); - _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd())); connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover())); diff --git a/Telegram/SourceFiles/intro/intropwdcheck.h b/Telegram/SourceFiles/intro/intropwdcheck.h index 01c37b7cf..8d4d1d1c0 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.h +++ b/Telegram/SourceFiles/intro/intropwdcheck.h @@ -20,11 +20,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/flatinput.h" #include "intro/introwidget.h" +class FlatInput; + namespace Ui { class RoundButton; +class LinkButton; } // namespace Ui class IntroPwdCheck final : public IntroStep { @@ -80,9 +82,9 @@ private: ChildWidget _pwdField; ChildWidget _codeField; - ChildWidget _toRecover; - ChildWidget _toPassword; - ChildWidget _reset; + ChildWidget _toRecover; + ChildWidget _toPassword; + ChildWidget _reset; mtpRequestId _sentRequest = 0; Text _hintText; diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index 0f674e5d5..450f28675 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -27,7 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/photocropbox.h" #include "lang.h" #include "application.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" IntroSignup::IntroSignup(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) @@ -42,7 +42,6 @@ IntroSignup::IntroSignup(IntroWidget *parent) : IntroStep(parent) setVisible(false); setGeometry(parent->innerRect()); - _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitName())); connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); diff --git a/Telegram/SourceFiles/intro/introsignup.h b/Telegram/SourceFiles/intro/introsignup.h index 3b7535ec8..8bfe59bfa 100644 --- a/Telegram/SourceFiles/intro/introsignup.h +++ b/Telegram/SourceFiles/intro/introsignup.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/flatbutton.h" #include "ui/flatinput.h" #include "intro/introwidget.h" diff --git a/Telegram/SourceFiles/intro/introstart.cpp b/Telegram/SourceFiles/intro/introstart.cpp index 6c24ab9e8..34e1d4520 100644 --- a/Telegram/SourceFiles/intro/introstart.cpp +++ b/Telegram/SourceFiles/intro/introstart.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "intro/introphone.h" #include "langloaderplain.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" IntroStart::IntroStart(IntroWidget *parent) : IntroStep(parent) , _intro(this, lang(lng_intro), FlatLabel::InitType::Rich, st::introLabel, st::introLabelTextStyle) @@ -53,7 +53,6 @@ IntroStart::IntroStart(IntroWidget *parent) : IntroStep(parent) setGeometry(parent->innerRect()); - _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_next, SIGNAL(clicked()), parent, SLOT(onStepSubmit())); connect(_changeLang, SIGNAL(clicked()), parent, SLOT(onChangeLang())); @@ -74,7 +73,7 @@ void IntroStart::paintEvent(QPaintEvent *e) { p.setPen(st::introHeaderFg); p.drawText((width() - _headerWidth) / 2, hy, qsl("Telegram Desktop")); - st::aboutIcon.paint(p, QPoint((width() - st::aboutIcon.width()) / 2, hy - st::introIconSkip - st::aboutIcon.height()), width()); + st::introIcon.paint(p, QPoint((width() - st::introIcon.width()) / 2, hy - st::introIconSkip - st::introIcon.height()), width()); } void IntroStart::resizeEvent(QResizeEvent *e) { diff --git a/Telegram/SourceFiles/intro/introstart.h b/Telegram/SourceFiles/intro/introstart.h index 9ad5733b6..a88be1238 100644 --- a/Telegram/SourceFiles/intro/introstart.h +++ b/Telegram/SourceFiles/intro/introstart.h @@ -21,9 +21,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #pragma once #include "intro/introwidget.h" -#include "ui/flatlabel.h" + +class FlatLabel; namespace Ui { +class LinkButton; class RoundButton; } // namespace Ui @@ -39,7 +41,7 @@ public: private: ChildWidget _intro; - ChildWidget _changeLang; + ChildWidget _changeLang; ChildWidget _next; diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index aea428d67..c41b8ac55 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -32,7 +32,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "application.h" #include "ui/text/text.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/effects/widget_fade_wrap.h" #include "styles/style_intro.h" #include "autoupdater.h" diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index 24b6bd452..36072d578 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class IconButton; +class RoundButton; template class WidgetFadeWrap; } // namespace Ui @@ -152,8 +153,8 @@ private: QString _firstname, _lastname; ChildWidget> _back; - ChildWidget _settings; - ChildWidget _update = { nullptr }; + ChildWidget _settings; + ChildWidget _update = { nullptr }; float64 _backFrom = 0.; float64 _backTo = 0.; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 720c031ed..32f8fba2a 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_dialogs.h" #include "ui/buttons/peer_avatar_button.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "window/section_memento.h" #include "window/section_widget.h" diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index e7e665031..bb6f4982b 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_dialogs.h" #include "styles/style_window.h" #include "ui/widgets/popup_menu.h" +#include "ui/widgets/buttons.h" #include "core/zlib_help.h" #include "lang.h" #include "shortcuts.h" @@ -52,7 +53,7 @@ ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const Q , _shadow(st::boxShadow) , _reconnect(this, QString()) { set(text, reconnect); - connect(&_reconnect, SIGNAL(clicked()), this, SLOT(onReconnect())); + connect(_reconnect, SIGNAL(clicked()), this, SLOT(onReconnect())); } void ConnectingWidget::set(const QString &text, const QString &reconnect) { @@ -60,12 +61,12 @@ void ConnectingWidget::set(const QString &text, const QString &reconnect) { _textWidth = st::linkFont->width(_text) + st::linkFont->spacew; int32 _reconnectWidth = 0; if (reconnect.isEmpty()) { - _reconnect.hide(); + _reconnect->hide(); } else { - _reconnect.setText(reconnect); - _reconnect.show(); - _reconnect.move(st::connectingPadding.left() + _textWidth, st::boxShadow.height() + st::connectingPadding.top()); - _reconnectWidth = _reconnect.width(); + _reconnect->setText(reconnect); + _reconnect->show(); + _reconnect->move(st::connectingPadding.left() + _textWidth, st::boxShadow.height() + st::connectingPadding.top()); + _reconnectWidth = _reconnect->width(); } resize(st::connectingPadding.left() + _textWidth + _reconnectWidth + st::connectingPadding.right() + st::boxShadow.width(), st::boxShadow.height() + st::connectingPadding.top() + st::linkFont->height + st::connectingPadding.bottom()); update(); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index c6d032f8a..8f53d7d32 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -47,6 +47,10 @@ class WarningWidget; } // namespace Theme } // namespace Window +namespace Ui { +class LinkButton; +} // namespace Ui + class ConnectingWidget : public TWidget { Q_OBJECT @@ -64,7 +68,7 @@ private: Ui::RectShadow _shadow; QString _text; int32 _textWidth; - LinkButton _reconnect; + ChildWidget _reconnect; }; diff --git a/Telegram/SourceFiles/media/player/media_player_button.h b/Telegram/SourceFiles/media/player/media_player_button.h index 1335e55b8..aabf46968 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.h +++ b/Telegram/SourceFiles/media/player/media_player_button.h @@ -20,7 +20,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/button.h" +#include "ui/abstract_button.h" #include "styles/style_media_player.h" namespace Media { diff --git a/Telegram/SourceFiles/media/player/media_player_cover.cpp b/Telegram/SourceFiles/media/player/media_player_cover.cpp index b2e252b1f..3a2eb7d4b 100644 --- a/Telegram/SourceFiles/media/player/media_player_cover.cpp +++ b/Telegram/SourceFiles/media/player/media_player_cover.cpp @@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/flatlabel.h" #include "ui/widgets/label_simple.h" #include "ui/widgets/media_slider.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "media/media_audio.h" #include "media/view/media_clip_playback.h" #include "media/player/media_player_button.h" @@ -38,7 +38,7 @@ namespace Player { using State = PlayButtonLayout::State; -class CoverWidget::PlayButton : public Button { +class CoverWidget::PlayButton : public Ui::AbstractButton { public: PlayButton(QWidget *parent); @@ -57,7 +57,7 @@ private: }; -CoverWidget::PlayButton::PlayButton(QWidget *parent) : Button(parent) +CoverWidget::PlayButton::PlayButton(QWidget *parent) : Ui::AbstractButton(parent) , _layout(st::mediaPlayerPanelButton, [this] { update(); }) { resize(st::mediaPlayerPanelButtonSize); setCursor(style::cur_pointer); diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp index 237127fa0..062032e71 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp @@ -22,7 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "media/player/media_player_volume_controller.h" #include "media/media_audio.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/media_slider.h" #include "styles/style_media_player.h" #include "styles/style_widgets.h" diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 5597a4509..4e22f965e 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/widgets/label_simple.h" #include "ui/widgets/filled_slider.h" #include "ui/widgets/shadow.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "media/media_audio.h" #include "media/view/media_clip_playback.h" #include "media/player/media_player_button.h" @@ -39,7 +39,7 @@ namespace Player { using State = PlayButtonLayout::State; -class Widget::PlayButton : public Button { +class Widget::PlayButton : public Ui::AbstractButton { public: PlayButton(QWidget *parent); @@ -58,7 +58,7 @@ private: }; -Widget::PlayButton::PlayButton(QWidget *parent) : Button(parent) +Widget::PlayButton::PlayButton(QWidget *parent) : Ui::AbstractButton(parent) , _layout(st::mediaPlayerButton, [this] { update(); }) { resize(st::mediaPlayerButtonSize); setCursor(style::cur_pointer); diff --git a/Telegram/SourceFiles/media/view/media_clip_controller.cpp b/Telegram/SourceFiles/media/view/media_clip_controller.cpp index 9b48227c0..9e66e6d66 100644 --- a/Telegram/SourceFiles/media/view/media_clip_controller.cpp +++ b/Telegram/SourceFiles/media/view/media_clip_controller.cpp @@ -27,7 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/widgets/label_simple.h" #include "ui/widgets/media_slider.h" #include "ui/effects/widget_fade_wrap.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "media/media_audio.h" namespace Media { diff --git a/Telegram/SourceFiles/media/view/mediaview.style b/Telegram/SourceFiles/media/view/mediaview.style index 0d0b3ea6a..895e68351 100644 --- a/Telegram/SourceFiles/media/view/mediaview.style +++ b/Telegram/SourceFiles/media/view/mediaview.style @@ -115,7 +115,7 @@ mediaviewFileExtPadding: 10px; mediaviewFileLinksTop: 57px; mediaviewFileIconSize: 80px; -mediaviewFileLink: linkButton(btnDefLink) { +mediaviewFileLink: LinkButton(defaultLinkButton) { color: #4595d3; overColor: #4595d3; downColor: #4595d3; diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index c28f02360..434c03b1b 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -27,6 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "ui/filedialog.h" #include "ui/widgets/popup_menu.h" +#include "ui/widgets/buttons.h" #include "media/media_clip_reader.h" #include "media/view/media_clip_controller.h" #include "styles/style_mediaview.h" @@ -130,9 +131,9 @@ MediaView::MediaView() : TWidget(App::wnd()) _controlsHideTimer.setSingleShot(true); connect(&_controlsHideTimer, SIGNAL(timeout()), this, SLOT(onHideControls())); - connect(&_docDownload, SIGNAL(clicked()), this, SLOT(onDownload())); - connect(&_docSaveAs, SIGNAL(clicked()), this, SLOT(onSaveAs())); - connect(&_docCancel, SIGNAL(clicked()), this, SLOT(onSaveCancel())); + connect(_docDownload, SIGNAL(clicked()), this, SLOT(onDownload())); + connect(_docSaveAs, SIGNAL(clicked()), this, SLOT(onSaveAs())); + connect(_docCancel, SIGNAL(clicked()), this, SLOT(onSaveCancel())); _dropdown->setHiddenCallback([this] { dropdownHidden(); }); } @@ -237,7 +238,7 @@ void MediaView::stopGif() { void MediaView::documentUpdated(DocumentData *doc) { if (_doc && _doc == doc && !fileShown()) { - if ((_doc->loading() && _docCancel.isHidden()) || (!_doc->loading() && !_docCancel.isHidden())) { + if ((_doc->loading() && _docCancel->isHidden()) || (!_doc->loading() && !_docCancel->isHidden())) { updateControls(); } else if (_doc->loading()) { updateDocSize(); @@ -289,29 +290,29 @@ void MediaView::updateDocSize() { void MediaView::updateControls() { if (_doc && !fileShown()) { if (_doc->loading()) { - _docDownload.hide(); - _docSaveAs.hide(); - _docCancel.moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); - _docCancel.show(); + _docDownload->hide(); + _docSaveAs->hide(); + _docCancel->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); + _docCancel->show(); } else { if (_doc->loaded(DocumentData::FilePathResolveChecked)) { - _docDownload.hide(); - _docSaveAs.moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); - _docSaveAs.show(); - _docCancel.hide(); + _docDownload->hide(); + _docSaveAs->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); + _docSaveAs->show(); + _docCancel->hide(); } else { - _docDownload.moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); - _docDownload.show(); - _docSaveAs.moveToLeft(_docRect.x() + 2.5 * st::mediaviewFilePadding + st::mediaviewFileIconSize + _docDownload.width(), _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); - _docSaveAs.show(); - _docCancel.hide(); + _docDownload->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); + _docDownload->show(); + _docSaveAs->moveToLeft(_docRect.x() + 2.5 * st::mediaviewFilePadding + st::mediaviewFileIconSize + _docDownload->width(), _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); + _docSaveAs->show(); + _docCancel->hide(); } } updateDocSize(); } else { - _docDownload.hide(); - _docSaveAs.hide(); - _docCancel.hide(); + _docDownload->hide(); + _docSaveAs->hide(); + _docCancel->hide(); } radialStart(); diff --git a/Telegram/SourceFiles/mediaview.h b/Telegram/SourceFiles/mediaview.h index b54900c1e..1cdcdcdcd 100644 --- a/Telegram/SourceFiles/mediaview.h +++ b/Telegram/SourceFiles/mediaview.h @@ -31,6 +31,7 @@ class Controller; namespace Ui { class PopupMenu; +class LinkButton; } // namespace Ui struct AudioPlaybackState; @@ -242,7 +243,9 @@ private: int _docNameWidth = 0, _docSizeWidth = 0, _docExtWidth = 0; QRect _docRect, _docIconRect; int _docThumbx = 0, _docThumby = 0, _docThumbw = 0; - LinkButton _docDownload, _docSaveAs, _docCancel; + ChildWidget _docDownload; + ChildWidget _docSaveAs; + ChildWidget _docCancel; QRect _photoRadialRect; Ui::RadialAnimation _radial; diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index d5b19764c..85f060e5d 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -29,7 +29,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/filedialog.h" #include "ui/widgets/popup_menu.h" #include "ui/widgets/tooltip.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "window/top_bar_widget.h" #include "window/window_theme.h" #include "lang.h" diff --git a/Telegram/SourceFiles/passcodewidget.cpp b/Telegram/SourceFiles/passcodewidget.cpp index 3cc48564f..0c1d3de2e 100644 --- a/Telegram/SourceFiles/passcodewidget.cpp +++ b/Telegram/SourceFiles/passcodewidget.cpp @@ -26,7 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "application.h" #include "ui/text/text.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" #include "styles/style_boxes.h" #include "window/slide_animation.h" @@ -39,7 +39,6 @@ PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent) connect(_passcode, SIGNAL(changed()), this, SLOT(onChanged())); connect(_passcode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - _submit->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); _submit->setClickedCallback([this] { onSubmit(); }); _logout->setClickedCallback([] { App::wnd()->onLogout(); }); diff --git a/Telegram/SourceFiles/passcodewidget.h b/Telegram/SourceFiles/passcodewidget.h index 6b682ddcc..3ccd192b7 100644 --- a/Telegram/SourceFiles/passcodewidget.h +++ b/Telegram/SourceFiles/passcodewidget.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #pragma once namespace Ui { +class LinkButton; class RoundButton; } // namespace Ui @@ -56,7 +57,7 @@ private: ChildWidget _passcode; ChildWidget _submit; - ChildWidget _logout; + ChildWidget _logout; QString _error; }; diff --git a/Telegram/SourceFiles/platform/win/window_title_win.cpp b/Telegram/SourceFiles/platform/win/window_title_win.cpp index 582e8fb28..e948614b9 100644 --- a/Telegram/SourceFiles/platform/win/window_title_win.cpp +++ b/Telegram/SourceFiles/platform/win/window_title_win.cpp @@ -21,7 +21,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include "platform/win/window_title_win.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "styles/style_window.h" diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index 2608aa84b..122ed6f26 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -25,10 +25,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_window.h" #include "profile/profile_cover_drop_area.h" #include "profile/profile_userpic_button.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" #include "ui/filedialog.h" #include "ui/flatlabel.h" -#include "ui/flatbutton.h" #include "observer_peer.h" #include "boxes/confirmbox.h" #include "boxes/contactsbox.h" @@ -354,7 +353,7 @@ void CoverWidget::refreshStatusText() { _statusText = lang(lng_settings_uploading_photo); _statusTextIsOnline = false; if (!_cancelPhotoUpload) { - _cancelPhotoUpload = new LinkButton(this, lang(lng_cancel), st::btnDefLink); + _cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton); connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload())); _cancelPhotoUpload->show(); _cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::profileStatusFont->width(_statusText) + st::profileStatusFont->spacew, _statusPosition.y()); @@ -455,7 +454,6 @@ void CoverWidget::clearButtons() { void CoverWidget::addButton(const QString &text, const char *slot, const style::RoundButton *replacementStyle) { auto &buttonStyle = _buttons.isEmpty() ? st::profilePrimaryButton : st::profileSecondaryButton; auto button = new Ui::RoundButton(this, text, buttonStyle); - button->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(button, SIGNAL(clicked()), this, slot); button->show(); diff --git a/Telegram/SourceFiles/profile/profile_cover.h b/Telegram/SourceFiles/profile/profile_cover.h index 3abd8e66e..6c5e925f7 100644 --- a/Telegram/SourceFiles/profile/profile_cover.h +++ b/Telegram/SourceFiles/profile/profile_cover.h @@ -24,10 +24,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/filedialog.h" class FlatLabel; -class LinkButton; namespace Ui { class RoundButton; +class LinkButton; } // namespace Ui namespace Notify { @@ -118,7 +118,7 @@ private: ChildWidget _dropArea = { nullptr }; ChildWidget _name; - ChildWidget _cancelPhotoUpload = { nullptr }; + ChildWidget _cancelPhotoUpload = { nullptr }; QPoint _statusPosition; QString _statusText; diff --git a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp index 584b480d7..03927b938 100644 --- a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp +++ b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_profile.h" #include "styles/style_window.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" #include "lang.h" #include "mainwidget.h" #include "boxes/addcontactbox.h" @@ -33,9 +33,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Profile { -class BackButton final : public Button, private base::Subscriber { +class BackButton final : public Ui::AbstractButton, private base::Subscriber { public: - BackButton(QWidget *parent) : Button(parent) { + BackButton(QWidget *parent) : Ui::AbstractButton(parent) { setCursor(style::cur_pointer); subscribe(Adaptive::Changed(), [this] { updateAdaptiveLayout(); }); @@ -58,8 +58,8 @@ protected: Window::TopBarWidget::paintUnreadCounter(p, width()); } - void onStateChanged(int oldState, ButtonStateChangeSource source) override { - if ((_state & Button::StateDown) && !(oldState & Button::StateDown)) { + void onStateChanged(int oldState, StateChangeSource source) override { + if ((_state & StateDown) && !(oldState & StateDown)) { emit clicked(); } } @@ -186,6 +186,7 @@ void FixedBar::addRightAction(RightActionType type, const QString &text, const c _rightActions[_currentAction].type = type; delete _rightActions[_currentAction].button; _rightActions[_currentAction].button = new Ui::RoundButton(this, text, st::profileFixedBarButton); + _rightActions[_currentAction].button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); connect(_rightActions[_currentAction].button, SIGNAL(clicked()), this, slot); bool showButton = !_animatingMode && (type != RightActionType::ShareContact || !_hideShareContactButton); _rightActions[_currentAction].button->setVisible(showButton); diff --git a/Telegram/SourceFiles/profile/profile_settings_widget.cpp b/Telegram/SourceFiles/profile/profile_settings_widget.cpp index c93ee264c..886cf9c8b 100644 --- a/Telegram/SourceFiles/profile/profile_settings_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_settings_widget.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_profile.h" #include "ui/buttons/left_outline_button.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" #include "boxes/confirmbox.h" #include "boxes/contactsbox.h" #include "observer_peer.h" diff --git a/Telegram/SourceFiles/profile/profile_userpic_button.cpp b/Telegram/SourceFiles/profile/profile_userpic_button.cpp index 547d93a10..267c35b0b 100644 --- a/Telegram/SourceFiles/profile/profile_userpic_button.cpp +++ b/Telegram/SourceFiles/profile/profile_userpic_button.cpp @@ -27,7 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Profile { -UserpicButton::UserpicButton(QWidget *parent, PeerData *peer) : Button(parent), _peer(peer) { +UserpicButton::UserpicButton(QWidget *parent, PeerData *peer) : AbstractButton(parent), _peer(peer) { resize(st::profilePhotoSize, st::profilePhotoSize); processPeerPhoto(); diff --git a/Telegram/SourceFiles/profile/profile_userpic_button.h b/Telegram/SourceFiles/profile/profile_userpic_button.h index 0bec52b7a..ca2d7076a 100644 --- a/Telegram/SourceFiles/profile/profile_userpic_button.h +++ b/Telegram/SourceFiles/profile/profile_userpic_button.h @@ -20,6 +20,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once +#include "ui/abstract_button.h" #include "core/observer.h" namespace Notify { @@ -28,7 +29,7 @@ struct PeerUpdate; namespace Profile { -class UserpicButton final : public Button, private base::Subscriber { +class UserpicButton : public Ui::AbstractButton, private base::Subscriber { public: UserpicButton(QWidget *parent, PeerData *peer); diff --git a/Telegram/SourceFiles/settings/settings_advanced_widget.cpp b/Telegram/SourceFiles/settings/settings_advanced_widget.cpp index 9502a6b14..e7485d0ae 100644 --- a/Telegram/SourceFiles/settings/settings_advanced_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced_widget.cpp @@ -28,6 +28,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/aboutbox.h" #include "boxes/localstoragebox.h" #include "mainwindow.h" +#include "ui/widgets/buttons.h" namespace Settings { diff --git a/Telegram/SourceFiles/settings/settings_advanced_widget.h b/Telegram/SourceFiles/settings/settings_advanced_widget.h index a6c8b75a2..5fb013d45 100644 --- a/Telegram/SourceFiles/settings/settings_advanced_widget.h +++ b/Telegram/SourceFiles/settings/settings_advanced_widget.h @@ -49,14 +49,14 @@ private: #endif // !TDESKTOP_DISABLE_NETWORK_PROXY void supportGot(const MTPhelp_Support &support); - ChildWidget _manageLocalStorage = { nullptr }; + ChildWidget _manageLocalStorage = { nullptr }; #ifndef TDESKTOP_DISABLE_NETWORK_PROXY ChildWidget _connectionType = { nullptr }; #endif // !TDESKTOP_DISABLE_NETWORK_PROXY - ChildWidget _askQuestion = { nullptr }; - ChildWidget _telegramFAQ = { nullptr }; - ChildWidget _about = { nullptr }; - ChildWidget _logOut = { nullptr }; + ChildWidget _askQuestion = { nullptr }; + ChildWidget _telegramFAQ = { nullptr }; + ChildWidget _about = { nullptr }; + ChildWidget _logOut = { nullptr }; mtpRequestId _supportGetRequest = 0; diff --git a/Telegram/SourceFiles/settings/settings_background_widget.cpp b/Telegram/SourceFiles/settings/settings_background_widget.cpp index e40b51c17..f4a0a18fa 100644 --- a/Telegram/SourceFiles/settings/settings_background_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_background_widget.cpp @@ -26,7 +26,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "boxes/backgroundbox.h" #include "ui/effects/widget_slide_wrap.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "localstorage.h" #include "mainwindow.h" #include "window/window_theme.h" @@ -34,8 +35,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Settings { BackgroundRow::BackgroundRow(QWidget *parent) : TWidget(parent) -, _chooseFromGallery(this, lang(lng_settings_bg_from_gallery), st::defaultBoxLinkButton) -, _chooseFromFile(this, lang(lng_settings_bg_from_file), st::defaultBoxLinkButton) +, _chooseFromGallery(this, lang(lng_settings_bg_from_gallery), st::boxLinkButton) +, _chooseFromFile(this, lang(lng_settings_bg_from_file), st::boxLinkButton) , _radial(animation(this, &BackgroundRow::step_radial)) { updateImage(); diff --git a/Telegram/SourceFiles/settings/settings_background_widget.h b/Telegram/SourceFiles/settings/settings_background_widget.h index 6b7d458f2..5793dfa9c 100644 --- a/Telegram/SourceFiles/settings/settings_background_widget.h +++ b/Telegram/SourceFiles/settings/settings_background_widget.h @@ -24,14 +24,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/effects/radial_animation.h" #include "ui/filedialog.h" -class LinkButton; - -namespace Ui { -class Checkbox; -template -class WidgetSlideWrap; -} // namespace Ui; - namespace Settings { class BackgroundRow : public TWidget { @@ -60,8 +52,8 @@ private: void step_radial(uint64 ms, bool timer); QPixmap _background; - ChildWidget _chooseFromGallery; - ChildWidget _chooseFromFile; + ChildWidget _chooseFromGallery; + ChildWidget _chooseFromFile; Ui::RadialAnimation _radial; diff --git a/Telegram/SourceFiles/settings/settings_block_widget.cpp b/Telegram/SourceFiles/settings/settings_block_widget.cpp index edfe760a4..ee8fc62d8 100644 --- a/Telegram/SourceFiles/settings/settings_block_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_block_widget.cpp @@ -22,7 +22,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_block_widget.h" #include "styles/style_settings.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" namespace Settings { @@ -85,17 +86,17 @@ void BlockWidget::rowHeightUpdated() { } void BlockWidget::createChildRow(ChildWidget &child, style::margins &margin, const QString &text, const char *slot, bool checked) { - child = new Ui::Checkbox(this, text, checked, st::defaultBoxCheckbox); + child.create(this, text, checked, st::defaultBoxCheckbox); connect(child, SIGNAL(changed()), this, slot); } void BlockWidget::createChildRow(ChildWidget &child, style::margins &margin, const QString &group, int value, const QString &text, const char *slot, bool checked) { - child = new Ui::Radiobutton(this, group, value, text, checked, st::defaultRadiobutton); + child .create(this, group, value, text, checked, st::defaultRadiobutton); connect(child, SIGNAL(changed()), this, slot); } -void BlockWidget::createChildRow(ChildWidget &child, style::margins &margin, const QString &text, const char *slot, const style::linkButton &st) { - child = new LinkButton(this, text, st); +void BlockWidget::createChildRow(ChildWidget &child, style::margins &margin, const QString &text, const char *slot, const style::LinkButton &st) { + child .create(this, text, st); connect(child, SIGNAL(clicked()), this, slot); } diff --git a/Telegram/SourceFiles/settings/settings_block_widget.h b/Telegram/SourceFiles/settings/settings_block_widget.h index 92e28a5ab..8d651f827 100644 --- a/Telegram/SourceFiles/settings/settings_block_widget.h +++ b/Telegram/SourceFiles/settings/settings_block_widget.h @@ -21,10 +21,12 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #pragma once #include "core/observer.h" +#include "styles/style_boxes.h" namespace Ui { class Checkbox; class Radiobutton; +class LinkButton; template class WidgetSlideWrap; } // namespace Ui @@ -88,7 +90,7 @@ private: } void createChildRow(ChildWidget &child, style::margins &margin, const QString &text, const char *slot, bool checked); void createChildRow(ChildWidget &child, style::margins &margin, const QString &group, int value, const QString &text, const char *slot, bool checked); - void createChildRow(ChildWidget &child, style::margins &margin, const QString &text, const char *slot, const style::linkButton &st = st::defaultBoxLinkButton); + void createChildRow(ChildWidget &child, style::margins &margin, const QString &text, const char *slot, const style::LinkButton &st = st::boxLinkButton); void addCreatedRow(TWidget *child, const style::margins &margin); void rowHeightUpdated(); @@ -107,7 +109,7 @@ private: !IsWidgetSlideWrap::value && !std_::is_same::value && !std_::is_same::value && - !std_::is_same::value>; + !std_::is_same::value>; template > void createChildRow(ChildWidget &child, style::margins &margin, Args&&... args) { diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp index c9527e6c8..6e1109246 100644 --- a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp @@ -24,7 +24,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_settings.h" #include "lang.h" #include "ui/effects/widget_slide_wrap.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "ui/flatlabel.h" #include "localstorage.h" #include "mainwidget.h" @@ -39,13 +40,12 @@ namespace Settings { LabeledLink::LabeledLink(QWidget *parent, const QString &label, const QString &text, Type type, const char *slot) : TWidget(parent) , _label(this, label, FlatLabel::InitType::Simple, (type == Type::Primary) ? st::settingsPrimaryLabel : st::labelDefFlat) -, _link(this, text, (type == Type::Primary) ? st::defaultBoxLinkButton : st::btnDefLink) { +, _link(this, text, (type == Type::Primary) ? st::boxLinkButton : st::defaultLinkButton) { connect(_link, SIGNAL(clicked()), parent, slot); } void LabeledLink::setLink(const QString &text) { - _link.destroy(); - _link = new LinkButton(this, text); + _link.create(this, text); } int LabeledLink::naturalWidth() const { @@ -159,7 +159,7 @@ void ChatSettingsWidget::createControls() { addChildRow(_replaceEmoji, marginSub, lang(lng_settings_replace_emojis), SLOT(onReplaceEmoji()), cReplaceEmojis()); style::margins marginList(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip); - addChildRow(_viewList, marginList, slidedPadding, lang(lng_settings_view_emojis), SLOT(onViewList()), st::btnDefLink); + addChildRow(_viewList, marginList, slidedPadding, lang(lng_settings_view_emojis), SLOT(onViewList()), st::defaultLinkButton); if (!cReplaceEmojis()) { _viewList->hideFast(); } diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.h b/Telegram/SourceFiles/settings/settings_chat_settings_widget.h index 2c1da6c74..71d997226 100644 --- a/Telegram/SourceFiles/settings/settings_chat_settings_widget.h +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.h @@ -36,7 +36,7 @@ public: void setLink(const QString &text); - LinkButton *link() { + Ui::LinkButton *link() { return _link; } @@ -47,7 +47,7 @@ protected: private: ChildWidget _label; - ChildWidget _link; + ChildWidget _link; }; @@ -83,7 +83,7 @@ private: State _state = State::Empty; ChildWidget _path; - ChildWidget _clear; + ChildWidget _clear; }; @@ -106,13 +106,13 @@ private: void createControls(); ChildWidget _replaceEmoji = { nullptr }; - ChildWidget> _viewList = { nullptr }; + ChildWidget> _viewList = { nullptr }; ChildWidget _dontAskDownloadPath = { nullptr }; ChildWidget> _downloadPath = { nullptr }; ChildWidget _sendByEnter = { nullptr }; ChildWidget _sendByCtrlEnter = { nullptr }; - ChildWidget _automaticMediaDownloadSettings = { nullptr }; - ChildWidget _manageStickerSets = { nullptr }; + ChildWidget _automaticMediaDownloadSettings = { nullptr }; + ChildWidget _manageStickerSets = { nullptr }; }; diff --git a/Telegram/SourceFiles/settings/settings_cover.cpp b/Telegram/SourceFiles/settings/settings_cover.cpp index 6792f8d05..05390244a 100644 --- a/Telegram/SourceFiles/settings/settings_cover.cpp +++ b/Telegram/SourceFiles/settings/settings_cover.cpp @@ -22,8 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_cover.h" #include "ui/flatlabel.h" -#include "ui/buttons/round_button.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "observer_peer.h" #include "lang.h" #include "application.h" @@ -50,9 +49,7 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent, _name->setSelectable(true); _name->setContextCopyText(lang(lng_profile_copy_fullname)); - _setPhoto->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_setPhoto, SIGNAL(clicked()), this, SLOT(onSetPhoto())); - _editName->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); connect(_editName, SIGNAL(clicked()), this, SLOT(onEditName())); connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName())); @@ -280,7 +277,7 @@ void CoverWidget::refreshStatusText() { _statusText = lang(lng_settings_uploading_photo); _statusTextIsOnline = false; if (!_cancelPhotoUpload) { - _cancelPhotoUpload = new LinkButton(this, lang(lng_cancel), st::btnDefLink); + _cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton); connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload())); _cancelPhotoUpload->show(); _cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::settingsStatusFont->width(_statusText) + st::settingsStatusFont->spacew, _statusPosition.y()); diff --git a/Telegram/SourceFiles/settings/settings_cover.h b/Telegram/SourceFiles/settings/settings_cover.h index 08ca9c0b4..c086fb201 100644 --- a/Telegram/SourceFiles/settings/settings_cover.h +++ b/Telegram/SourceFiles/settings/settings_cover.h @@ -26,8 +26,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_block_widget.h" class FlatLabel; -class LinkButton; - namespace Ui { class RoundButton; class IconButton; @@ -95,7 +93,7 @@ private: ChildWidget _name; ChildWidget _editNameInline; - ChildWidget _cancelPhotoUpload = { nullptr }; + ChildWidget _cancelPhotoUpload = { nullptr }; QPoint _statusPosition; QString _statusText; diff --git a/Telegram/SourceFiles/settings/settings_fixed_bar.cpp b/Telegram/SourceFiles/settings/settings_fixed_bar.cpp index 5954df433..079c91343 100644 --- a/Telegram/SourceFiles/settings/settings_fixed_bar.cpp +++ b/Telegram/SourceFiles/settings/settings_fixed_bar.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_settings.h" #include "styles/style_boxes.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "mainwindow.h" #include "lang.h" diff --git a/Telegram/SourceFiles/settings/settings_general_widget.cpp b/Telegram/SourceFiles/settings/settings_general_widget.cpp index 2b38960a7..3225a158d 100644 --- a/Telegram/SourceFiles/settings/settings_general_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_general_widget.cpp @@ -24,8 +24,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_settings.h" #include "lang.h" #include "ui/effects/widget_slide_wrap.h" -#include "ui/flatbutton.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "localstorage.h" #include "pspecific.h" #include "mainwindow.h" @@ -168,7 +168,7 @@ void UpdateStateRow::onFailed() { #endif // !TDESKTOP_DISABLE_AUTOUPDATE GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_general)) -, _changeLanguage(this, lang(lng_settings_change_lang), st::defaultBoxLinkButton) { +, _changeLanguage(this, lang(lng_settings_change_lang), st::boxLinkButton) { connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage())); subscribe(Global::RefChooseCustomLang(), [this]() { chooseCustomLang(); }); subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) { @@ -178,7 +178,7 @@ GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(pare } int GeneralWidget::resizeGetHeight(int newWidth) { - _changeLanguage->moveToRight(contentLeft(), st::settingsBlockMarginTop + st::settingsBlockTitleTop + st::settingsBlockTitleFont->ascent - st::btnDefLink.font->ascent, newWidth); + _changeLanguage->moveToRight(contentLeft(), st::settingsBlockMarginTop + st::settingsBlockTitleTop + st::settingsBlockTitleFont->ascent - st::defaultLinkButton.font->ascent, newWidth); return BlockWidget::resizeGetHeight(newWidth); } diff --git a/Telegram/SourceFiles/settings/settings_general_widget.h b/Telegram/SourceFiles/settings/settings_general_widget.h index 228cf182a..48ab3cb2a 100644 --- a/Telegram/SourceFiles/settings/settings_general_widget.h +++ b/Telegram/SourceFiles/settings/settings_general_widget.h @@ -23,14 +23,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_block_widget.h" #include "ui/filedialog.h" -class LinkButton; - -namespace Ui { -class Checkbox; -template -class WidgetSlideWrap; -} // namespace Ui - namespace Settings { #ifndef TDESKTOP_DISABLE_AUTOUPDATE @@ -73,8 +65,8 @@ private: void setState(State state, bool force = false); void setDownloadProgress(qint64 ready, qint64 total); - ChildWidget _check; - ChildWidget _restart; + ChildWidget _check; + ChildWidget _restart; State _state = State::None; QString _downloadText; @@ -114,7 +106,7 @@ private: void chooseCustomLang(); void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update); - ChildWidget _changeLanguage; + ChildWidget _changeLanguage; #ifndef TDESKTOP_DISABLE_AUTOUPDATE ChildWidget _updateAutomatically = { nullptr }; ChildWidget> _updateRow = { nullptr }; diff --git a/Telegram/SourceFiles/settings/settings_notifications_widget.cpp b/Telegram/SourceFiles/settings/settings_notifications_widget.cpp index 2bd3b7ce8..441b0c4f3 100644 --- a/Telegram/SourceFiles/settings/settings_notifications_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications_widget.cpp @@ -25,7 +25,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "lang.h" #include "localstorage.h" #include "ui/effects/widget_slide_wrap.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" #include "mainwindow.h" #include "window/notifications_manager.h" #include "boxes/notifications_box.h" diff --git a/Telegram/SourceFiles/settings/settings_notifications_widget.h b/Telegram/SourceFiles/settings/settings_notifications_widget.h index 404457c5c..0a2b44e94 100644 --- a/Telegram/SourceFiles/settings/settings_notifications_widget.h +++ b/Telegram/SourceFiles/settings/settings_notifications_widget.h @@ -51,7 +51,7 @@ private: ChildWidget _nativeNotifications = { nullptr }; ChildWidget _playSound = { nullptr }; ChildWidget _includeMuted = { nullptr }; - ChildWidget> _advanced = { nullptr }; + ChildWidget> _advanced = { nullptr }; }; diff --git a/Telegram/SourceFiles/settings/settings_privacy_widget.cpp b/Telegram/SourceFiles/settings/settings_privacy_widget.cpp index 9d177e243..20cf8ec35 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_widget.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_privacy_widget.h" #include "ui/effects/widget_slide_wrap.h" +#include "ui/widgets/buttons.h" #include "styles/style_settings.h" #include "lang.h" #include "application.h" @@ -33,8 +34,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Settings { LocalPasscodeState::LocalPasscodeState(QWidget *parent) : TWidget(parent) -, _edit(this, lang(Global::LocalPasscode() ? lng_passcode_change : lng_passcode_turn_on), st::defaultBoxLinkButton) -, _turnOff(this, lang(lng_passcode_turn_off), st::defaultBoxLinkButton) { +, _edit(this, lang(Global::LocalPasscode() ? lng_passcode_change : lng_passcode_turn_on), st::boxLinkButton) +, _turnOff(this, lang(lng_passcode_turn_off), st::boxLinkButton) { updateControls(); connect(_edit, SIGNAL(clicked()), this, SLOT(onEdit())); connect(_turnOff, SIGNAL(clicked()), this, SLOT(onTurnOff())); @@ -62,8 +63,8 @@ void LocalPasscodeState::updateControls() { } CloudPasswordState::CloudPasswordState(QWidget *parent) : TWidget(parent) -, _edit(this, lang(lng_cloud_password_set), st::defaultBoxLinkButton) -, _turnOff(this, lang(lng_passcode_turn_off), st::defaultBoxLinkButton) { +, _edit(this, lang(lng_cloud_password_set), st::boxLinkButton) +, _turnOff(this, lang(lng_passcode_turn_off), st::boxLinkButton) { _turnOff->hide(); connect(_edit, SIGNAL(clicked()), this, SLOT(onEdit())); connect(_turnOff, SIGNAL(clicked()), this, SLOT(onTurnOff())); diff --git a/Telegram/SourceFiles/settings/settings_privacy_widget.h b/Telegram/SourceFiles/settings/settings_privacy_widget.h index 54d7ca8bb..8bc1a947b 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_widget.h +++ b/Telegram/SourceFiles/settings/settings_privacy_widget.h @@ -41,8 +41,8 @@ private slots: private: void updateControls(); - ChildWidget _edit; - ChildWidget _turnOff; + ChildWidget _edit; + ChildWidget _turnOff; }; @@ -67,8 +67,8 @@ private: void offPasswordDone(const MTPBool &result); bool offPasswordFail(const RPCError &error); - ChildWidget _edit; - ChildWidget _turnOff; + ChildWidget _edit; + ChildWidget _turnOff; QString _waitingConfirm; QByteArray _curPasswordSalt; @@ -95,7 +95,7 @@ private: ChildWidget _localPasscodeState = { nullptr }; ChildWidget> _autoLock = { nullptr }; ChildWidget _cloudPasswordState = { nullptr }; - ChildWidget _showAllSessions = { nullptr }; + ChildWidget _showAllSessions = { nullptr }; }; diff --git a/Telegram/SourceFiles/settings/settings_scale_widget.cpp b/Telegram/SourceFiles/settings/settings_scale_widget.cpp index 63a9674a7..d16c9af9d 100644 --- a/Telegram/SourceFiles/settings/settings_scale_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_scale_widget.cpp @@ -22,7 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_scale_widget.h" #include "styles/style_settings.h" -#include "ui/buttons/checkbox.h" +#include "ui/widgets/checkbox.h" #include "lang.h" #include "localstorage.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index 42ef303d6..fde5cb65d 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -72,7 +72,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/twidget.h" #include "ui/flatinput.h" #include "ui/flattextarea.h" -#include "ui/flatbutton.h" #include "ui/scrollarea.h" #include "ui/images.h" #include "ui/text/text.h" diff --git a/Telegram/SourceFiles/stickers/emoji_pan.cpp b/Telegram/SourceFiles/stickers/emoji_pan.cpp index f52735d6b..3413ddee3 100644 --- a/Telegram/SourceFiles/stickers/emoji_pan.cpp +++ b/Telegram/SourceFiles/stickers/emoji_pan.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_stickers.h" #include "styles/style_intro.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "boxes/confirmbox.h" #include "boxes/stickersetbox.h" #include "boxes/stickers_box.h" @@ -804,7 +804,7 @@ StickerPanInner::StickerPanInner() : TWidget() setMouseTracking(true); setAttribute(Qt::WA_OpaquePaintEvent); - connect(&_settings, SIGNAL(clicked()), this, SLOT(onSettings())); + connect(_settings, SIGNAL(clicked()), this, SLOT(onSettings())); _previewTimer.setSingleShot(true); connect(&_previewTimer, SIGNAL(timeout()), this, SLOT(onPreview())); @@ -821,7 +821,7 @@ StickerPanInner::StickerPanInner() : TWidget() void StickerPanInner::setMaxHeight(int32 h) { _maxHeight = h; resize(st::emojiPanWidth - st::emojiScroll.width, countHeight()); - _settings.moveToLeft((st::emojiPanWidth - _settings.width()) / 2, height() / 3); + _settings->moveToLeft((st::emojiPanWidth - _settings->width()) / 2, height() / 3); } void StickerPanInner::setVisibleTopBottom(int visibleTop, int visibleBottom) { @@ -1425,9 +1425,9 @@ void StickerPanInner::refreshStickers() { int h = countHeight(); if (h != height()) resize(width(), h); - _settings.setVisible(_section == Section::Stickers && _mySets.isEmpty()); + _settings->setVisible(_section == Section::Stickers && _mySets.isEmpty()); } else { - _settings.hide(); + _settings->hide(); } emit refreshIcons(kRefreshIconsNoAnimation); @@ -1499,7 +1499,7 @@ bool StickerPanInner::inlineRowFinalize(InlineRow &row, int32 &sumWidth, bool fo void StickerPanInner::refreshSavedGifs() { if (_section == Section::Gifs) { - _settings.hide(); + _settings->hide(); clearInlineRows(false); auto &saved = cSavedGifs(); @@ -1728,7 +1728,7 @@ void StickerPanInner::refreshSwitchPmButton(const InlineCacheEntry *entry) { _switchPmStartToken.clear(); } else { if (!_switchPmButton) { - _switchPmButton = std_::make_unique(this, QString(), st::switchPmButton); + _switchPmButton = std_::make_unique(this, QString(), st::switchPmButton); _switchPmButton->show(); _switchPmButton->move(st::inlineResultsLeft, st::emojiPanHeader); connect(_switchPmButton.get(), SIGNAL(clicked()), this, SLOT(onSwitchPm())); @@ -1768,7 +1768,7 @@ int StickerPanInner::refreshInlineRows(UserData *bot, const InlineCacheEntry *en _inlineBotTitle = lng_inline_bot_results(lt_inline_bot, _inlineBot->username.isEmpty() ? _inlineBot->name : ('@' + _inlineBot->username)); _section = Section::Inlines; - _settings.hide(); + _settings->hide(); int32 count = entry->results.size(), from = validateExistingInlineRows(entry->results), added = 0; @@ -2492,7 +2492,7 @@ void EmojiPanel::paintEvent(QPaintEvent *e) { p.drawTextLeft(st::emojiPanHeaderLeft, st::emojiPanHeaderTop, width(), _text); } -EmojiSwitchButton::EmojiSwitchButton(QWidget *parent, bool toStickers) : Button(parent) +EmojiSwitchButton::EmojiSwitchButton(QWidget *parent, bool toStickers) : AbstractButton(parent) , _toStickers(toStickers) { setCursor(style::cur_pointer); updateText(); diff --git a/Telegram/SourceFiles/stickers/emoji_pan.h b/Telegram/SourceFiles/stickers/emoji_pan.h index afa4e6374..6fed74829 100644 --- a/Telegram/SourceFiles/stickers/emoji_pan.h +++ b/Telegram/SourceFiles/stickers/emoji_pan.h @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/twidget.h" #include "ui/effects/rect_shadow.h" +#include "ui/abstract_button.h" namespace InlineBots { namespace Layout { @@ -32,6 +33,8 @@ class Result; namespace Ui { class IconButton; +class LinkButton; +class RoundButton; } // namesapce Ui namespace internal { @@ -372,7 +375,7 @@ private: QTimer _updateInlineItems; bool _inlineWithThumb = false; - std_::unique_ptr _switchPmButton; + std_::unique_ptr _switchPmButton; QString _switchPmStartToken; typedef QVector InlineItems; @@ -417,7 +420,7 @@ private: QString _addText; int _addWidth; - LinkButton _settings; + ChildWidget _settings; QTimer _previewTimer; bool _previewShown = false; @@ -463,7 +466,7 @@ private: }; -class EmojiSwitchButton : public Button { +class EmojiSwitchButton : public Ui::AbstractButton { public: EmojiSwitchButton(QWidget *parent, bool toStickers); // otherwise toEmoji diff --git a/Telegram/SourceFiles/ui/button.cpp b/Telegram/SourceFiles/ui/abstract_button.cpp similarity index 64% rename from Telegram/SourceFiles/ui/button.cpp rename to Telegram/SourceFiles/ui/abstract_button.cpp index ff58f77d2..0ce112850 100644 --- a/Telegram/SourceFiles/ui/button.cpp +++ b/Telegram/SourceFiles/ui/abstract_button.cpp @@ -19,30 +19,29 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #include "stdafx.h" -#include "button.h" +#include "ui/abstract_button.h" -Button::Button(QWidget *parent) : TWidget(parent), _state(StateNone), _acceptBoth(false) { -} +namespace Ui { -void Button::leaveEvent(QEvent *e) { +void AbstractButton::leaveEvent(QEvent *e) { if (_state & StateDown) return; - setOver(false, ButtonByHover); + setOver(false, StateChangeSource::ByHover); setMouseTracking(false); return TWidget::leaveEvent(e); } -void Button::enterEvent(QEvent *e) { - setOver(true, ButtonByHover); +void AbstractButton::enterEvent(QEvent *e) { + setOver(true, StateChangeSource::ByHover); setMouseTracking(true); return TWidget::enterEvent(e); } -void Button::setAcceptBoth(bool acceptBoth) { +void AbstractButton::setAcceptBoth(bool acceptBoth) { _acceptBoth = acceptBoth; } -void Button::mousePressEvent(QMouseEvent *e) { +void AbstractButton::mousePressEvent(QMouseEvent *e) { if (_acceptBoth || e->buttons() & Qt::LeftButton) { if (!(_state & StateOver)) { enterEvent(0); @@ -50,28 +49,26 @@ void Button::mousePressEvent(QMouseEvent *e) { if (!(_state & StateDown)) { int oldState = _state; _state |= StateDown; - emit stateChanged(oldState, ButtonByPress); - onStateChanged(oldState, ButtonByPress); + onStateChanged(oldState, StateChangeSource::ByPress); e->accept(); } } } -void Button::mouseMoveEvent(QMouseEvent *e) { +void AbstractButton::mouseMoveEvent(QMouseEvent *e) { if (rect().contains(e->pos())) { - setOver(true, ButtonByHover); + setOver(true, StateChangeSource::ByHover); } else { - setOver(false, ButtonByHover); + setOver(false, StateChangeSource::ByHover); } } -void Button::mouseReleaseEvent(QMouseEvent *e) { +void AbstractButton::mouseReleaseEvent(QMouseEvent *e) { if (_state & StateDown) { int oldState = _state; _state &= ~StateDown; - emit stateChanged(oldState, ButtonByPress); - onStateChanged(oldState, ButtonByPress); + onStateChanged(oldState, StateChangeSource::ByPress); if (oldState & StateOver) { _modifiers = e->modifiers(); if (_clickedCallback) { @@ -84,40 +81,37 @@ void Button::mouseReleaseEvent(QMouseEvent *e) { } } -void Button::setOver(bool over, ButtonStateChangeSource source) { +void AbstractButton::setOver(bool over, StateChangeSource source) { if (over && !(_state & StateOver)) { int oldState = _state; _state |= StateOver; - emit stateChanged(oldState, source); onStateChanged(oldState, source); } else if (!over && (_state & StateOver)) { int oldState = _state; _state &= ~StateOver; - emit stateChanged(oldState, source); onStateChanged(oldState, source); } } -void Button::setDisabled(bool disabled) { +void AbstractButton::setDisabled(bool disabled) { int oldState = _state; if (disabled && !(_state & StateDisabled)) { _state |= StateDisabled; - emit stateChanged(oldState, ButtonByUser); - onStateChanged(oldState, ButtonByUser); + onStateChanged(oldState, StateChangeSource::ByUser); } else if (!disabled && (_state & StateDisabled)) { _state &= ~StateDisabled; - emit stateChanged(oldState, ButtonByUser); - onStateChanged(oldState, ButtonByUser); + onStateChanged(oldState, StateChangeSource::ByUser); } } -void Button::clearState() { +void AbstractButton::clearState() { int oldState = _state; _state = StateNone; - emit stateChanged(oldState, ButtonByUser); - onStateChanged(oldState, ButtonByUser); + onStateChanged(oldState, StateChangeSource::ByUser); } -int Button::getState() const { +int AbstractButton::getState() const { return _state; } + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/button.h b/Telegram/SourceFiles/ui/abstract_button.h similarity index 76% rename from Telegram/SourceFiles/ui/button.h rename to Telegram/SourceFiles/ui/abstract_button.h index 298bc7e8c..2d68d1d95 100644 --- a/Telegram/SourceFiles/ui/button.h +++ b/Telegram/SourceFiles/ui/abstract_button.h @@ -20,26 +20,28 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include #include "ui/twidget.h" #include "core/lambda_wrap.h" -typedef enum { - ButtonByUser = 0x00, // by clearState() call - ButtonByPress = 0x01, - ButtonByHover = 0x02, -} ButtonStateChangeSource; +namespace Ui { -class Button : public TWidget { +class AbstractButton : public TWidget { Q_OBJECT public: - Button(QWidget *parent); + enum class StateChangeSource { + ByUser = 0x00, + ByPress = 0x01, + ByHover = 0x02, + }; + + AbstractButton(QWidget *parent) : TWidget(parent) { + } enum { - StateNone = 0x00, - StateOver = 0x01, - StateDown = 0x02, + StateNone = 0x00, + StateOver = 0x01, + StateDown = 0x02, StateDisabled = 0x04, }; @@ -51,7 +53,7 @@ public: int getState() const; void setDisabled(bool disabled = true); - void setOver(bool over, ButtonStateChangeSource source = ButtonByUser); + void setOver(bool over, StateChangeSource source = StateChangeSource::ByUser); bool disabled() const { return (_state & StateDisabled); } @@ -71,16 +73,17 @@ protected: signals: void clicked(); - void stateChanged(int oldState, ButtonStateChangeSource source); protected: - virtual void onStateChanged(int oldState, ButtonStateChangeSource source) { + virtual void onStateChanged(int oldState, StateChangeSource source) { } Qt::KeyboardModifiers _modifiers; - int _state; - bool _acceptBoth; + int _state = StateNone; + bool _acceptBoth = false; base::lambda_unique _clickedCallback; }; + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/history_down_button.cpp b/Telegram/SourceFiles/ui/buttons/history_down_button.cpp index 9eab4635d..b55e65c22 100644 --- a/Telegram/SourceFiles/ui/buttons/history_down_button.cpp +++ b/Telegram/SourceFiles/ui/buttons/history_down_button.cpp @@ -26,7 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { -HistoryDownButton::HistoryDownButton(QWidget *parent) : Button(parent) +HistoryDownButton::HistoryDownButton(QWidget *parent) : AbstractButton(parent) //, a_arrowOpacity(st::historyAttachEmoji.opacity, st::historyAttachEmoji.opacity) , _a_arrowOver(animation(this, &HistoryDownButton::step_arrowOver)) { setCursor(style::cur_pointer); @@ -78,10 +78,10 @@ void HistoryDownButton::paintEvent(QPaintEvent *e) { } } -void HistoryDownButton::onStateChanged(int oldState, ButtonStateChangeSource source) { +void HistoryDownButton::onStateChanged(int oldState, StateChangeSource source) { //a_arrowOpacity.start((_state & (StateOver | StateDown)) ? st::historyAttachEmoji.overOpacity : st::historyAttachEmoji.opacity); - if (source == ButtonByUser || source == ButtonByPress) { + if (source == StateChangeSource::ByUser || source == StateChangeSource::ByPress) { _a_arrowOver.stop(); a_arrowOpacity.finish(); update(); @@ -133,7 +133,7 @@ void HistoryDownButton::step_arrowOver(float64 ms, bool timer) { if (timer) update(); } -EmojiButton::EmojiButton(QWidget *parent, const style::IconButton &st) : Button(parent) +EmojiButton::EmojiButton(QWidget *parent, const style::IconButton &st) : AbstractButton(parent) , _st(st) , _a_loading(animation(this, &EmojiButton::step_loading)) { resize(_st.width, _st.height); @@ -183,7 +183,7 @@ void EmojiButton::setLoading(bool loading) { } } -void EmojiButton::onStateChanged(int oldState, ButtonStateChangeSource source) { +void EmojiButton::onStateChanged(int oldState, StateChangeSource source) { auto over = (_state & StateOver); if (over != (oldState & StateOver)) { update(); diff --git a/Telegram/SourceFiles/ui/buttons/history_down_button.h b/Telegram/SourceFiles/ui/buttons/history_down_button.h index 70dc27247..87d228302 100644 --- a/Telegram/SourceFiles/ui/buttons/history_down_button.h +++ b/Telegram/SourceFiles/ui/buttons/history_down_button.h @@ -20,12 +20,12 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/button.h" +#include "ui/abstract_button.h" #include "styles/style_widgets.h" namespace Ui { -class HistoryDownButton : public Button { +class HistoryDownButton : public AbstractButton { public: HistoryDownButton(QWidget *parent); @@ -44,7 +44,7 @@ public: protected: void paintEvent(QPaintEvent *e) override; - void onStateChanged(int oldState, ButtonStateChangeSource source) override; + void onStateChanged(int oldState, StateChangeSource source) override; private: void toggleAnimated(); @@ -62,7 +62,7 @@ private: }; -class EmojiButton : public Button { +class EmojiButton : public AbstractButton { public: EmojiButton(QWidget *parent, const style::IconButton &st); @@ -70,7 +70,7 @@ public: protected: void paintEvent(QPaintEvent *e) override; - void onStateChanged(int oldState, ButtonStateChangeSource source) override; + void onStateChanged(int oldState, StateChangeSource source) override; private: const style::IconButton &_st; diff --git a/Telegram/SourceFiles/ui/buttons/icon_button.cpp b/Telegram/SourceFiles/ui/buttons/icon_button.cpp deleted file mode 100644 index f1003d0a1..000000000 --- a/Telegram/SourceFiles/ui/buttons/icon_button.cpp +++ /dev/null @@ -1,124 +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-2016 John Preston, https://desktop.telegram.org -*/ -#include "stdafx.h" -#include "ui/buttons/icon_button.h" - -namespace Ui { - -IconButton::IconButton(QWidget *parent, const style::IconButton &st) : Button(parent) -, _st(st) { - resize(_st.width, _st.height); - setCursor(style::cur_pointer); -} - -void IconButton::setIcon(const style::icon *icon, const style::icon *iconOver) { - _iconOverride = icon; - _iconOverrideOver = iconOver; - update(); -} - -void IconButton::paintEvent(QPaintEvent *e) { - Painter p(this); - - auto over = _a_over.current(getms(), (_state & StateOver) ? 1. : 0.); - auto overIcon = [this] { - if (_iconOverrideOver) { - return _iconOverrideOver; - } else if (!_st.iconOver.empty()) { - return &_st.iconOver; - } else if (_iconOverride) { - return _iconOverride; - } - return &_st.icon; - }; - auto justIcon = [this] { - if (_iconOverride) { - return _iconOverride; - } - return &_st.icon; - }; - auto icon = (over == 1.) ? overIcon() : justIcon(); - auto position = (_state & StateDown) ? _st.iconPositionDown : _st.iconPosition; - if (position.x() < 0) { - position.setX((width() - icon->width()) / 2); - } - if (position.y() < 0) { - position.setY((height() - icon->height()) / 2); - } - icon->paint(p, position, width()); - if (over > 0. && over < 1.) { - auto iconOver = overIcon(); - if (iconOver != icon) { - p.setOpacity(over); - iconOver->paint(p, position, width()); - } - } -} - -void IconButton::onStateChanged(int oldState, ButtonStateChangeSource source) { - auto over = (_state & StateOver); - if (over != (oldState & StateOver)) { - if (_st.duration) { - auto from = over ? 0. : 1.; - auto to = over ? 1. : 0.; - _a_over.start([this] { update(); }, from, to, _st.duration); - } else { - update(); - } - } -} - -MaskButton::MaskButton(QWidget *parent, const style::MaskButton &st) : Button(parent) -, _st(st) { - resize(_st.width, _st.height); - setCursor(style::cur_pointer); - setAttribute(Qt::WA_OpaquePaintEvent); -} - -void MaskButton::onStateChanged(int oldState, ButtonStateChangeSource source) { - auto over = (_state & StateOver); - if (over != (oldState & StateOver)) { - _a_iconOver.start([this] { update(); }, over ? 0. : 1., over ? 1. : 0., _st.duration); - } -} - -void MaskButton::paintEvent(QPaintEvent *e) { - Painter p(this); - - auto clip = e->rect(); - auto position = (_state & StateDown) ? _st.iconPositionDown : _st.iconPosition; - if (position.x() < 0) { - position.setX((width() - _st.icon.width()) / 2); - } - if (position.y() < 0) { - position.setY((height() - _st.icon.height()) / 2); - } - auto icon = myrtlrect(position.x(), position.y(), _st.icon.width(), _st.icon.height()); - if (!icon.contains(clip)) { - p.fillRect(clip, _st.bg); - } - if (icon.intersects(clip)) { - p.fillRect(icon.intersected(clip), anim::brush(_st.iconBg, _st.iconBgOver, _a_iconOver.current(getms(), (_state & StateOver) ? 1. : 0.))); - _st.icon.paint(p, position, width()); - } -} - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/icon_button.h b/Telegram/SourceFiles/ui/buttons/icon_button.h deleted file mode 100644 index 7decf5144..000000000 --- a/Telegram/SourceFiles/ui/buttons/icon_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-2016 John Preston, https://desktop.telegram.org -*/ -#pragma once - -#include "ui/button.h" -#include "styles/style_widgets.h" - -namespace Ui { - -class IconButton : public Button { -public: - IconButton(QWidget *parent, const style::IconButton &st); - - // Pass nullptr to restore the default icon. - void setIcon(const style::icon *icon, const style::icon *iconOver = nullptr); - -protected: - void paintEvent(QPaintEvent *e) override; - - void onStateChanged(int oldState, ButtonStateChangeSource source) override; - -private: - const style::IconButton &_st; - const style::icon *_iconOverride = nullptr; - const style::icon *_iconOverrideOver = nullptr; - - FloatAnimation _a_over; - -}; - -class MaskButton : public Button { -public: - MaskButton(QWidget *parent, const style::MaskButton &st); - -protected: - void paintEvent(QPaintEvent *e) override; - - void onStateChanged(int oldState, ButtonStateChangeSource source) override; - -private: - const style::MaskButton &_st; - - FloatAnimation _a_iconOver; - -}; - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/left_outline_button.cpp b/Telegram/SourceFiles/ui/buttons/left_outline_button.cpp index 04d94a4b2..ba8de2ffc 100644 --- a/Telegram/SourceFiles/ui/buttons/left_outline_button.cpp +++ b/Telegram/SourceFiles/ui/buttons/left_outline_button.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { -LeftOutlineButton::LeftOutlineButton(QWidget *parent, const QString &text, const style::OutlineButton &st) : Button(parent) +LeftOutlineButton::LeftOutlineButton(QWidget *parent, const QString &text, const style::OutlineButton &st) : AbstractButton(parent) , _text(text) , _fullText(text) , _textWidth(st.font->width(_text)) @@ -54,7 +54,7 @@ int LeftOutlineButton::resizeGetHeight(int newWidth) { void LeftOutlineButton::paintEvent(QPaintEvent *e) { Painter p(this); - bool over = (_state & Button::StateOver); + bool over = (_state & StateOver); if (width() > _st.outlineWidth) { p.fillRect(rtlrect(0, 0, _st.outlineWidth, height(), width()), over ? _st.outlineFgOver : _st.outlineFg); p.fillRect(rtlrect(_st.outlineWidth, 0, width() - _st.outlineWidth, height(), width()), over ? _st.textBgOver : _st.textBg); @@ -64,7 +64,7 @@ void LeftOutlineButton::paintEvent(QPaintEvent *e) { p.drawTextLeft(_st.padding.left(), _st.padding.top(), width(), _text, _textWidth); } -void LeftOutlineButton::onStateChanged(int oldState, ButtonStateChangeSource source) { +void LeftOutlineButton::onStateChanged(int oldState, StateChangeSource source) { update(); } diff --git a/Telegram/SourceFiles/ui/buttons/left_outline_button.h b/Telegram/SourceFiles/ui/buttons/left_outline_button.h index 011b4c2ad..590535d32 100644 --- a/Telegram/SourceFiles/ui/buttons/left_outline_button.h +++ b/Telegram/SourceFiles/ui/buttons/left_outline_button.h @@ -20,11 +20,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/button.h" +#include "ui/abstract_button.h" namespace Ui { -class LeftOutlineButton : public Button { +class LeftOutlineButton : public AbstractButton { public: LeftOutlineButton(QWidget *parent, const QString &text, const style::OutlineButton &st = st::defaultLeftOutlineButton); @@ -33,7 +33,7 @@ public: protected: void paintEvent(QPaintEvent *e) override; - void onStateChanged(int oldState, ButtonStateChangeSource source) override; + void onStateChanged(int oldState, StateChangeSource source) override; int resizeGetHeight(int newWidth) override; diff --git a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp b/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp index 23acb4609..b37bf850a 100644 --- a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp +++ b/Telegram/SourceFiles/ui/buttons/peer_avatar_button.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { -PeerAvatarButton::PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st) : Button(parent) +PeerAvatarButton::PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st) : AbstractButton(parent) , _peer(peer) , _st(st) { resize(_st.size, _st.size); diff --git a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h b/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h index eca0f3122..7a31ba9db 100644 --- a/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h +++ b/Telegram/SourceFiles/ui/buttons/peer_avatar_button.h @@ -20,13 +20,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/button.h" +#include "ui/abstract_button.h" class PeerData; namespace Ui { -class PeerAvatarButton : public Button { +class PeerAvatarButton : public AbstractButton { public: PeerAvatarButton(QWidget *parent, PeerData *peer, const style::PeerAvatarButton &st); diff --git a/Telegram/SourceFiles/ui/buttons/round_button.cpp b/Telegram/SourceFiles/ui/buttons/round_button.cpp deleted file mode 100644 index fad19eccc..000000000 --- a/Telegram/SourceFiles/ui/buttons/round_button.cpp +++ /dev/null @@ -1,131 +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-2016 John Preston, https://desktop.telegram.org -*/ -#include "stdafx.h" -#include "ui/buttons/round_button.h" - -namespace Ui { - -RoundButton::RoundButton(QWidget *parent, const QString &text, const style::RoundButton &st) : Button(parent) -, _text(text) -, _fullText(text) -, _textWidth(st.font->width(_text)) -, _st(st) { - resizeToText(); - - setCursor(style::cur_pointer); -} - -void RoundButton::setTextTransform(TextTransform transform) { - _transform = transform; - updateText(); -} - -void RoundButton::setText(const QString &text) { - _fullText = text; - updateText(); -} - -void RoundButton::setSecondaryText(const QString &secondaryText) { - _fullSecondaryText = secondaryText; - updateText(); -} - -void RoundButton::setFullWidth(int newFullWidth) { - _fullWidthOverride = newFullWidth; - resizeToText(); -} - -void RoundButton::updateText() { - if (_transform == TextTransform::ToUpper) { - _text = _fullText.toUpper(); - _secondaryText = _fullSecondaryText.toUpper(); - } else { - _text = _fullText; - _secondaryText = _fullSecondaryText; - } - _textWidth = _text.isEmpty() ? 0 : _st.font->width(_text); - _secondaryTextWidth = _secondaryText.isEmpty() ? 0 : _st.font->width(_secondaryText); - - resizeToText(); -} - -void RoundButton::resizeToText() { - int innerWidth = contentWidth(); - if (_fullWidthOverride < 0) { - resize(innerWidth - _fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom()); - } else if (_st.width <= 0) { - resize(innerWidth - _st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); - } else { - if (_st.width < innerWidth + (_st.height - _st.font->height)) { - _text = _st.font->elided(_fullText, qMax(_st.width - (_st.height - _st.font->height), 1)); - innerWidth = _st.font->width(_text); - } - resize(_st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); - } -} - -int RoundButton::contentWidth() const { - int result = _textWidth + _secondaryTextWidth; - if (_textWidth > 0 && _secondaryTextWidth > 0) { - result += _st.secondarySkip; - } - return result; -} - -void RoundButton::paintEvent(QPaintEvent *e) { - Painter p(this); - - int innerWidth = contentWidth(); - auto rounded = rtlrect(rect().marginsRemoved(_st.padding), width()); - if (_fullWidthOverride < 0) { - rounded = QRect(0, rounded.top(), innerWidth - _fullWidthOverride, rounded.height()); - } - App::roundRect(p, rounded, _st.textBg, ImageRoundRadius::Small); - - auto over = (_state & StateOver); - if (over) { - App::roundRect(p, rounded, _st.textBgOver, ImageRoundRadius::Small); - } - - p.setFont(_st.font); - int textLeft = _st.padding.left() + ((width() - innerWidth - _st.padding.left() - _st.padding.right()) / 2); - if (_fullWidthOverride < 0) { - textLeft = -_fullWidthOverride / 2; - } - int textTopDelta = (_state & StateDown) ? (_st.downTextTop - _st.textTop) : 0; - int textTop = _st.padding.top() + _st.textTop + textTopDelta; - if (!_text.isEmpty()) { - p.setPen(over ? _st.textFgOver : _st.textFg); - p.drawTextLeft(textLeft, textTop, width(), _text); - } - if (!_secondaryText.isEmpty()) { - textLeft += _textWidth + (_textWidth ? _st.secondarySkip : 0); - p.setPen(over ? _st.secondaryTextFgOver : _st.secondaryTextFg); - p.drawTextLeft(textLeft, textTop, width(), _secondaryText); - } - _st.icon.paint(p, QPoint(_st.padding.left(), _st.padding.right() + textTopDelta), width()); -} - -void RoundButton::onStateChanged(int oldState, ButtonStateChangeSource source) { - update(); -} - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/round_button.h b/Telegram/SourceFiles/ui/buttons/round_button.h deleted file mode 100644 index 406ce1346..000000000 --- a/Telegram/SourceFiles/ui/buttons/round_button.h +++ /dev/null @@ -1,67 +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-2016 John Preston, https://desktop.telegram.org -*/ -#pragma once - -#include "ui/button.h" - -namespace Ui { - -class RoundButton : public Button { -public: - RoundButton(QWidget *parent, const QString &text, const style::RoundButton &st); - - void setText(const QString &text); - void setSecondaryText(const QString &secondaryText); - - int contentWidth() const; - - void setFullWidth(int newFullWidth); - - enum class TextTransform { - NoTransform, - ToUpper, - }; - void setTextTransform(TextTransform transform); - -protected: - void paintEvent(QPaintEvent *e) override; - - void onStateChanged(int oldState, ButtonStateChangeSource source) override; - -private: - void updateText(); - void resizeToText(); - - QString _text, _fullText; - int _textWidth; - - QString _secondaryText, _fullSecondaryText; - int _secondaryTextWidth = 0; - - int _fullWidthOverride = 0; - - const style::RoundButton &_st; - - TextTransform _transform = TextTransform::NoTransform; - -}; - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/countryinput.h b/Telegram/SourceFiles/ui/countryinput.h index be20f24ea..d3416c068 100644 --- a/Telegram/SourceFiles/ui/countryinput.h +++ b/Telegram/SourceFiles/ui/countryinput.h @@ -22,7 +22,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/flatinput.h" #include "ui/scrollarea.h" -#include "ui/flatbutton.h" #include "ui/effects/rect_shadow.h" #include "boxes/abstractbox.h" #include "styles/style_intro.h" diff --git a/Telegram/SourceFiles/ui/flatbutton.cpp b/Telegram/SourceFiles/ui/flatbutton.cpp deleted file mode 100644 index 5d44c1b74..000000000 --- a/Telegram/SourceFiles/ui/flatbutton.cpp +++ /dev/null @@ -1,203 +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-2016 John Preston, https://desktop.telegram.org -*/ -#include "stdafx.h" -#include "ui/flatbutton.h" - -#include "styles/style_history.h" - -FlatButton::FlatButton(QWidget *parent, const QString &text, const style::flatButton &st) : Button(parent) -, _text(text) -, _st(st) -, a_over(0) -, _a_appearance(animation(this, &FlatButton::step_appearance)) { - if (_st.width < 0) { - _width = textWidth() - _st.width; - } else if (!_st.width) { - _width = textWidth() + _st.height - _st.font->height; - } else { - _width = _st.width; - } - connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource))); - resize(_width, _st.height); - setCursor(_st.cursor); -} - -void FlatButton::setOpacity(float64 o) { - _opacity = o; - update(); -} - -float64 FlatButton::opacity() const { - return _opacity; -} - -void FlatButton::setText(const QString &text) { - _text = text; - update(); -} - -void FlatButton::setWidth(int32 w) { - _width = w; - if (_width < 0) { - _width = textWidth() - _st.width; - } else if (!_width) { - _width = textWidth() + _st.height - _st.font->height; - } - resize(_width, height()); -} - -int32 FlatButton::textWidth() const { - return _st.font->width(_text); -} - -void FlatButton::step_appearance(float64 ms, bool timer) { - float64 dt = ms / _st.duration; - if (dt >= 1) { - _a_appearance.stop(); - a_over.finish(); - } else { - a_over.update(dt, anim::linear); - } - if (timer) update(); -} - -void FlatButton::onStateChange(int oldState, ButtonStateChangeSource source) { - a_over.start((_state & StateOver) ? 1. : 0.); - if (source == ButtonByUser || source == ButtonByPress) { - _a_appearance.stop(); - a_over.finish(); - update(); - } else { - _a_appearance.start(); - } -} - -void FlatButton::paintEvent(QPaintEvent *e) { - QPainter p(this); - - QRect r(0, height() - _st.height, width(), _st.height); - - p.setOpacity(_opacity); - p.fillRect(r, anim::brush(_st.bgColor, _st.overBgColor, a_over.current())); - - p.setFont((_state & StateOver) ? _st.overFont : _st.font); - p.setRenderHint(QPainter::TextAntialiasing); - p.setPen(anim::pen(_st.color, _st.overColor, a_over.current())); - - int32 top = (_state & StateOver) ? ((_state & StateDown) ? _st.downTextTop : _st.overTextTop) : _st.textTop; - r.setTop(top); - - p.drawText(r, _text, style::al_top); -} - -LinkButton::LinkButton(QWidget *parent, const QString &text, const style::linkButton &st) : Button(parent) -, _text(text) -, _textWidth(st.font->width(_text)) -, _st(st) { - connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource))); - resize(_textWidth, _st.font->height); - setCursor(style::cur_pointer); -} - -int LinkButton::naturalWidth() const { - return _textWidth; -} - -void LinkButton::paintEvent(QPaintEvent *e) { - Painter p(this); - auto &font = ((_state & StateOver) ? _st.overFont : _st.font); - auto &pen = ((_state & StateDown) ? _st.downColor : ((_state & StateOver) ? _st.overColor : _st.color)); - p.setFont(font); - p.setPen(pen); - if (_textWidth > width()) { - p.drawText(0, font->ascent, font->elided(_text, width())); - } else { - p.drawText(0, font->ascent, _text); - } -} - -void LinkButton::setText(const QString &text) { - _text = text; - _textWidth = _st.font->width(_text); - resize(_textWidth, _st.font->height); - update(); -} - -void LinkButton::onStateChange(int oldState, ButtonStateChangeSource source) { - update(); -} - -LinkButton::~LinkButton() { -} - -BoxButton::BoxButton(QWidget *parent, const QString &text, const style::RoundButton &st) : Button(parent) -, _text(text.toUpper()) -, _fullText(text.toUpper()) -, _textWidth(st.font->width(_text)) -, _st(st) { - resizeToText(); - - connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource))); - - setCursor(style::cur_pointer); - - setAttribute(Qt::WA_OpaquePaintEvent); -} - -void BoxButton::setText(const QString &text) { - _text = text; - _fullText = text; - _textWidth = _st.font->width(_text); - resizeToText(); - update(); -} - -void BoxButton::resizeToText() { - if (_st.width <= 0) { - resize(_textWidth - _st.width, _st.height); - } else { - if (_st.width < _textWidth + (_st.height - _st.font->height)) { - _text = _st.font->elided(_fullText, qMax(_st.width - (_st.height - _st.font->height), 1)); - _textWidth = _st.font->width(_text); - } - resize(_st.width, _st.height); - } -} - -void BoxButton::paintEvent(QPaintEvent *e) { - Painter p(this); - - auto over = (_state & StateOver); - p.fillRect(rect(), _st.textBg); - - if (over) { - App::roundRect(p, rect(), _st.textBgOver, ImageRoundRadius::Small); - } - p.setPen(over ? _st.textFgOver : _st.textFg); - p.setFont(_st.font); - - auto textTop = (_state & StateDown) ? _st.downTextTop : _st.textTop; - p.drawText((width() - _textWidth) / 2, textTop + _st.font->ascent, _text); -} - -void BoxButton::onStateChange(int oldState, ButtonStateChangeSource source) { - update(); -} diff --git a/Telegram/SourceFiles/ui/flatbutton.h b/Telegram/SourceFiles/ui/flatbutton.h deleted file mode 100644 index bb11410cc..000000000 --- a/Telegram/SourceFiles/ui/flatbutton.h +++ /dev/null @@ -1,108 +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-2016 John Preston, https://desktop.telegram.org -*/ -#pragma once - -#include "ui/button.h" -#include "ui/animation.h" - -class FlatButton : public Button { - Q_OBJECT - -public: - FlatButton(QWidget *parent, const QString &text, const style::flatButton &st); - - void step_appearance(float64 ms, bool timer); - void paintEvent(QPaintEvent *e); - void setOpacity(float64 o); - float64 opacity() const; - - void setText(const QString &text); - void setWidth(int32 w); - - int32 textWidth() const; - - ~FlatButton() { - } - -public slots: - void onStateChange(int oldState, ButtonStateChangeSource source); - -private: - QString _text, _textForAutoSize; - int _width, _textWidth; - - const style::flatButton &_st; - - anim::fvalue a_over; - Animation _a_appearance; - - float64 _opacity = 1.; - -}; - -class LinkButton : public Button { - Q_OBJECT - -public: - LinkButton(QWidget *parent, const QString &text, const style::linkButton &st = st::btnDefLink); - - int naturalWidth() const override; - - void setText(const QString &text); - - ~LinkButton(); - -protected: - void paintEvent(QPaintEvent *e) override; - -public slots: - void onStateChange(int oldState, ButtonStateChangeSource source); - -private: - QString _text; - int _textWidth = 0; - const style::linkButton &_st; - -}; - -class BoxButton : public Button { - Q_OBJECT - -public: - BoxButton(QWidget *parent, const QString &text, const style::RoundButton &st); - - void setText(const QString &text); - void paintEvent(QPaintEvent *e) override; - - void step_over(float64 ms, bool timer); - -public slots: - void onStateChange(int oldState, ButtonStateChangeSource source); - -private: - void resizeToText(); - - QString _text, _fullText; - int32 _textWidth; - - const style::RoundButton &_st; - -}; diff --git a/Telegram/SourceFiles/ui/widgets/buttons.cpp b/Telegram/SourceFiles/ui/widgets/buttons.cpp new file mode 100644 index 000000000..c36909300 --- /dev/null +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -0,0 +1,311 @@ +/* +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/widgets/buttons.h" + +namespace Ui { + +FlatButton::FlatButton(QWidget *parent, const QString &text, const style::FlatButton &st) : AbstractButton(parent) +, _text(text) +, _st(st) +, a_over(0) +, _a_appearance(animation(this, &FlatButton::step_appearance)) { + if (_st.width < 0) { + _width = textWidth() - _st.width; + } else if (!_st.width) { + _width = textWidth() + _st.height - _st.font->height; + } else { + _width = _st.width; + } + resize(_width, _st.height); + setCursor(_st.cursor); +} + +void FlatButton::setOpacity(float64 o) { + _opacity = o; + update(); +} + +float64 FlatButton::opacity() const { + return _opacity; +} + +void FlatButton::setText(const QString &text) { + _text = text; + update(); +} + +void FlatButton::setWidth(int32 w) { + _width = w; + if (_width < 0) { + _width = textWidth() - _st.width; + } else if (!_width) { + _width = textWidth() + _st.height - _st.font->height; + } + resize(_width, height()); +} + +int32 FlatButton::textWidth() const { + return _st.font->width(_text); +} + +void FlatButton::step_appearance(float64 ms, bool timer) { + float64 dt = ms / _st.duration; + if (dt >= 1) { + _a_appearance.stop(); + a_over.finish(); + } else { + a_over.update(dt, anim::linear); + } + if (timer) update(); +} + +void FlatButton::onStateChanged(int oldState, StateChangeSource source) { + a_over.start((_state & StateOver) ? 1. : 0.); + if (source == StateChangeSource::ByUser || source == StateChangeSource::ByPress) { + _a_appearance.stop(); + a_over.finish(); + update(); + } else { + _a_appearance.start(); + } +} + +void FlatButton::paintEvent(QPaintEvent *e) { + QPainter p(this); + + QRect r(0, height() - _st.height, width(), _st.height); + + p.setOpacity(_opacity); + p.fillRect(r, anim::brush(_st.bgColor, _st.overBgColor, a_over.current())); + + p.setFont((_state & StateOver) ? _st.overFont : _st.font); + p.setRenderHint(QPainter::TextAntialiasing); + p.setPen(anim::pen(_st.color, _st.overColor, a_over.current())); + + int32 top = (_state & StateOver) ? ((_state & StateDown) ? _st.downTextTop : _st.overTextTop) : _st.textTop; + r.setTop(top); + + p.drawText(r, _text, style::al_top); +} + +LinkButton::LinkButton(QWidget *parent, const QString &text, const style::LinkButton &st) : AbstractButton(parent) +, _text(text) +, _textWidth(st.font->width(_text)) +, _st(st) { + resize(_textWidth, _st.font->height); + setCursor(style::cur_pointer); +} + +int LinkButton::naturalWidth() const { + return _textWidth; +} + +void LinkButton::paintEvent(QPaintEvent *e) { + Painter p(this); + auto &font = ((_state & StateOver) ? _st.overFont : _st.font); + auto &pen = ((_state & StateDown) ? _st.downColor : ((_state & StateOver) ? _st.overColor : _st.color)); + p.setFont(font); + p.setPen(pen); + if (_textWidth > width()) { + p.drawText(0, font->ascent, font->elided(_text, width())); + } else { + p.drawText(0, font->ascent, _text); + } +} + +void LinkButton::setText(const QString &text) { + _text = text; + _textWidth = _st.font->width(_text); + resize(_textWidth, _st.font->height); + update(); +} + +void LinkButton::onStateChanged(int oldState, StateChangeSource source) { + update(); +} + +RoundButton::RoundButton(QWidget *parent, const QString &text, const style::RoundButton &st) : AbstractButton(parent) +, _fullText(text) +, _st(st) { + setCursor(style::cur_pointer); + updateText(); +} + +void RoundButton::setTextTransform(TextTransform transform) { + _transform = transform; + updateText(); +} + +void RoundButton::setText(const QString &text) { + _fullText = text; + updateText(); +} + +void RoundButton::setSecondaryText(const QString &secondaryText) { + _fullSecondaryText = secondaryText; + updateText(); +} + +void RoundButton::setFullWidth(int newFullWidth) { + _fullWidthOverride = newFullWidth; + resizeToText(); +} + +void RoundButton::updateText() { + if (_transform == TextTransform::ToUpper) { + _text = _fullText.toUpper(); + _secondaryText = _fullSecondaryText.toUpper(); + } else { + _text = _fullText; + _secondaryText = _fullSecondaryText; + } + _textWidth = _text.isEmpty() ? 0 : _st.font->width(_text); + _secondaryTextWidth = _secondaryText.isEmpty() ? 0 : _st.font->width(_secondaryText); + + resizeToText(); +} + +void RoundButton::resizeToText() { + int innerWidth = contentWidth(); + if (_fullWidthOverride < 0) { + resize(innerWidth - _fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom()); + } else if (_st.width <= 0) { + resize(innerWidth - _st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); + } else { + if (_st.width < innerWidth + (_st.height - _st.font->height)) { + _text = _st.font->elided(_fullText, qMax(_st.width - (_st.height - _st.font->height), 1)); + innerWidth = _st.font->width(_text); + } + resize(_st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); + } +} + +int RoundButton::contentWidth() const { + int result = _textWidth + _secondaryTextWidth; + if (_textWidth > 0 && _secondaryTextWidth > 0) { + result += _st.secondarySkip; + } + return result; +} + +void RoundButton::paintEvent(QPaintEvent *e) { + Painter p(this); + + int innerWidth = contentWidth(); + auto rounded = rtlrect(rect().marginsRemoved(_st.padding), width()); + if (_fullWidthOverride < 0) { + rounded = QRect(0, rounded.top(), innerWidth - _fullWidthOverride, rounded.height()); + } + App::roundRect(p, rounded, _st.textBg, ImageRoundRadius::Small); + + auto over = (_state & StateOver); + if (over) { + App::roundRect(p, rounded, _st.textBgOver, ImageRoundRadius::Small); + } + + p.setFont(_st.font); + int textLeft = _st.padding.left() + ((width() - innerWidth - _st.padding.left() - _st.padding.right()) / 2); + if (_fullWidthOverride < 0) { + textLeft = -_fullWidthOverride / 2; + } + int textTopDelta = (_state & StateDown) ? (_st.downTextTop - _st.textTop) : 0; + int textTop = _st.padding.top() + _st.textTop + textTopDelta; + if (!_text.isEmpty()) { + p.setPen(over ? _st.textFgOver : _st.textFg); + p.drawTextLeft(textLeft, textTop, width(), _text); + } + if (!_secondaryText.isEmpty()) { + textLeft += _textWidth + (_textWidth ? _st.secondarySkip : 0); + p.setPen(over ? _st.secondaryTextFgOver : _st.secondaryTextFg); + p.drawTextLeft(textLeft, textTop, width(), _secondaryText); + } + _st.icon.paint(p, QPoint(_st.padding.left(), _st.padding.right() + textTopDelta), width()); +} + +void RoundButton::onStateChanged(int oldState, StateChangeSource source) { + update(); +} + +IconButton::IconButton(QWidget *parent, const style::IconButton &st) : AbstractButton(parent) +, _st(st) { + resize(_st.width, _st.height); + setCursor(style::cur_pointer); +} + +void IconButton::setIcon(const style::icon *icon, const style::icon *iconOver) { + _iconOverride = icon; + _iconOverrideOver = iconOver; + update(); +} + +void IconButton::paintEvent(QPaintEvent *e) { + Painter p(this); + + auto over = _a_over.current(getms(), (_state & StateOver) ? 1. : 0.); + auto overIcon = [this] { + if (_iconOverrideOver) { + return _iconOverrideOver; + } else if (!_st.iconOver.empty()) { + return &_st.iconOver; + } else if (_iconOverride) { + return _iconOverride; + } + return &_st.icon; + }; + auto justIcon = [this] { + if (_iconOverride) { + return _iconOverride; + } + return &_st.icon; + }; + auto icon = (over == 1.) ? overIcon() : justIcon(); + auto position = (_state & StateDown) ? _st.iconPositionDown : _st.iconPosition; + if (position.x() < 0) { + position.setX((width() - icon->width()) / 2); + } + if (position.y() < 0) { + position.setY((height() - icon->height()) / 2); + } + icon->paint(p, position, width()); + if (over > 0. && over < 1.) { + auto iconOver = overIcon(); + if (iconOver != icon) { + p.setOpacity(over); + iconOver->paint(p, position, width()); + } + } +} + +void IconButton::onStateChanged(int oldState, StateChangeSource source) { + auto over = (_state & StateOver); + if (over != (oldState & StateOver)) { + if (_st.duration) { + auto from = over ? 0. : 1.; + auto to = over ? 1. : 0.; + _a_over.start([this] { update(); }, from, to, _st.duration); + } else { + update(); + } + } +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/widgets/buttons.h b/Telegram/SourceFiles/ui/widgets/buttons.h new file mode 100644 index 000000000..cf6557d03 --- /dev/null +++ b/Telegram/SourceFiles/ui/widgets/buttons.h @@ -0,0 +1,139 @@ +/* +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 +*/ +#pragma once + +#include "ui/abstract_button.h" +#include "styles/style_widgets.h" + +namespace Ui { + +class FlatButton : public AbstractButton { +public: + FlatButton(QWidget *parent, const QString &text, const style::FlatButton &st); + + void step_appearance(float64 ms, bool timer); + void paintEvent(QPaintEvent *e); + void setOpacity(float64 o); + float64 opacity() const; + + void setText(const QString &text); + void setWidth(int32 w); + + int32 textWidth() const; + +protected: + void onStateChanged(int oldState, StateChangeSource source) override; + +private: + QString _text, _textForAutoSize; + int _width, _textWidth; + + const style::FlatButton &_st; + + anim::fvalue a_over; + Animation _a_appearance; + + float64 _opacity = 1.; + +}; + +class LinkButton : public AbstractButton { +public: + LinkButton(QWidget *parent, const QString &text, const style::LinkButton &st = st::defaultLinkButton); + + int naturalWidth() const override; + + void setText(const QString &text); + +protected: + void paintEvent(QPaintEvent *e) override; + + void onStateChanged(int oldState, StateChangeSource source) override; + +private: + QString _text; + int _textWidth = 0; + const style::LinkButton &_st; + +}; + +class RoundButton : public AbstractButton { +public: + RoundButton(QWidget *parent, const QString &text, const style::RoundButton &st); + + void setText(const QString &text); + void setSecondaryText(const QString &secondaryText); + + int contentWidth() const; + + void setFullWidth(int newFullWidth); + + enum class TextTransform { + NoTransform, + ToUpper, + }; + void setTextTransform(TextTransform transform); + +protected: + void paintEvent(QPaintEvent *e) override; + + void onStateChanged(int oldState, StateChangeSource source) override; + +private: + void updateText(); + void resizeToText(); + + QString _text, _fullText; + int _textWidth; + + QString _secondaryText, _fullSecondaryText; + int _secondaryTextWidth = 0; + + int _fullWidthOverride = 0; + + const style::RoundButton &_st; + + TextTransform _transform = TextTransform::ToUpper; + +}; + +class IconButton : public AbstractButton { +public: + IconButton(QWidget *parent, const style::IconButton &st); + + // Pass nullptr to restore the default icon. + void setIcon(const style::icon *icon, const style::icon *iconOver = nullptr); + +protected: + void paintEvent(QPaintEvent *e) override; + + void onStateChanged(int oldState, StateChangeSource source) override; + +private: + const style::IconButton &_st; + const style::icon *_iconOverride = nullptr; + const style::icon *_iconOverrideOver = nullptr; + + FloatAnimation _a_over; + +}; + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/buttons/checkbox.cpp b/Telegram/SourceFiles/ui/widgets/checkbox.cpp similarity index 95% rename from Telegram/SourceFiles/ui/buttons/checkbox.cpp rename to Telegram/SourceFiles/ui/widgets/checkbox.cpp index b5188f52d..94af0c601 100644 --- a/Telegram/SourceFiles/ui/buttons/checkbox.cpp +++ b/Telegram/SourceFiles/ui/widgets/checkbox.cpp @@ -19,7 +19,7 @@ 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/checkbox.h" +#include "ui/widgets/checkbox.h" #include "lang.h" @@ -87,7 +87,7 @@ void RadiobuttonGroup::remove(Radiobutton * const &radio) { } } -Checkbox::Checkbox(QWidget *parent, const QString &text, bool checked, const style::Checkbox &st) : Button(parent) +Checkbox::Checkbox(QWidget *parent, const QString &text, bool checked, const style::Checkbox &st) : AbstractButton(parent) , _st(st) , a_over(0) , a_checked(checked ? 1 : 0) @@ -109,7 +109,6 @@ Checkbox::Checkbox(QWidget *parent, const QString &text, bool checked, const sty _checkRect = myrtlrect(0, 0, _st.diameter, _st.diameter); connect(this, SIGNAL(clicked()), this, SLOT(onClicked())); - connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource))); setCursor(style::cur_pointer); @@ -222,7 +221,7 @@ void Checkbox::onClicked() { setChecked(!checked()); } -void Checkbox::onStateChange(int oldState, ButtonStateChangeSource source) { +void Checkbox::onStateChanged(int oldState, StateChangeSource source) { if ((_state & StateOver) && !(oldState & StateOver)) { a_over.start(1); _a_over.start(); @@ -237,7 +236,7 @@ void Checkbox::onStateChange(int oldState, ButtonStateChangeSource source) { } } -Radiobutton::Radiobutton(QWidget *parent, const QString &group, int32 value, const QString &text, bool checked, const style::Radiobutton &st) : Button(parent) +Radiobutton::Radiobutton(QWidget *parent, const QString &group, int32 value, const QString &text, bool checked, const style::Radiobutton &st) : AbstractButton(parent) , _st(st) , a_over(0) , a_checked(checked ? 1 : 0) @@ -261,7 +260,6 @@ Radiobutton::Radiobutton(QWidget *parent, const QString &group, int32 value, con _checkRect = myrtlrect(0, 0, _st.diameter, _st.diameter); connect(this, SIGNAL(clicked()), this, SLOT(onClicked())); - connect(this, SIGNAL(stateChanged(int, ButtonStateChangeSource)), this, SLOT(onStateChange(int, ButtonStateChangeSource))); setCursor(style::cur_pointer); @@ -381,7 +379,7 @@ void Radiobutton::onClicked() { setChecked(!checked()); } -void Radiobutton::onStateChange(int oldState, ButtonStateChangeSource source) { +void Radiobutton::onStateChanged(int oldState, StateChangeSource source) { if ((_state & StateOver) && !(oldState & StateOver)) { a_over.start(1); _a_over.start(); diff --git a/Telegram/SourceFiles/ui/buttons/checkbox.h b/Telegram/SourceFiles/ui/widgets/checkbox.h similarity index 87% rename from Telegram/SourceFiles/ui/buttons/checkbox.h rename to Telegram/SourceFiles/ui/widgets/checkbox.h index 8b7ccf367..ad5b8c7cc 100644 --- a/Telegram/SourceFiles/ui/buttons/checkbox.h +++ b/Telegram/SourceFiles/ui/widgets/checkbox.h @@ -20,11 +20,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/button.h" +#include "ui/abstract_button.h" namespace Ui { -class Checkbox : public Button { +class Checkbox : public AbstractButton { Q_OBJECT public: @@ -44,9 +44,10 @@ public: protected: void paintEvent(QPaintEvent *e) override; - public slots: + void onStateChanged(int oldState, StateChangeSource source) override; + +public slots: void onClicked(); - void onStateChange(int oldState, ButtonStateChangeSource source); signals: void changed(); @@ -67,7 +68,7 @@ private: }; -class Radiobutton : public Button { +class Radiobutton : public AbstractButton { Q_OBJECT public: @@ -83,13 +84,15 @@ public: void step_over(float64 ms, bool timer); void step_checked(float64 ms, bool timer); - void paintEvent(QPaintEvent *e); - ~Radiobutton(); - public slots: +protected: + void paintEvent(QPaintEvent *e) override; + + void onStateChanged(int oldState, StateChangeSource source) override; + +public slots: void onClicked(); - void onStateChange(int oldState, ButtonStateChangeSource source); signals: void changed(); diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index f803a8c60..dfcbb1b4e 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -22,7 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/widgets/multi_select.h" #include "styles/style_widgets.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "lang.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/widgets/widgets.style b/Telegram/SourceFiles/ui/widgets/widgets.style index 85ad525d0..f3ba2c336 100644 --- a/Telegram/SourceFiles/ui/widgets/widgets.style +++ b/Telegram/SourceFiles/ui/widgets/widgets.style @@ -27,6 +27,34 @@ LabelSimple { textFg: color; } +LinkButton { + color: color; + overColor: color; + downColor: color; + font: font; + overFont: font; +} + +FlatButton { + color: color; + overColor: color; + + bgColor: color; + overBgColor: color; + + width: pixels; + height: pixels; + + textTop: pixels; + overTextTop: pixels; + downTextTop: pixels; + + font: font; + overFont: font; + duration: int; + cursor: cursor; +} + IconButton { width: pixels; height: pixels; @@ -53,22 +81,6 @@ Shadow { fallback: color; } -MaskButton { - width: pixels; - height: pixels; - - bg: color; - icon: icon; - - iconBg: color; - iconBgOver: color; - - iconPosition: point; - iconPositionDown: point; - - duration: int; -} - MediaSlider { width: pixels; activeFg: color; @@ -212,17 +224,19 @@ defaultLabelSimple: LabelSimple { textFg: windowTextFg; } +defaultLinkButton: LinkButton { + color: btnYesColor; + overColor: btnYesColor; + downColor: btnYesHover; + font: linkFont; + overFont: linkOverFont; +} + defaultIconButton: IconButton { iconPosition: point(-1px, -1px); iconPositionDown: point(-1px, -1px); } -defaultMaskButton: MaskButton { - iconPosition: point(-1px, -1px); - iconPositionDown: point(-1px, -1px); - duration: 150; -} - widgetSlideDuration: 200; widgetFadeDuration: 200; diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index ca8a35195..40218c278 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "mainwindow.h" #include "lang.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "dialogs/dialogs_layout.h" #include "styles/style_dialogs.h" #include "styles/style_window.h" @@ -919,8 +919,8 @@ void HideAllButton::paintEvent(QPaintEvent *e) { p.fillRect(0, st::notifyBorderWidth, st::notifyBorderWidth, height() - 2 * st::notifyBorderWidth, st::notifyBorder); p.fillRect(width() - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorderWidth, height() - 2 * st::notifyBorderWidth, st::notifyBorder); - p.setFont(st::btnDefLink.font); - p.setPen(st::btnDefLink.color); + p.setFont(st::defaultLinkButton.font); + p.setPen(st::defaultLinkButton.color); p.drawText(rect(), lang(lng_notification_hide_all), style::al_center); } diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index a4ba92062..67b5956e6 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Ui { class IconButton; +class RoundButton; } // namespace Ui namespace Window { @@ -245,7 +246,7 @@ private: HistoryItem *_item; int _forwardedCount; ChildWidget _close; - ChildWidget _reply; + ChildWidget _reply; ChildWidget _background = { nullptr }; ChildWidget _replyArea = { nullptr }; ChildWidget _replySend = { nullptr }; diff --git a/Telegram/SourceFiles/window/top_bar_widget.cpp b/Telegram/SourceFiles/window/top_bar_widget.cpp index 1d5d68439..76978560f 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.cpp +++ b/Telegram/SourceFiles/window/top_bar_widget.cpp @@ -30,10 +30,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "shortcuts.h" #include "lang.h" #include "ui/buttons/peer_avatar_button.h" -#include "ui/buttons/round_button.h" -#include "ui/buttons/icon_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/dropdown_menu.h" -#include "ui/flatbutton.h" #include "dialogs/dialogs_layout.h" namespace Window { @@ -47,9 +45,7 @@ TopBarWidget::TopBarWidget(MainWidget *w) : TWidget(w) , _mediaType(this, lang(lng_media_type), st::topBarButton) , _search(this, st::topBarSearch) , _menuToggle(this, st::topBarMenuToggle) { - _clearSelection->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); - _forward->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); - _delete->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + _mediaType->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); _forward->setClickedCallback([this] { onForwardSelection(); }); _delete->setClickedCallback([this] { onDeleteSelection(); }); diff --git a/Telegram/SourceFiles/window/window_theme_warning.cpp b/Telegram/SourceFiles/window/window_theme_warning.cpp index e75a33c05..ffcae6d66 100644 --- a/Telegram/SourceFiles/window/window_theme_warning.cpp +++ b/Telegram/SourceFiles/window/window_theme_warning.cpp @@ -22,7 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "window/window_theme_warning.h" #include "styles/style_boxes.h" -#include "ui/buttons/round_button.h" +#include "ui/widgets/buttons.h" #include "window/window_theme.h" #include "lang.h" diff --git a/Telegram/SourceFiles/window/window_theme_warning.h b/Telegram/SourceFiles/window/window_theme_warning.h index 27e4b7ad7..af9529831 100644 --- a/Telegram/SourceFiles/window/window_theme_warning.h +++ b/Telegram/SourceFiles/window/window_theme_warning.h @@ -22,7 +22,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/effects/rect_shadow.h" -class BoxButton; +namespace Ui { +class RoundButton; +} // namespace Ui namespace Window { namespace Theme { @@ -60,8 +62,8 @@ private: QString _text; Ui::RectShadow _shadow; - ChildWidget _keepChanges; - ChildWidget _revert; + ChildWidget _keepChanges; + ChildWidget _revert; base::lambda_unique _hiddenCallback; diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 93504aea6..788c11023 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -449,18 +449,12 @@ '<(src_loc)/stickers/emoji_pan.h', '<(src_loc)/stickers/stickers.cpp', '<(src_loc)/stickers/stickers.h', - '<(src_loc)/ui/buttons/checkbox.cpp', - '<(src_loc)/ui/buttons/checkbox.h', '<(src_loc)/ui/buttons/history_down_button.cpp', '<(src_loc)/ui/buttons/history_down_button.h', - '<(src_loc)/ui/buttons/icon_button.cpp', - '<(src_loc)/ui/buttons/icon_button.h', '<(src_loc)/ui/buttons/left_outline_button.cpp', '<(src_loc)/ui/buttons/left_outline_button.h', '<(src_loc)/ui/buttons/peer_avatar_button.cpp', '<(src_loc)/ui/buttons/peer_avatar_button.h', - '<(src_loc)/ui/buttons/round_button.cpp', - '<(src_loc)/ui/buttons/round_button.h', '<(src_loc)/ui/effects/panel_animation.cpp', '<(src_loc)/ui/effects/panel_animation.h', '<(src_loc)/ui/effects/radial_animation.cpp', @@ -495,6 +489,10 @@ '<(src_loc)/ui/toast/toast_manager.h', '<(src_loc)/ui/toast/toast_widget.cpp', '<(src_loc)/ui/toast/toast_widget.h', + '<(src_loc)/ui/widgets/buttons.cpp', + '<(src_loc)/ui/widgets/buttons.h', + '<(src_loc)/ui/widgets/checkbox.cpp', + '<(src_loc)/ui/widgets/checkbox.h', '<(src_loc)/ui/widgets/continuous_slider.cpp', '<(src_loc)/ui/widgets/continuous_slider.h', '<(src_loc)/ui/widgets/discrete_slider.cpp', @@ -519,18 +517,16 @@ '<(src_loc)/ui/widgets/shadow.h', '<(src_loc)/ui/widgets/tooltip.cpp', '<(src_loc)/ui/widgets/tooltip.h', + '<(src_loc)/ui/abstract_button.cpp', + '<(src_loc)/ui/abstract_button.h', '<(src_loc)/ui/animation.cpp', '<(src_loc)/ui/animation.h', - '<(src_loc)/ui/button.cpp', - '<(src_loc)/ui/button.h', '<(src_loc)/ui/countryinput.cpp', '<(src_loc)/ui/countryinput.h', '<(src_loc)/ui/emoji_config.cpp', '<(src_loc)/ui/emoji_config.h', '<(src_loc)/ui/filedialog.cpp', '<(src_loc)/ui/filedialog.h', - '<(src_loc)/ui/flatbutton.cpp', - '<(src_loc)/ui/flatbutton.h', '<(src_loc)/ui/flatinput.cpp', '<(src_loc)/ui/flatinput.h', '<(src_loc)/ui/flatlabel.cpp',