1 /* 2 Copyright (c) 2008-2021, Benoit AUTHEMAN All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions are met: 6 * Redistributions of source code must retain the above copyright 7 notice, this list of conditions and the following disclaimer. 8 * Redistributions in binary form must reproduce the above copyright 9 notice, this list of conditions and the following disclaimer in the 10 documentation and/or other materials provided with the distribution. 11 * Neither the name of the author or Destrat.io nor the 12 names of its contributors may be used to endorse or promote products 13 derived from this software without specific prior written permission. 14 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY 19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 //----------------------------------------------------------------------------- 28 // This file is a part of the QuickQanava software library. 29 // 30 // \file qanDraggable.h 31 // \author benoit@destrat.io 32 // \date 2017 03 15 33 //----------------------------------------------------------------------------- 34 35 #ifndef qanDraggable_h 36 #define qanDraggable_h 37 38 // Std headers 39 #include <memory> 40 41 // Qt headers 42 #include <QObject> // Q_DECLARE_INTERFACE 43 #include <QPointer> 44 #include <QQuickItem> 45 46 // QuickQanava headers 47 /* Nil */ 48 49 namespace qan { // ::qan 50 51 class Graph; 52 53 /*! \brief Interface for a draggable and droppable qan::Node or qan::Group. 54 * 55 * \nosubgrouping 56 */ 57 class Draggable 58 { 59 /*! \name Draggable Object Management *///--------------------------------- 60 //@{ 61 public: 62 explicit Draggable(); 63 virtual ~Draggable(); 64 Draggable( const Draggable& ) = delete; 65 66 protected: 67 //! Configure this \c qan::Draggable interface with a valid \c target (usually a qan::Node or qan::Group). 68 void configure(QQuickItem* target); 69 private: 70 QPointer<QQuickItem> _target; 71 QPointer<qan::Graph> _graph; 72 //@} 73 //------------------------------------------------------------------------- 74 75 /*! \name Draggable Management *///---------------------------------------- 76 //@{ 77 public: 78 void setDraggable( bool draggable ) noexcept; getDraggable()79 inline bool getDraggable() const noexcept { return _draggable; } 80 protected: 81 virtual void emitDraggableChanged() = 0; 82 private: 83 /*! \brief Define if the node could actually be dragged by mouse (default to true). 84 * 85 * Set this property to true if you want to allow this node to be moved by mouse (if false, the node position is 86 * fixed and should be changed programmatically). 87 * 88 * Default to true. 89 */ 90 bool _draggable{true}; 91 92 public: 93 void setDragged( bool dragged ) noexcept; getDragged()94 inline bool getDragged() const noexcept { return _dragged; } 95 protected: 96 virtual void emitDraggedChanged() = 0; 97 private: 98 //! True when the node is currently beeing dragged. 99 bool _dragged{false}; 100 101 public: 102 void setDroppable( bool droppable ) noexcept; getDroppable()103 inline bool getDroppable() const noexcept { return _droppable; } 104 protected: 105 virtual void emitDroppableChanged() = 0; 106 private: 107 /*! \brief Define if the target node or group could be dropped in another node or in a node group. 108 * 109 * Set this property to true if you want to allow this node to be dropped in a qan::Group automatically. 110 * Default to true. 111 * Setting this property to false may lead to a significant performance improvement if group dropping is not needed. 112 */ 113 bool _droppable{true}; 114 115 public: 116 void setAcceptDrops( bool acceptDrops ) noexcept; getAcceptDrops()117 inline bool getAcceptDrops() const noexcept { return _acceptDrops; } 118 protected: 119 virtual void emitAcceptDropsChanged() = 0; 120 private: 121 /*! \brief Define if the group actually accept insertion of nodes via drag'n drop (default to true). 122 * 123 * Default to true. 124 * 125 * Setting this property to false may lead to a significant performance improvement if DropNode support is not needed. 126 */ 127 bool _acceptDrops{true}; 128 //@} 129 //------------------------------------------------------------------------- 130 }; 131 132 } // ::qan 133 134 Q_DECLARE_INTERFACE( 135 qan::Draggable, 136 "com.destrat.io.QuickQanava.Draggable/3.0" 137 ) 138 139 #endif // qanDraggable_h 140