From 0cbb0014db6318e86bf2f5186c4aa033f8099ffe Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Nov 2016 11:23:50 +0300 Subject: [PATCH] Removed blue window title, new small title used only in Windows. --- Telegram/Resources/basic.style | 101 +---- Telegram/Resources/basic_types.style | 8 - Telegram/Resources/colors.palette | 16 +- Telegram/Resources/icons/box_button_close.png | Bin 151 -> 148 bytes .../Resources/icons/box_button_close@2x.png | Bin 283 -> 269 bytes .../Resources/icons/title_button_close.png | Bin 169 -> 164 bytes .../Resources/icons/title_button_close@2x.png | Bin 264 -> 224 bytes .../Resources/icons/title_button_maximize.png | Bin 124 -> 119 bytes .../icons/title_button_maximize@2x.png | Bin 165 -> 144 bytes .../Resources/icons/title_button_minimize.png | Bin 109 -> 100 bytes .../icons/title_button_minimize@2x.png | Bin 147 -> 122 bytes .../Resources/icons/title_button_restore.png | Bin 144 -> 136 bytes .../icons/title_button_restore@2x.png | Bin 185 -> 160 bytes .../Resources/icons/title_button_update.png | Bin 142 -> 0 bytes .../icons/title_button_update@2x.png | Bin 218 -> 0 bytes Telegram/Resources/icons/title_icon.png | Bin 265 -> 0 bytes Telegram/Resources/icons/title_icon@2x.png | Bin 401 -> 0 bytes Telegram/Resources/icons/title_icon_bg.png | Bin 363 -> 0 bytes Telegram/Resources/icons/title_icon_bg@2x.png | Bin 701 -> 0 bytes Telegram/Resources/sample.tdesktop-theme | 11 +- Telegram/SourceFiles/app.cpp | 1 - Telegram/SourceFiles/boxes/boxes.style | 4 +- Telegram/SourceFiles/boxes/passcodebox.cpp | 1 - Telegram/SourceFiles/core/lambda_wrap.h | 21 + Telegram/SourceFiles/core/parse_helper.h | 4 +- Telegram/SourceFiles/history/history.style | 2 + Telegram/SourceFiles/historywidget.cpp | 13 +- Telegram/SourceFiles/intro/introwidget.cpp | 12 +- Telegram/SourceFiles/intro/introwidget.h | 1 - Telegram/SourceFiles/layerwidget.cpp | 3 +- Telegram/SourceFiles/layerwidget.h | 2 + Telegram/SourceFiles/mainwidget.cpp | 53 +-- Telegram/SourceFiles/mainwidget.h | 3 +- Telegram/SourceFiles/mainwindow.cpp | 385 +++++++--------- Telegram/SourceFiles/mainwindow.h | 51 +-- .../media/player/media_player.style | 14 - .../player/media_player_title_button.cpp | 122 ----- .../media/player/media_player_widget.cpp | 2 +- Telegram/SourceFiles/overviewwidget.cpp | 5 +- Telegram/SourceFiles/passcodewidget.cpp | 7 - Telegram/SourceFiles/passcodewidget.h | 14 +- .../platform/linux/main_window_linux.cpp | 15 +- .../platform/linux/main_window_linux.h | 5 +- .../linux/notifications_manager_linux.h | 13 - .../platform/mac/main_window_mac.h | 5 +- .../platform/mac/main_window_mac.mm | 35 +- .../platform/mac/notifications_manager_mac.h | 14 - .../platform/platform_file_dialog.h | 28 +- .../platform/platform_notifications_manager.h | 18 + .../platform/platform_window_title.h | 35 ++ .../platform/win/main_window_win.cpp | 26 +- .../platform/win/main_window_win.h | 2 - .../platform/win/notifications_manager_win.h | 9 - .../platform/win/window_title_win.cpp | 106 +++++ .../platform/win/window_title_win.h | 63 +++ .../platform/win/windows_event_filter.cpp | 62 +-- .../SourceFiles/profile/profile_cover.cpp | 3 +- .../profile/profile_inner_widget.cpp | 3 +- Telegram/SourceFiles/pspecific.h | 4 - Telegram/SourceFiles/pspecific_mac_p.mm | 2 +- .../settings/settings_scale_widget.cpp | 1 - .../SourceFiles/settings/settings_widget.cpp | 15 +- .../SourceFiles/settings/settings_widget.h | 2 +- Telegram/SourceFiles/structs.cpp | 12 +- Telegram/SourceFiles/sysbuttons.cpp | 147 ------ Telegram/SourceFiles/sysbuttons.h | 102 ----- Telegram/SourceFiles/title.cpp | 427 ------------------ Telegram/SourceFiles/title.h | 98 ---- Telegram/SourceFiles/window/window.style | 62 ++- Telegram/SourceFiles/window/window_theme.cpp | 77 ++-- .../window_title.h} | 51 +-- Telegram/gyp/Telegram.gyp | 11 +- 72 files changed, 726 insertions(+), 1583 deletions(-) delete mode 100644 Telegram/Resources/icons/title_button_update.png delete mode 100644 Telegram/Resources/icons/title_button_update@2x.png delete mode 100644 Telegram/Resources/icons/title_icon.png delete mode 100644 Telegram/Resources/icons/title_icon@2x.png delete mode 100644 Telegram/Resources/icons/title_icon_bg.png delete mode 100644 Telegram/Resources/icons/title_icon_bg@2x.png delete mode 100644 Telegram/SourceFiles/media/player/media_player_title_button.cpp create mode 100644 Telegram/SourceFiles/platform/platform_window_title.h create mode 100644 Telegram/SourceFiles/platform/win/window_title_win.cpp create mode 100644 Telegram/SourceFiles/platform/win/window_title_win.h delete mode 100644 Telegram/SourceFiles/sysbuttons.cpp delete mode 100644 Telegram/SourceFiles/sysbuttons.h delete mode 100644 Telegram/SourceFiles/title.cpp delete mode 100644 Telegram/SourceFiles/title.h rename Telegram/SourceFiles/{media/player/media_player_title_button.h => window/window_title.h} (61%) diff --git a/Telegram/Resources/basic.style b/Telegram/Resources/basic.style index 4da47a1fb..5b3a6aa48 100644 --- a/Telegram/Resources/basic.style +++ b/Telegram/Resources/basic.style @@ -34,17 +34,6 @@ emojiPadding: 0px; lineWidth: 1px; -wndMinWidth: 380px; - -adaptiveNormalWidth: 640px; -adaptiveWideWidth: 1366px; - -wndMinHeight: 480px; -wndDefWidth: 800px; -wndDefHeight: 600px; -wndShadow: icon {{ "window_shadow", windowShadowFg }}; -wndShadowShift: 1px; - labelDefFlat: flatLabel { font: font(fsize); width: 0px; @@ -277,20 +266,11 @@ boxScroll: flatScroll(solidScroll) { boxScrollSkip: 6px; boxScrollShadowBg: #00000012; -titleHeight: 39px; -titleFont: font(17px); -titlePos: point(44px, 29px); -titleMenuOffset: 36px; - -titleRed: #ee4928; -titleGray: #777777; -titleGreen: #41a903; - -titleStatusFg: #999999; -titleStatusActiveFg: #0080c0; -titleTypingFg: #0080c0; - statusFont: font(fsize); +statusFg: #999999; +statusFgActive: #0080c0; +statusFgTyping: statusFgActive; + versionColor: #777777; shadowColor: #00000018; @@ -302,63 +282,11 @@ slideFadeOutBg: #0000003c; slideShadow: icon {{ "slide_shadow", #000000 }}; slideFunction: transition(easeOutCirc); -titleButtonFg: #c4d8e9; -titleButtonActiveFg: #ffffff; -titleButtonDuration: 150; -sysBtnDelta: 6px; -sysUpd: sysButton { - size: size(31px, 39px); - icon: icon {{ "title_button_update", titleBg }}; - color: titleButtonFg; - overColor: titleButtonActiveFg; - duration: titleButtonDuration; -} -updateBlinkDuration: 500; -sysMin: sysButton(sysUpd) { - icon: icon {{ "title_button_minimize", titleBg }}; -} -sysMax: sysButton(sysUpd) { - icon: icon {{ "title_button_maximize", titleBg }}; -} -sysRes: sysButton(sysUpd) { - icon: icon {{ "title_button_restore", titleBg }}; -} -sysCls: sysButton(sysUpd) { - icon: icon {{ "title_button_close", titleBg }}; -} -sysLock: sysButton(sysUpd) { - icon: icon {{ "title_button_lock", titleBg }}; -} -sysUnlock: sysButton(sysUpd) { - icon: icon {{ "title_button_unlock", titleBg }}; -} - btnYesColor: #0080c0; btnYesHover: #0073ad; btnNoColor: #8b8b8b; btnNoHover: #777777; -titleTextButton: flatButton { - color: #d4e3ef; - overColor: #ffffff; - downColor: #ffffff; - bgColor: transparent; - overBgColor: transparent; - downBgColor: transparent; - - width: -14px; - height: 39px; - - textTop: 10px; - overTextTop: 10px; - downTextTop: 11px; - - font: font(fsize); - overFont: font(fsize); - duration: 150; - cursor: cursor(default); -} - linkCropLimit: 360px; linkFont: normalFont; linkOverFont: font(fsize underline); @@ -919,8 +847,8 @@ confirmCompressedSkip: 10px; profileMaxWidth: 410px; profilePadding: margins(28px, 30px, 28px, 0px); -profileOnlineFg: titleStatusActiveFg; -profileOfflineFg: titleStatusFg; +profileOnlineFg: statusFgActive; +profileOfflineFg: statusFg; membersPadding: margins(0px, 10px, 0px, 10px); @@ -1064,17 +992,6 @@ medviewSaveMsgHiding: 2500; medviewSaveMsgFg: #ffffff; medviewSaveMsg: #000000b2; -// Mac specific - -macAccessoryWidth: 450.; -macAccessoryHeight: 90.; -macEnableFilterAdd: 2; -macEnableFilterTop: 5; -macSelectorTop: 6; -macAlwaysThisAppTop: 4; -macAppHintTop: 8; -macCautionIconSize: 16; - radialSize: size(50px, 50px); radialLine: 3px; radialDuration: 350; @@ -1191,9 +1108,9 @@ infoButton: PeerAvatarButton { profileTopBarBackIconFg: #0290d7; profileTopBarBackIcon: icon {{ "title_previous", profileTopBarBackIconFg }}; -historyReplyCancelIcon: icon {{ "box_button_close", historyReplyBg }}; -boxSearchCancelIcon: icon {{ "box_button_close", boxSearchBg }}; -settingsFixedBarCloseIcon: icon {{ "box_button_close", settingsFixedBarBg }}; +historyReplyCancelIcon: icon {{ "box_button_close-invert", historyReplyBg }}; +boxSearchCancelIcon: icon {{ "box_button_close-invert", boxSearchBg }}; +settingsFixedBarCloseIcon: icon {{ "box_button_close-invert", settingsFixedBarBg }}; notifyFadeRight: icon {{ "fade_horizontal_right", notificationBg }}; diff --git a/Telegram/Resources/basic_types.style b/Telegram/Resources/basic_types.style index c0d17c4c4..2ca21038a 100644 --- a/Telegram/Resources/basic_types.style +++ b/Telegram/Resources/basic_types.style @@ -38,14 +38,6 @@ linkButton { overFont: font; } -sysButton { - size: size; - icon: icon; - color: color; - overColor: color; - duration: int; -} - flatButton { color: color; overColor: color; diff --git a/Telegram/Resources/colors.palette b/Telegram/Resources/colors.palette index ddc62dd09..c449b8ed8 100644 --- a/Telegram/Resources/colors.palette +++ b/Telegram/Resources/colors.palette @@ -29,11 +29,18 @@ windowSubTextFgOver: #7c99b2; // gray over light blue: fallback for subtext over windowActiveTextFg: #1485c2; // online blue: fallback for active color windowShadowFg: #000000; // black: fallback for shadow color -titleBg: #6389a8; - imageBg: #000000; imageBgTransparent: #ffffff; +// custom title bar for Windows +titleBg: #f3f3f3; +titleShadow: #00000003; +titleButtonFg: #ababab; +titleButtonBgOver: #e5e5e5; +titleButtonFgOver: #9a9a9a; +titleButtonCloseBgOver: #e81123; +titleButtonCloseFgOver: #ffffff; + // tray icon trayCounterBg: #f23c34; trayCounterBgMute: #888888; @@ -56,11 +63,6 @@ lightButtonBgOver: #f2f7fa | lightButtonBg; lightButtonFg: #2b99d5; lightButtonFgOver: lightButtonFg; -// window title -titleCounterBg: trayCounterBg; -titleCounterBgMute: trayCounterBgMute; -titleCounterFg: trayCounterFg; - // layers layerBg: #0000007f; diff --git a/Telegram/Resources/icons/box_button_close.png b/Telegram/Resources/icons/box_button_close.png index 57abcfb8230614a33ff15da39cb1c991dad2ebf7..3b0402893ab0c64450b8d081ba33aa55f8cc5e01 100644 GIT binary patch delta 119 zcmV--0EqvW0h9rdByd|vL_t(2k)2V&4FE9+B3;A%pYGuzum< Zg$E&69LDP^wuk@#002ovPDHLkV1nvzF}MH# delta 122 zcmV-=0EPdQ0ha-gBy(O#L_t(2k)4sj4Ztu61Fej4lQ0MSf0@I5^pjLgD(WZlfdOTv z0e=Z_W?FzH9iiEyXW?YFeFHn_t){8jV%SYxfEn6F9O~+Kq}I}{vvwahB0_+wYP)Au c2~b4n0wttN3IP`wjQ{`u07*qoM6N<$f~ib0-T(jq diff --git a/Telegram/Resources/icons/box_button_close@2x.png b/Telegram/Resources/icons/box_button_close@2x.png index bf2a19e72c50b6a1294447c938a480d0b3e21a18..fea726bdbee71641f170e4b68cfa3ae5365fba56 100644 GIT binary patch delta 241 zcmVNh2crJb1pLXePPSBh`ZMXX{!}+22D%i zM$P{v3IP!jswx4{%qSw4u9Ol1P*vMKRb?rKBw1^{grt;MYb8mRQW^q)>oJS0b^zJRr^1SM(M^RR%s6- zxKjQDlb8sAyQ8X@8Bed?JF1Gi10e2BtrZcWl=2Aay;Dj-M5wjm?ue=)BFB9fd5`b6 zsv>4~dXPm%@x37cPmom{cma2jtM~_yMI!MN5JjT#A#jCc;&@YFg=EKR3e1q~Oj`mg zBsz_MLGDjr3K8%{JH zK~7s{Hoihs^>fp|8y_LZrVp=UOKa^b#}+fAwRRj^egW=g9&exM6_o%0002ovPDHLk FV1oJ|cMt#o diff --git a/Telegram/Resources/icons/title_button_close.png b/Telegram/Resources/icons/title_button_close.png index 0686fc88a97cb28d60edc3bafd7acf156ec6026f..22cfe520c4a6e3b0da93e628ac6a63dbdfbd3ff8 100644 GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^{2(?58;~rMGjRk`*`6+rAsQ36PCCeYK!JzZ_o&Ft z`u;Nqnc@!D25x0hoV99NMMBZ0NdXKTp0be!2j1~by6iNm;QNEs@{=a1OuF^aFvjU2 zQ_lwuodcG8CjM|P+Vy<<<#pfZZoS69koN7y(wU7VRCwgTe~DWM4fa(F?q literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7S1|*9D%+3I*0#6sm5R2ZoQv$gT7;reh?OR&j z+5Y11$$z&)qbD3p_-XP)QOj)76s6eE1^oxl_}sDO*|~eh&76XO_j8q;7#6!uV%hLT zJwl|z!TUzA0dwmH!3m8)H}c%ymxY;a-jtixxY#=QYKa-cidDgTC;sQQy2ATvU1#O` S3Ql97-3*?telF{r5}E*q7ePt@ diff --git a/Telegram/Resources/icons/title_button_close@2x.png b/Telegram/Resources/icons/title_button_close@2x.png index f598165f0c13974284966f4e82287f8e98d1d98e..e43b4d8a7f57ad85cab66305bb7f748d60fcbf96 100644 GIT binary patch literal 224 zcmV<603ZK}P)J-q9X2TZf}TBYdSdg=YtDpgEik-bCl%E8qq? z4@dY7bPc}3H&B+HTryhKYn5zu$;(ypIh7nBB}Zo2B~f-Qc05^iSgM+#Ji7kreCI#c aPr@fwnMp8>+vjos0000a9?KzKt*W(q_zaoMtBY?+Df~&S~4ch~Yr)`ak=_Uw(RAUKz8) zCLwm4%5>j5Pj5Uf3n;OU;-8Z;ef5DRE1s9bbW7WAJqK Kb6Mw<&;$T)TyC5I diff --git a/Telegram/Resources/icons/title_button_maximize.png b/Telegram/Resources/icons/title_button_maximize.png index a3522751f8107677d1aa615d2bf4223db402f1c6..2759b3f41fb4546fd9657d29a75ff0376a61f91a 100644 GIT binary patch literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^0w6XA8<1SE`<)7qvh#Ft4AGdFoRX06w QK$93eUHx3vIVCg!0O)}s5dZ)H literal 124 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7S1|*9D%+3HQXHOT$5R2aAKmY&#uV>R@RLhby z*}7njLI#baSWcWelF{r5}E)c#U-Es diff --git a/Telegram/Resources/icons/title_button_maximize@2x.png b/Telegram/Resources/icons/title_button_maximize@2x.png index 037bb98de5b2d88646c3b0fe4e251da6211930ec..00daaae190fcb9c1850a3310d52ce1d8b17e11ca 100644 GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Ey!3HF+&5pANQsJI1jv*eMZ>Je@9WdZw_Fwq_ z|0e5HPSXmGj1?xgocSUx!~!I?&go}oc<@pxw0yDR%guS^3Jkeyex=55OwLZY+sMG8 rz`!Vxf9Ur9$J2nkj+mqM>=le|%G@S}fK!Jzh;<6wA z_s{W*<#Nmm2;Q-MmyBab&zUo;7yd4BIBIYT2(v=C1vjcLuyVWYcgA4Vo#geQ;V*Oe zx6hrCI0Xq_`C_~6_1phn_jk_y$C71jcvu4nSFm4K;0-YCJ^ux0FN3G6pUXO@geCwr C%tJf? diff --git a/Telegram/Resources/icons/title_button_minimize.png b/Telegram/Resources/icons/title_button_minimize.png index 229cb7dc5eb9938a22d0ba6c9f59bbf28226ce98..85934ddde82b3cd1145635cb7d27990c40a2d6ca 100644 GIT binary patch literal 100 zcmeAS@N?(olHy`uVBq!ia0vp^0w6XA8<1SE`<)7q()M(54AGdFoRX06R@RLhby z$-1#3adBJVRRggUK4oR)lWYppg|`$-E?s)@K`+B9DK-X=N-pJnAG3Oa`WZZ3{an^L HB{Ts5^V=Xs diff --git a/Telegram/Resources/icons/title_button_minimize@2x.png b/Telegram/Resources/icons/title_button_minimize@2x.png index ddfc4713a245d00daaca421ff95f2911329c8330..d70a497345422f53019806ba8e63117d01e31278 100644 GIT binary patch literal 122 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Ey!3HF+&5pANQjVT3jv*eMZ?A3SWia4iK3G2G zZ@3zFi=L3{JRz?6D`XZ(%rTYJb7){-WMbhEVA!zR`ReUOQ=aUS|KHG%p#4v_fWb0@ V)mTvD=VG8?44$rjF6*2UngCEZBTxVU literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^Y9P$P1|(P5zFY^SqC8z3Ln2z=-q^^?puoWzxWDlK z)Iz4N>?x1pyo(h>maNL+-BQn9!m}7V^fUMPq_UuzrRVO9#E|Ob{qr4?&C?`Ofv}X3 Yxrxhj^YdLiKwB6*UHx3vIVCg!07t?u&Hw-a diff --git a/Telegram/Resources/icons/title_button_restore.png b/Telegram/Resources/icons/title_button_restore.png index 4ad86be0e4ef5d5a8c682ba1f8d5a737a74833e3..c9f276b51732c3288cbfd0f6fcb37689c993d295 100644 GIT binary patch literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^0w6XA8<1SE`<)7q^7nLc4AGdlb+R{?gCY;J`lG+= zW5N$Pzh-}QdQ)qr(~5=z0cYC;)0e3*bQRaWTyWXA_uZ?kLhd?w#oe2V)2)9jZ=HLr kL-@h6-t})d4*h9mOA8iM_L-zo4m6s<)78&qol`;+0BFE5bpQYW literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7S1|*9D%+3I*a8DP<5R2aAKmY&#uV>R@RLhcd zDLowV!PCgdNXUf2a>|S6MkTW^GVVJ4Qk-$gGAWV#Nm379G;9-e@M(DbiSgi#BWwkc s78RR?bCnxrJaL?oI7KYC+58NHkeHI-x9WdZ=Dt+@W z{MqIyVf(F!t!yGE!*kUIn2XrsKm>;9&`;gwlW3Q+Npm;amC7jp^PvS%t^16s-8>FVdQ I&MBb@0A_(UdjJ3c literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^Y9P$P1|(P5zFY^S8a!PbLn2z=&N#?*z<}fEvlsvW zZ?b+Hp^~)n(CNJbO{J;N-u*LqvR8M5bCO7BVA!_>GpBOAndWpmNoets^f&6iA9kc| z$u;Z@ykuPVE6`~DjhAQTE^eD~MC0MwHMicBq&*i~-83yf+6Sar#f|fO#8vHPpsKg` h({j5#dz1`MvAfNY3@vRw#SL@|gQu&X%Q~loCIIJjPqY94 diff --git a/Telegram/Resources/icons/title_button_update.png b/Telegram/Resources/icons/title_button_update.png deleted file mode 100644 index b7dc595fb273ab1ca1777c6741b09ea520f4c5bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 142 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7S1|*9D%+3I*P)`@f5R2aAKmY&#uV>R@RLhby zF=#V1G736wFvIbPM8|c55@rs`j>`ryQXeHdt{OP$9Z)^rf}D9MA#=Pgg&ebxsLQ0MvjhRR910 diff --git a/Telegram/Resources/icons/title_button_update@2x.png b/Telegram/Resources/icons/title_button_update@2x.png deleted file mode 100644 index bf26691ea3c4e977e90a2619ee0e90a70211e3bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 218 zcmeAS@N?(olHy`uVBq!ia0vp^Y9P$P1|(P5zFY^S7J9lkhD5Z!y=KVAY{=nqv2Y7} z({K5_ZN7r)JPJpnK4x>ko&@ z?qGIj+&%Aqc$vAu*2a}!gPDV^#l-IEm4$Bah&{gV#(^tr%ghY6N>__sI-~eiSrX`2 N22WQ%mvv4FO#r4ZPW1o) diff --git a/Telegram/Resources/icons/title_icon.png b/Telegram/Resources/icons/title_icon.png deleted file mode 100644 index 12772e6a3ae3111478ba0af28580d8f14f4f43b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 265 zcmV+k0rvihP)ST6a>&qB=Vf-mYNZuUUF7@Ndl&64$i^3W3$yv&XnB_`%Z7S}%Vk+c-}kYqDx&g<*Y+1u zRTYCEz@}-a%U{DV%rJC39`Sy^FDma6MbYpP$g;c&&}FyVeLCyMj@C$B*JB^miOF$4g3y2z8j+VA&0NRp)WAppQI44+6@ vmNaYWAfD%+5W(G<4*>wOEQ`9XQ?2<0Hp`?04t7E<00000NkvXXu0mjfYPPbN diff --git a/Telegram/Resources/icons/title_icon_bg.png b/Telegram/Resources/icons/title_icon_bg.png deleted file mode 100644 index ebdf862916dd6905c371cfd96bed344a17dd5675..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 363 zcmV-x0hIoUP)L!ReYlGEt~ z*L7c`VHo0mzb^vE+-^7czCVwKVfYa?P2cxeuh-8gW9;J&e@AN#$8jF$`F#EpIOcdf zexpJNBj6a%^I*ksOeVA2?a10}Hb&9yc1x?i?_t}vF|=tKS^ diff --git a/Telegram/Resources/icons/title_icon_bg@2x.png b/Telegram/Resources/icons/title_icon_bg@2x.png deleted file mode 100644 index 33924433d23e67484eb4a4b2dbdf83e4b870bd22..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 701 zcmV;u0z&=q zzOOC&!7R(7uIm^CK`QQ6K@gy>>&UX~^PvpGV5if;Fbs18FAKvEJDmiK}jGpV9(#sG>sVYn5Jnz zLj^&=BuPj+F-Z~>1mSxqP1EQ&4r${l$8jzn4!>S>yIs<@t9rfOIkZ?TKJ>JCRY4G7 zu~wHg!<5lKU`M3Dw$?LYL{{X5Y8eoxwv+Tm~jYOz?5 zcBD3+&w+AXm$V}_*L8s!jYgy$sf|V>D3r@(+-x?aEk9PNRDkk*AKv+@+O`e8?*jk; zHX04me>-p1Xf)2(OylvGwCSqhaCp7A69j>@>#B<-^Y68@Wm%+cr!335J%C_Y7Cp}+ zZA8!WzMG$(k4{8U#3+i0A)_clQ53Tc$y8M(GTKR!1XWeNZ|tZj3dV8#*N|}>qoOGJ z2Dv=X<8rxtIdZvNBG2>rC(iIS?lDdCWk}OBPh*>hpnu+ElgZ?1z{zBC>!x`OdfX&Q z!hXM>>z5&lA{-0`C`r;?=L7&O9JTkxFbv4D43Z=P$8k`tR)OQVvtwM>h4p$3uIs{d jItAOdVY}VtIURfgG(+updateConnectingStatus(); - w->getTitle()->updateControlsVisibility(); } return true; } diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 5c6f5e84a..1852efe0c 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -37,7 +37,7 @@ boxBlueClose: MaskButton(defaultMaskButton) { iconBg: #c8e1f0; iconBgOver: #ffffff; - icon: icon {{ "box_button_close", boxBlueTitleBg }}; + icon: icon {{ "box_button_close-invert", boxBlueTitleBg }}; } confirmInviteTitle: flatLabel(labelDefFlat) { @@ -198,7 +198,7 @@ notificationsBoxMonitorTop: 63px; notificationsBoxMonitor: icon {{ "monitor", notificationsBoxMonitorFg }}; notificationsBoxScreenTop: 10px; notificationsBoxScreenSize: size(280px, 160px); -notificationsBoxScreenBg: titleBg; +notificationsBoxScreenBg: #6389a8; notificationsBoxCountLabelTop: 80px; notificationsBoxCountTop: 30px; diff --git a/Telegram/SourceFiles/boxes/passcodebox.cpp b/Telegram/SourceFiles/boxes/passcodebox.cpp index 8f8decb21..6340da7fc 100644 --- a/Telegram/SourceFiles/boxes/passcodebox.cpp +++ b/Telegram/SourceFiles/boxes/passcodebox.cpp @@ -405,7 +405,6 @@ void PasscodeBox::onSave(bool force) { cSetPasscodeBadTries(0); Local::setPasscode(pwd.toUtf8()); App::wnd()->checkAutoLock(); - App::wnd()->getTitle()->updateControlsVisibility(); onClose(); } } diff --git a/Telegram/SourceFiles/core/lambda_wrap.h b/Telegram/SourceFiles/core/lambda_wrap.h index 3e211781d..cd1a15559 100644 --- a/Telegram/SourceFiles/core/lambda_wrap.h +++ b/Telegram/SourceFiles/core/lambda_wrap.h @@ -394,4 +394,25 @@ public: }; +class lambda_slot_wrap : public QObject { + Q_OBJECT + +public: + lambda_slot_wrap(QObject *parent, lambda_unique lambda) : QObject(parent), _lambda(std_::move(lambda)) { + } + +public slots: + void action() { + _lambda(); + } + +private: + lambda_unique _lambda; + +}; + +inline lambda_slot_wrap *lambda_slot(QObject *parent, lambda_unique lambda) { + return new lambda_slot_wrap(parent, std_::move(lambda)); +} + } // namespace base diff --git a/Telegram/SourceFiles/core/parse_helper.h b/Telegram/SourceFiles/core/parse_helper.h index 6284baaf6..9c7006d04 100644 --- a/Telegram/SourceFiles/core/parse_helper.h +++ b/Telegram/SourceFiles/core/parse_helper.h @@ -38,7 +38,7 @@ inline bool skipWhitespaces(const char *&from, const char *end) { return (from != end); } -inline QByteArray readName(const char *&from, const char *end) { +inline QLatin1String readName(const char *&from, const char *end) { t_assert(from <= end); auto start = from; while (from != end && ( @@ -48,7 +48,7 @@ inline QByteArray readName(const char *&from, const char *end) { (*from == '_'))) { ++from; } - return QByteArray::fromRawData(start, from - start); + return QLatin1String(start, from - start); } } // namespace parse diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index a5486dc6d..6988e7ff9 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -36,6 +36,8 @@ historyToDownPaddingTop: 10px; historyToDownBadgeFont: semiboldFont; historyToDownBadgeSize: 22px; +historyToDownShownAfter: 480px; + historyEmptyDog: icon {{ "history_empty_dog", #ffffff }}; historyEmptySize: 128px; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index a7714d59f..b28f1914f 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2701,7 +2701,6 @@ HistoryHider::HistoryHider(MainWidget *parent, const QString &url, const QString void HistoryHider::init() { connect(&_send, SIGNAL(clicked()), this, SLOT(forward())); connect(&_cancel, SIGNAL(clicked()), this, SLOT(startHide())); - connect(App::wnd()->getTitle(), SIGNAL(hiderClicked()), this, SLOT(startHide())); _chooseWidth = st::forwardFont->width(lang(_botAndQuery.isEmpty() ? lng_forward_choose : lng_inline_switch_choose)); @@ -2720,7 +2719,6 @@ void HistoryHider::step_appearance(float64 ms, bool timer) { } else { a_opacity.update(dt, anim::linear); } - App::wnd()->getTitle()->setHideLevel(a_opacity.current()); if (timer) update(); } @@ -2746,7 +2744,7 @@ void HistoryHider::paintEvent(QPaintEvent *e) { _toText.drawElided(p, _box.left() + st::boxPadding.left(), _box.top() + st::boxPadding.top(), _toTextWidth + 2); } else { int32 w = st::forwardMargins.left() + _chooseWidth + st::forwardMargins.right(), h = st::forwardMargins.top() + st::forwardFont->height + st::forwardMargins.bottom(); - App::roundRect(p, (width() - w) / 2, (height() - st::titleHeight - h) / 2, w, h, st::forwardBg, ForwardCorners); + App::roundRect(p, (width() - w) / 2, (height() - h) / 2, w, h, st::forwardBg, ForwardCorners); p.setPen(st::forwardFg); p.drawText(_box, lang(_botAndQuery.isEmpty() ? lng_forward_choose : lng_inline_switch_choose), QTextOption(style::al_center)); @@ -2835,7 +2833,7 @@ void HistoryHider::resizeEvent(QResizeEvent *e) { _send.hide(); _cancel.hide(); } - _box = QRect((width() - w) / 2, (height() - st::titleHeight - h) / 2, w, h); + _box = QRect((width() - w) / 2, (height() - h) / 2, w, h); _send.moveToRight(width() - (_box.x() + _box.width()) + st::boxButtonPadding.right(), _box.y() + h - st::boxButtonPadding.bottom() - _send.height()); _cancel.moveToRight(width() - (_box.x() + _box.width()) + st::boxButtonPadding.right() + _send.width() + st::boxButtonPadding.left(), _send.y()); } @@ -2909,7 +2907,6 @@ bool HistoryHider::wasOffered() const { HistoryHider::~HistoryHider() { if (_sendPath) cSetSendPaths(QStringList()); - if (App::wnd()) App::wnd()->getTitle()->setHideLevel(0); parent()->noHider(this); } @@ -6269,10 +6266,10 @@ void HistoryWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { QRect rectForName(st::topBarArrowPadding.right() + increaseLeft, st::topBarArrowPadding.top(), width() - decreaseWidth - st::topBarArrowPadding.left() - st::topBarArrowPadding.right(), st::msgNameFont->height); p.setFont(st::dialogsTextFont); if (_history->typing.isEmpty() && _history->sendActions.isEmpty()) { - p.setPen(_titlePeerTextOnline ? st::titleStatusActiveFg : st::titleStatusFg); + p.setPen(_titlePeerTextOnline ? st::statusFgActive : st::statusFg); p.drawText(rectForName.x(), st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height + st::dialogsTextFont->ascent, _titlePeerText); } else { - p.setPen(st::titleTypingFg); + p.setPen(st::statusFgTyping); _history->typingText.drawElided(p, rectForName.x(), st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height, rectForName.width()); } @@ -7394,7 +7391,7 @@ void HistoryWidget::updateToEndVisibility() { if (!_history->loadedAtBottom() || _replyReturn) { return true; } - if (_scroll.scrollTop() + st::wndMinHeight < _scroll.scrollTopMax()) { + if (_scroll.scrollTop() + st::historyToDownShownAfter < _scroll.scrollTopMax()) { return true; } if (haveUnreadBelowBottom(_history) || haveUnreadBelowBottom(_migrated)) { diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 630fe9cb1..5a225e54a 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -40,8 +40,6 @@ IntroWidget::IntroWidget(QWidget *parent) : TWidget(parent) , _a_stage(animation(this, &IntroWidget::step_stage)) , _a_show(animation(this, &IntroWidget::step_show)) , _back(this, new Ui::IconButton(this, st::introBackButton), base::lambda_unique(), st::introSlideDuration) { - setGeometry(QRect(0, st::titleHeight, App::wnd()->width(), App::wnd()->height() - st::titleHeight)); - _back->entity()->setClickedCallback([this] { onBack(); }); _back->hideFast(); @@ -52,8 +50,6 @@ IntroWidget::IntroWidget(QWidget *parent) : TWidget(parent) _stepHistory.push_back(new IntroStart(this)); _back->raise(); - connect(parent, SIGNAL(resized(const QSize&)), this, SLOT(onParentResize(const QSize&))); - show(); setFocus(); @@ -76,10 +72,6 @@ void IntroWidget::onChangeLang() { App::restart(); } -void IntroWidget::onParentResize(const QSize &newSize) { - resize(newSize); -} - void IntroWidget::onStepSubmit() { step()->onSubmit(); } @@ -339,8 +331,8 @@ bool IntroWidget::codeByTelegram() const { } void IntroWidget::resizeEvent(QResizeEvent *e) { - QRect r(innerRect()); - for (IntroStep *step : _stepHistory) { + auto r = innerRect(); + for (auto step : _stepHistory) { step->setGeometry(r); } } diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index e14d255ce..9837539f4 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -92,7 +92,6 @@ public: public slots: void onStepSubmit(); void onBack(); - void onParentResize(const QSize &newSize); void onChangeLang(); signals: diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index f22513bcb..f625b1f49 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -294,8 +294,7 @@ void LayerStackWidget::showLayer(LayerWidget *l) { void LayerStackWidget::showSpecialLayer(LayerWidget *l) { clearLayers(); if (_specialLayer) { - _specialLayer->hide(); - _specialLayer->deleteLater(); + _specialLayer.destroyDelayed(); } _specialLayer = l; activateLayer(l); diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index 8e0585547..b44b4bc32 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -26,6 +26,8 @@ class LayerWidget : public TWidget { Q_OBJECT public: + using TWidget::TWidget; + virtual void parentResized() = 0; virtual void showDone() { } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index b2a776fd1..b9749d72f 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -67,7 +67,7 @@ StackItemSection::StackItemSection(std_::unique_ptr &&me StackItemSection::~StackItemSection() { } -MainWidget::MainWidget(MainWindow *window) : TWidget(window) +MainWidget::MainWidget(QWidget *parent) : TWidget(parent) , _a_show(animation(this, &MainWidget::step_show)) , _dialogsWidth(st::dialogsWidthMin) , _sideShadow(this, st::shadowColor) @@ -78,13 +78,10 @@ MainWidget::MainWidget(MainWindow *window) : TWidget(window) , _playerPanel(this, Media::Player::Panel::Layout::Full) , _mediaType(this, st::historyAttachDropdownMenu) , _api(new ApiWrap(this)) { - setGeometry(QRect(0, st::titleHeight, App::wnd()->width(), App::wnd()->height() - st::titleHeight)); - MTP::setGlobalDoneHandler(rpcDone(&MainWidget::updateReceived)); _ptsWaiter.setRequesting(true); updateScrollColors(); - connect(App::wnd(), SIGNAL(resized(const QSize&)), this, SLOT(onParentResize(const QSize&))); connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); connect(_history, SIGNAL(cancelled()), _dialogs, SLOT(activate())); connect(this, SIGNAL(peerPhotoChanged(PeerData*)), this, SIGNAL(dialogsUpdated())); @@ -156,7 +153,6 @@ MainWidget::MainWidget(MainWindow *window) : TWidget(window) } else { _history->show(); } - App::wnd()->getTitle()->updateControlsVisibility(); _topBar->hide(); orderWidgets(); @@ -614,7 +610,6 @@ void MainWidget::noHider(HistoryHider *destroyed) { _history->showAnimated(Window::SlideDirection::FromRight, animationParams); } } - App::wnd()->getTitle()->updateControlsVisibility(); } else { if (_forwardConfirm) { _forwardConfirm->deleteLater(); @@ -651,7 +646,6 @@ void MainWidget::hiderLayer(HistoryHider *h) { resizeEvent(0); _dialogs->showAnimated(Window::SlideDirection::FromLeft, animationParams); } - App::wnd()->getTitle()->updateControlsVisibility(); } else { _hider->show(); resizeEvent(0); @@ -1588,6 +1582,9 @@ void MainWidget::handleAudioUpdate(const AudioMsgId &audioId) { if (!_playerUsingPanel && !_player && Media::Player::exists()) { createPlayer(); } + } else if (_player && _player->isHidden() && !_playerUsingPanel) { + _player.destroyDelayed(); + _playerVolume.destroyDelayed(); } } @@ -1632,8 +1629,12 @@ void MainWidget::switchToFixedPlayer() { } void MainWidget::closeBothPlayers() { - _playerUsingPanel = false; - _player.destroyDelayed(); + if (_playerUsingPanel) { + _playerUsingPanel = false; + _player.destroyDelayed(); + } else { + _player->slideUp(); + } _playerVolume.destroyDelayed(); if (Media::Player::exists()) { @@ -1651,7 +1652,7 @@ void MainWidget::closeBothPlayers() { void MainWidget::createPlayer() { _player.create(this, [this] { playerHeightUpdated(); }); - _player->entity()->setCloseCallback([this] { switchToPanelPlayer(); }); + _player->entity()->setCloseCallback([this] { closeBothPlayers(); }); _playerVolume.create(this); _player->entity()->volumeWidgetCreated(_playerVolume); orderWidgets(); @@ -1660,9 +1661,11 @@ void MainWidget::createPlayer() { _player->hide(); } else { _player->hideFast(); - _player->slideDown(); - _playerHeight = _contentScrollAddToY = _player->contentHeight(); - updateControlsGeometry(); + if (_player) { + _player->slideDown(); + _playerHeight = _contentScrollAddToY = _player->contentHeight(); + updateControlsGeometry(); + } } Shortcuts::enableMediaShortcuts(); @@ -1675,9 +1678,13 @@ void MainWidget::playerHeightUpdated() { _playerHeight = playerHeight; updateControlsGeometry(); } - if (_playerUsingPanel && !_playerHeight && _player->isHidden()) { - _playerVolume.destroyDelayed(); - _player.destroyDelayed(); + if (!_playerHeight && _player->isHidden()) { + AudioMsgId playing; + auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song); + if (playing && (playbackState.state & AudioPlayerStoppedMask)) { + _playerVolume.destroyDelayed(); + _player.destroyDelayed(); + } } } @@ -1768,10 +1775,6 @@ void MainWidget::mediaMarkRead(const HistoryItemsMap &items) { } } -void MainWidget::onParentResize(const QSize &newSize) { - resize(newSize); -} - void MainWidget::updateOnlineDisplay() { if (this != App::main()) return; _history->updateOnlineDisplay(); @@ -2216,7 +2219,6 @@ void MainWidget::ui_showPeerHistory(quint64 peerId, qint32 showAtMsgId, Ui::Show _dialogs->update(); } topBar()->showAll(); - App::wnd()->getTitle()->updateControlsVisibility(); } PeerData *MainWidget::ui_getPeerForMouseAction() { @@ -2337,8 +2339,6 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool if (Adaptive::OneColumn()) _dialogs->hide(); orderWidgets(); - - App::wnd()->getTitle()->updateControlsVisibility(); } void MainWidget::showWideSection(const Window::SectionMemento &memento) { @@ -2465,8 +2465,6 @@ void MainWidget::showWideSectionAnimated(const Window::SectionMemento *memento, if (Adaptive::OneColumn()) _dialogs->hide(); orderWidgets(); - - App::wnd()->getTitle()->updateControlsVisibility(); } bool MainWidget::stackIsEmpty() const { @@ -3412,7 +3410,6 @@ void MainWidget::getDifference() { _getDifferenceTimeByPts = 0; - LOG(("Getting difference! no updates timer: %1, remains: %2").arg(noUpdatesTimer.isActive() ? 1 : 0).arg(noUpdatesTimer.remainingTime())); if (requestingDifference()) return; _bySeqUpdates.clear(); @@ -3421,7 +3418,6 @@ void MainWidget::getDifference() { noUpdatesTimer.stop(); _getDifferenceTimeAfterFail = 0; - LOG(("Getting difference for %1, %2").arg(_ptsWaiter.current()).arg(updDate)); _ptsWaiter.setRequesting(true); MTP::send(MTPupdates_GetDifference(MTP_int(_ptsWaiter.current()), MTP_int(updDate), MTP_int(updQts)), rpcDone(&MainWidget::gotDifference), rpcFail(&MainWidget::failDifference)); } @@ -3433,14 +3429,12 @@ void MainWidget::getChannelDifference(ChannelData *channel, GetChannelDifference _channelGetDifferenceTimeByPts.remove(channel); } - LOG(("Getting channel difference!")); if (!channel->ptsInited() || channel->ptsRequesting()) return; if (from != GetChannelDifferenceFromFail) { _channelGetDifferenceTimeAfterFail.remove(channel); } - LOG(("Getting channel difference for %1").arg(channel->pts())); channel->ptsSetRequesting(true); auto filter = MTP_channelMessagesFilterEmpty(); @@ -3456,7 +3450,6 @@ void MainWidget::start(const MTPUser &user) { if (MTP::authedId() != uid) { MTP::setAuthedId(uid); Local::writeMtpData(); - App::wnd()->getTitle()->updateControlsVisibility(); } Local::readSavedPeers(); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 60f7b6f6c..32cf8519b 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -139,7 +139,7 @@ class MainWidget : public TWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: - MainWidget(MainWindow *window); + MainWidget(QWidget *parent); bool needBackButton(); @@ -426,7 +426,6 @@ public slots: void dialogsCancelled(); - void onParentResize(const QSize &newSize); void getDifference(); void onGetDifferenceTimeByPts(); void onGetDifferenceTimeAfterFail(); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 063248c52..83a2309b6 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -23,13 +23,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "dialogs/dialogs_layout.h" #include "styles/style_dialogs.h" +#include "styles/style_window.h" #include "ui/widgets/popup_menu.h" #include "core/zlib_help.h" #include "lang.h" #include "shortcuts.h" #include "application.h" #include "pspecific.h" -#include "title.h" #include "passcodewidget.h" #include "intro/introwidget.h" #include "mainwidget.h" @@ -44,11 +44,12 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "settings/settings_widget.h" #include "platform/platform_notifications_manager.h" +#include "platform/platform_window_title.h" #include "window/notifications_manager.h" #include "window/window_theme.h" #include "window/window_theme_warning.h" -ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : QWidget(parent) +ConnectingWidget::ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect) : TWidget(parent) , _shadow(st::boxShadow) , _reconnect(this, QString()) { set(text, reconnect); @@ -85,7 +86,7 @@ void ConnectingWidget::onReconnect() { MTP::restart(); } -MainWindow::MainWindow() { +MainWindow::MainWindow() : Platform::MainWindow(), _body(this) { icon16 = icon256.scaledToWidth(16, Qt::SmoothTransformation); icon32 = icon256.scaledToWidth(32, Qt::SmoothTransformation); icon64 = icon256.scaledToWidth(64, Qt::SmoothTransformation); @@ -107,12 +108,10 @@ MainWindow::MainWindow() { if (objectName().isEmpty()) { setObjectName(qsl("MainWindow")); } - resize(st::wndDefWidth, st::wndDefHeight); + resize(st::windowDefWidth, st::windowDefHeight); setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); - centralwidget = new QWidget(this); - centralwidget->setObjectName(qsl("centralwidget")); - setCentralWidget(centralwidget); + setCentralWidget(_body); QMetaObject::connectSlotsByName(this); @@ -170,6 +169,8 @@ void MainWindow::init() { psInitFrameless(); setWindowIcon(wndIcon); + _title = Platform::CreateTitleWidget(this); + Application::instance()->installEventFilter(this); connect(windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onStateChanged(Qt::WindowState))); connect(windowHandle(), SIGNAL(activeChanged()), this, SLOT(onWindowActiveChanged()), Qt::QueuedConnection); @@ -178,9 +179,9 @@ void MainWindow::init() { p.setColor(QPalette::Window, st::windowBg->c); setPalette(p); - title = new TitleWidget(this); - - psInitSize(); + setMinimumWidth(st::windowMinWidth); + setMinimumHeight(st::windowMinHeight); + psInitSize(); } void MainWindow::onWindowActiveChanged() { @@ -224,38 +225,28 @@ QWidget *MainWindow::filedialogParent() { void MainWindow::clearWidgets() { Ui::hideLayer(true); - if (_passcode) { - _passcode->hide(); - _passcode->deleteLater(); - _passcode = 0; - } - if (main) { - delete main; - main = nullptr; - } - if (intro) { - intro->stop_show(); - intro->hide(); - intro->deleteLater(); - intro->rpcClear(); - intro = 0; + _passcode.destroyDelayed(); + _main.destroy(); + if (_intro) { + _intro->stop_show(); + _intro->rpcClear(); + _intro.destroyDelayed(); } if (_mediaView) { hideMediaview(); _mediaView->rpcClear(); } - title->updateControlsVisibility(); updateGlobalMenu(); } QPixmap MainWindow::grabInner() { QPixmap result; - if (settings) { - result = myGrab(settings); - } else if (intro) { - result = myGrab(intro); - } else if (main) { - result = myGrab(main); + if (_settings) { + result = myGrab(_settings); + } else if (_intro) { + result = myGrab(_intro); + } else if (_main) { + result = myGrab(_main); } else if (_passcode) { result = myGrab(_passcode); } @@ -268,20 +259,17 @@ void MainWindow::clearPasscode() { QPixmap bg = grabInner(); _passcode->stop_show(); - _passcode->hide(); - _passcode->deleteLater(); - _passcode = 0; - if (intro) { - intro->animShow(bg, true); + _passcode.destroyDelayed(); + if (_intro) { + _intro->animShow(bg, true); } else { - main->animShow(bg, true); + _main->animShow(bg, true); } notifyUpdateAll(); - title->updateControlsVisibility(); updateGlobalMenu(); - if (auto main = App::main()) { - main->checkStartUrl(); + if (_main) { + _main->checkStartUrl(); } } @@ -290,16 +278,16 @@ void MainWindow::setupPasscode(bool anim) { if (_passcode) { _passcode->stop_show(); - _passcode->hide(); - _passcode->deleteLater(); + _passcode.destroyDelayed(); } - _passcode = new PasscodeWidget(this); - _passcode->move(0, st::titleHeight); - if (main) main->hide(); - if (settings) { - settings->deleteLater(); + _passcode.create(_body); + updateControlsGeometry(); + + if (_main) _main->hide(); + if (_settings) { + _settings.destroyDelayed(); } - if (intro) intro->hide(); + if (_intro) _intro->hide(); if (anim) { _passcode->animShow(bg); } else { @@ -307,7 +295,6 @@ void MainWindow::setupPasscode(bool anim) { } _shouldLockAt = 0; notifyUpdateAll(); - title->updateControlsVisibility(); updateGlobalMenu(); } @@ -335,7 +322,7 @@ void MainWindow::checkAutoLock() { void MainWindow::setupIntro(bool anim) { cSetContactsReceived(false); cSetDialogsReceived(false); - if (intro && !intro->isHidden() && !main) return; + if (_intro && !_intro->isHidden() && !_main) return; if (_mediaView) { _mediaView->clearData(); @@ -345,10 +332,11 @@ void MainWindow::setupIntro(bool anim) { QPixmap bg = anim ? grabInner() : QPixmap(); clearWidgets(); - intro = new IntroWidget(this); - intro->move(0, st::titleHeight); + _intro.create(_body); + updateControlsGeometry(); + if (anim) { - intro->animShow(bg); + _intro->animShow(bg); } fixOrder(); @@ -363,13 +351,13 @@ void MainWindow::setupIntro(bool anim) { } void MainWindow::serviceNotification(const QString &msg, const MTPMessageMedia &media, bool force) { - History *h = (main && App::userLoaded(ServiceUserId)) ? App::history(ServiceUserId) : 0; + History *h = (_main && App::userLoaded(ServiceUserId)) ? App::history(ServiceUserId) : 0; if (!h || (!force && h->isEmpty())) { _delayedServiceMsgs.push_back(DelayedServiceMsg(msg, media)); return sendServiceHistoryRequest(); } - main->serviceNotification(msg, media); + _main->serviceNotification(msg, media); } void MainWindow::showDelayedServiceMsgs() { @@ -381,32 +369,32 @@ void MainWindow::showDelayedServiceMsgs() { } void MainWindow::sendServiceHistoryRequest() { - if (!main || !main->started() || _delayedServiceMsgs.isEmpty() || _serviceHistoryRequest) return; + if (!_main || !_main->started() || _delayedServiceMsgs.isEmpty() || _serviceHistoryRequest) return; UserData *user = App::userLoaded(ServiceUserId); if (!user) { MTPDuser::Flags userFlags = MTPDuser::Flag::f_first_name | MTPDuser::Flag::f_phone | MTPDuser::Flag::f_status | MTPDuser::Flag::f_verified; user = App::feedUsers(MTP_vector(1, MTP_user(MTP_flags(userFlags), MTP_int(ServiceUserId), MTPlong(), MTP_string("Telegram"), MTPstring(), MTPstring(), MTP_string("42777"), MTP_userProfilePhotoEmpty(), MTP_userStatusRecently(), MTPint(), MTPstring(), MTPstring()))); } - _serviceHistoryRequest = MTP::send(MTPmessages_GetHistory(user->input, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(1), MTP_int(0), MTP_int(0)), main->rpcDone(&MainWidget::serviceHistoryDone), main->rpcFail(&MainWidget::serviceHistoryFail)); + _serviceHistoryRequest = MTP::send(MTPmessages_GetHistory(user->input, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(1), MTP_int(0), MTP_int(0)), _main->rpcDone(&MainWidget::serviceHistoryDone), _main->rpcFail(&MainWidget::serviceHistoryFail)); } void MainWindow::setupMain(bool anim, const MTPUser *self) { QPixmap bg = anim ? grabInner() : QPixmap(); clearWidgets(); - main = new MainWidget(this); - main->move(0, st::titleHeight); + _main.create(_body); + updateControlsGeometry(); + if (anim) { - main->animShow(bg); + _main->animShow(bg); } else { - main->activate(); + _main->activate(); } if (self) { - main->start(*self); + _main->start(*self); } else { - MTP::send(MTPusers_GetUsers(MTP_vector(1, MTP_inputUserSelf())), main->rpcDone(&MainWidget::startFull)); + MTP::send(MTPusers_GetUsers(MTP_vector(1, MTP_inputUserSelf())), _main->rpcDone(&MainWidget::startFull)); } - title->updateControlsVisibility(); fixOrder(); @@ -416,7 +404,6 @@ void MainWindow::setupMain(bool anim, const MTPUser *self) { void MainWindow::updateUnreadCounter() { if (!Global::started() || App::quitting()) return; - title->updateCounter(); psUpdateCounter(); } @@ -425,22 +412,22 @@ void MainWindow::showSettings() { if (isHidden()) showFromTray(); - if (settings) { + if (_settings) { Ui::hideSettingsAndLayer(); return; } - if (!layerBg) { - layerBg = new LayerStackWidget(this); + if (!_layerBg) { + _layerBg.create(_body); } - settings = new Settings::Widget(); - connect(settings, SIGNAL(destroyed(QObject*)), this, SLOT(onSettingsDestroyed(QObject*))); - layerBg->showSpecialLayer(settings); + _settings.create(this); + connect(_settings, SIGNAL(destroyed(QObject*)), this, SLOT(onSettingsDestroyed(QObject*))); + _layerBg->showSpecialLayer(_settings); } void MainWindow::ui_hideSettingsAndLayer(ShowLayerOptions options) { - if (layerBg) { - layerBg->onClose(); + if (_layerBg) { + _layerBg->onClose(); } } @@ -454,7 +441,7 @@ void MainWindow::mtpStateChanged(int32 dc, int32 state) { void MainWindow::updateConnectingStatus() { int32 state = MTP::dcstate(); if (state == MTP::ConnectingState || state == MTP::DisconnectedState || (state < 0 && state > -600)) { - if (main || getms() > 5000 || _connecting) { + if (_main || getms() > 5000 || _connecting) { showConnecting(lang(lng_connecting)); } } else if (state < 0) { @@ -466,11 +453,11 @@ void MainWindow::updateConnectingStatus() { } IntroWidget *MainWindow::introWidget() { - return intro; + return _intro; } MainWidget *MainWindow::mainWidget() { - return main; + return _main; } PasscodeWidget *MainWindow::passcodeWidget() { @@ -504,31 +491,29 @@ void MainWindow::showDocument(DocumentData *doc, HistoryItem *item) { void MainWindow::ui_showLayer(LayerWidget *box, ShowLayerOptions options) { if (box) { - if (!layerBg) { - layerBg = new LayerStackWidget(this); + if (!_layerBg) { + _layerBg.create(_body); } if (options.testFlag(KeepOtherLayers)) { if (options.testFlag(ShowAfterOtherLayers)) { - layerBg->prependLayer(box); + _layerBg->prependLayer(box); } else { - layerBg->appendLayer(box); + _layerBg->appendLayer(box); } } else { - layerBg->showLayer(box); + _layerBg->showLayer(box); } if (options.testFlag(ForceFastShowLayer)) { - layerBg->showFast(); + _layerBg->showFast(); } } else { - if (layerBg) { - if (settings) { - layerBg->onCloseLayers(); + if (_layerBg) { + if (_settings) { + _layerBg->onCloseLayers(); } else { - layerBg->onClose(); + _layerBg->onClose(); if (options.testFlag(ForceFastShowLayer)) { - layerBg->hide(); - layerBg->deleteLater(); - layerBg = nullptr; + _layerBg.destroyDelayed(); } } } @@ -537,7 +522,7 @@ void MainWindow::ui_showLayer(LayerWidget *box, ShowLayerOptions options) { } bool MainWindow::ui_isLayerShown() { - return !!layerBg; + return _layerBg != nullptr; } bool MainWindow::ui_isMediaViewShown() { @@ -547,7 +532,7 @@ bool MainWindow::ui_isMediaViewShown() { void MainWindow::ui_showMediaPreview(DocumentData *document) { if (!document || ((!document->isAnimation() || !document->loaded()) && !document->sticker())) return; if (!_mediaPreview) { - _mediaPreview = std_::make_unique(this); + _mediaPreview.create(_body); updateControlsGeometry(); } if (_mediaPreview->isHidden()) { @@ -559,7 +544,7 @@ void MainWindow::ui_showMediaPreview(DocumentData *document) { void MainWindow::ui_showMediaPreview(PhotoData *photo) { if (!photo) return; if (!_mediaPreview) { - _mediaPreview = std_::make_unique(this); + _mediaPreview.create(_body); updateControlsGeometry(); } if (_mediaPreview->isHidden()) { @@ -576,8 +561,8 @@ void MainWindow::ui_hideMediaPreview() { PeerData *MainWindow::ui_getPeerForMouseAction() { if (_mediaView && !_mediaView->isHidden()) { return _mediaView->ui_getPeerForMouseAction(); - } else if (main) { - return main->ui_getPeerForMouseAction(); + } else if (_main) { + return _main->ui_getPeerForMouseAction(); } return nullptr; } @@ -586,8 +571,7 @@ void MainWindow::showConnecting(const QString &text, const QString &reconnect) { if (_connecting) { _connecting->set(text, reconnect); } else { - _connecting.create(this, text, reconnect); - _connecting->show(); + _connecting.create(_body, text, reconnect); updateControlsGeometry(); fixOrder(); } @@ -602,33 +586,31 @@ void MainWindow::hideConnecting() { void MainWindow::themeUpdated(const Window::Theme::BackgroundUpdate &data) { using Type = Window::Theme::BackgroundUpdate::Type; if (data.type == Type::TestingTheme) { + if (_title) _title->update(); if (!_testingThemeWarning) { - _testingThemeWarning.create(this); + _testingThemeWarning.create(_body); _testingThemeWarning->setGeometry(rect()); _testingThemeWarning->setHiddenCallback([this] { _testingThemeWarning.destroyDelayed(); }); } _testingThemeWarning->showAnimated(); } else if (data.type == Type::RevertingTheme || data.type == Type::ApplyingTheme) { + if (_title) _title->update(); _testingThemeWarning->hideAnimated(); } } bool MainWindow::doWeReadServerHistory() const { - return isActive(false) && main && !Ui::isLayerShown() && main->doWeReadServerHistory(); + return isActive(false) && _main && !Ui::isLayerShown() && _main->doWeReadServerHistory(); } void MainWindow::checkHistoryActivation() { - if (main && MTP::authedId() && doWeReadServerHistory()) { - main->markActiveHistoryAsRead(); + if (_main && MTP::authedId() && doWeReadServerHistory()) { + _main->markActiveHistoryAsRead(); } } void MainWindow::layerHidden() { - if (layerBg) { - layerBg->hide(); - layerBg->deleteLater(); - } - layerBg = nullptr; + _layerBg.destroyDelayed(); hideMediaview(); setInnerFocus(); } @@ -658,85 +640,61 @@ void MainWindow::hideMediaview() { } bool MainWindow::contentOverlapped(const QRect &globalRect) { - if (main && main->contentOverlapped(globalRect)) return true; - if (layerBg && layerBg->contentOverlapped(globalRect)) return true; + if (_main && _main->contentOverlapped(globalRect)) return true; + if (_layerBg && _layerBg->contentOverlapped(globalRect)) return true; return false; } void MainWindow::setInnerFocus() { if (_testingThemeWarning) { _testingThemeWarning->setFocus(); - } else if (layerBg && layerBg->canSetFocus()) { - layerBg->setInnerFocus(); + } else if (_layerBg && _layerBg->canSetFocus()) { + _layerBg->setInnerFocus(); } else if (_passcode) { _passcode->setInnerFocus(); - } else if (settings) { - settings->setInnerFocus(); - } else if (main) { - main->setInnerFocus(); + } else if (_settings) { + _settings->setInnerFocus(); + } else if (_main) { + _main->setInnerFocus(); } } -QRect MainWindow::clientRect() const { - return QRect(0, st::titleHeight, width(), height() - st::titleHeight); -} - -QRect MainWindow::photoRect() const { - if (settings) { - return settings->geometry(); - } else if (main) { - QRect r(main->historyRect()); - r.moveLeft(r.left() + main->x()); - r.moveTop(r.top() + main->y()); - return r; - } - return QRect(0, 0, 0, 0); -} - -void MainWindow::wStartDrag(QMouseEvent *e) { - dragStart = e->globalPos() - frameGeometry().topLeft(); - dragging = true; -} - -void MainWindow::paintEvent(QPaintEvent *e) { -} - -HitTestType MainWindow::hitTest(const QPoint &p) const { +Window::HitTestResult MainWindow::hitTest(const QPoint &p) const { int x(p.x()), y(p.y()), w(width()), h(height()); const int32 raw = psResizeRowWidth(); if (!windowState().testFlag(Qt::WindowMaximized)) { if (y < raw) { if (x < raw) { - return HitTestType::TopLeft; + return Window::HitTestResult::TopLeft; } else if (x > w - raw - 1) { - return HitTestType::TopRight; + return Window::HitTestResult::TopRight; } - return HitTestType::Top; + return Window::HitTestResult::Top; } else if (y > h - raw - 1) { if (x < raw) { - return HitTestType::BottomLeft; + return Window::HitTestResult::BottomLeft; } else if (x > w - raw - 1) { - return HitTestType::BottomRight; + return Window::HitTestResult::BottomRight; } - return HitTestType::Bottom; + return Window::HitTestResult::Bottom; } else if (x < raw) { - return HitTestType::Left; + return Window::HitTestResult::Left; } else if (x > w - raw - 1) { - return HitTestType::Right; + return Window::HitTestResult::Right; } } - auto titleTest = title->hitTest(p - title->geometry().topLeft()); - if (titleTest != HitTestType::None) { + auto titleTest = _title ? _title->hitTest(p - _title->geometry().topLeft()) : Window::HitTestResult::None; + if (titleTest != Window::HitTestResult::None) { return titleTest; } else if (x >= 0 && y >= 0 && x < w && y < h) { - return HitTestType::Client; + return Window::HitTestResult::Client; } - return HitTestType::None; + return Window::HitTestResult::None; } QRect MainWindow::iconRect() const { - return title->iconRect(); + return _title ? _title->iconRect() : QRect(); } bool MainWindow::eventFilter(QObject *obj, QEvent *e) { @@ -749,9 +707,9 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *e) { break; case QEvent::MouseMove: - if (main && main->isIdle()) { + if (_main && _main->isIdle()) { psUserActionDone(); - main->checkIdleFinish(); + _main->checkIdleFinish(); } break; @@ -781,8 +739,8 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *e) { QString url = static_cast(e)->url().toEncoded().trimmed(); if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) { cSetStartUrl(url.mid(0, 8192)); - if (auto main = App::main()) { - main->checkStartUrl(); + if (_main) { + _main->checkStartUrl(); } } activate(); @@ -807,26 +765,6 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *e) { return Platform::MainWindow::eventFilter(obj, e); } -void MainWindow::mouseMoveEvent(QMouseEvent *e) { - if (e->buttons() & Qt::LeftButton) { - if (dragging) { - if (windowState().testFlag(Qt::WindowMaximized)) { - setWindowState(windowState() & ~Qt::WindowMaximized); - - dragStart = e->globalPos() - frameGeometry().topLeft(); - } else { - move(e->globalPos() - dragStart); - } - } - } else if (dragging) { - dragging = false; - } -} - -void MainWindow::mouseReleaseEvent(QMouseEvent *e) { - dragging = false; -} - bool MainWindow::minimizeToTray() { if (App::quitting() || !psHasTrayIcon()) return false; @@ -883,25 +821,25 @@ void MainWindow::updateTrayMenu(bool force) { void MainWindow::onShowAddContact() { if (isHidden()) showFromTray(); - if (main) main->showAddContact(); + if (_main) _main->showAddContact(); } void MainWindow::onShowNewGroup() { if (isHidden()) showFromTray(); - if (main) Ui::showLayer(new GroupInfoBox(CreatingGroupGroup, false), KeepOtherLayers); + if (_main) Ui::showLayer(new GroupInfoBox(CreatingGroupGroup, false), KeepOtherLayers); } void MainWindow::onShowNewChannel() { if (isHidden()) showFromTray(); - if (main) Ui::showLayer(new GroupInfoBox(CreatingGroupChannel, false), KeepOtherLayers); + if (_main) Ui::showLayer(new GroupInfoBox(CreatingGroupChannel, false), KeepOtherLayers); } void MainWindow::onLogout() { if (isHidden()) showFromTray(); - ConfirmBox *box = new ConfirmBox(lang(lng_sure_logout), lang(lng_settings_logout), st::attentionBoxButton); + auto box = new ConfirmBox(lang(lng_sure_logout), lang(lng_settings_logout), st::attentionBoxButton); connect(box, SIGNAL(confirmed()), this, SLOT(onLogoutSure())); Ui::showLayer(box); } @@ -930,46 +868,46 @@ void MainWindow::activate() { activateWindow(); updateIsActive(Global::OnlineFocusTimeout()); if (wasHidden) { - if (main) { - main->windowShown(); + if (_main) { + _main->windowShown(); } } } void MainWindow::noIntro(IntroWidget *was) { - if (was == intro) { - intro = nullptr; + if (was == _intro) { + _intro = nullptr; } } void MainWindow::onSettingsDestroyed(QObject *was) { - if (was == settings) { - settings = nullptr; + if (was == _settings) { + _settings = nullptr; } checkHistoryActivation(); } void MainWindow::noMain(MainWidget *was) { - if (was == main) { - main = 0; + if (was == _main) { + _main = nullptr; } } void MainWindow::noLayerStack(LayerStackWidget *was) { - if (was == layerBg) { - layerBg = nullptr; + if (was == _layerBg) { + _layerBg = nullptr; } } void MainWindow::layerFinishedHide(LayerStackWidget *was) { - if (was == layerBg) { + if (was == _layerBg) { QTimer::singleShot(0, this, SLOT(layerHidden())); } } void MainWindow::fixOrder() { - title->raise(); - if (layerBg) layerBg->raise(); + if (_title) _title->raise(); + if (_layerBg) _layerBg->raise(); if (_mediaPreview) _mediaPreview->raise(); if (_connecting) _connecting->raise(); if (_testingThemeWarning) _testingThemeWarning->raise(); @@ -1041,12 +979,8 @@ void MainWindow::closeEvent(QCloseEvent *e) { } } -TitleWidget *MainWindow::getTitle() { - return title; -} - void MainWindow::resizeEvent(QResizeEvent *e) { - if (!title) return; + if (!_title) return; Adaptive::Layout layout = Adaptive::OneColumnLayout; if (width() > st::adaptiveWideWidth) { @@ -1058,16 +992,25 @@ void MainWindow::resizeEvent(QResizeEvent *e) { Global::SetAdaptiveLayout(layout); Adaptive::Changed().notify(true); } + + auto bodyTop = 0; + if (_title) { + _title->setGeometry(0, bodyTop, width(), st::titleHeight); + bodyTop += _title->height(); + } + _body->setGeometry(0, bodyTop, width(), height() - bodyTop); updateControlsGeometry(); - emit resized(QSize(width(), height() - st::titleHeight)); } void MainWindow::updateControlsGeometry() { - title->setGeometry(0, 0, width(), st::titleHeight); - if (layerBg) layerBg->resize(width(), height()); - if (_mediaPreview) _mediaPreview->setGeometry(0, title->height(), width(), height() - title->height()); - if (_connecting) _connecting->setGeometry(0, height() - _connecting->height(), _connecting->width(), _connecting->height()); - if (_testingThemeWarning) _testingThemeWarning->setGeometry(rect()); + auto body = _body->rect(); + if (_passcode) _passcode->setGeometry(body); + if (_main) _main->setGeometry(body); + if (_intro) _intro->setGeometry(body); + if (_layerBg) _layerBg->setGeometry(body); + if (_mediaPreview) _mediaPreview->setGeometry(body); + if (_connecting) _connecting->moveToLeft(0, body.height() - _connecting->height()); + if (_testingThemeWarning) _testingThemeWarning->setGeometry(body); } MainWindow::TempDirState MainWindow::tempDirState() { @@ -1156,8 +1099,8 @@ void MainWindow::notifySchedule(History *history, HistoryItem *item) { int delay = item->Has() ? 500 : 100, t = unixtime(); uint64 ms = getms(true); - bool isOnline = main->lastWasOnline(), otherNotOld = ((cOtherOnline() * uint64(1000)) + Global::OnlineCloudTimeout() > t * uint64(1000)); - bool otherLaterThanMe = (cOtherOnline() * uint64(1000) + (ms - main->lastSetOnline()) > t * uint64(1000)); + bool isOnline = _main->lastWasOnline(), otherNotOld = ((cOtherOnline() * uint64(1000)) + Global::OnlineCloudTimeout() > t * uint64(1000)); + bool otherLaterThanMe = (cOtherOnline() * uint64(1000) + (ms - _main->lastSetOnline()) > t * uint64(1000)); if (!isOnline && otherNotOld && otherLaterThanMe) { delay = Global::NotifyCloudDelay(); } else if (cOtherOnline() >= t) { @@ -1528,13 +1471,13 @@ void MainWindow::sendPaths() { if (App::passcoded()) return; hideMediaview(); Ui::hideSettingsAndLayer(); - if (main) { - main->activate(); + if (_main) { + _main->activate(); } } void MainWindow::mediaOverviewUpdated(PeerData *peer, MediaOverviewType type) { - if (main) main->mediaOverviewUpdated(peer, type); + if (_main) _main->mediaOverviewUpdated(peer, type); if (_mediaView && !_mediaView->isHidden()) { _mediaView->mediaOverviewUpdated(peer, type); } @@ -1552,7 +1495,7 @@ void MainWindow::documentUpdated(DocumentData *doc) { } void MainWindow::changingMsgId(HistoryItem *row, MsgId newId) { - if (main) main->changingMsgId(row, newId); + if (_main) _main->changingMsgId(row, newId); if (!_mediaView || _mediaView->isHidden()) return; _mediaView->changingMsgId(row, newId); } @@ -1565,7 +1508,7 @@ bool MainWindow::isActive(bool cached) const { void MainWindow::updateIsActive(int timeout) { if (timeout) return _isActiveTimer.start(timeout); _isActive = isActive(false); - if (main) main->updateOnline(); + if (_main) _main->updateOnline(); } MainWindow::~MainWindow() { @@ -1578,9 +1521,9 @@ MainWindow::~MainWindow() { delete _mediaView; delete trayIcon; delete trayIconMenu; - delete intro; - delete main; - delete settings; + delete _intro; + delete _main; + delete _settings; } PreLaunchWindow *PreLaunchWindowInstance = 0; @@ -2000,11 +1943,11 @@ void LastCrashedWindow::addReportFieldPart(const QLatin1String &name, const QLat void LastCrashedWindow::onSendReport() { if (_checkReply) { _checkReply->deleteLater(); - _checkReply = 0; + _checkReply = nullptr; } if (_sendReply) { _sendReply->deleteLater(); - _sendReply = 0; + _sendReply = nullptr; } App::setProxySettings(_sendManager); @@ -2034,7 +1977,7 @@ void LastCrashedWindow::onCheckingFinished() { QByteArray result = _checkReply->readAll().trimmed(); _checkReply->deleteLater(); - _checkReply = 0; + _checkReply = nullptr; LOG(("Crash report check for sending done, result: %1").arg(QString::fromUtf8(result))); @@ -2057,7 +2000,7 @@ void LastCrashedWindow::onCheckingFinished() { return; } - QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + auto multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); addReportFieldPart(qstr("platform"), qstr("Platform:"), multipart); addReportFieldPart(qstr("version"), qstr("Version:"), multipart); @@ -2454,11 +2397,11 @@ void LastCrashedWindow::onSendingError(QNetworkReply::NetworkError e) { _sendingState = SendingFail; if (_checkReply) { _checkReply->deleteLater(); - _checkReply = 0; + _checkReply = nullptr; } if (_sendReply) { _sendReply->deleteLater(); - _sendReply = 0; + _sendReply = nullptr; } updateControls(); } @@ -2469,7 +2412,7 @@ void LastCrashedWindow::onSendingFinished() { LOG(("Crash report sending done, result: %1").arg(QString::fromUtf8(result))); _sendReply->deleteLater(); - _sendReply = 0; + _sendReply = nullptr; _pleaseSendReport.setText(qsl("Thank you for your report!")); _sendingState = SendingDone; updateControls(); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index a51423e7f..7578e6a7d 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -20,14 +20,13 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "title.h" #include "pspecific.h" #include "ui/effects/rect_shadow.h" #include "platform/platform_main_window.h" +#include "window/window_title.h" #include "core/single_timer.h" class MediaView; -class TitleWidget; class PasscodeWidget; class IntroWidget; class MainWidget; @@ -49,13 +48,15 @@ class WarningWidget; } // namespace Theme } // namespace Window -class ConnectingWidget : public QWidget { +class ConnectingWidget : public TWidget { Q_OBJECT public: ConnectingWidget(QWidget *parent, const QString &text, const QString &reconnect); void set(const QString &text, const QString &reconnect); - void paintEvent(QPaintEvent *e); + +protected: + void paintEvent(QPaintEvent *e) override; public slots: void onReconnect(); @@ -82,20 +83,9 @@ public: QWidget *filedialogParent(); - bool eventFilter(QObject *obj, QEvent *evt); - void inactivePress(bool inactive); bool inactivePress() const; - void wStartDrag(QMouseEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void closeEvent(QCloseEvent *e); - - void paintEvent(QPaintEvent *e); - - void resizeEvent(QResizeEvent *e); - void setupPasscode(bool anim); void clearPasscode(); void checkAutoLockIn(int msec); @@ -107,14 +97,9 @@ public: void mtpStateChanged(int32 dc, int32 state); - TitleWidget *getTitle(); - - HitTestType hitTest(const QPoint &p) const; + Window::HitTestResult hitTest(const QPoint &p) const; QRect iconRect() const; - QRect clientRect() const; - QRect photoRect() const; - IntroWidget *introWidget(); MainWidget *mainWidget(); PasscodeWidget *passcodeWidget(); @@ -184,6 +169,11 @@ public: void ui_hideMediaPreview(); PeerData *ui_getPeerForMouseAction(); +protected: + bool eventFilter(QObject *o, QEvent *e) override; + void closeEvent(QCloseEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + public slots: void updateIsActive(int timeout = 0); @@ -220,7 +210,6 @@ public slots: void app_activateClickHandler(ClickHandlerPtr handler, Qt::MouseButton button); signals: - void resized(const QSize &size); void tempDirCleared(int task); void tempDirClearFailed(int task); void newAuthorization(); @@ -250,13 +239,14 @@ private: QVector _delayedServiceMsgs; mtpRequestId _serviceHistoryRequest = 0; - TitleWidget *title = nullptr; - PasscodeWidget *_passcode = nullptr; - IntroWidget *intro = nullptr; - MainWidget *main = nullptr; - ChildWidget settings = { nullptr }; - ChildWidget layerBg = { nullptr }; - std_::unique_ptr _mediaPreview; + Window::TitleWidget *_title = nullptr; + ChildWidget _body; + ChildWidget _passcode = { nullptr }; + ChildWidget _intro = { nullptr }; + ChildWidget _main = { nullptr }; + ChildWidget _settings = { nullptr }; + ChildWidget _layerBg = { nullptr }; + ChildWidget _mediaPreview = { nullptr }; QTimer _isActiveTimer; bool _isActive = false; @@ -268,9 +258,6 @@ private: void clearWidgets(); - bool dragging = false; - QPoint dragStart; - bool _inactivePress = false; QTimer _inactiveTimer; diff --git a/Telegram/SourceFiles/media/player/media_player.style b/Telegram/SourceFiles/media/player/media_player.style index fd7d12a42..85e9d2aa6 100644 --- a/Telegram/SourceFiles/media/player/media_player.style +++ b/Telegram/SourceFiles/media/player/media_player.style @@ -144,22 +144,8 @@ mediaPlayerPlayback: FilledSlider { duration: 150; } -mediaPlayerTitleButtonSize: size(titleHeight, titleHeight); -mediaPlayerTitleButtonInner: size(25px, 25px); -mediaPlayerTitleButtonInnerBg: #49708f; mediaPlayerButtonTransformDuration: 200; -mediaPlayerTitleButton: MediaPlayerButton { - playPosition: point(10px, 7px); - playOuter: size(29px, 25px); - pausePosition: point(8px, 8px); - pauseOuter: size(25px, 25px); - pauseStroke: 3px; - cancelPosition: point(8px, 8px); - cancelOuter: size(25px, 25px); - cancelStroke: 2px; -} - mediaPlayerPanelButton: MediaPlayerButton { playPosition: point(3px, 0px); playOuter: size(22px, 18px); diff --git a/Telegram/SourceFiles/media/player/media_player_title_button.cpp b/Telegram/SourceFiles/media/player/media_player_title_button.cpp deleted file mode 100644 index 2903a10af..000000000 --- a/Telegram/SourceFiles/media/player/media_player_title_button.cpp +++ /dev/null @@ -1,122 +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 "media/player/media_player_title_button.h" - -#include "media/player/media_player_button.h" -#include "media/media_audio.h" -#include "media/player/media_player_instance.h" -#include "shortcuts.h" - -namespace Media { -namespace Player { - -using State = PlayButtonLayout::State; - -TitleButton::TitleButton(QWidget *parent) : Button(parent) -, _layout(std_::make_unique(st::mediaPlayerTitleButton, [this] { update(); })) { - setAttribute(Qt::WA_OpaquePaintEvent); - resize(st::mediaPlayerTitleButtonSize); - - setClickedCallback([this]() { - if (exists()) { - instance()->playPauseCancelClicked(); - } - }); - - if (exists()) { - subscribe(instance()->updatedNotifier(), [this](const UpdatedEvent &e) { - updatePauseState(); - }); - updatePauseState(); - _layout->finishTransform(); - } -} - -void TitleButton::updatePauseState() { - AudioMsgId playing; - auto playbackState = audioPlayer()->currentState(&playing, AudioMsgId::Type::Song); - auto stopped = ((playbackState.state & AudioPlayerStoppedMask) || playbackState.state == AudioPlayerFinishing); - auto showPause = !stopped && (playbackState.state == AudioPlayerPlaying || playbackState.state == AudioPlayerResuming || playbackState.state == AudioPlayerStarting); - if (exists() && instance()->isSeeking()) { - showPause = true; - } - auto state = [audio = playing.audio(), showPause] { - if (audio && audio->loading()) { - return State::Cancel; - } else if (showPause) { - return State::Pause; - } - return State::Play; - }; - _layout->setState(state()); -} - -void TitleButton::paintEvent(QPaintEvent *e) { - Painter p(this); - p.fillRect(rect(), st::titleBg); - - p.setBrush(st::mediaPlayerTitleButtonInnerBg); - p.setPen(Qt::NoPen); - - p.setRenderHint(QPainter::HighQualityAntialiasing, true); - p.drawEllipse((width() - st::mediaPlayerTitleButtonInner.width()) / 2, (height() - st::mediaPlayerTitleButtonInner.height()) / 2, st::mediaPlayerTitleButtonInner.width(), st::mediaPlayerTitleButtonInner.height()); - p.setRenderHint(QPainter::HighQualityAntialiasing, false); - - paintIcon(p); -} - -void TitleButton::onStateChanged(int oldState, ButtonStateChangeSource source) { - if ((oldState & StateOver) != (_state & StateOver)) { - auto over = (_state & StateOver); - _iconFg.start([this] { update(); }, over ? st::titleButtonFg->c : st::titleButtonActiveFg->c, over ? st::titleButtonActiveFg->c : st::titleButtonFg->c, st::titleButtonDuration); - } -} - -void TitleButton::paintIcon(Painter &p) { - auto over = (_state & StateOver); - auto icon = _iconFg.current(getms(), over ? st::titleButtonActiveFg->c : st::titleButtonFg->c); - - auto left = (width() - st::mediaPlayerTitleButtonInner.width()) / 2; - auto top = (height() - st::mediaPlayerTitleButtonInner.height()) / 2; - p.translate(left, top); - - _layout->paint(p, icon); -} - -void TitleButton::enterEvent(QEvent *e) { - if (exists()) { - instance()->titleButtonOver().notify(true, true); - } - return Button::enterEvent(e); -} - -void TitleButton::leaveEvent(QEvent *e) { - if (exists()) { - instance()->titleButtonOver().notify(false, true); - } - return Button::leaveEvent(e); -} - -TitleButton::~TitleButton() = default; - -} // namespace Player -} // namespace Media diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index e9fded51f..5597a4509 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -82,7 +82,7 @@ Widget::Widget(QWidget *parent) : TWidget(parent) , _playback(new Ui::FilledSlider(this, st::mediaPlayerPlayback)) { setAttribute(Qt::WA_OpaquePaintEvent); setMouseTracking(true); - resize(st::wndMinWidth, st::mediaPlayerHeight + st::lineWidth); + resize(width(), st::mediaPlayerHeight + st::lineWidth); _nameLabel->setAttribute(Qt::WA_TransparentForMouseEvents); _timeLabel->setAttribute(Qt::WA_TransparentForMouseEvents); diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index 063357479..3a952395f 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "styles/style_overview.h" #include "styles/style_dialogs.h" +#include "styles/style_window.h" #include "boxes/addcontactbox.h" #include "boxes/confirmbox.h" #include "boxes/photocropbox.h" @@ -56,13 +57,13 @@ OverviewInner::OverviewInner(OverviewWidget *overview, ScrollArea *scroll, PeerD , _search(this, st::dlgFilter, lang(lng_dlg_filter)) , _cancelSearch(this, st::dialogsCancelSearch) , _itemsToBeLoaded(LinksOverviewPerPage * 2) -, _width(st::wndMinWidth) { +, _width(st::windowMinWidth) { subscribe(FileDownload::ImageLoaded(), [this] { update(); }); subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) { itemRemoved(item); }); - resize(_width, st::wndMinHeight); + resize(_width, st::windowMinHeight); App::contextItem(0); diff --git a/Telegram/SourceFiles/passcodewidget.cpp b/Telegram/SourceFiles/passcodewidget.cpp index 275857ad6..a31ed5301 100644 --- a/Telegram/SourceFiles/passcodewidget.cpp +++ b/Telegram/SourceFiles/passcodewidget.cpp @@ -33,9 +33,6 @@ PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent) , _passcode(this, st::passcodeInput) , _submit(this, lang(lng_passcode_submit), st::passcodeSubmit) , _logout(this, lang(lng_passcode_logout)) { - setGeometry(QRect(0, st::titleHeight, App::wnd()->width(), App::wnd()->height() - st::titleHeight)); - connect(App::wnd(), SIGNAL(resized(const QSize&)), this, SLOT(onParentResize(const QSize&))); - _passcode.setEchoMode(QLineEdit::Password); connect(&_submit, SIGNAL(clicked()), this, SLOT(onSubmit())); @@ -48,10 +45,6 @@ PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent) _passcode.setFocus(); } -void PasscodeWidget::onParentResize(const QSize &newSize) { - resize(newSize); -} - void PasscodeWidget::onSubmit() { if (_passcode.text().isEmpty()) { _passcode.notaBene(); diff --git a/Telegram/SourceFiles/passcodewidget.h b/Telegram/SourceFiles/passcodewidget.h index effd6c68f..3f7e6d36a 100644 --- a/Telegram/SourceFiles/passcodewidget.h +++ b/Telegram/SourceFiles/passcodewidget.h @@ -24,13 +24,8 @@ class PasscodeWidget : public TWidget { Q_OBJECT public: - PasscodeWidget(QWidget *parent); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mousePressEvent(QMouseEvent *e); - void keyPressEvent(QKeyEvent *e); void setInnerFocus(); void animShow(const QPixmap &bgAnimCache, bool back = false); @@ -39,15 +34,18 @@ public: ~PasscodeWidget(); -public slots: +protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; - void onParentResize(const QSize &newSize); +public slots: void onError(); void onChanged(); void onSubmit(); private: - void showAll(); void hideAll(); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 5d3916610..167d9202f 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -21,6 +21,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include "platform/linux/main_window_linux.h" +#include "styles/style_window.h" #include "platform/linux/linux_libs.h" #include "platform/platform_notifications_manager.h" #include "mainwindow.h" @@ -205,9 +206,6 @@ void MainWindow::psStatusIconCheck() { void MainWindow::psShowTrayMenu() { } -void MainWindow::psRefreshTaskbarIcon() { -} - void MainWindow::psTrayMenuUpdated() { if (noQtTrayIcon && (useAppIndicator || useStatusIcon)) { const QList &actions = trayIconMenu->actions(); @@ -434,13 +432,10 @@ void MainWindow::LibsLoaded() { } void MainWindow::psInitSize() { - setMinimumWidth(st::wndMinWidth); - setMinimumHeight(st::wndMinHeight); - TWindowPos pos(cWindowPos()); QRect avail(QDesktopWidget().availableGeometry()); bool maximized = false; - QRect geom(avail.x() + (avail.width() - st::wndDefWidth) / 2, avail.y() + (avail.height() - st::wndDefHeight) / 2, st::wndDefWidth, st::wndDefHeight); + QRect geom(avail.x() + (avail.width() - st::windowDefWidth) / 2, avail.y() + (avail.height() - st::windowDefHeight) / 2, st::windowDefWidth, st::windowDefHeight); if (pos.w && pos.h) { QList screens = Application::screens(); for (QList::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) { @@ -448,7 +443,7 @@ void MainWindow::psInitSize() { if (pos.moncrc == hashCrc32(name.constData(), name.size())) { QRect screen((*i)->geometry()); int32 w = screen.width(), h = screen.height(); - if (w >= st::wndMinWidth && h >= st::wndMinHeight) { + if (w >= st::windowMinWidth && h >= st::windowMinHeight) { if (pos.w > w) pos.w = w; if (pos.h > h) pos.h = h; pos.x += screen.x(); @@ -649,10 +644,6 @@ void MainWindow::psFirstShow() { posInited = true; } -bool MainWindow::psHandleTitle() { - return false; -} - void MainWindow::psInitSysMenu() { } diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index 57f788115..63551b249 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -43,14 +43,13 @@ public: void psUpdateMargins(); void psUpdatedPosition(); - bool psHandleTitle(); - void psFlash(); void psNotifySettingGot(); void psUpdateWorkmode(); - void psRefreshTaskbarIcon(); + void psRefreshTaskbarIcon() { + } bool psPosInited() const { return posInited; diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h index c1f28d40d..c8e0583e2 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h @@ -27,19 +27,6 @@ namespace Notifications { inline void defaultNotificationShown(QWidget *widget) { } -inline bool skipAudio() { - return false; -} -inline bool skipToast() { - return false; -} - -class Manager; - -void start(); -Manager *manager(); -bool supported(); -void finish(); class Manager : public Window::Notifications::NativeManager { public: diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index fdbb7bd01..e82f2b27d 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -51,13 +51,12 @@ public: void psUpdateMargins(); void psUpdatedPosition(); - bool psHandleTitle(); - void psFlash(); void psUpdateWorkmode(); - void psRefreshTaskbarIcon(); + void psRefreshTaskbarIcon() { + } bool psPosInited() const { return posInited; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 64229f4bb..0de7a6a3f 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -18,6 +18,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include "platform/mac/main_window_mac.h" +#include "styles/style_window.h" #include "mainwindow.h" #include "mainwidget.h" #include "application.h" @@ -25,6 +26,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "localstorage.h" #include "window/notifications_manager_default.h" #include "platform/mac/notifications_manager_mac.h" +#include "boxes/contactsbox.h" +#include "boxes/aboutbox.h" #include "lang.h" @@ -90,9 +93,6 @@ QImage MainWindow::psTrayIcon(bool selected) const { void MainWindow::psShowTrayMenu() { } -void MainWindow::psRefreshTaskbarIcon() { -} - void MainWindow::psTrayMenuUpdated() { } @@ -191,13 +191,10 @@ void MainWindow::psUpdateCounter() { } void MainWindow::psInitSize() { - setMinimumWidth(st::wndMinWidth); - setMinimumHeight(st::wndMinHeight); - TWindowPos pos(cWindowPos()); QRect avail(QDesktopWidget().availableGeometry()); bool maximized = false; - QRect geom(avail.x() + (avail.width() - st::wndDefWidth) / 2, avail.y() + (avail.height() - st::wndDefHeight) / 2, st::wndDefWidth, st::wndDefHeight); + QRect geom(avail.x() + (avail.width() - st::windowDefWidth) / 2, avail.y() + (avail.height() - st::windowDefHeight) / 2, st::windowDefWidth, st::windowDefHeight); if (pos.w && pos.h) { QList screens = Application::screens(); for (QList::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) { @@ -205,7 +202,7 @@ void MainWindow::psInitSize() { if (pos.moncrc == hashCrc32(name.constData(), name.size())) { QRect screen((*i)->geometry()); int32 w = screen.width(), h = screen.height(); - if (w >= st::wndMinWidth && h >= st::wndMinHeight) { + if (w >= st::windowMinWidth && h >= st::windowMinHeight) { if (pos.w > w) pos.w = w; if (pos.h > h) pos.h = h; pos.x += screen.x(); @@ -302,8 +299,14 @@ void MainWindow::psFirstShow() { posInited = true; // init global menu - QMenu *main = psMainMenu.addMenu(qsl("Telegram")); - main->addAction(lng_mac_menu_about_telegram(lt_telegram, qsl("Telegram")), App::wnd()->getTitle(), SLOT(onAbout()))->setMenuRole(QAction::AboutQtRole); + auto main = psMainMenu.addMenu(qsl("Telegram")); + auto about = main->addAction(lng_mac_menu_about_telegram(lt_telegram, qsl("Telegram"))); + connect(about, SIGNAL(triggered()), base::lambda_slot(about, [] { + if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); + Ui::showLayer(new AboutBox()); + }), SLOT(action())); + about->setMenuRole(QAction::AboutQtRole); + main->addSeparator(); QAction *prefs = main->addAction(lang(lng_mac_menu_preferences), App::wnd(), SLOT(showSettings()), QKeySequence(Qt::ControlModifier | Qt::Key_Comma)); prefs->setMenuRole(QAction::PreferencesRole); @@ -323,7 +326,13 @@ void MainWindow::psFirstShow() { psSelectAll = edit->addAction(lang(lng_mac_menu_select_all), this, SLOT(psMacSelectAll()), QKeySequence::SelectAll); QMenu *window = psMainMenu.addMenu(lang(lng_mac_menu_window)); - psContacts = window->addAction(lang(lng_mac_menu_contacts), App::wnd()->getTitle(), SLOT(onContacts())); + psContacts = window->addAction(lang(lng_mac_menu_contacts)); + connect(psContacts, SIGNAL(triggered()), base::lambda_slot(psContacts, [] { + if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); + + if (!App::self()) return; + Ui::showLayer(new ContactsBox()); + }, SLOT(action())); psAddContact = window->addAction(lang(lng_mac_menu_add_contact), App::wnd(), SLOT(onShowAddContact())); window->addSeparator(); psNewGroup = window->addAction(lang(lng_mac_menu_new_group), App::wnd(), SLOT(onShowNewGroup())); @@ -379,10 +388,6 @@ void MainWindow::psMacSelectAll() { _sendKeySequence(Qt::Key_A, Qt::ControlModifier); } -bool MainWindow::psHandleTitle() { - return false; -} - void MainWindow::psInitSysMenu() { } diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h index a7fd87922..631021944 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.h @@ -25,20 +25,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Platform { namespace Notifications { -void defaultNotificationShown(QWidget *widget); -inline bool skipAudio() { - return false; -} -inline bool skipToast() { - return false; -} - -class Manager; - -void start(); -Manager *manager(); -void finish(); - class Manager : public Window::Notifications::NativeManager { public: Manager(); diff --git a/Telegram/SourceFiles/platform/platform_file_dialog.h b/Telegram/SourceFiles/platform/platform_file_dialog.h index 29bd064b8..1a1a6c554 100644 --- a/Telegram/SourceFiles/platform/platform_file_dialog.h +++ b/Telegram/SourceFiles/platform/platform_file_dialog.h @@ -22,20 +22,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/filedialog.h" -#ifdef Q_OS_MAC -namespace Platform { -namespace FileDialog { -inline bool Supported() { - return false; -} -inline bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile) { - return false; -} -} // namespace FileDialog -} // namespace Platform -#elif defined Q_OS_LINUX // Q_OS_MAC +#if defined Q_OS_LINUX #include "platform/linux/file_dialog_linux.h" -#elif defined Q_OS_WINRT // Q_OS_MAC || Q_OS_LINUX +#else // Q_OS_LINUX namespace Platform { namespace FileDialog { inline bool Supported() { @@ -46,15 +35,4 @@ inline bool Get(QStringList &files, QByteArray &remoteContent, const QString &ca } } // namespace FileDialog } // namespace Platform -#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT -namespace Platform { -namespace FileDialog { -inline bool Supported() { - return false; -} -inline bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, ::FileDialog::internal::Type type, QString startFile) { - return false; -} -} // namespace FileDialog -} // namespace Platform -#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || Q_OS_WIN +#endif // else for Q_OS_LINUX diff --git a/Telegram/SourceFiles/platform/platform_notifications_manager.h b/Telegram/SourceFiles/platform/platform_notifications_manager.h index 81c10ae29..ec7682ef2 100644 --- a/Telegram/SourceFiles/platform/platform_notifications_manager.h +++ b/Telegram/SourceFiles/platform/platform_notifications_manager.h @@ -20,6 +20,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once +// Platform module must define a Platform::Notifications::Manager class. +// It should be Window::Notifications::Manager or its derivative. #ifdef Q_OS_MAC #include "platform/mac/notifications_manager_mac.h" #elif defined Q_OS_LINUX // Q_OS_MAC @@ -29,3 +31,19 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT #include "platform/win/notifications_manager_win.h" #endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || Q_OS_WIN + +// Platform-independent API. +namespace Platform { +namespace Notifications { + +void defaultNotificationShown(QWidget *widget); +bool skipAudio(); +bool skipToast(); + +void start(); +Manager *manager(); +bool supported(); +void finish(); + +} // namespace Notifications +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/platform_window_title.h b/Telegram/SourceFiles/platform/platform_window_title.h new file mode 100644 index 000000000..b124c469f --- /dev/null +++ b/Telegram/SourceFiles/platform/platform_window_title.h @@ -0,0 +1,35 @@ +/* +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 "window/window_title.h" + +#if defined Q_OS_WIN +#include "platform/win/window_title_win.h" +#else // Q_OS_WIN +namespace Platform { + +inline Window::TitleWidget *CreateTitleWidget() { + return nullptr; +} + +} // namespace Platform +#endif // else for Q_OS_WIN diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index bf500168a..b44401412 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -21,6 +21,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include "platform/win/main_window_win.h" +#include "styles/style_window.h" #include "platform/platform_notifications_manager.h" #include "platform/win/windows_dlls.h" #include "window/notifications_manager.h" @@ -140,13 +141,13 @@ public: } bool init(QColor c) { - _fullsize = st::wndShadow.width(); - _shift = st::wndShadowShift; + _fullsize = st::windowShadow.width(); + _shift = st::windowShadowShift; QImage cornersImage(_fullsize, _fullsize, QImage::Format_ARGB32_Premultiplied); { Painter p(&cornersImage); p.setCompositionMode(QPainter::CompositionMode_Source); - st::wndShadow.paint(p, 0, 0, _fullsize); + st::windowShadow.paint(p, 0, 0, _fullsize); } if (rtl()) cornersImage = cornersImage.mirrored(true, false); @@ -191,9 +192,9 @@ public: QRect avail(Sandbox::availableGeometry()); max_w = avail.width(); - if (max_w < st::wndMinWidth) max_w = st::wndMinWidth; + accumulate_max(max_w, st::windowMinWidth); max_h = avail.height(); - if (max_h < st::wndMinHeight) max_h = st::wndMinHeight; + accumulate_max(max_h, st::windowMinHeight); HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0); HWND hwnd = App::wnd() ? App::wnd()->psHwnd() : 0; @@ -645,7 +646,7 @@ void MainWindow::psShowTrayMenu() { void MainWindow::psRefreshTaskbarIcon() { QWidget *w = new QWidget(this); - w->setWindowFlags(::operator|(Qt::Tool, Qt::FramelessWindowHint)); + w->setWindowFlags(static_cast(Qt::Tool) | Qt::FramelessWindowHint); w->setGeometry(x() + 1, y() + 1, 1, 1); QPalette p(w->palette()); p.setColor(QPalette::Background, st::titleBg->c); @@ -776,20 +777,17 @@ BOOL CALLBACK _monitorEnumProc( } // namespace void MainWindow::psInitSize() { - setMinimumWidth(st::wndMinWidth); - setMinimumHeight(st::wndMinHeight); - TWindowPos pos(cWindowPos()); QRect avail(Sandbox::availableGeometry()); bool maximized = false; - QRect geom(avail.x() + (avail.width() - st::wndDefWidth) / 2, avail.y() + (avail.height() - st::wndDefHeight) / 2, st::wndDefWidth, st::wndDefHeight); + QRect geom(avail.x() + (avail.width() - st::windowDefWidth) / 2, avail.y() + (avail.height() - st::windowDefHeight) / 2, st::windowDefWidth, st::windowDefHeight); if (pos.w && pos.h) { if (pos.y < 0) pos.y = 0; enumMonitor = 0; EnumDisplayMonitors(0, 0, &_monitorEnumProc, pos.moncrc); if (enumMonitor) { int32 w = enumMonitorWork.right - enumMonitorWork.left, h = enumMonitorWork.bottom - enumMonitorWork.top; - if (w >= st::wndMinWidth && h >= st::wndMinHeight) { + if (w >= st::windowMinWidth && h >= st::windowMinHeight) { if (pos.w > w) pos.w = w; if (pos.h > h) pos.h = h; pos.x += enumMonitorWork.left; @@ -853,7 +851,7 @@ void MainWindow::psSavePosition(Qt::WindowState state) { curPos.moncrc = hashCrc32(info.szDevice, sizeof(info.szDevice)); } - if (curPos.w >= st::wndMinWidth && curPos.h >= st::wndMinHeight) { + if (curPos.w >= st::windowMinWidth && curPos.h >= st::windowMinHeight) { if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) { cSetWindowPos(curPos); Local::writeSettings(); @@ -902,10 +900,6 @@ void MainWindow::psFirstShow() { } } -bool MainWindow::psHandleTitle() { - return true; -} - void MainWindow::psInitSysMenu() { Qt::WindowStates states = windowState(); ps_menu = GetSystemMenu(ps_hWnd, FALSE); diff --git a/Telegram/SourceFiles/platform/win/main_window_win.h b/Telegram/SourceFiles/platform/win/main_window_win.h index 73658bc50..0aad21bc1 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.h +++ b/Telegram/SourceFiles/platform/win/main_window_win.h @@ -50,8 +50,6 @@ public: void psUpdateMargins(); void psUpdatedPosition(); - bool psHandleTitle(); - void psFlash(); void psNotifySettingGot(); diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.h b/Telegram/SourceFiles/platform/win/notifications_manager_win.h index 403e4e00a..ce5316409 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.h +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.h @@ -27,15 +27,6 @@ namespace Notifications { inline void defaultNotificationShown(QWidget *widget) { } -bool skipAudio(); -bool skipToast(); - -class Manager; - -void start(); -Manager *manager(); -bool supported(); -void finish(); class Manager : public Window::Notifications::NativeManager { public: diff --git a/Telegram/SourceFiles/platform/win/window_title_win.cpp b/Telegram/SourceFiles/platform/win/window_title_win.cpp new file mode 100644 index 000000000..61c348fd5 --- /dev/null +++ b/Telegram/SourceFiles/platform/win/window_title_win.cpp @@ -0,0 +1,106 @@ +/* +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 "platform/win/window_title_win.h" + +#include "ui/buttons/icon_button.h" +#include "styles/style_window.h" + +namespace Platform { + +TitleWidget::TitleWidget(QWidget *parent) : Window::TitleWidget(parent) +, _minimize(this, st::titleButtonMinimize) +, _maximizeRestore(this, st::titleButtonMaximize) +, _close(this, st::titleButtonClose) +, _maximized(parent->window()->windowState() & Qt::WindowMaximized) { + _minimize->setClickedCallback([this]() { + window()->setWindowState(Qt::WindowMinimized); + _minimize->clearState(); + }); + _maximizeRestore->setClickedCallback([this]() { + window()->setWindowState(_maximized ? Qt::WindowNoState : Qt::WindowMaximized); + _maximizeRestore->clearState(); + }); + _close->setClickedCallback([this]() { + window()->close(); + _close->clearState(); + }); + + setAttribute(Qt::WA_OpaquePaintEvent); + updateMaximizeRestoreButton(); + + onWindowStateChanged(); + + connect(parent->window()->windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onWindowStateChanged(Qt::WindowState))); +} + +void TitleWidget::paintEvent(QPaintEvent *e) { + Painter(this).fillRect(rect(), st::titleBg); +} + +void TitleWidget::updateControlsPosition() { + auto right = 0; + _close->moveToRight(right, 0); right += _close->width(); + _maximizeRestore->moveToRight(right, 0); right += _maximizeRestore->width(); + _minimize->moveToRight(right, 0); +} + +void TitleWidget::resizeEvent(QResizeEvent *e) { + updateControlsPosition(); +} + +void TitleWidget::updateControlsVisibility() { + updateControlsPosition(); + update(); +} + +void TitleWidget::onWindowStateChanged(Qt::WindowState state) { + if (state == Qt::WindowMinimized) return; + + auto maximized = (state == Qt::WindowMaximized); + if (_maximized != maximized) { + _maximized = maximized; + updateMaximizeRestoreButton(); + } +} + +void TitleWidget::updateMaximizeRestoreButton() { + if (_maximized) { + _maximizeRestore->setIcon(&st::titleButtonRestoreIcon, &st::titleButtonRestoreIconOver); + } else { + _maximizeRestore->setIcon(nullptr, nullptr); + } +} + +Window::HitTestResult TitleWidget::hitTest(const QPoint &p) const { + if (false + || (_minimize->geometry().contains(p)) + || (_maximizeRestore->geometry().contains(p)) + || (_close->geometry().contains(p)) + ) { + return Window::HitTestResult::SysButton; + } else if (rect().contains(p)) { + return Window::HitTestResult::Caption; + } + return Window::HitTestResult::None; +} + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/window_title_win.h b/Telegram/SourceFiles/platform/win/window_title_win.h new file mode 100644 index 000000000..1fd97d0bf --- /dev/null +++ b/Telegram/SourceFiles/platform/win/window_title_win.h @@ -0,0 +1,63 @@ +/* +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 "window/window_title.h" + +namespace Ui { +class IconButton; +} // namespace Ui + +namespace Platform { + +class TitleWidget : public Window::TitleWidget, private base::Subscriber { + Q_OBJECT + +public: + TitleWidget(QWidget *parent); + + Window::HitTestResult hitTest(const QPoint &p) const override; + +public slots: + void onWindowStateChanged(Qt::WindowState state = Qt::WindowNoState); + void updateControlsVisibility(); + +protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + +private: + void updateMaximizeRestoreButton(); + void updateControlsPosition(); + + ChildWidget _minimize; + ChildWidget _maximizeRestore; + ChildWidget _close; + + bool _maximized = false; + +}; + +inline Window::TitleWidget *CreateTitleWidget(QWidget *parent) { + return new TitleWidget(parent); +} + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/windows_event_filter.cpp b/Telegram/SourceFiles/platform/win/windows_event_filter.cpp index a9a96d9f0..b3202da59 100644 --- a/Telegram/SourceFiles/platform/win/windows_event_filter.cpp +++ b/Telegram/SourceFiles/platform/win/windows_event_filter.cpp @@ -183,20 +183,20 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa GetWindowRect(hWnd, &r); auto res = App::wnd()->hitTest(QPoint(p.x - r.left + App::wnd()->deltaLeft(), p.y - r.top + App::wnd()->deltaTop())); switch (res) { - case HitTestType::Client: - case HitTestType::SysButton: *result = HTCLIENT; break; - case HitTestType::Icon: *result = HTCAPTION; break; - case HitTestType::Caption: *result = HTCAPTION; break; - case HitTestType::Top: *result = HTTOP; break; - case HitTestType::TopRight: *result = HTTOPRIGHT; break; - case HitTestType::Right: *result = HTRIGHT; break; - case HitTestType::BottomRight: *result = HTBOTTOMRIGHT; break; - case HitTestType::Bottom: *result = HTBOTTOM; break; - case HitTestType::BottomLeft: *result = HTBOTTOMLEFT; break; - case HitTestType::Left: *result = HTLEFT; break; - case HitTestType::TopLeft: *result = HTTOPLEFT; break; - case HitTestType::None: - default: *result = HTTRANSPARENT; break; + case Window::HitTestResult::Client: + case Window::HitTestResult::SysButton: *result = HTCLIENT; break; + case Window::HitTestResult::Icon: *result = HTCAPTION; break; + case Window::HitTestResult::Caption: *result = HTCAPTION; break; + case Window::HitTestResult::Top: *result = HTTOP; break; + case Window::HitTestResult::TopRight: *result = HTTOPRIGHT; break; + case Window::HitTestResult::Right: *result = HTRIGHT; break; + case Window::HitTestResult::BottomRight: *result = HTBOTTOMRIGHT; break; + case Window::HitTestResult::Bottom: *result = HTBOTTOM; break; + case Window::HitTestResult::BottomLeft: *result = HTBOTTOMLEFT; break; + case Window::HitTestResult::Left: *result = HTLEFT; break; + case Window::HitTestResult::TopLeft: *result = HTTOPLEFT; break; + case Window::HitTestResult::None: + default: *result = HTTRANSPARENT; break; }; } return true; @@ -210,23 +210,23 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa GetWindowRect(hWnd, &r); auto res = App::wnd()->hitTest(QPoint(p.x - r.left + App::wnd()->deltaLeft(), p.y - r.top + App::wnd()->deltaTop())); switch (res) { - case HitTestType::Icon: - if (menuHidden && getms() < menuHidden + 10) { - menuHidden = 0; - if (getms() < menuShown + GetDoubleClickTime()) { - App::wnd()->close(); + case Window::HitTestResult::Icon: + if (menuHidden && getms() < menuHidden + 10) { + menuHidden = 0; + if (getms() < menuShown + GetDoubleClickTime()) { + App::wnd()->close(); + } + } else { + QRect icon = App::wnd()->iconRect(); + p.x = r.left - App::wnd()->deltaLeft() + icon.left(); + p.y = r.top - App::wnd()->deltaTop() + icon.top() + icon.height(); + App::wnd()->psUpdateSysMenu(App::wnd()->windowHandle()->windowState()); + menuShown = getms(); + menuHidden = 0; + TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0); + menuHidden = getms(); } - } else { - QRect icon = App::wnd()->iconRect(); - p.x = r.left - App::wnd()->deltaLeft() + icon.left(); - p.y = r.top - App::wnd()->deltaTop() + icon.top() + icon.height(); - App::wnd()->psUpdateSysMenu(App::wnd()->windowHandle()->windowState()); - menuShown = getms(); - menuHidden = 0; - TrackPopupMenu(App::wnd()->psMenu(), TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, p.x, p.y, 0, hWnd, 0); - menuHidden = getms(); - } - return true; + return true; }; } return false; @@ -236,7 +236,7 @@ bool EventFilter::mainWindowEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa GetWindowRect(hWnd, &r); auto res = App::wnd()->hitTest(QPoint(p.x - r.left + App::wnd()->deltaLeft(), p.y - r.top + App::wnd()->deltaTop())); switch (res) { - case HitTestType::Icon: App::wnd()->close(); return true; + case Window::HitTestResult::Icon: App::wnd()->close(); return true; }; } return false; diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index 96dd3da7a..2608aa84b 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "profile/profile_cover.h" #include "styles/style_profile.h" +#include "styles/style_window.h" #include "profile/profile_cover_drop_area.h" #include "profile/profile_userpic_button.h" #include "ui/buttons/round_button.h" @@ -112,7 +113,7 @@ void CoverWidget::onCancelPhotoUpload() { int CoverWidget::countPhotoLeft(int newWidth) const { int result = st::profilePhotoLeftMin; - result += (newWidth - st::wndMinWidth) / 2; + result += (newWidth - st::windowMinWidth) / 2; return qMin(result, st::profilePhotoLeftMax); } diff --git a/Telegram/SourceFiles/profile/profile_inner_widget.cpp b/Telegram/SourceFiles/profile/profile_inner_widget.cpp index de59ee911..87635380e 100644 --- a/Telegram/SourceFiles/profile/profile_inner_widget.cpp +++ b/Telegram/SourceFiles/profile/profile_inner_widget.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "profile/profile_inner_widget.h" #include "styles/style_profile.h" +#include "styles/style_window.h" #include "profile/profile_cover.h" #include "profile/profile_info_widget.h" #include "profile/profile_settings_widget.h" @@ -132,7 +133,7 @@ int InnerWidget::countBlocksHeight(BlockSide countSide) const { int InnerWidget::countBlocksLeft(int newWidth) const { int result = st::profileBlockLeftMin; - result += (newWidth - st::wndMinWidth) / 2; + result += (newWidth - st::windowMinWidth) / 2; return qMin(result, st::profileBlockLeftMax); } diff --git a/Telegram/SourceFiles/pspecific.h b/Telegram/SourceFiles/pspecific.h index fb3dd1697..961515c98 100644 --- a/Telegram/SourceFiles/pspecific.h +++ b/Telegram/SourceFiles/pspecific.h @@ -20,10 +20,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include -#include -#include "sysbuttons.h" - #ifdef Q_OS_MAC #include "pspecific_mac.h" #elif defined Q_OS_LINUX // Q_OS_MAC diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index fb69469b1..a99d5585a 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -24,7 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "localstorage.h" #include "media/player/media_player_instance.h" #include "platform/mac/mac_utilities.h" - +#include "styles/style_window.h" #include "lang.h" #include diff --git a/Telegram/SourceFiles/settings/settings_scale_widget.cpp b/Telegram/SourceFiles/settings/settings_scale_widget.cpp index c85be6440..710bd4a39 100644 --- a/Telegram/SourceFiles/settings/settings_scale_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_scale_widget.cpp @@ -85,7 +85,6 @@ void ScaleWidget::setScale(DBIScale newScale) { cSetConfigScale(newScale); Local::writeSettings(); - App::wnd()->getTitle()->updateControlsVisibility(); if (newScale == dbisAuto && !_auto->checked()) { _auto->setChecked(true); } else if (newScale != dbisAuto && _auto->checked()) { diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index 9e5da544a..0bad833c0 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "settings/settings_inner_widget.h" #include "settings/settings_fixed_bar.h" #include "styles/style_settings.h" +#include "styles/style_window.h" #include "styles/style_boxes.h" #include "ui/widgets/shadow.h" #include "ui/scrollarea.h" @@ -123,7 +124,7 @@ void codesFeedString(const QString &text) { } // namespace -Widget::Widget() : LayerWidget() +Widget::Widget(QWidget *parent) : LayerWidget(parent) , _scroll(this, st::setScroll) , _inner(this) , _fixedBar(this) @@ -147,18 +148,18 @@ void Widget::parentResized() { if (windowWidth <= st::settingsMaxWidth) { newWidth = windowWidth; newContentLeft = st::settingsMinPadding; - if (windowWidth > st::wndMinWidth) { - // Width changes from st::wndMinWidth to st::settingsMaxWidth. + if (windowWidth > st::windowMinWidth) { + // Width changes from st::windowMinWidth to st::settingsMaxWidth. // Padding changes from st::settingsMinPadding to st::settingsMaxPadding. - newContentLeft += ((newWidth - st::wndMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::wndMinWidth); + newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth); } } else if (windowWidth < st::settingsMaxWidth + 2 * st::settingsMargin) { newWidth = windowWidth - 2 * st::settingsMargin; newContentLeft = st::settingsMinPadding; - if (windowWidth > st::wndMinWidth) { - // Width changes from st::wndMinWidth to st::settingsMaxWidth. + if (windowWidth > st::windowMinWidth) { + // Width changes from st::windowMinWidth to st::settingsMaxWidth. // Padding changes from st::settingsMinPadding to st::settingsMaxPadding. - newContentLeft += ((newWidth - st::wndMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::wndMinWidth); + newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth); } } diff --git a/Telegram/SourceFiles/settings/settings_widget.h b/Telegram/SourceFiles/settings/settings_widget.h index 43207c997..06dde46d8 100644 --- a/Telegram/SourceFiles/settings/settings_widget.h +++ b/Telegram/SourceFiles/settings/settings_widget.h @@ -35,7 +35,7 @@ class Widget : public LayerWidget { Q_OBJECT public: - Widget(); + Widget(QWidget *parent); void parentResized() override; void showDone() override; diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 8b0162193..1e40b0fb0 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -981,11 +981,11 @@ void DocumentOpenClickHandler::doOpen(DocumentData *data, HistoryItem *context, auto &location = data->location(true); if (auto applyTheme = data->name.endsWith(qstr(".tdesktop-theme"))) { if (!location.isEmpty() && location.accessEnable()) { - if (Window::Theme::Apply(location.name())) { - location.accessDisable(); - return; + if (!Window::Theme::Apply(location.name())) { + // show error? } location.accessDisable(); + return; } } if (!location.isEmpty() || (!data->data().isEmpty() && (playVoice || playMusic || playVideo || playAnimation))) { @@ -1290,11 +1290,11 @@ void DocumentData::performActionOnLoad() { bool playAnimation = isAnimation() && (_actionOnLoad == ActionOnLoadPlayInline || _actionOnLoad == ActionOnLoadOpen) && showImage && item && item->getMedia(); if (auto applyTheme = name.endsWith(qstr(".tdesktop-theme"))) { if (!loc.isEmpty() && loc.accessEnable()) { - if (Window::Theme::Apply(loc.name())) { - loc.accessDisable(); - return; + if (!Window::Theme::Apply(loc.name())) { + // show error? } loc.accessDisable(); + return; } } if (playVoice) { diff --git a/Telegram/SourceFiles/sysbuttons.cpp b/Telegram/SourceFiles/sysbuttons.cpp deleted file mode 100644 index 63a60eca8..000000000 --- a/Telegram/SourceFiles/sysbuttons.cpp +++ /dev/null @@ -1,147 +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 "sysbuttons.h" - -#include "lang.h" -#include "shortcuts.h" -#include "application.h" -#include "autoupdater.h" - -SysBtn::SysBtn(QWidget *parent, const style::sysButton &st, const QString &text) : Button(parent) -, _st(&st) -, a_color(_st->color->c) -, _a_color(animation(this, &SysBtn::step_color)) -, _text(text) { - int32 w = _st->size.width() + (_text.isEmpty() ? 0 : ((_st->size.width() - _st->icon.width()) / 2 + st::titleTextButton.font->width(_text))); - resize(w, _st->size.height()); - setCursor(style::cur_default); -} - -void SysBtn::setText(const QString &text) { - _text = text; - int32 w = _st->size.width() + (_text.isEmpty() ? 0 : ((_st->size.width() - _st->icon.width()) / 2 + st::titleTextButton.font->width(_text))); - resize(w, _st->size.height()); -} - -void SysBtn::setOverLevel(float64 level) { - _overLevel = level; - update(); -} - -void SysBtn::onStateChanged(int oldState, ButtonStateChangeSource source) { - a_color.start((_state & StateOver ? _st->overColor : _st->color)->c); - - if (source == ButtonByUser || source == ButtonByPress) { - _a_color.stop(); - a_color.finish(); - update(); - } else { - _a_color.start(); - } -} - -void SysBtn::paintEvent(QPaintEvent *e) { - Painter p(this); - - int x = width() - ((_st->size.width() + _st->icon.width()) / 2), y = (height() - _st->icon.height()) / 2; - QColor c = a_color.current(); - if (_overLevel > 0) { - if (_overLevel >= 1) { - c = _st->overColor->c; - } else { - c.setRedF(c.redF() * (1 - _overLevel) + _st->overColor->c.redF() * _overLevel); - c.setGreenF(c.greenF() * (1 - _overLevel) + _st->overColor->c.greenF() * _overLevel); - c.setBlueF(c.blueF() * (1 - _overLevel) + _st->overColor->c.blueF() * _overLevel); - } - } - p.fillRect(x, y, _st->icon.width(), _st->icon.height(), c); - _st->icon.paint(p, x, y, width()); - - if (!_text.isEmpty()) { - p.setFont(st::titleTextButton.font->f); - p.setPen(c); - p.drawText((_st->size.width() - _st->icon.width()) / 2, st::titleTextButton.textTop + st::titleTextButton.font->ascent, _text); - } -} - -void SysBtn::setSysBtnStyle(const style::sysButton &st) { - _st = &st; - update(); -} - -HitTestType SysBtn::hitTest(const QPoint &p) const { - int x(p.x()), y(p.y()), w(width()), h(height()); - if (x >= 0 && y >= 0 && x < w && y < h && isVisible()) { - return HitTestType::SysButton; - } - return HitTestType::None; -} - -void SysBtn::step_color(float64 ms, bool timer) { - float64 dt = ms / _st->duration; - if (dt >= 1) { - _a_color.stop(); - a_color.finish(); - } else { - a_color.update(dt, anim::linear); - } - if (timer) update(); -} - -MinimizeBtn::MinimizeBtn(QWidget *parent) : SysBtn(parent, st::sysMin) { - setClickedCallback([this]() { - window()->setWindowState(Qt::WindowMinimized); - }); -} - -MaximizeBtn::MaximizeBtn(QWidget *parent) : SysBtn(parent, st::sysMax) { - setClickedCallback([this]() { - window()->setWindowState(Qt::WindowMaximized); - }); -} - -RestoreBtn::RestoreBtn(QWidget *parent) : SysBtn(parent, st::sysRes) { - setClickedCallback([this]() { - window()->setWindowState(Qt::WindowNoState); - }); -} - -CloseBtn::CloseBtn(QWidget *parent) : SysBtn(parent, st::sysCls) { - setClickedCallback([this]() { - window()->close(); - }); -} - -UpdateBtn::UpdateBtn(QWidget *parent) : SysBtn(parent, st::sysUpd, lang(lng_menu_update)) { - setClickedCallback([]() { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - checkReadyUpdate(); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE - App::restart(); - }); -} - -LockBtn::LockBtn(QWidget *parent) : SysBtn(parent, st::sysLock) { - setClickedCallback([] { - Shortcuts::launch(qsl("lock_telegram")); - }); -} diff --git a/Telegram/SourceFiles/sysbuttons.h b/Telegram/SourceFiles/sysbuttons.h deleted file mode 100644 index 06dba6ac9..000000000 --- a/Telegram/SourceFiles/sysbuttons.h +++ /dev/null @@ -1,102 +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/animation.h" -#include "ui/button.h" - -enum class HitTestType { - None = 0, - Client, - SysButton, - Icon, - Caption, - Top, - TopRight, - Right, - BottomRight, - Bottom, - BottomLeft, - Left, - TopLeft, -}; - -class SysBtn : public Button { -public: - SysBtn(QWidget *parent, const style::sysButton &st, const QString &text = QString()); - - void setText(const QString &text); - void setSysBtnStyle(const style::sysButton &st); - - HitTestType hitTest(const QPoint &p) const; - - void setOverLevel(float64 level); - - void step_color(float64 ms, bool timer); - -protected: - void onStateChanged(int oldState, ButtonStateChangeSource source) override; - void paintEvent(QPaintEvent *e) override; - - const style::sysButton *_st; - anim::cvalue a_color; - Animation _a_color; - - float64 _overLevel = 0.; - QString _text; - -}; - -class MinimizeBtn : public SysBtn { -public: - MinimizeBtn(QWidget *parent); - -}; - -class MaximizeBtn : public SysBtn { -public: - MaximizeBtn(QWidget *parent); - -}; - -class RestoreBtn : public SysBtn { -public: - RestoreBtn(QWidget *parent); - -}; - -class CloseBtn : public SysBtn { -public: - CloseBtn(QWidget *parent); - -}; - -class UpdateBtn : public SysBtn { -public: - UpdateBtn(QWidget *parent); - -}; - -class LockBtn : public SysBtn { -public: - LockBtn(QWidget *parent); - -}; diff --git a/Telegram/SourceFiles/title.cpp b/Telegram/SourceFiles/title.cpp deleted file mode 100644 index 1e1ec37c1..000000000 --- a/Telegram/SourceFiles/title.cpp +++ /dev/null @@ -1,427 +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 "title.h" - -#include "lang.h" -#include "mainwidget.h" -#include "mainwindow.h" -#include "application.h" -#include "boxes/contactsbox.h" -#include "boxes/aboutbox.h" -#include "media/media_audio.h" -#include "media/player/media_player_title_button.h" -#include "media/player/media_player_panel.h" -#include "media/player/media_player_instance.h" -#include "styles/style_window.h" - -class TitleWidget::Hider : public TWidget { -public: - Hider(QWidget *parent); - - using ClickedCallback = base::lambda_unique; - void setClickedCallback(ClickedCallback &&callback) { - _callback = std_::move(callback); - } - void setLevel(float64 level); - -protected: - void paintEvent(QPaintEvent *e) override; - void mousePressEvent(QMouseEvent *e) override; - -private: - ClickedCallback _callback; - float64 _level = 0; - -}; - -TitleWidget::Hider::Hider(QWidget *parent) : TWidget(parent) { -} - -void TitleWidget::Hider::paintEvent(QPaintEvent *e) { - QPainter p(this); - p.setOpacity(_level); - p.fillRect(App::main()->dlgsWidth(), 0, width() - App::main()->dlgsWidth(), height(), st::layerBg); -} - -void TitleWidget::Hider::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::LeftButton && _callback) { - _callback(); - } -} - -void TitleWidget::Hider::setLevel(float64 level) { - _level = level; - update(); -} - -TitleWidget::TitleWidget(QWidget *parent) : TWidget(parent) -, _cancel(this, lang(lng_cancel), st::titleTextButton) -, _settings(this, lang(lng_menu_settings), st::titleTextButton) -, _contacts(this, lang(lng_menu_contacts), st::titleTextButton) -, _about(this, lang(lng_menu_about), st::titleTextButton) -, _lock(this) -, _update(this) -, _minimize(this) -, _maximize(this) -, _restore(this) -, _close(this) -, _a_update(animation(this, &TitleWidget::step_update)) -, lastMaximized(!(parent->windowState() & Qt::WindowMaximized)) { - setGeometry(0, 0, parent->width(), st::titleHeight); - setAttribute(Qt::WA_OpaquePaintEvent); - - onWindowStateChanged(); - updateControlsVisibility(); - - connect(&_cancel, SIGNAL(clicked()), this, SIGNAL(hiderClicked())); - connect(&_settings, SIGNAL(clicked()), parent, SLOT(showSettings())); - connect(&_contacts, SIGNAL(clicked()), this, SLOT(onContacts())); - connect(&_about, SIGNAL(clicked()), this, SLOT(onAbout())); - connect(parent->windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onWindowStateChanged(Qt::WindowState))); - -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Sandbox::connect(SIGNAL(updateReady()), this, SLOT(updateControlsVisibility())); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE - - subscribe(Adaptive::Changed(), [this]() { updateAdaptiveLayout(); }); - if (Media::Player::exists()) { - subscribe(Media::Player::instance()->usePanelPlayer(), [this](bool usePanel) { - updatePlayerButton(usePanel); - }); - } - - if (cPlatform() != dbipWindows) { - _minimize.hide(); - _maximize.hide(); - _restore.hide(); - _close.hide(); - } -} - -void TitleWidget::paintEvent(QPaintEvent *e) { - Painter p(this); - p.fillRect(rect(), st::titleBg); - if (!_cancel.isHidden()) { - p.setPen(st::titleTextButton.color); - p.setFont(st::titleTextButton.font); - bool inlineSwitchChoose = (App::main() && App::main()->selectingPeerForInlineSwitch()); - auto chooseText = lang(inlineSwitchChoose ? lng_inline_switch_choose : lng_forward_choose); - p.drawText(st::titleMenuOffset - st::titleTextButton.width / 2, st::titleTextButton.textTop + st::titleTextButton.font->ascent, chooseText); - } - st::titleIcon.paint(p, st::titleIconPosition, width()); - if (Adaptive::OneColumn() && !_counter.isNull() && App::main()) { - p.drawPixmap(st::titleCounterPosition, _counter); - } -} - -void TitleWidget::step_update(float64 ms, bool timer) { - float64 phase = sin(M_PI_2 * (ms / st::updateBlinkDuration)); - if (phase < 0) phase = -phase; - _update.setOverLevel(phase); -} - -void TitleWidget::setHideLevel(float64 level) { - if (level != hideLevel) { - hideLevel = level; - if (hideLevel) { - if (!_hider) { - _hider.create(this); - _hider->setGeometry(rect()); - _hider->setClickedCallback([this]() { emit hiderClicked(); }); - _hider->setVisible(!Adaptive::OneColumn()); - } - _hider->setLevel(hideLevel); - } else { - if (_hider) { - _hider.destroyDelayed(); - } - } - } -} - -void TitleWidget::onContacts() { - if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); - - if (!App::self()) return; - Ui::showLayer(new ContactsBox()); -} - -void TitleWidget::onAbout() { - if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray(); - Ui::showLayer(new AboutBox()); -} - -void TitleWidget::updatePlayerButton(bool usePanel) { - if (usePanel && !_player) { - _player.create(this); - } else if (!usePanel && _player) { - _player.destroyDelayed(); - } - updateControlsVisibility(); -} - -void TitleWidget::updateControlsPosition() { - QPoint p(width() - ((cPlatform() == dbipWindows && lastMaximized) ? 0 : st::sysBtnDelta), 0); - - if (!_update.isHidden()) { - p.setX(p.x() - _update.width()); - _update.move(p); - if (!_lock.isHidden()) { - p.setX(p.x() - _lock.width()); - _lock.move(p); - p.setX(p.x() + _lock.width()); - } - p.setX(p.x() + _update.width()); - } - _cancel.move(p.x() - _cancel.width(), 0); - - if (cPlatform() == dbipWindows) { - p.setX(p.x() - _close.width()); - _close.move(p); - - p.setX(p.x() - _maximize.width()); - _restore.move(p); _maximize.move(p); - - p.setX(p.x() - _minimize.width()); - _minimize.move(p); - } - if (_update.isHidden() && !_lock.isHidden()) { - p.setX(p.x() - _lock.width()); - _lock.move(p); - } - if (_player) { - p.setX(p.x() - _player->width()); - _player->move(p); - } - - _settings.move(st::titleMenuOffset, 0); - if (_contacts.isHidden()) { - _about.move(_settings.x() + _settings.width(), 0); - } else { - _contacts.move(_settings.x() + _settings.width(), 0); - _about.move(_contacts.x() + _contacts.width(), 0); - } - - if (_hider) { - _hider->resize(size()); - } -} - -void TitleWidget::resizeEvent(QResizeEvent *e) { - updateControlsPosition(); -} - -void TitleWidget::updateControlsVisibility() { - auto passcoded = App::passcoded(); - auto authed = (App::main() != nullptr); - auto selecting = authed && App::main()->selectingPeer(); - auto oneColumnSelecting = (Adaptive::OneColumn() && selecting && !passcoded); - - _cancel.setVisible(oneColumnSelecting); - - updateRestartButtonVisibility(); - updateMenuButtonsVisibility(); - updateSystemButtonsVisibility(); - - updateControlsPosition(); - update(); -} - -void TitleWidget::updateRestartButtonVisibility() { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - bool updateReady = (Sandbox::updatingState() == Application::UpdatingReady); -#else // !TDESKTOP_DISABLE_AUTOUPDATE - bool updateReady = false; -#endif // else for !TDESKTOP_DISABLE_AUTOUPDATE - auto scaleRestarting = cEvalScale(cConfigScale()) != cEvalScale(cRealScale()); - - auto updateVisible = _cancel.isHidden() && (updateReady || scaleRestarting); - if (updateVisible) { - _update.setText(lang(updateReady ? lng_menu_update : lng_menu_restart)); - _update.show(); - _a_update.start(); - } else { - _update.hide(); - _a_update.stop(); - } -} - -void TitleWidget::updateMenuButtonsVisibility() { - if (_cancel.isHidden()) { - if (App::passcoded()) { - _settings.hide(); - _contacts.hide(); - _about.hide(); - _lock.setSysBtnStyle(st::sysUnlock); - } else { - _lock.setSysBtnStyle(st::sysLock); - _settings.show(); - _contacts.setVisible(App::main() != nullptr); - _about.show(); - } - } else { - _settings.hide(); - _contacts.hide(); - _about.hide(); - } -} - -void TitleWidget::updateSystemButtonsVisibility() { - if (_cancel.isHidden()) { - _lock.setVisible(Global::LocalPasscode()); - if (_player) { - _player->show(); - } - } else { - _lock.hide(); - if (_player) { - _player->hide(); - } - } - if (_update.isHidden() && _cancel.isHidden() && cPlatform() == dbipWindows) { - _minimize.show(); - maximizedChanged(lastMaximized, true); - _close.show(); - } else { - _minimize.hide(); - _restore.hide(); - _maximize.hide(); - _close.hide(); - } -} - -void TitleWidget::updateAdaptiveLayout() { - updateControlsVisibility(); - if (Adaptive::OneColumn()) { - updateCounter(); - } - if (_hider) { - _hider->setVisible(!Adaptive::OneColumn()); - } -} - -void TitleWidget::updateCounter() { - if (!Adaptive::OneColumn() || !MTP::authedId()) return; - - int32 counter = App::histories().unreadBadge(); - bool muted = App::histories().unreadOnlyMuted(); - - if (counter > 0) { - int32 size = cRetina() ? -32 : -16; - switch (cScale()) { - case dbisOneAndQuarter: size = -20; break; - case dbisOneAndHalf: size = -24; break; - case dbisTwo: size = -32; break; - } - auto &bg = (muted ? st::titleCounterBgMute : st::titleCounterBg); - auto &fg = st::titleCounterFg; - _counter = App::pixmapFromImageInPlace(App::wnd()->iconWithCounter(size, counter, bg, fg, false)); - _counter.setDevicePixelRatio(cRetinaFactor()); - update(QRect(st::titleCounterPosition, _counter.size() / cIntRetinaFactor())); - } else { - if (!_counter.isNull()) { - update(QRect(st::titleCounterPosition, _counter.size() / cIntRetinaFactor())); - _counter = QPixmap(); - } - } -} - -void TitleWidget::mousePressEvent(QMouseEvent *e) { - if (auto wnd = App::wnd()) { - if (wnd->psHandleTitle()) return; - if (e->buttons() & Qt::LeftButton) { - wnd->wStartDrag(e); - e->accept(); - } - } -} - -void TitleWidget::mouseDoubleClickEvent(QMouseEvent *e) { - if (auto wnd = App::wnd()) { - if (wnd->psHandleTitle()) return; - Qt::WindowStates s(wnd->windowState()); - if (s.testFlag(Qt::WindowMaximized)) { - wnd->setWindowState(s & ~Qt::WindowMaximized); - } else { - wnd->setWindowState(s | Qt::WindowMaximized); - } - } -} - -void TitleWidget::onWindowStateChanged(Qt::WindowState state) { - if (state == Qt::WindowMinimized) return; - maximizedChanged(state == Qt::WindowMaximized); -} - -void TitleWidget::maximizedChanged(bool maximized, bool force) { - if (lastMaximized == maximized && !force) return; - - lastMaximized = maximized; - - if (cPlatform() != dbipWindows || !_update.isHidden()) return; - if (maximized) { - _maximize.clearState(); - } else { - _restore.clearState(); - } - - _maximize.setVisible(!maximized); - _restore.setVisible(maximized); - - updateControlsPosition(); -} - -HitTestType TitleWidget::hitTest(const QPoint &p) { - if (App::wnd() && Ui::isLayerShown()) return HitTestType::None; - - int x(p.x()), y(p.y()), w(width()), h(height()); - if (!Adaptive::OneColumn() && _hider && x >= App::main()->dlgsWidth()) return HitTestType::None; - - if (x >= st::titleIconPosition.x() && y >= st::titleIconPosition.y() && x < st::titleIconPosition.x() + st::titleIcon.width() && y < st::titleIconPosition.y() + st::titleIcon.height()) { - return HitTestType::Icon; - } else if (false - || (_player && _player->geometry().contains(p)) - || (_lock.hitTest(p - _lock.geometry().topLeft()) == HitTestType::SysButton && _lock.isVisible()) - || (_update.hitTest(p - _update.geometry().topLeft()) == HitTestType::SysButton && _update.isVisible()) - || (_minimize.hitTest(p - _minimize.geometry().topLeft()) == HitTestType::SysButton) - || (_maximize.hitTest(p - _maximize.geometry().topLeft()) == HitTestType::SysButton) - || (_restore.hitTest(p - _restore.geometry().topLeft()) == HitTestType::SysButton) - || (_close.hitTest(p - _close.geometry().topLeft()) == HitTestType::SysButton) - ) { - return HitTestType::SysButton; - } else if (x >= 0 && x < w && y >= 0 && y < h) { - if (false - || (!_cancel.isHidden() && _cancel.geometry().contains(x, y)) - || (!_settings.isHidden() && _settings.geometry().contains(x, y)) - || (!_contacts.isHidden() && _contacts.geometry().contains(x, y)) - || (!_about.isHidden() && _about.geometry().contains(x, y)) - ) { - return HitTestType::Client; - } - return HitTestType::Caption; - } - return HitTestType::None; -} - -QRect TitleWidget::iconRect() const { - return myrtlrect(QRect(st::titleIconPosition, st::titleIcon.size())); -} diff --git a/Telegram/SourceFiles/title.h b/Telegram/SourceFiles/title.h deleted file mode 100644 index ea278669e..000000000 --- a/Telegram/SourceFiles/title.h +++ /dev/null @@ -1,98 +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 -#include "sysbuttons.h" - -class MainWindow; -namespace Media { -namespace Player { -class TitleButton; -} // namespace Player -} // namespace Media -class AudioMsgId; - -class TitleWidget : public TWidget, private base::Subscriber { - Q_OBJECT - -public: - TitleWidget(QWidget *parent); - - void updateCounter(); - - void maximizedChanged(bool maximized, bool force = false); - - HitTestType hitTest(const QPoint &p); - QRect iconRect() const; - - void setHideLevel(float64 level); - - void step_update(float64 ms, bool timer); - -public slots: - void onWindowStateChanged(Qt::WindowState state = Qt::WindowNoState); - void updateControlsVisibility(); - void onContacts(); - void onAbout(); - -signals: - void hiderClicked(); - -protected: - void paintEvent(QPaintEvent *e) override; - void resizeEvent(QResizeEvent *e) override; - void mousePressEvent(QMouseEvent *e) override; - void mouseDoubleClickEvent(QMouseEvent *e) override; - -private: - void updatePlayerButton(bool usePanel); - void updateAdaptiveLayout(); - void updateRestartButtonVisibility(); - void updateMenuButtonsVisibility(); - void updateSystemButtonsVisibility(); - void updateControlsPosition(); - - style::color statusColor; - - class Hider; - float64 hideLevel = 0; - ChildWidget _hider = { nullptr }; - - float64 _lastUpdateMs; - - FlatButton _cancel, _settings, _contacts, _about; - - ChildWidget _player = { nullptr }; - LockBtn _lock; - UpdateBtn _update; - MinimizeBtn _minimize; - MaximizeBtn _maximize; - RestoreBtn _restore; - CloseBtn _close; - - Animation _a_update; - - bool lastMaximized; - - QPixmap _counter; - -}; diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index bf3b19430..262520044 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -22,12 +22,15 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org using "basic.style"; using "ui/widgets/widgets.style"; -titleIconPosition: point(9px, 9px); -titleIcon: icon { - { "title_icon_bg", #49708f }, - { "title_icon", #ffffff, point(4px, 4px) } -}; -titleCounterPosition: point(17px, 17px); +windowMinWidth: 380px; +windowMinHeight: 480px; +windowDefWidth: 800px; +windowDefHeight: 600px; +windowShadow: icon {{ "window_shadow", windowShadowFg }}; +windowShadowShift: 1px; + +adaptiveNormalWidth: 640px; +adaptiveWideWidth: 1366px; notifyBorder: #f1f1f1; notifyBorderWidth: 1px; @@ -78,3 +81,50 @@ notifySendReply: IconButton { iconPosition: point(0px, 0px); iconPositionDown: point(0px, 1px); } + +titleHeight: 21px; +titleButtonMinimize: IconButton { + width: 24px; + height: 21px; + + icon: icon {{ "title_button_minimize", titleButtonFg, point(4px, 4px) }}; + iconOver: icon { + { size(24px, 21px), titleButtonBgOver }, + { "title_button_minimize", titleButtonFgOver, point(4px, 4px) }, + }; + + iconPosition: point(0px, 0px); + iconPositionDown: point(0px, 0px); +} +titleButtonMaximize: IconButton(titleButtonMinimize) { + icon: icon {{ "title_button_maximize", titleButtonFg, point(4px, 4px) }}; + iconOver: icon { + { size(24px, 21px), titleButtonBgOver }, + { "title_button_maximize", titleButtonFgOver, point(4px, 4px) }, + }; +} +titleButtonRestoreIcon: icon {{ "title_button_restore", titleButtonFg, point(4px, 4px) }}; +titleButtonRestoreIconOver: icon { + { size(24px, 21px), titleButtonBgOver }, + { "title_button_restore", titleButtonFgOver, point(4px, 4px) }, +}; +titleButtonClose: IconButton(titleButtonMinimize) { + width: 25px; + + icon: icon {{ "title_button_close", titleButtonFg, point(5px, 4px) }}; + iconOver: icon { + { size(25px, 21px), titleButtonCloseBgOver }, + { "title_button_close", titleButtonCloseFgOver, point(5px, 4px) }, + }; +} + +// Mac specific + +macAccessoryWidth: 450.; +macAccessoryHeight: 90.; +macEnableFilterAdd: 2; +macEnableFilterTop: 5; +macSelectorTop: 6; +macAlwaysThisAppTop: 4; +macAppHintTop: 8; +macCautionIconSize: 16; diff --git a/Telegram/SourceFiles/window/window_theme.cpp b/Telegram/SourceFiles/window/window_theme.cpp index 01e74ab87..67ced2a08 100644 --- a/Telegram/SourceFiles/window/window_theme.cpp +++ b/Telegram/SourceFiles/window/window_theme.cpp @@ -82,14 +82,14 @@ inline uchar readHexUchar(char char1, char char2, bool &error) { return ((readHexUchar(char1, error) & 0x0F) << 4) | (readHexUchar(char2, error) & 0x0F); } -bool readNameAndValue(const char *&from, const char *end, QByteArray *outName, QByteArray *outValue) { +bool readNameAndValue(const char *&from, const char *end, QLatin1String *outName, QLatin1String *outValue) { using base::parse::skipWhitespaces; using base::parse::readName; if (!skipWhitespaces(from, end)) return true; *outName = readName(from, end); - if (outName->isEmpty()) { + if (outName->size() == 0) { LOG(("Error: Could not read name in the color scheme.")); return false; } @@ -108,11 +108,11 @@ bool readNameAndValue(const char *&from, const char *end, QByteArray *outName, Q auto valueStart = from; if (*from == '#') ++from; - if (readName(from, end).isEmpty()) { + if (readName(from, end).size() == 0) { LOG(("Error: Expected a color value in #rrggbb or #rrggbbaa format in the color scheme.")); return false; } - *outValue = QByteArray::fromRawData(valueStart, from - valueStart); + *outValue = QLatin1String(valueStart, from - valueStart); if (!skipWhitespaces(from, end)) { LOG(("Error: Unexpected end of the color scheme.")); @@ -126,47 +126,66 @@ bool readNameAndValue(const char *&from, const char *end, QByteArray *outName, Q return true; } +enum class SetResult { + Ok, + Bad, + NotFound, +}; +SetResult setColorSchemeValue(QLatin1String name, QLatin1String value, Instance *out) { + auto found = false; + auto size = value.size(); + auto data = value.data(); + if (data[0] == '#' && (size == 7 || size == 9)) { + auto error = false; + auto r = readHexUchar(data[1], data[2], error); + auto g = readHexUchar(data[3], data[4], error); + auto b = readHexUchar(data[5], data[6], error); + auto a = (size == 9) ? readHexUchar(data[7], data[8], error) : uchar(255); + if (error) { + LOG(("Error: Expected a color value in #rrggbb or #rrggbbaa format in the color scheme (while applying '%1: %2')").arg(QLatin1String(name)).arg(QLatin1String(value))); + return SetResult::Bad; + } else if (out) { + found = out->palette.setColor(name, r, g, b, a); + } else { + found = style::main_palette::setColor(name, r, g, b, a); + } + } else { + if (out) { + found = out->palette.setColor(name, value); + } else { + found = style::main_palette::setColor(name, value); + } + } + return found ? SetResult::Ok : SetResult::NotFound; +} + bool loadColorScheme(const QByteArray &content, Instance *out = nullptr) { if (content.size() > kThemeSchemeSizeLimit) { LOG(("Error: color scheme file too large (should be less than 1 MB, got %2)").arg(content.size())); return false; } + QMap unsupported; auto data = base::parse::stripComments(content); auto from = data.constData(), end = from + data.size(); while (from != end) { - QByteArray name, value; + QLatin1String name, value; if (!readNameAndValue(from, end, &name, &value)) { return false; } - if (name.isEmpty()) { // End of content reached. + if (name.size() == 0) { // End of content reached. return true; } - auto size = value.size(); - auto error = false; - if (value[0] == '#' && (size == 7 || size == 9)) { - auto r = readHexUchar(value[1], value[2], error); - auto g = readHexUchar(value[3], value[4], error); - auto b = readHexUchar(value[5], value[6], error); - auto a = (size == 9) ? readHexUchar(value[7], value[8], error) : uchar(255); - if (!error) { - if (out) { - error = !out->palette.setColor(QLatin1String(name), r, g, b, a); - } else { - error = !style::main_palette::setColor(QLatin1String(name), r, g, b, a); - } - } - } else { - if (out) { - error = !out->palette.setColor(QLatin1String(name), QLatin1String(value)); - } else { - error = !style::main_palette::setColor(QLatin1String(name), QLatin1String(value)); - } - } - if (error) { - LOG(("Error: Expected a color value in #rrggbb or #rrggbbaa format in the color scheme (while applying '%1: %2')").arg(QLatin1String(name)).arg(QLatin1String(value))); + // Find the named value in the already read unsupported list. + value = unsupported.value(value, value); + + auto result = setColorSchemeValue(name, value, out); + if (result == SetResult::Bad) { return false; + } else if (result == SetResult::NotFound) { + LOG(("Warning: unexpected name or value in the color scheme (while applying '%1: %2')").arg(name).arg(value)); + unsupported.insert(name, value); } } return true; diff --git a/Telegram/SourceFiles/media/player/media_player_title_button.h b/Telegram/SourceFiles/window/window_title.h similarity index 61% rename from Telegram/SourceFiles/media/player/media_player_title_button.h rename to Telegram/SourceFiles/window/window_title.h index b9b0f4e47..41916387a 100644 --- a/Telegram/SourceFiles/media/player/media_player_title_button.h +++ b/Telegram/SourceFiles/window/window_title.h @@ -20,35 +20,34 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include "ui/button.h" +namespace Window { -namespace Media { -namespace Player { +enum class HitTestResult { + None = 0, + Client, + SysButton, + Icon, + Caption, + Top, + TopRight, + Right, + BottomRight, + Bottom, + BottomLeft, + Left, + TopLeft, +}; -class PlayButtonLayout; - -class TitleButton : public Button, private base::Subscriber { +class TitleWidget : public TWidget { public: - TitleButton(QWidget *parent); - - void updatePauseState(); - - ~TitleButton(); - -protected: - void paintEvent(QPaintEvent *e) override; - void enterEvent(QEvent *e) override; - void leaveEvent(QEvent *e) override; - - void onStateChanged(int oldState, ButtonStateChangeSource source) override; - -private: - void paintIcon(Painter &p); - - std_::unique_ptr _layout; - ColorAnimation _iconFg; + using TWidget::TWidget; + virtual HitTestResult hitTest(const QPoint &p) const { + return HitTestResult::None; + } + virtual QRect iconRect() const { + return QRect(); + } }; -} // namespace Clip -} // namespace Media +} // namespace Window diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index c3448f815..6faf9b7d5 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -151,10 +151,6 @@ '<(src_loc)/shortcuts.h', '<(src_loc)/structs.cpp', '<(src_loc)/structs.h', - '<(src_loc)/sysbuttons.cpp', - '<(src_loc)/sysbuttons.h', - '<(src_loc)/title.cpp', - '<(src_loc)/title.h', '<(src_loc)/mainwindow.cpp', '<(src_loc)/mainwindow.h', '<(src_loc)/boxes/aboutbox.cpp', @@ -288,8 +284,6 @@ '<(src_loc)/media/player/media_player_list.h', '<(src_loc)/media/player/media_player_panel.cpp', '<(src_loc)/media/player/media_player_panel.h', - '<(src_loc)/media/player/media_player_title_button.cpp', - '<(src_loc)/media/player/media_player_title_button.h', '<(src_loc)/media/player/media_player_volume_controller.cpp', '<(src_loc)/media/player/media_player_volume_controller.h', '<(src_loc)/media/player/media_player_widget.cpp', @@ -348,6 +342,7 @@ '<(src_loc)/mtproto/session.h', '<(src_loc)/overview/overview_layout.cpp', '<(src_loc)/overview/overview_layout.h', + '<(src_loc)/pspecific.h', '<(src_loc)/pspecific_win.cpp', '<(src_loc)/pspecific_win.h', '<(src_loc)/pspecific_mac.cpp', @@ -378,6 +373,8 @@ '<(src_loc)/platform/win/main_window_win.h', '<(src_loc)/platform/win/notifications_manager_win.cpp', '<(src_loc)/platform/win/notifications_manager_win.h', + '<(src_loc)/platform/win/window_title_win.cpp', + '<(src_loc)/platform/win/window_title_win.h', '<(src_loc)/platform/win/windows_app_user_model_id.cpp', '<(src_loc)/platform/win/windows_app_user_model_id.h', '<(src_loc)/platform/win/windows_dlls.cpp', @@ -387,6 +384,7 @@ '<(src_loc)/platform/platform_file_dialog.h', '<(src_loc)/platform/platform_main_window.h', '<(src_loc)/platform/platform_notifications_manager.h', + '<(src_loc)/platform/platform_window_title.h', '<(src_loc)/profile/profile_actions_widget.cpp', '<(src_loc)/profile/profile_actions_widget.h', '<(src_loc)/profile/profile_block_widget.cpp', @@ -561,6 +559,7 @@ '<(src_loc)/window/window_theme.h', '<(src_loc)/window/window_theme_warning.cpp', '<(src_loc)/window/window_theme_warning.h', + '<(src_loc)/window/window_title.h', '<(sp_media_key_tap_loc)/SPMediaKeyTap.m', '<(sp_media_key_tap_loc)/SPMediaKeyTap.h',