// This file is part of Desktop App Toolkit, // a set of libraries for developing nice desktop applications. // // For license and copyright information please follow this link: // https://github.com/desktop-app/legal/blob/master/LEGAL // #pragma once #include "base/flat_map.h" #include "base/weak_ptr.h" #include "ui/rp_widget.h" #include "ui/effects/animations.h" #include "ui/layers/layer_widget.h" #include "ui/text/text_entity.h" #include class Painter; namespace style { struct IconButton; struct PopupMenu; } // namespace style namespace Ui::Menu { struct MenuCallback; } // namespace Ui::Menu namespace Ui::Toast { struct Config; class Instance; } // namespace Ui::Toast namespace Ui { class Show; class BoxContent; class IconButton; class PopupMenu; class LayerStackWidget; class LayerWidget; class FlatLabel; class InputField; template class FadeWrapScaled; template class FadeWrap; struct SeparatePanelArgs { QWidget *parent = nullptr; bool onAllSpaces = false; Fn animationsPaused; const style::PopupMenu *menuSt = nullptr; }; class SeparatePanel final : public RpWidget { public: explicit SeparatePanel(SeparatePanelArgs &&args = {}); ~SeparatePanel(); void setTitle(rpl::producer title); void setTitleHeight(int height); void setTitleBadge(object_ptr badge); void setInnerSize(QSize size, bool allowResize = false); [[nodiscard]] QRect innerGeometry() const; void toggleFullScreen(bool fullscreen); void allowChildFullScreenControls(bool allow); [[nodiscard]] rpl::producer fullScreenValue() const; [[nodiscard]] QMargins computePadding() const; void setHideOnDeactivate(bool hideOnDeactivate); void showAndActivate(); int hideGetDuration(); [[nodiscard]] RpWidget *inner() const; void showInner(base::unique_qptr inner); void showBox( object_ptr box, LayerOptions options, anim::type animated); void showLayer( std::unique_ptr layer, LayerOptions options, anim::type animated); void hideLayer(anim::type animated); [[nodiscard]] rpl::producer<> backRequests() const; [[nodiscard]] rpl::producer<> closeRequests() const; [[nodiscard]] rpl::producer<> closeEvents() const; void setBackAllowed(bool allowed); void updateBackToggled(); void setMenuAllowed( Fn fill, Fn, bool fullscreen)> created = nullptr); void setSearchAllowed( rpl::producer placeholder, Fn)> queryChanged); bool closeSearch(); void overrideTitleColor(std::optional color); void overrideBodyColor(std::optional color); void overrideBottomBarColor(std::optional color); void setBottomBarHeight(int height); [[nodiscard]] style::palette *titleOverridePalette() const; base::weak_ptr showToast(Toast::Config &&config); base::weak_ptr showToast( TextWithEntities &&text, crl::time duration = 0); base::weak_ptr showToast( const QString &text, crl::time duration = 0); [[nodiscard]] std::shared_ptr uiShow(); protected: void paintEvent(QPaintEvent *e) override; void closeEvent(QCloseEvent *e) override; void resizeEvent(QResizeEvent *e) override; void focusInEvent(QFocusEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void leaveEventHook(QEvent *e) override; void leaveToChildEvent(QEvent *e, QWidget *child) override; void keyPressEvent(QKeyEvent *e) override; bool eventHook(QEvent *e) override; private: class ResizeEdge; class FullScreenButton; void initControls(); void initLayout(const SeparatePanelArgs &args); void initGeometry(QSize size); void updateGeometry(QSize size); void showControls(); void updateControlsGeometry(); void updateControlsVisibility(bool fullscreen); void validateBorderImage(); [[nodiscard]] QPixmap createBorderImage(QColor color) const; void opacityCallback(); void ensureLayerCreated(); void destroyLayer(); void updateTitleGeometry(int newWidth) const; void paintShadowBorder(QPainter &p) const; void paintOpaqueBorder(QPainter &p) const; void paintBodyBg(QPainter &p, int radius = 0) const; void toggleOpacityAnimation(bool visible); void finishAnimating(); void finishClose(); void showMenu(Fn fill); [[nodiscard]] bool createMenu(not_null button); void createFullScreenButtons(); void initFullScreenButton(not_null button); void updateTitleButtonColors(not_null button); void updateTitleColors(); void toggleSearch(bool shown); [[nodiscard]] rpl::producer<> allBackRequests() const; [[nodiscard]] rpl::producer<> allCloseRequests() const; const style::PopupMenu &_menuSt; object_ptr _close; object_ptr _menuToggle = { nullptr }; Fn, bool fullscreen)> _menuToggleCreated; object_ptr> _searchToggle = { nullptr }; rpl::variable _searchPlaceholder; Fn)> _searchQueryChanged; object_ptr> _searchWrap = { nullptr }; InputField *_searchField = nullptr; object_ptr _title = { nullptr }; object_ptr _titleBadge = { nullptr }; object_ptr> _back; object_ptr _body; base::unique_qptr _inner; base::unique_qptr _layer = { nullptr }; base::unique_qptr _menu; std::vector> _resizeEdges; std::unique_ptr _fsClose; std::unique_ptr _fsMenuToggle; std::unique_ptr> _fsBack; bool _fsAllowChildControls = false; rpl::event_stream<> _synteticBackRequests; rpl::event_stream<> _userCloseRequests; rpl::event_stream<> _closeEvents; int _titleHeight = 0; bool _allowResize = false; bool _hideOnDeactivate = false; bool _useTransparency = true; bool _backAllowed = false; style::margins _padding; bool _dragging = false; QPoint _dragStartMousePosition; QPoint _dragStartMyPosition; Animations::Simple _titleLeft; bool _visible = false; rpl::variable _fullscreen = false; Animations::Simple _opacityAnimation; QPixmap _animationCache; QPixmap _borderParts; std::optional _titleOverrideColor; QPixmap _titleOverrideBorderParts; std::unique_ptr _titleOverridePalette; base::flat_map< not_null, std::unique_ptr> _titleOverrideStyles; std::optional _bodyOverrideColor; QPixmap _bodyOverrideBorderParts; std::optional _bottomBarOverrideColor; QPixmap _bottomBarOverrideBorderParts; int _bottomBarHeight = 0; Fn _animationsPaused; }; } // namespace Ui