1 /* 2 This file is part of Telegram Desktop, 3 the official desktop application for the Telegram messaging service. 4 5 For license and copyright information please follow this link: 6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 7 */ 8 #pragma once 9 10 #include "ui/rp_widget.h" 11 #include "ui/effects/animations.h" 12 #include "ui/layers/layer_widget.h" 13 14 namespace Ui { 15 class BoxContent; 16 class IconButton; 17 class LayerStackWidget; 18 class FlatLabel; 19 template <typename Widget> 20 class FadeWrapScaled; 21 } // namespace Ui 22 23 namespace Ui { 24 25 class SeparatePanel final : public Ui::RpWidget { 26 public: 27 SeparatePanel(); 28 29 void setTitle(rpl::producer<QString> title); 30 void setInnerSize(QSize size); 31 [[nodiscard]] QRect innerGeometry() const; 32 33 void setHideOnDeactivate(bool hideOnDeactivate); 34 void showAndActivate(); 35 int hideGetDuration(); 36 37 void showInner(base::unique_qptr<Ui::RpWidget> inner); 38 void showBox( 39 object_ptr<Ui::BoxContent> box, 40 Ui::LayerOptions options, 41 anim::type animated); 42 void showToast(const TextWithEntities &text); 43 void destroyLayer(); 44 45 [[nodiscard]] rpl::producer<> backRequests() const; 46 [[nodiscard]] rpl::producer<> closeRequests() const; 47 [[nodiscard]] rpl::producer<> closeEvents() const; 48 void setBackAllowed(bool allowed); 49 50 protected: 51 void paintEvent(QPaintEvent *e) override; 52 void closeEvent(QCloseEvent *e) override; 53 void resizeEvent(QResizeEvent *e) override; 54 void focusInEvent(QFocusEvent *e) override; 55 void mousePressEvent(QMouseEvent *e) override; 56 void mouseReleaseEvent(QMouseEvent *e) override; 57 void mouseMoveEvent(QMouseEvent *e) override; 58 void leaveEventHook(QEvent *e) override; 59 void leaveToChildEvent(QEvent *e, QWidget *child) override; 60 void keyPressEvent(QKeyEvent *e) override; 61 bool eventHook(QEvent *e) override; 62 63 private: 64 void initControls(); 65 void initLayout(); 66 void initGeometry(QSize size); 67 void updateGeometry(QSize size); 68 void showControls(); 69 void updateControlsGeometry(); 70 void createBorderImage(); 71 void opacityCallback(); 72 void ensureLayerCreated(); 73 74 void updateTitleGeometry(int newWidth); 75 void updateTitlePosition(); 76 void paintShadowBorder(Painter &p) const; 77 void paintOpaqueBorder(Painter &p) const; 78 79 void toggleOpacityAnimation(bool visible); 80 void finishAnimating(); 81 void finishClose(); 82 83 object_ptr<Ui::IconButton> _close; 84 object_ptr<Ui::FlatLabel> _title = { nullptr }; 85 object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _back; 86 object_ptr<Ui::RpWidget> _body; 87 base::unique_qptr<Ui::RpWidget> _inner; 88 base::unique_qptr<Ui::LayerStackWidget> _layer = { nullptr }; 89 rpl::event_stream<> _synteticBackRequests; 90 rpl::event_stream<> _userCloseRequests; 91 rpl::event_stream<> _closeEvents; 92 93 bool _hideOnDeactivate = false; 94 bool _useTransparency = true; 95 style::margins _padding; 96 97 bool _dragging = false; 98 QPoint _dragStartMousePosition; 99 QPoint _dragStartMyPosition; 100 101 Ui::Animations::Simple _titleLeft; 102 bool _visible = false; 103 104 Ui::Animations::Simple _opacityAnimation; 105 QPixmap _animationCache; 106 QPixmap _borderParts; 107 108 }; 109 110 } // namespace Ui 111