history_drag_area.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/rp_widget.h"
  9. #include "ui/effects/animations.h"
  10. namespace Storage {
  11. enum class MimeDataState;
  12. } // namespace Storage
  13. class DragArea : public Ui::RpWidget {
  14. public:
  15. DragArea(QWidget *parent);
  16. struct Areas {
  17. DragArea *document;
  18. DragArea *photo;
  19. };
  20. using CallbackComputeState
  21. = Fn<Storage::MimeDataState(const QMimeData *data)>;
  22. static Areas SetupDragAreaToContainer(
  23. not_null<Ui::RpWidget*> container,
  24. Fn<bool(not_null<const QMimeData*>)> &&dragEnterFilter = nullptr,
  25. Fn<void(bool)> &&setAcceptDropsField = nullptr,
  26. Fn<void()> &&updateControlsGeometry = nullptr,
  27. CallbackComputeState &&computeState = nullptr,
  28. bool hideSubtext = false);
  29. void setText(const QString &text, const QString &subtext);
  30. void otherEnter();
  31. void otherLeave();
  32. bool overlaps(const QRect &globalRect);
  33. void hideFast();
  34. void setDroppedCallback(Fn<void(const QMimeData *data)> callback) {
  35. _droppedCallback = std::move(callback);
  36. }
  37. protected:
  38. void paintEvent(QPaintEvent *e) override;
  39. void mouseMoveEvent(QMouseEvent *e) override;
  40. void dragMoveEvent(QDragMoveEvent *e) override;
  41. // These events should be filtered by parent!
  42. void dragEnterEvent(QDragEnterEvent *e) override;
  43. void dragLeaveEvent(QDragLeaveEvent *e) override;
  44. void dropEvent(QDropEvent *e) override;
  45. private:
  46. void hideStart();
  47. void hideFinish();
  48. void showStart();
  49. void setIn(bool in);
  50. void opacityAnimationCallback();
  51. bool _hiding = false;
  52. bool _in = false;
  53. QPixmap _cache;
  54. Fn<void(const QMimeData *data)> _droppedCallback;
  55. Ui::Animations::Simple _a_opacity;
  56. Ui::Animations::Simple _a_in;
  57. QString _text, _subtext;
  58. };