Sayonara Player
Dragable.h
1 /* Dragable.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef DRAGGABLE_H
22 #define DRAGGABLE_H
23 
24 #include "Utils/Pimpl.h"
25 #include <QObject>
26 
27 class QPoint;
28 class QPixmap;
29 class QMimeData;
30 class QWidget;
31 class QDrag;
32 class QMouseEvent;
33 class QAbstractItemView;
34 
35 namespace Gui
36 {
37  class Dragable;
38  class DragableConnector : public QObject
39  {
40  friend class Dragable;
41 
42  Q_OBJECT
43  PIMPL(DragableConnector)
44 
45  private:
46  DragableConnector(QAbstractItemView* widget, Dragable* dragable);
47  ~DragableConnector() override;
48 
49  private slots:
50  void mousePressed(QMouseEvent* e);
51  void mouseMoved(QMouseEvent* e);
52 
53  void dragDestroyed();
54  };
55 
60  class Dragable
61  {
62  friend class DragableConnector;
63 
64  public:
65  explicit Dragable(QAbstractItemView* parent);
66  virtual ~Dragable();
67 
68  enum class ReleaseReason : char
69  {
70  Dropped,
71  Destroyed
72  };
73 
74  private:
75  PIMPL(Dragable)
76 
77  QDrag* createDrag() const;
78  void startDrag(const QPoint& p);
79  QDrag* moveDrag(const QPoint& p);
80  void releaseDrag();
81 
82  protected:
83  virtual QMimeData* dragableMimedata() const=0;
84  virtual bool isValidDragPosition(const QPoint& p) const;
85  virtual bool hasDragLabel() const;
86  virtual QString dragLabel() const;
87  };
88 }
89 
90 #endif // DRAGGABLE_H
Gui::Dragable
The Dragable class.
Definition: Dragable.h:61
Gui::DragableConnector
Definition: Dragable.h:39