floatingdragpreview.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 Uwe Kindler
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and The Qt Company. For licensing terms
  13. ** and conditions see https://www.qt.io/terms-conditions. For further
  14. ** information use the contact form at https://www.qt.io/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 or (at your option) any later version.
  19. ** The licenses are as published by the Free Software Foundation
  20. ** and appearing in the file LICENSE.LGPLv21 included in the packaging
  21. ** of this file. Please review the following information to ensure
  22. ** the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 3 or (at your option) any later version
  28. ** approved by the KDE Free Qt Foundation. The licenses are as published by
  29. ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  30. ** included in the packaging of this file. Please review the following
  31. ** information to ensure the GNU General Public License requirements will
  32. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  33. **
  34. ****************************************************************************/
  35. #pragma once
  36. #include "floatingdockcontainer.h"
  37. #include <QWidget>
  38. namespace ADS {
  39. class DockWidget;
  40. class DockAreaWidget;
  41. struct FloatingDragPreviewPrivate;
  42. /**
  43. * A floating overlay is a temporary floating widget that is just used to
  44. * indicate the floating widget movement.
  45. * This widget is used as a placeholder for drag operations for non-opaque
  46. * docking
  47. */
  48. class FloatingDragPreview : public QWidget, public AbstractFloatingWidget
  49. {
  50. Q_OBJECT
  51. private:
  52. FloatingDragPreviewPrivate *d;
  53. friend struct FloatingDragPreviewPrivate;
  54. /**
  55. * Cancel non opaque undocking if application becomes inactive
  56. */
  57. void onApplicationStateChanged(Qt::ApplicationState state);
  58. protected:
  59. /**
  60. * Updates the drop overlays
  61. */
  62. virtual void moveEvent(QMoveEvent *event) override;
  63. /**
  64. * Cares about painting the
  65. */
  66. virtual void paintEvent(QPaintEvent *event) override;
  67. /**
  68. * The content is a DockArea or a DockWidget
  69. */
  70. FloatingDragPreview(QWidget *content, QWidget *parent);
  71. public:
  72. using Super = QWidget;
  73. /**
  74. * Creates an instance for undocking the DockWidget in Content parameter
  75. */
  76. FloatingDragPreview(DockWidget *content);
  77. /**
  78. * Creates an instance for undocking the DockArea given in Content
  79. * parameters
  80. */
  81. FloatingDragPreview(DockAreaWidget *content);
  82. /**
  83. * Delete private data
  84. */
  85. ~FloatingDragPreview() override;
  86. /**
  87. * We filter the events of the assigned content widget to receive
  88. * escape key presses for canceling the drag operation
  89. */
  90. virtual bool eventFilter(QObject *watched, QEvent *event) override;
  91. public: // implements AbstractFloatingWidget
  92. virtual void startFloating(const QPoint &dragStartMousePos,
  93. const QSize &size,
  94. eDragState dragState,
  95. QWidget *mouseEventHandler) override;
  96. /**
  97. * Moves the widget to a new position relative to the position given when
  98. * startFloating() was called
  99. */
  100. virtual void moveFloating() override;
  101. /**
  102. * Finishes dragging.
  103. * Hides the dock overlays and executes the real undocking and docking
  104. * of the assigned Content widget
  105. */
  106. virtual void finishDragging() override;
  107. signals:
  108. /**
  109. * This signal is emitted, if dragging has been canceled by escape key
  110. * or by active application switching via task manager
  111. */
  112. void draggingCanceled();
  113. }; // class FloatingDragPreview
  114. } // namespace ADS